@sanity/client 6.22.4 → 6.22.5-beta.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -349,7 +349,7 @@
349
349
  });
350
350
  }
351
351
 
352
- function noop() { }
352
+ function noop$1() { }
353
353
 
354
354
  function errorContext(cb) {
355
355
  {
@@ -512,9 +512,9 @@
512
512
  }
513
513
  var EMPTY_OBSERVER = {
514
514
  closed: true,
515
- next: noop,
515
+ next: noop$1,
516
516
  error: defaultErrorHandler,
517
- complete: noop,
517
+ complete: noop$1,
518
518
  };
519
519
 
520
520
  var observable = (function () { return (typeof Symbol === 'function' && Symbol.observable) || '@@observable'; })();
@@ -1044,8 +1044,7 @@
1044
1044
  let e = JSON.stringify(t);
1045
1045
  return `${u}${Array.from(e).map((r) => {
1046
1046
  let n = r.charCodeAt(0);
1047
- if (n > 255)
1048
- throw new Error(`Only ASCII edit info can be encoded. Error attempting to encode ${e} on character ${r} (${n})`);
1047
+ if (n > 255) throw new Error(`Only ASCII edit info can be encoded. Error attempting to encode ${e} on character ${r} (${n})`);
1049
1048
  return Array.from(n.toString(4).padStart(4, "0")).map((o) => String.fromCodePoint(c[o])).join("");
1050
1049
  }).join("")}`;
1051
1050
  }
@@ -1173,8 +1172,7 @@
1173
1172
  ]);
1174
1173
  }
1175
1174
  function shouldRetry(err, attempt, options) {
1176
- if (options.maxRetries === 0)
1177
- return !1;
1175
+ if (options.maxRetries === 0) return !1;
1178
1176
  const isSafe = options.method === "GET" || options.method === "HEAD", isQuery = (options.uri || options.url).startsWith("/data/query"), isRetriableResponse = err.response && (err.response.statusCode === 429 || err.response.statusCode === 502 || err.response.statusCode === 503);
1179
1177
  return (isSafe || isQuery) && isRetriableResponse ? !0 : _$1.shouldRetry(err, attempt, options);
1180
1178
  }
@@ -1679,7 +1677,7 @@ ${selectionOpts}`);
1679
1677
  autoGenerateArrayKeys: options.autoGenerateArrayKeys,
1680
1678
  skipCrossDatasetReferenceValidation: options.skipCrossDatasetReferenceValidation
1681
1679
  }), isResponse = (event) => event.type === "response", getBody = (event) => event.body, indexBy = (docs, attr) => docs.reduce((indexed, doc) => (indexed[attr(doc)] = doc, indexed), /* @__PURE__ */ Object.create(null)), getQuerySizeLimit = 11264;
1682
- function _fetch(client, httpRequest, _stega, query, _params = {}, options = {}) {
1680
+ function _fetch$1(client, httpRequest, _stega, query, _params = {}, options = {}) {
1683
1681
  const stega = "stega" in options ? {
1684
1682
  ..._stega || {},
1685
1683
  ...typeof options.stega == "boolean" ? { enabled: options.stega } : options.stega || {}
@@ -1967,7 +1965,7 @@ ${selectionOpts}`);
1967
1965
  shouldEmitReconnect && observer.next({ type: "reconnect" });
1968
1966
  }
1969
1967
  async function getEventSource() {
1970
- const { default: EventSource2 } = await Promise.resolve().then(function () { return browser$1; });
1968
+ const { EventSource: EventSource2 } = await Promise.resolve().then(function () { return index; });
1971
1969
  if (unsubscribed)
1972
1970
  return;
1973
1971
  const evs = new EventSource2(uri, esOptions);
@@ -2065,7 +2063,7 @@ ${selectionOpts}`);
2065
2063
  }
2066
2064
  }
2067
2065
  async function getEventSource() {
2068
- const EventSourceImplementation = typeof EventSource > "u" || esOptions.headers || esOptions.withCredentials ? (await Promise.resolve().then(function () { return browser$1; })).default : EventSource;
2066
+ const EventSourceImplementation = typeof EventSource > "u" || esOptions.headers || esOptions.withCredentials ? (await Promise.resolve().then(function () { return index; })).EventSource : EventSource;
2069
2067
  if (unsubscribed)
2070
2068
  return;
2071
2069
  try {
@@ -2330,7 +2328,7 @@ ${selectionOpts}`);
2330
2328
  });
2331
2329
  }
2332
2330
  fetch(query, params, options) {
2333
- return _fetch(
2331
+ return _fetch$1(
2334
2332
  this,
2335
2333
  this.#httpRequest,
2336
2334
  this.#clientConfig.stega,
@@ -2484,7 +2482,7 @@ ${selectionOpts}`);
2484
2482
  }
2485
2483
  fetch(query, params, options) {
2486
2484
  return lastValueFrom(
2487
- _fetch(
2485
+ _fetch$1(
2488
2486
  this,
2489
2487
  this.#httpRequest,
2490
2488
  this.#clientConfig.stega,
@@ -2908,8 +2906,7 @@ ${selectionOpts}`);
2908
2906
  const { baseUrl, workspace, tool } = resolveStudioBaseRoute(
2909
2907
  typeof config.studioUrl == "function" ? config.studioUrl(sourceDocument) : config.studioUrl
2910
2908
  );
2911
- if (!baseUrl)
2912
- return value;
2909
+ if (!baseUrl) return value;
2913
2910
  const { _id: id, _type: type, _projectId: projectId, _dataset: dataset } = sourceDocument;
2914
2911
  return C(
2915
2912
  value,
@@ -2959,1080 +2956,315 @@ ${selectionOpts}`);
2959
2956
  stegaEncodeSourceMap$1: stegaEncodeSourceMap$1
2960
2957
  });
2961
2958
 
2962
- function getDefaultExportFromCjs (x) {
2963
- return x && x.__esModule && Object.prototype.hasOwnProperty.call(x, 'default') ? x['default'] : x;
2964
- }
2965
-
2966
- var eventsource$1 = {exports: {}};
2967
-
2968
- /** @license
2969
- * eventsource.js
2970
- * Available under MIT License (MIT)
2971
- * https://github.com/Yaffle/EventSource/
2972
- */
2973
- var eventsource = eventsource$1.exports;
2974
-
2975
- var hasRequiredEventsource;
2976
-
2977
- function requireEventsource () {
2978
- if (hasRequiredEventsource) return eventsource$1.exports;
2979
- hasRequiredEventsource = 1;
2980
- (function (module, exports) {
2981
- /*jslint indent: 2, vars: true, plusplus: true */
2982
- /*global setTimeout, clearTimeout */
2983
-
2984
- (function (global) {
2985
-
2986
- var setTimeout = global.setTimeout;
2987
- var clearTimeout = global.clearTimeout;
2988
- var XMLHttpRequest = global.XMLHttpRequest;
2989
- var XDomainRequest = global.XDomainRequest;
2990
- var ActiveXObject = global.ActiveXObject;
2991
- var NativeEventSource = global.EventSource;
2992
-
2993
- var document = global.document;
2994
- var Promise = global.Promise;
2995
- var fetch = global.fetch;
2996
- var Response = global.Response;
2997
- var TextDecoder = global.TextDecoder;
2998
- var TextEncoder = global.TextEncoder;
2999
- var AbortController = global.AbortController;
3000
-
3001
- if (typeof window !== "undefined" && typeof document !== "undefined" && !("readyState" in document) && document.body == null) { // Firefox 2
3002
- document.readyState = "loading";
3003
- window.addEventListener("load", function (event) {
3004
- document.readyState = "complete";
3005
- }, false);
3006
- }
3007
-
3008
- if (XMLHttpRequest == null && ActiveXObject != null) { // https://developer.mozilla.org/en-US/docs/Web/API/XMLHttpRequest/Using_XMLHttpRequest_in_IE6
3009
- XMLHttpRequest = function () {
3010
- return new ActiveXObject("Microsoft.XMLHTTP");
3011
- };
3012
- }
3013
-
3014
- if (Object.create == undefined) {
3015
- Object.create = function (C) {
3016
- function F(){}
3017
- F.prototype = C;
3018
- return new F();
3019
- };
3020
- }
3021
-
3022
- if (!Date.now) {
3023
- Date.now = function now() {
3024
- return new Date().getTime();
3025
- };
3026
- }
3027
-
3028
- // see #118 (Promise#finally with polyfilled Promise)
3029
- // see #123 (data URLs crash Edge)
3030
- // see #125 (CSP violations)
3031
- // see pull/#138
3032
- // => No way to polyfill Promise#finally
3033
-
3034
- if (AbortController == undefined) {
3035
- var originalFetch2 = fetch;
3036
- fetch = function (url, options) {
3037
- var signal = options.signal;
3038
- return originalFetch2(url, {headers: options.headers, credentials: options.credentials, cache: options.cache}).then(function (response) {
3039
- var reader = response.body.getReader();
3040
- signal._reader = reader;
3041
- if (signal._aborted) {
3042
- signal._reader.cancel();
3043
- }
3044
- return {
3045
- status: response.status,
3046
- statusText: response.statusText,
3047
- headers: response.headers,
3048
- body: {
3049
- getReader: function () {
3050
- return reader;
3051
- }
3052
- }
3053
- };
3054
- });
3055
- };
3056
- AbortController = function () {
3057
- this.signal = {
3058
- _reader: null,
3059
- _aborted: false
3060
- };
3061
- this.abort = function () {
3062
- if (this.signal._reader != null) {
3063
- this.signal._reader.cancel();
3064
- }
3065
- this.signal._aborted = true;
3066
- };
3067
- };
3068
- }
3069
-
3070
- function TextDecoderPolyfill() {
3071
- this.bitsNeeded = 0;
3072
- this.codePoint = 0;
3073
- }
3074
-
3075
- TextDecoderPolyfill.prototype.decode = function (octets) {
3076
- function valid(codePoint, shift, octetsCount) {
3077
- if (octetsCount === 1) {
3078
- return codePoint >= 0x0080 >> shift && codePoint << shift <= 0x07FF;
3079
- }
3080
- if (octetsCount === 2) {
3081
- return codePoint >= 0x0800 >> shift && codePoint << shift <= 0xD7FF || codePoint >= 0xE000 >> shift && codePoint << shift <= 0xFFFF;
3082
- }
3083
- if (octetsCount === 3) {
3084
- return codePoint >= 0x010000 >> shift && codePoint << shift <= 0x10FFFF;
3085
- }
3086
- throw new Error();
3087
- }
3088
- function octetsCount(bitsNeeded, codePoint) {
3089
- if (bitsNeeded === 6 * 1) {
3090
- return codePoint >> 6 > 15 ? 3 : codePoint > 31 ? 2 : 1;
3091
- }
3092
- if (bitsNeeded === 6 * 2) {
3093
- return codePoint > 15 ? 3 : 2;
3094
- }
3095
- if (bitsNeeded === 6 * 3) {
3096
- return 3;
3097
- }
3098
- throw new Error();
3099
- }
3100
- var REPLACER = 0xFFFD;
3101
- var string = "";
3102
- var bitsNeeded = this.bitsNeeded;
3103
- var codePoint = this.codePoint;
3104
- for (var i = 0; i < octets.length; i += 1) {
3105
- var octet = octets[i];
3106
- if (bitsNeeded !== 0) {
3107
- if (octet < 128 || octet > 191 || !valid(codePoint << 6 | octet & 63, bitsNeeded - 6, octetsCount(bitsNeeded, codePoint))) {
3108
- bitsNeeded = 0;
3109
- codePoint = REPLACER;
3110
- string += String.fromCharCode(codePoint);
3111
- }
3112
- }
3113
- if (bitsNeeded === 0) {
3114
- if (octet >= 0 && octet <= 127) {
3115
- bitsNeeded = 0;
3116
- codePoint = octet;
3117
- } else if (octet >= 192 && octet <= 223) {
3118
- bitsNeeded = 6 * 1;
3119
- codePoint = octet & 31;
3120
- } else if (octet >= 224 && octet <= 239) {
3121
- bitsNeeded = 6 * 2;
3122
- codePoint = octet & 15;
3123
- } else if (octet >= 240 && octet <= 247) {
3124
- bitsNeeded = 6 * 3;
3125
- codePoint = octet & 7;
3126
- } else {
3127
- bitsNeeded = 0;
3128
- codePoint = REPLACER;
3129
- }
3130
- if (bitsNeeded !== 0 && !valid(codePoint, bitsNeeded, octetsCount(bitsNeeded, codePoint))) {
3131
- bitsNeeded = 0;
3132
- codePoint = REPLACER;
3133
- }
3134
- } else {
3135
- bitsNeeded -= 6;
3136
- codePoint = codePoint << 6 | octet & 63;
3137
- }
3138
- if (bitsNeeded === 0) {
3139
- if (codePoint <= 0xFFFF) {
3140
- string += String.fromCharCode(codePoint);
3141
- } else {
3142
- string += String.fromCharCode(0xD800 + (codePoint - 0xFFFF - 1 >> 10));
3143
- string += String.fromCharCode(0xDC00 + (codePoint - 0xFFFF - 1 & 0x3FF));
3144
- }
3145
- }
3146
- }
3147
- this.bitsNeeded = bitsNeeded;
3148
- this.codePoint = codePoint;
3149
- return string;
3150
- };
3151
-
3152
- // Firefox < 38 throws an error with stream option
3153
- var supportsStreamOption = function () {
3154
- try {
3155
- return new TextDecoder().decode(new TextEncoder().encode("test"), {stream: true}) === "test";
3156
- } catch (error) {
3157
- console.debug("TextDecoder does not support streaming option. Using polyfill instead: " + error);
3158
- }
3159
- return false;
3160
- };
3161
-
3162
- // IE, Edge
3163
- if (TextDecoder == undefined || TextEncoder == undefined || !supportsStreamOption()) {
3164
- TextDecoder = TextDecoderPolyfill;
3165
- }
3166
-
3167
- var k = function () {
3168
- };
3169
-
3170
- function XHRWrapper(xhr) {
3171
- this.withCredentials = false;
3172
- this.readyState = 0;
3173
- this.status = 0;
3174
- this.statusText = "";
3175
- this.responseText = "";
3176
- this.onprogress = k;
3177
- this.onload = k;
3178
- this.onerror = k;
3179
- this.onreadystatechange = k;
3180
- this._contentType = "";
3181
- this._xhr = xhr;
3182
- this._sendTimeout = 0;
3183
- this._abort = k;
3184
- }
3185
-
3186
- XHRWrapper.prototype.open = function (method, url) {
3187
- this._abort(true);
3188
-
3189
- var that = this;
3190
- var xhr = this._xhr;
3191
- var state = 1;
3192
- var timeout = 0;
3193
-
3194
- this._abort = function (silent) {
3195
- if (that._sendTimeout !== 0) {
3196
- clearTimeout(that._sendTimeout);
3197
- that._sendTimeout = 0;
3198
- }
3199
- if (state === 1 || state === 2 || state === 3) {
3200
- state = 4;
3201
- xhr.onload = k;
3202
- xhr.onerror = k;
3203
- xhr.onabort = k;
3204
- xhr.onprogress = k;
3205
- xhr.onreadystatechange = k;
3206
- // IE 8 - 9: XDomainRequest#abort() does not fire any event
3207
- // Opera < 10: XMLHttpRequest#abort() does not fire any event
3208
- xhr.abort();
3209
- if (timeout !== 0) {
3210
- clearTimeout(timeout);
3211
- timeout = 0;
3212
- }
3213
- if (!silent) {
3214
- that.readyState = 4;
3215
- that.onabort(null);
3216
- that.onreadystatechange();
3217
- }
3218
- }
3219
- state = 0;
3220
- };
3221
-
3222
- var onStart = function () {
3223
- if (state === 1) {
3224
- //state = 2;
3225
- var status = 0;
3226
- var statusText = "";
3227
- var contentType = undefined;
3228
- if (!("contentType" in xhr)) {
3229
- try {
3230
- status = xhr.status;
3231
- statusText = xhr.statusText;
3232
- contentType = xhr.getResponseHeader("Content-Type");
3233
- } catch (error) {
3234
- // IE < 10 throws exception for `xhr.status` when xhr.readyState === 2 || xhr.readyState === 3
3235
- // Opera < 11 throws exception for `xhr.status` when xhr.readyState === 2
3236
- // https://bugs.webkit.org/show_bug.cgi?id=29121
3237
- status = 0;
3238
- statusText = "";
3239
- contentType = undefined;
3240
- // Firefox < 14, Chrome ?, Safari ?
3241
- // https://bugs.webkit.org/show_bug.cgi?id=29658
3242
- // https://bugs.webkit.org/show_bug.cgi?id=77854
3243
- }
3244
- } else {
3245
- status = 200;
3246
- statusText = "OK";
3247
- contentType = xhr.contentType;
3248
- }
3249
- if (status !== 0) {
3250
- state = 2;
3251
- that.readyState = 2;
3252
- that.status = status;
3253
- that.statusText = statusText;
3254
- that._contentType = contentType;
3255
- that.onreadystatechange();
3256
- }
3257
- }
3258
- };
3259
- var onProgress = function () {
3260
- onStart();
3261
- if (state === 2 || state === 3) {
3262
- state = 3;
3263
- var responseText = "";
3264
- try {
3265
- responseText = xhr.responseText;
3266
- } catch (error) {
3267
- // IE 8 - 9 with XMLHttpRequest
3268
- }
3269
- that.readyState = 3;
3270
- that.responseText = responseText;
3271
- that.onprogress();
3272
- }
3273
- };
3274
- var onFinish = function (type, event) {
3275
- if (event == null || event.preventDefault == null) {
3276
- event = {
3277
- preventDefault: k
3278
- };
3279
- }
3280
- // Firefox 52 fires "readystatechange" (xhr.readyState === 4) without final "readystatechange" (xhr.readyState === 3)
3281
- // IE 8 fires "onload" without "onprogress"
3282
- onProgress();
3283
- if (state === 1 || state === 2 || state === 3) {
3284
- state = 4;
3285
- if (timeout !== 0) {
3286
- clearTimeout(timeout);
3287
- timeout = 0;
3288
- }
3289
- that.readyState = 4;
3290
- if (type === "load") {
3291
- that.onload(event);
3292
- } else if (type === "error") {
3293
- that.onerror(event);
3294
- } else if (type === "abort") {
3295
- that.onabort(event);
3296
- } else {
3297
- throw new TypeError();
3298
- }
3299
- that.onreadystatechange();
3300
- }
3301
- };
3302
- var onReadyStateChange = function (event) {
3303
- if (xhr != undefined) { // Opera 12
3304
- if (xhr.readyState === 4) {
3305
- if (!("onload" in xhr) || !("onerror" in xhr) || !("onabort" in xhr)) {
3306
- onFinish(xhr.responseText === "" ? "error" : "load", event);
3307
- }
3308
- } else if (xhr.readyState === 3) {
3309
- if (!("onprogress" in xhr)) { // testing XMLHttpRequest#responseText too many times is too slow in IE 11
3310
- // and in Firefox 3.6
3311
- onProgress();
3312
- }
3313
- } else if (xhr.readyState === 2) {
3314
- onStart();
3315
- }
3316
- }
3317
- };
3318
- var onTimeout = function () {
3319
- timeout = setTimeout(function () {
3320
- onTimeout();
3321
- }, 500);
3322
- if (xhr.readyState === 3) {
3323
- onProgress();
3324
- }
3325
- };
3326
-
3327
- // XDomainRequest#abort removes onprogress, onerror, onload
3328
- if ("onload" in xhr) {
3329
- xhr.onload = function (event) {
3330
- onFinish("load", event);
3331
- };
3332
- }
3333
- if ("onerror" in xhr) {
3334
- xhr.onerror = function (event) {
3335
- onFinish("error", event);
3336
- };
3337
- }
3338
- // improper fix to match Firefox behaviour, but it is better than just ignore abort
3339
- // see https://bugzilla.mozilla.org/show_bug.cgi?id=768596
3340
- // https://bugzilla.mozilla.org/show_bug.cgi?id=880200
3341
- // https://code.google.com/p/chromium/issues/detail?id=153570
3342
- // IE 8 fires "onload" without "onprogress
3343
- if ("onabort" in xhr) {
3344
- xhr.onabort = function (event) {
3345
- onFinish("abort", event);
3346
- };
3347
- }
3348
-
3349
- if ("onprogress" in xhr) {
3350
- xhr.onprogress = onProgress;
3351
- }
3352
-
3353
- // IE 8 - 9 (XMLHTTPRequest)
3354
- // Opera < 12
3355
- // Firefox < 3.5
3356
- // Firefox 3.5 - 3.6 - ? < 9.0
3357
- // onprogress is not fired sometimes or delayed
3358
- // see also #64 (significant lag in IE 11)
3359
- if ("onreadystatechange" in xhr) {
3360
- xhr.onreadystatechange = function (event) {
3361
- onReadyStateChange(event);
3362
- };
3363
- }
3364
-
3365
- if ("contentType" in xhr || !("ontimeout" in XMLHttpRequest.prototype)) {
3366
- url += (url.indexOf("?") === -1 ? "?" : "&") + "padding=true";
3367
- }
3368
- xhr.open(method, url, true);
3369
-
3370
- if ("readyState" in xhr) {
3371
- // workaround for Opera 12 issue with "progress" events
3372
- // #91 (XMLHttpRequest onprogress not fired for streaming response in Edge 14-15-?)
3373
- timeout = setTimeout(function () {
3374
- onTimeout();
3375
- }, 0);
3376
- }
3377
- };
3378
- XHRWrapper.prototype.abort = function () {
3379
- this._abort(false);
3380
- };
3381
- XHRWrapper.prototype.getResponseHeader = function (name) {
3382
- return this._contentType;
3383
- };
3384
- XHRWrapper.prototype.setRequestHeader = function (name, value) {
3385
- var xhr = this._xhr;
3386
- if ("setRequestHeader" in xhr) {
3387
- xhr.setRequestHeader(name, value);
3388
- }
3389
- };
3390
- XHRWrapper.prototype.getAllResponseHeaders = function () {
3391
- // XMLHttpRequest#getAllResponseHeaders returns null for CORS requests in Firefox 3.6.28
3392
- return this._xhr.getAllResponseHeaders != undefined ? this._xhr.getAllResponseHeaders() || "" : "";
3393
- };
3394
- XHRWrapper.prototype.send = function () {
3395
- // loading indicator in Safari < ? (6), Chrome < 14, Firefox
3396
- // https://bugzilla.mozilla.org/show_bug.cgi?id=736723
3397
- if ((!("ontimeout" in XMLHttpRequest.prototype) || (!("sendAsBinary" in XMLHttpRequest.prototype) && !("mozAnon" in XMLHttpRequest.prototype))) &&
3398
- document != undefined &&
3399
- document.readyState != undefined &&
3400
- document.readyState !== "complete") {
3401
- var that = this;
3402
- that._sendTimeout = setTimeout(function () {
3403
- that._sendTimeout = 0;
3404
- that.send();
3405
- }, 4);
3406
- return;
3407
- }
3408
-
3409
- var xhr = this._xhr;
3410
- // withCredentials should be set after "open" for Safari and Chrome (< 19 ?)
3411
- if ("withCredentials" in xhr) {
3412
- xhr.withCredentials = this.withCredentials;
3413
- }
3414
- try {
3415
- // xhr.send(); throws "Not enough arguments" in Firefox 3.0
3416
- xhr.send(undefined);
3417
- } catch (error1) {
3418
- // Safari 5.1.7, Opera 12
3419
- throw error1;
3420
- }
3421
- };
3422
-
3423
- function toLowerCase(name) {
3424
- return name.replace(/[A-Z]/g, function (c) {
3425
- return String.fromCharCode(c.charCodeAt(0) + 0x20);
3426
- });
3427
- }
3428
-
3429
- function HeadersPolyfill(all) {
3430
- // Get headers: implemented according to mozilla's example code: https://developer.mozilla.org/en-US/docs/Web/API/XMLHttpRequest/getAllResponseHeaders#Example
3431
- var map = Object.create(null);
3432
- var array = all.split("\r\n");
3433
- for (var i = 0; i < array.length; i += 1) {
3434
- var line = array[i];
3435
- var parts = line.split(": ");
3436
- var name = parts.shift();
3437
- var value = parts.join(": ");
3438
- map[toLowerCase(name)] = value;
3439
- }
3440
- this._map = map;
3441
- }
3442
- HeadersPolyfill.prototype.get = function (name) {
3443
- return this._map[toLowerCase(name)];
3444
- };
3445
-
3446
- if (XMLHttpRequest != null && XMLHttpRequest.HEADERS_RECEIVED == null) { // IE < 9, Firefox 3.6
3447
- XMLHttpRequest.HEADERS_RECEIVED = 2;
3448
- }
3449
-
3450
- function XHRTransport() {
3451
- }
3452
-
3453
- XHRTransport.prototype.open = function (xhr, onStartCallback, onProgressCallback, onFinishCallback, url, withCredentials, headers) {
3454
- xhr.open("GET", url);
3455
- var offset = 0;
3456
- xhr.onprogress = function () {
3457
- var responseText = xhr.responseText;
3458
- var chunk = responseText.slice(offset);
3459
- offset += chunk.length;
3460
- onProgressCallback(chunk);
3461
- };
3462
- xhr.onerror = function (event) {
3463
- event.preventDefault();
3464
- onFinishCallback(new Error("NetworkError"));
3465
- };
3466
- xhr.onload = function () {
3467
- onFinishCallback(null);
3468
- };
3469
- xhr.onabort = function () {
3470
- onFinishCallback(null);
3471
- };
3472
- xhr.onreadystatechange = function () {
3473
- if (xhr.readyState === XMLHttpRequest.HEADERS_RECEIVED) {
3474
- var status = xhr.status;
3475
- var statusText = xhr.statusText;
3476
- var contentType = xhr.getResponseHeader("Content-Type");
3477
- var headers = xhr.getAllResponseHeaders();
3478
- onStartCallback(status, statusText, contentType, new HeadersPolyfill(headers));
3479
- }
3480
- };
3481
- xhr.withCredentials = withCredentials;
3482
- for (var name in headers) {
3483
- if (Object.prototype.hasOwnProperty.call(headers, name)) {
3484
- xhr.setRequestHeader(name, headers[name]);
3485
- }
3486
- }
3487
- xhr.send();
3488
- return xhr;
3489
- };
3490
-
3491
- function HeadersWrapper(headers) {
3492
- this._headers = headers;
3493
- }
3494
- HeadersWrapper.prototype.get = function (name) {
3495
- return this._headers.get(name);
3496
- };
3497
-
3498
- function FetchTransport() {
3499
- }
3500
-
3501
- FetchTransport.prototype.open = function (xhr, onStartCallback, onProgressCallback, onFinishCallback, url, withCredentials, headers) {
3502
- var reader = null;
3503
- var controller = new AbortController();
3504
- var signal = controller.signal;
3505
- var textDecoder = new TextDecoder();
3506
- fetch(url, {
3507
- headers: headers,
3508
- credentials: withCredentials ? "include" : "same-origin",
3509
- signal: signal,
3510
- cache: "no-store"
3511
- }).then(function (response) {
3512
- reader = response.body.getReader();
3513
- onStartCallback(response.status, response.statusText, response.headers.get("Content-Type"), new HeadersWrapper(response.headers));
3514
- // see https://github.com/promises-aplus/promises-spec/issues/179
3515
- return new Promise(function (resolve, reject) {
3516
- var readNextChunk = function () {
3517
- reader.read().then(function (result) {
3518
- if (result.done) {
3519
- //Note: bytes in textDecoder are ignored
3520
- resolve(undefined);
3521
- } else {
3522
- var chunk = textDecoder.decode(result.value, {stream: true});
3523
- onProgressCallback(chunk);
3524
- readNextChunk();
3525
- }
3526
- })["catch"](function (error) {
3527
- reject(error);
3528
- });
3529
- };
3530
- readNextChunk();
3531
- });
3532
- })["catch"](function (error) {
3533
- if (error.name === "AbortError") {
3534
- return undefined;
3535
- } else {
3536
- return error;
3537
- }
3538
- }).then(function (error) {
3539
- onFinishCallback(error);
3540
- });
3541
- return {
3542
- abort: function () {
3543
- if (reader != null) {
3544
- reader.cancel(); // https://bugzilla.mozilla.org/show_bug.cgi?id=1583815
3545
- }
3546
- controller.abort();
3547
- }
3548
- };
3549
- };
3550
-
3551
- function EventTarget() {
3552
- this._listeners = Object.create(null);
3553
- }
3554
-
3555
- function throwError(e) {
3556
- setTimeout(function () {
3557
- throw e;
3558
- }, 0);
3559
- }
3560
-
3561
- EventTarget.prototype.dispatchEvent = function (event) {
3562
- event.target = this;
3563
- var typeListeners = this._listeners[event.type];
3564
- if (typeListeners != undefined) {
3565
- var length = typeListeners.length;
3566
- for (var i = 0; i < length; i += 1) {
3567
- var listener = typeListeners[i];
3568
- try {
3569
- if (typeof listener.handleEvent === "function") {
3570
- listener.handleEvent(event);
3571
- } else {
3572
- listener.call(this, event);
3573
- }
3574
- } catch (e) {
3575
- throwError(e);
3576
- }
3577
- }
3578
- }
3579
- };
3580
- EventTarget.prototype.addEventListener = function (type, listener) {
3581
- type = String(type);
3582
- var listeners = this._listeners;
3583
- var typeListeners = listeners[type];
3584
- if (typeListeners == undefined) {
3585
- typeListeners = [];
3586
- listeners[type] = typeListeners;
3587
- }
3588
- var found = false;
3589
- for (var i = 0; i < typeListeners.length; i += 1) {
3590
- if (typeListeners[i] === listener) {
3591
- found = true;
3592
- }
3593
- }
3594
- if (!found) {
3595
- typeListeners.push(listener);
3596
- }
3597
- };
3598
- EventTarget.prototype.removeEventListener = function (type, listener) {
3599
- type = String(type);
3600
- var listeners = this._listeners;
3601
- var typeListeners = listeners[type];
3602
- if (typeListeners != undefined) {
3603
- var filtered = [];
3604
- for (var i = 0; i < typeListeners.length; i += 1) {
3605
- if (typeListeners[i] !== listener) {
3606
- filtered.push(typeListeners[i]);
3607
- }
3608
- }
3609
- if (filtered.length === 0) {
3610
- delete listeners[type];
3611
- } else {
3612
- listeners[type] = filtered;
3613
- }
3614
- }
3615
- };
3616
-
3617
- function Event(type) {
3618
- this.type = type;
3619
- this.target = undefined;
3620
- }
3621
-
3622
- function MessageEvent(type, options) {
3623
- Event.call(this, type);
3624
- this.data = options.data;
3625
- this.lastEventId = options.lastEventId;
3626
- }
3627
-
3628
- MessageEvent.prototype = Object.create(Event.prototype);
3629
-
3630
- function ConnectionEvent(type, options) {
3631
- Event.call(this, type);
3632
- this.status = options.status;
3633
- this.statusText = options.statusText;
3634
- this.headers = options.headers;
3635
- }
3636
-
3637
- ConnectionEvent.prototype = Object.create(Event.prototype);
3638
-
3639
- function ErrorEvent(type, options) {
3640
- Event.call(this, type);
3641
- this.error = options.error;
3642
- }
3643
-
3644
- ErrorEvent.prototype = Object.create(Event.prototype);
3645
-
3646
- var WAITING = -1;
3647
- var CONNECTING = 0;
3648
- var OPEN = 1;
3649
- var CLOSED = 2;
3650
-
3651
- var AFTER_CR = -1;
3652
- var FIELD_START = 0;
3653
- var FIELD = 1;
3654
- var VALUE_START = 2;
3655
- var VALUE = 3;
3656
-
3657
- var contentTypeRegExp = /^text\/event\-stream(;.*)?$/i;
3658
-
3659
- var MINIMUM_DURATION = 1000;
3660
- var MAXIMUM_DURATION = 18000000;
3661
-
3662
- var parseDuration = function (value, def) {
3663
- var n = value == null ? def : parseInt(value, 10);
3664
- if (n !== n) {
3665
- n = def;
3666
- }
3667
- return clampDuration(n);
3668
- };
3669
- var clampDuration = function (n) {
3670
- return Math.min(Math.max(n, MINIMUM_DURATION), MAXIMUM_DURATION);
3671
- };
3672
-
3673
- var fire = function (that, f, event) {
3674
- try {
3675
- if (typeof f === "function") {
3676
- f.call(that, event);
3677
- }
3678
- } catch (e) {
3679
- throwError(e);
3680
- }
3681
- };
3682
-
3683
- function EventSourcePolyfill(url, options) {
3684
- EventTarget.call(this);
3685
- options = options || {};
3686
-
3687
- this.onopen = undefined;
3688
- this.onmessage = undefined;
3689
- this.onerror = undefined;
3690
-
3691
- this.url = undefined;
3692
- this.readyState = undefined;
3693
- this.withCredentials = undefined;
3694
- this.headers = undefined;
3695
-
3696
- this._close = undefined;
3697
-
3698
- start(this, url, options);
3699
- }
3700
-
3701
- function getBestXHRTransport() {
3702
- return (XMLHttpRequest != undefined && ("withCredentials" in XMLHttpRequest.prototype)) || XDomainRequest == undefined
3703
- ? new XMLHttpRequest()
3704
- : new XDomainRequest();
3705
- }
3706
-
3707
- var isFetchSupported = fetch != undefined && Response != undefined && "body" in Response.prototype;
3708
-
3709
- function start(es, url, options) {
3710
- url = String(url);
3711
- var withCredentials = Boolean(options.withCredentials);
3712
- var lastEventIdQueryParameterName = options.lastEventIdQueryParameterName || "lastEventId";
3713
-
3714
- var initialRetry = clampDuration(1000);
3715
- var heartbeatTimeout = parseDuration(options.heartbeatTimeout, 45000);
3716
-
3717
- var lastEventId = "";
3718
- var retry = initialRetry;
3719
- var wasActivity = false;
3720
- var textLength = 0;
3721
- var headers = options.headers || {};
3722
- var TransportOption = options.Transport;
3723
- var xhr = isFetchSupported && TransportOption == undefined ? undefined : new XHRWrapper(TransportOption != undefined ? new TransportOption() : getBestXHRTransport());
3724
- var transport = TransportOption != null && typeof TransportOption !== "string" ? new TransportOption() : (xhr == undefined ? new FetchTransport() : new XHRTransport());
3725
- var abortController = undefined;
3726
- var timeout = 0;
3727
- var currentState = WAITING;
3728
- var dataBuffer = "";
3729
- var lastEventIdBuffer = "";
3730
- var eventTypeBuffer = "";
3731
-
3732
- var textBuffer = "";
3733
- var state = FIELD_START;
3734
- var fieldStart = 0;
3735
- var valueStart = 0;
3736
-
3737
- var onStart = function (status, statusText, contentType, headers) {
3738
- if (currentState === CONNECTING) {
3739
- if (status === 200 && contentType != undefined && contentTypeRegExp.test(contentType)) {
3740
- currentState = OPEN;
3741
- wasActivity = Date.now();
3742
- retry = initialRetry;
3743
- es.readyState = OPEN;
3744
- var event = new ConnectionEvent("open", {
3745
- status: status,
3746
- statusText: statusText,
3747
- headers: headers
3748
- });
3749
- es.dispatchEvent(event);
3750
- fire(es, es.onopen, event);
3751
- } else {
3752
- var message = "";
3753
- if (status !== 200) {
3754
- if (statusText) {
3755
- statusText = statusText.replace(/\s+/g, " ");
3756
- }
3757
- message = "EventSource's response has a status " + status + " " + statusText + " that is not 200. Aborting the connection.";
3758
- } else {
3759
- message = "EventSource's response has a Content-Type specifying an unsupported type: " + (contentType == undefined ? "-" : contentType.replace(/\s+/g, " ")) + ". Aborting the connection.";
3760
- }
3761
- close();
3762
- var event = new ConnectionEvent("error", {
3763
- status: status,
3764
- statusText: statusText,
3765
- headers: headers
3766
- });
3767
- es.dispatchEvent(event);
3768
- fire(es, es.onerror, event);
3769
- console.error(message);
3770
- }
3771
- }
3772
- };
3773
-
3774
- var onProgress = function (textChunk) {
3775
- if (currentState === OPEN) {
3776
- var n = -1;
3777
- for (var i = 0; i < textChunk.length; i += 1) {
3778
- var c = textChunk.charCodeAt(i);
3779
- if (c === "\n".charCodeAt(0) || c === "\r".charCodeAt(0)) {
3780
- n = i;
3781
- }
3782
- }
3783
- var chunk = (n !== -1 ? textBuffer : "") + textChunk.slice(0, n + 1);
3784
- textBuffer = (n === -1 ? textBuffer : "") + textChunk.slice(n + 1);
3785
- if (textChunk !== "") {
3786
- wasActivity = Date.now();
3787
- textLength += textChunk.length;
3788
- }
3789
- for (var position = 0; position < chunk.length; position += 1) {
3790
- var c = chunk.charCodeAt(position);
3791
- if (state === AFTER_CR && c === "\n".charCodeAt(0)) {
3792
- state = FIELD_START;
3793
- } else {
3794
- if (state === AFTER_CR) {
3795
- state = FIELD_START;
3796
- }
3797
- if (c === "\r".charCodeAt(0) || c === "\n".charCodeAt(0)) {
3798
- if (state !== FIELD_START) {
3799
- if (state === FIELD) {
3800
- valueStart = position + 1;
3801
- }
3802
- var field = chunk.slice(fieldStart, valueStart - 1);
3803
- var value = chunk.slice(valueStart + (valueStart < position && chunk.charCodeAt(valueStart) === " ".charCodeAt(0) ? 1 : 0), position);
3804
- if (field === "data") {
3805
- dataBuffer += "\n";
3806
- dataBuffer += value;
3807
- } else if (field === "id") {
3808
- lastEventIdBuffer = value;
3809
- } else if (field === "event") {
3810
- eventTypeBuffer = value;
3811
- } else if (field === "retry") {
3812
- initialRetry = parseDuration(value, initialRetry);
3813
- retry = initialRetry;
3814
- } else if (field === "heartbeatTimeout") {
3815
- heartbeatTimeout = parseDuration(value, heartbeatTimeout);
3816
- if (timeout !== 0) {
3817
- clearTimeout(timeout);
3818
- timeout = setTimeout(function () {
3819
- onTimeout();
3820
- }, heartbeatTimeout);
3821
- }
3822
- }
3823
- }
3824
- if (state === FIELD_START) {
3825
- if (dataBuffer !== "") {
3826
- lastEventId = lastEventIdBuffer;
3827
- if (eventTypeBuffer === "") {
3828
- eventTypeBuffer = "message";
3829
- }
3830
- var event = new MessageEvent(eventTypeBuffer, {
3831
- data: dataBuffer.slice(1),
3832
- lastEventId: lastEventIdBuffer
3833
- });
3834
- es.dispatchEvent(event);
3835
- if (eventTypeBuffer === "open") {
3836
- fire(es, es.onopen, event);
3837
- } else if (eventTypeBuffer === "message") {
3838
- fire(es, es.onmessage, event);
3839
- } else if (eventTypeBuffer === "error") {
3840
- fire(es, es.onerror, event);
3841
- }
3842
- if (currentState === CLOSED) {
3843
- return;
3844
- }
3845
- }
3846
- dataBuffer = "";
3847
- eventTypeBuffer = "";
3848
- }
3849
- state = c === "\r".charCodeAt(0) ? AFTER_CR : FIELD_START;
3850
- } else {
3851
- if (state === FIELD_START) {
3852
- fieldStart = position;
3853
- state = FIELD;
3854
- }
3855
- if (state === FIELD) {
3856
- if (c === ":".charCodeAt(0)) {
3857
- valueStart = position + 1;
3858
- state = VALUE_START;
3859
- }
3860
- } else if (state === VALUE_START) {
3861
- state = VALUE;
3862
- }
3863
- }
3864
- }
3865
- }
3866
- }
3867
- };
3868
-
3869
- var onFinish = function (error) {
3870
- if (currentState === OPEN || currentState === CONNECTING) {
3871
- currentState = WAITING;
3872
- if (timeout !== 0) {
3873
- clearTimeout(timeout);
3874
- timeout = 0;
3875
- }
3876
- timeout = setTimeout(function () {
3877
- onTimeout();
3878
- }, retry);
3879
- retry = clampDuration(Math.min(initialRetry * 16, retry * 2));
3880
-
3881
- es.readyState = CONNECTING;
3882
- var event = new ErrorEvent("error", {error: error});
3883
- es.dispatchEvent(event);
3884
- fire(es, es.onerror, event);
3885
- if (error != undefined) {
3886
- console.error(error);
3887
- }
3888
- }
3889
- };
3890
-
3891
- var close = function () {
3892
- currentState = CLOSED;
3893
- if (abortController != undefined) {
3894
- abortController.abort();
3895
- abortController = undefined;
3896
- }
3897
- if (timeout !== 0) {
3898
- clearTimeout(timeout);
3899
- timeout = 0;
3900
- }
3901
- es.readyState = CLOSED;
3902
- };
3903
-
3904
- var onTimeout = function () {
3905
- timeout = 0;
3906
-
3907
- if (currentState !== WAITING) {
3908
- if (!wasActivity && abortController != undefined) {
3909
- onFinish(new Error("No activity within " + heartbeatTimeout + " milliseconds." + " " + (currentState === CONNECTING ? "No response received." : textLength + " chars received.") + " " + "Reconnecting."));
3910
- if (abortController != undefined) {
3911
- abortController.abort();
3912
- abortController = undefined;
3913
- }
3914
- } else {
3915
- var nextHeartbeat = Math.max((wasActivity || Date.now()) + heartbeatTimeout - Date.now(), 1);
3916
- wasActivity = false;
3917
- timeout = setTimeout(function () {
3918
- onTimeout();
3919
- }, nextHeartbeat);
3920
- }
3921
- return;
3922
- }
3923
-
3924
- wasActivity = false;
3925
- textLength = 0;
3926
- timeout = setTimeout(function () {
3927
- onTimeout();
3928
- }, heartbeatTimeout);
3929
-
3930
- currentState = CONNECTING;
3931
- dataBuffer = "";
3932
- eventTypeBuffer = "";
3933
- lastEventIdBuffer = lastEventId;
3934
- textBuffer = "";
3935
- fieldStart = 0;
3936
- valueStart = 0;
3937
- state = FIELD_START;
3938
-
3939
- // https://bugzilla.mozilla.org/show_bug.cgi?id=428916
3940
- // Request header field Last-Event-ID is not allowed by Access-Control-Allow-Headers.
3941
- var requestURL = url;
3942
- if (url.slice(0, 5) !== "data:" && url.slice(0, 5) !== "blob:") {
3943
- if (lastEventId !== "") {
3944
- // Remove the lastEventId parameter if it's already part of the request URL.
3945
- var i = url.indexOf("?");
3946
- requestURL = i === -1 ? url : url.slice(0, i + 1) + url.slice(i + 1).replace(/(?:^|&)([^=&]*)(?:=[^&]*)?/g, function (p, paramName) {
3947
- return paramName === lastEventIdQueryParameterName ? '' : p;
3948
- });
3949
- // Append the current lastEventId to the request URL.
3950
- requestURL += (url.indexOf("?") === -1 ? "?" : "&") + lastEventIdQueryParameterName +"=" + encodeURIComponent(lastEventId);
3951
- }
3952
- }
3953
- var withCredentials = es.withCredentials;
3954
- var requestHeaders = {};
3955
- requestHeaders["Accept"] = "text/event-stream";
3956
- var headers = es.headers;
3957
- if (headers != undefined) {
3958
- for (var name in headers) {
3959
- if (Object.prototype.hasOwnProperty.call(headers, name)) {
3960
- requestHeaders[name] = headers[name];
3961
- }
3962
- }
3963
- }
3964
- try {
3965
- abortController = transport.open(xhr, onStart, onProgress, onFinish, requestURL, withCredentials, requestHeaders);
3966
- } catch (error) {
3967
- close();
3968
- throw error;
3969
- }
3970
- };
3971
-
3972
- es.url = url;
3973
- es.readyState = CONNECTING;
3974
- es.withCredentials = withCredentials;
3975
- es.headers = headers;
3976
- es._close = close;
3977
-
3978
- onTimeout();
3979
- }
3980
-
3981
- EventSourcePolyfill.prototype = Object.create(EventTarget.prototype);
3982
- EventSourcePolyfill.prototype.CONNECTING = CONNECTING;
3983
- EventSourcePolyfill.prototype.OPEN = OPEN;
3984
- EventSourcePolyfill.prototype.CLOSED = CLOSED;
3985
- EventSourcePolyfill.prototype.close = function () {
3986
- this._close();
3987
- };
3988
-
3989
- EventSourcePolyfill.CONNECTING = CONNECTING;
3990
- EventSourcePolyfill.OPEN = OPEN;
3991
- EventSourcePolyfill.CLOSED = CLOSED;
3992
- EventSourcePolyfill.prototype.withCredentials = undefined;
3993
-
3994
- var R = NativeEventSource;
3995
- if (XMLHttpRequest != undefined && (NativeEventSource == undefined || !("withCredentials" in NativeEventSource.prototype))) {
3996
- // Why replace a native EventSource ?
3997
- // https://bugzilla.mozilla.org/show_bug.cgi?id=444328
3998
- // https://bugzilla.mozilla.org/show_bug.cgi?id=831392
3999
- // https://code.google.com/p/chromium/issues/detail?id=260144
4000
- // https://code.google.com/p/chromium/issues/detail?id=225654
4001
- // ...
4002
- R = EventSourcePolyfill;
4003
- }
4004
-
4005
- (function (factory) {
4006
- {
4007
- var v = factory(exports);
4008
- if (v !== undefined) module.exports = v;
4009
- }
4010
- })(function (exports) {
4011
- exports.EventSourcePolyfill = EventSourcePolyfill;
4012
- exports.NativeEventSource = NativeEventSource;
4013
- exports.EventSource = R;
4014
- });
4015
- }(typeof globalThis === 'undefined' ? (typeof window !== 'undefined' ? window : typeof self !== 'undefined' ? self : eventsource) : globalThis));
4016
- } (eventsource$1, eventsource$1.exports));
4017
- return eventsource$1.exports;
4018
- }
4019
-
4020
- var browser$2;
4021
- var hasRequiredBrowser;
4022
-
4023
- function requireBrowser () {
4024
- if (hasRequiredBrowser) return browser$2;
4025
- hasRequiredBrowser = 1;
4026
- browser$2 = requireEventsource().EventSourcePolyfill;
4027
- return browser$2;
4028
- }
4029
-
4030
- var browserExports = /*@__PURE__*/ requireBrowser();
4031
- var browser = /*@__PURE__*/getDefaultExportFromCjs(browserExports);
4032
-
4033
- var browser$1 = /*#__PURE__*/Object.freeze({
2959
+ var __defProp = Object.defineProperty, __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: !0, configurable: !0, writable: !0, value }) : obj[key] = value, __publicField = (obj, key, value) => __defNormalProp(obj, typeof key != "symbol" ? key + "" : key, value);
2960
+ class ParseError extends Error {
2961
+ constructor(message, options) {
2962
+ super(message), __publicField(this, "type"), __publicField(this, "field"), __publicField(this, "value"), __publicField(this, "line"), this.name = "ParseError", this.type = options.type, this.field = options.field, this.value = options.value, this.line = options.line;
2963
+ }
2964
+ }
2965
+ function noop(_arg) {
2966
+ }
2967
+ function createParser(callbacks) {
2968
+ const { onEvent = noop, onError = noop, onRetry = noop, onComment } = callbacks;
2969
+ let incompleteLine = "", isFirstChunk = !0, id, data = "", eventType = "";
2970
+ function feed(newChunk) {
2971
+ const chunk = isFirstChunk ? newChunk.replace(/^\xEF\xBB\xBF/, "") : newChunk, [complete, incomplete] = splitLines(`${incompleteLine}${chunk}`);
2972
+ for (const line of complete)
2973
+ parseLine(line);
2974
+ incompleteLine = incomplete, isFirstChunk = !1;
2975
+ }
2976
+ function parseLine(line) {
2977
+ if (line === "") {
2978
+ dispatchEvent();
2979
+ return;
2980
+ }
2981
+ if (line.startsWith(":")) {
2982
+ onComment && onComment(line.slice(line.startsWith(": ") ? 2 : 1));
2983
+ return;
2984
+ }
2985
+ const fieldSeparatorIndex = line.indexOf(":");
2986
+ if (fieldSeparatorIndex !== -1) {
2987
+ const field = line.slice(0, fieldSeparatorIndex), offset = line[fieldSeparatorIndex + 1] === " " ? 2 : 1, value = line.slice(fieldSeparatorIndex + offset);
2988
+ processField(field, value, line);
2989
+ return;
2990
+ }
2991
+ processField(line, "", line);
2992
+ }
2993
+ function processField(field, value, line) {
2994
+ switch (field) {
2995
+ case "event":
2996
+ eventType = value;
2997
+ break;
2998
+ case "data":
2999
+ data = `${data}${value}
3000
+ `;
3001
+ break;
3002
+ case "id":
3003
+ id = value.includes("\0") ? void 0 : value;
3004
+ break;
3005
+ case "retry":
3006
+ /^\d+$/.test(value) ? onRetry(parseInt(value, 10)) : onError(
3007
+ new ParseError(`Invalid \`retry\` value: "${value}"`, {
3008
+ type: "invalid-retry",
3009
+ value,
3010
+ line
3011
+ })
3012
+ );
3013
+ break;
3014
+ default:
3015
+ onError(
3016
+ new ParseError(
3017
+ `Unknown field "${field.length > 20 ? `${field.slice(0, 20)}\u2026` : field}"`,
3018
+ { type: "unknown-field", field, value, line }
3019
+ )
3020
+ );
3021
+ break;
3022
+ }
3023
+ }
3024
+ function dispatchEvent() {
3025
+ data.length > 0 && onEvent({
3026
+ id,
3027
+ event: eventType || void 0,
3028
+ // If the data buffer's last character is a U+000A LINE FEED (LF) character,
3029
+ // then remove the last character from the data buffer.
3030
+ data: data.endsWith(`
3031
+ `) ? data.slice(0, -1) : data
3032
+ }), id = void 0, data = "", eventType = "";
3033
+ }
3034
+ function reset(options = {}) {
3035
+ incompleteLine && options.consume && parseLine(incompleteLine), id = void 0, data = "", eventType = "", incompleteLine = "";
3036
+ }
3037
+ return { feed, reset };
3038
+ }
3039
+ function splitLines(chunk) {
3040
+ const lines = [];
3041
+ let incompleteLine = "";
3042
+ const totalLength = chunk.length;
3043
+ for (let i = 0; i < totalLength; i++) {
3044
+ const char = chunk[i];
3045
+ char === "\r" && chunk[i + 1] === `
3046
+ ` ? (lines.push(incompleteLine), incompleteLine = "", i++) : char === "\r" || char === `
3047
+ ` ? (lines.push(incompleteLine), incompleteLine = "") : incompleteLine += char;
3048
+ }
3049
+ return [lines, incompleteLine];
3050
+ }
3051
+
3052
+ class ErrorEvent extends Event {
3053
+ }
3054
+ function syntaxError(message) {
3055
+ const DomException = globalThis.DOMException;
3056
+ return typeof DomException == "function" ? new DomException(message, "SyntaxError") : new SyntaxError(message);
3057
+ }
3058
+ var __typeError = (msg) => {
3059
+ throw TypeError(msg);
3060
+ }, __accessCheck = (obj, member, msg) => member.has(obj) || __typeError("Cannot " + msg), __privateGet = (obj, member, getter) => (__accessCheck(obj, member, "read from private field"), getter ? getter.call(obj) : member.get(obj)), __privateAdd = (obj, member, value) => member.has(obj) ? __typeError("Cannot add the same private member more than once") : member instanceof WeakSet ? member.add(obj) : member.set(obj, value), __privateSet = (obj, member, value, setter) => (__accessCheck(obj, member, "write to private field"), member.set(obj, value), value), __privateMethod = (obj, member, method) => (__accessCheck(obj, member, "access private method"), method), _readyState, _url, _redirectUrl, _withCredentials, _fetch, _reconnectInterval, _reconnectTimer, _lastEventId, _controller, _parser, _onError, _onMessage, _onOpen, _EventSource_instances, connect_fn, _onFetchResponse, _onFetchError, getRequestOptions_fn, _onEvent, _onRetryChange, failConnection_fn, scheduleReconnect_fn, _reconnect;
3061
+ let EventSource$1 = class EventSource extends EventTarget {
3062
+ constructor(url, eventSourceInitDict) {
3063
+ var _a, _b;
3064
+ super(), __privateAdd(this, _EventSource_instances), this.CONNECTING = 0, this.OPEN = 1, this.CLOSED = 2, __privateAdd(this, _readyState), __privateAdd(this, _url), __privateAdd(this, _redirectUrl), __privateAdd(this, _withCredentials), __privateAdd(this, _fetch), __privateAdd(this, _reconnectInterval), __privateAdd(this, _reconnectTimer), __privateAdd(this, _lastEventId, null), __privateAdd(this, _controller), __privateAdd(this, _parser), __privateAdd(this, _onError, null), __privateAdd(this, _onMessage, null), __privateAdd(this, _onOpen, null), __privateAdd(this, _onFetchResponse, async (response) => {
3065
+ var _a2;
3066
+ __privateGet(this, _parser).reset();
3067
+ const { body, redirected, status, headers } = response;
3068
+ if (status === 204) {
3069
+ __privateMethod(this, _EventSource_instances, failConnection_fn).call(this, "Server sent HTTP 204, not reconnecting", 204), this.close();
3070
+ return;
3071
+ }
3072
+ if (redirected ? __privateSet(this, _redirectUrl, new URL(response.url)) : __privateSet(this, _redirectUrl, void 0), status !== 200) {
3073
+ __privateMethod(this, _EventSource_instances, failConnection_fn).call(this, `Non-200 status code (${status})`, status);
3074
+ return;
3075
+ }
3076
+ if (!(headers.get("content-type") || "").startsWith("text/event-stream")) {
3077
+ __privateMethod(this, _EventSource_instances, failConnection_fn).call(this, 'Invalid content type, expected "text/event-stream"', status);
3078
+ return;
3079
+ }
3080
+ if (__privateGet(this, _readyState) === this.CLOSED)
3081
+ return;
3082
+ __privateSet(this, _readyState, this.OPEN);
3083
+ const openEvent = new Event("open");
3084
+ if ((_a2 = __privateGet(this, _onOpen)) == null || _a2.call(this, openEvent), this.dispatchEvent(openEvent), typeof body != "object" || !body || !("getReader" in body)) {
3085
+ __privateMethod(this, _EventSource_instances, failConnection_fn).call(this, "Invalid response body, expected a web ReadableStream", status), this.close();
3086
+ return;
3087
+ }
3088
+ const decoder = new TextDecoder(), reader = body.getReader();
3089
+ let open = !0;
3090
+ do {
3091
+ const { done, value } = await reader.read();
3092
+ value && __privateGet(this, _parser).feed(decoder.decode(value, { stream: !done })), done && (open = !1, __privateGet(this, _parser).reset(), __privateMethod(this, _EventSource_instances, scheduleReconnect_fn).call(this));
3093
+ } while (open);
3094
+ }), __privateAdd(this, _onFetchError, (err) => {
3095
+ __privateSet(this, _controller, void 0), !(err.name === "AbortError" || err.type === "aborted") && __privateMethod(this, _EventSource_instances, scheduleReconnect_fn).call(this);
3096
+ }), __privateAdd(this, _onEvent, (event) => {
3097
+ typeof event.id == "string" && __privateSet(this, _lastEventId, event.id);
3098
+ const messageEvent = new MessageEvent(event.event || "message", {
3099
+ data: event.data,
3100
+ origin: __privateGet(this, _redirectUrl) ? __privateGet(this, _redirectUrl).origin : __privateGet(this, _url).origin,
3101
+ lastEventId: event.id || ""
3102
+ });
3103
+ __privateGet(this, _onMessage) && (!event.event || event.event === "message") && __privateGet(this, _onMessage).call(this, messageEvent), this.dispatchEvent(messageEvent);
3104
+ }), __privateAdd(this, _onRetryChange, (value) => {
3105
+ __privateSet(this, _reconnectInterval, value);
3106
+ }), __privateAdd(this, _reconnect, () => {
3107
+ __privateSet(this, _reconnectTimer, void 0), __privateGet(this, _readyState) === this.CONNECTING && __privateMethod(this, _EventSource_instances, connect_fn).call(this);
3108
+ });
3109
+ try {
3110
+ if (url instanceof URL)
3111
+ __privateSet(this, _url, url);
3112
+ else if (typeof url == "string")
3113
+ __privateSet(this, _url, new URL(url, getBaseURL()));
3114
+ else
3115
+ throw new Error("Invalid URL");
3116
+ } catch {
3117
+ throw syntaxError("An invalid or illegal string was specified");
3118
+ }
3119
+ __privateSet(this, _parser, createParser({
3120
+ onEvent: __privateGet(this, _onEvent),
3121
+ onRetry: __privateGet(this, _onRetryChange)
3122
+ })), __privateSet(this, _readyState, this.CONNECTING), __privateSet(this, _reconnectInterval, 3e3), __privateSet(this, _fetch, (_a = eventSourceInitDict == null ? void 0 : eventSourceInitDict.fetch) != null ? _a : globalThis.fetch), __privateSet(this, _withCredentials, (_b = eventSourceInitDict == null ? void 0 : eventSourceInitDict.withCredentials) != null ? _b : !1), __privateMethod(this, _EventSource_instances, connect_fn).call(this);
3123
+ }
3124
+ /**
3125
+ * Returns the state of this EventSource object's connection. It can have the values described below.
3126
+ *
3127
+ * [MDN Reference](https://developer.mozilla.org/docs/Web/API/EventSource/readyState)
3128
+ *
3129
+ * Note: typed as `number` instead of `0 | 1 | 2` for compatibility with the `EventSource` interface,
3130
+ * defined in the TypeScript `dom` library.
3131
+ *
3132
+ * @public
3133
+ */
3134
+ get readyState() {
3135
+ return __privateGet(this, _readyState);
3136
+ }
3137
+ /**
3138
+ * Returns the URL providing the event stream.
3139
+ *
3140
+ * [MDN Reference](https://developer.mozilla.org/docs/Web/API/EventSource/url)
3141
+ *
3142
+ * @public
3143
+ */
3144
+ get url() {
3145
+ return __privateGet(this, _url).href;
3146
+ }
3147
+ /**
3148
+ * Returns true if the credentials mode for connection requests to the URL providing the event stream is set to "include", and false otherwise.
3149
+ *
3150
+ * [MDN Reference](https://developer.mozilla.org/docs/Web/API/EventSource/withCredentials)
3151
+ */
3152
+ get withCredentials() {
3153
+ return __privateGet(this, _withCredentials);
3154
+ }
3155
+ /** [MDN Reference](https://developer.mozilla.org/docs/Web/API/EventSource/error_event) */
3156
+ get onerror() {
3157
+ return __privateGet(this, _onError);
3158
+ }
3159
+ set onerror(value) {
3160
+ __privateSet(this, _onError, value);
3161
+ }
3162
+ /** [MDN Reference](https://developer.mozilla.org/docs/Web/API/EventSource/message_event) */
3163
+ get onmessage() {
3164
+ return __privateGet(this, _onMessage);
3165
+ }
3166
+ set onmessage(value) {
3167
+ __privateSet(this, _onMessage, value);
3168
+ }
3169
+ /** [MDN Reference](https://developer.mozilla.org/docs/Web/API/EventSource/open_event) */
3170
+ get onopen() {
3171
+ return __privateGet(this, _onOpen);
3172
+ }
3173
+ set onopen(value) {
3174
+ __privateSet(this, _onOpen, value);
3175
+ }
3176
+ addEventListener(type, listener, options) {
3177
+ const listen = listener;
3178
+ super.addEventListener(type, listen, options);
3179
+ }
3180
+ removeEventListener(type, listener, options) {
3181
+ const listen = listener;
3182
+ super.removeEventListener(type, listen, options);
3183
+ }
3184
+ /**
3185
+ * Aborts any instances of the fetch algorithm started for this EventSource object, and sets the readyState attribute to CLOSED.
3186
+ *
3187
+ * [MDN Reference](https://developer.mozilla.org/docs/Web/API/EventSource/close)
3188
+ *
3189
+ * @public
3190
+ */
3191
+ close() {
3192
+ __privateGet(this, _reconnectTimer) && clearTimeout(__privateGet(this, _reconnectTimer)), __privateGet(this, _readyState) !== this.CLOSED && (__privateGet(this, _controller) && __privateGet(this, _controller).abort(), __privateSet(this, _readyState, this.CLOSED), __privateSet(this, _controller, void 0));
3193
+ }
3194
+ };
3195
+ _readyState = /* @__PURE__ */ new WeakMap(), _url = /* @__PURE__ */ new WeakMap(), _redirectUrl = /* @__PURE__ */ new WeakMap(), _withCredentials = /* @__PURE__ */ new WeakMap(), _fetch = /* @__PURE__ */ new WeakMap(), _reconnectInterval = /* @__PURE__ */ new WeakMap(), _reconnectTimer = /* @__PURE__ */ new WeakMap(), _lastEventId = /* @__PURE__ */ new WeakMap(), _controller = /* @__PURE__ */ new WeakMap(), _parser = /* @__PURE__ */ new WeakMap(), _onError = /* @__PURE__ */ new WeakMap(), _onMessage = /* @__PURE__ */ new WeakMap(), _onOpen = /* @__PURE__ */ new WeakMap(), _EventSource_instances = /* @__PURE__ */ new WeakSet(), /**
3196
+ * Connect to the given URL and start receiving events
3197
+ *
3198
+ * @internal
3199
+ */
3200
+ connect_fn = function() {
3201
+ __privateSet(this, _readyState, this.CONNECTING), __privateSet(this, _controller, new AbortController()), __privateGet(this, _fetch)(__privateGet(this, _url), __privateMethod(this, _EventSource_instances, getRequestOptions_fn).call(this)).then(__privateGet(this, _onFetchResponse)).catch(__privateGet(this, _onFetchError));
3202
+ }, _onFetchResponse = /* @__PURE__ */ new WeakMap(), _onFetchError = /* @__PURE__ */ new WeakMap(), /**
3203
+ * Get request options for the `fetch()` request
3204
+ *
3205
+ * @returns The request options
3206
+ * @internal
3207
+ */
3208
+ getRequestOptions_fn = function() {
3209
+ var _a;
3210
+ const init = {
3211
+ // [spec] Let `corsAttributeState` be `Anonymous`…
3212
+ // [spec] …will have their mode set to "cors"…
3213
+ mode: "cors",
3214
+ redirect: "follow",
3215
+ headers: { Accept: "text/event-stream", ...__privateGet(this, _lastEventId) ? { "Last-Event-ID": __privateGet(this, _lastEventId) } : void 0 },
3216
+ cache: "no-store",
3217
+ signal: (_a = __privateGet(this, _controller)) == null ? void 0 : _a.signal
3218
+ };
3219
+ return "window" in globalThis && (init.credentials = this.withCredentials ? "include" : "same-origin"), init;
3220
+ }, _onEvent = /* @__PURE__ */ new WeakMap(), _onRetryChange = /* @__PURE__ */ new WeakMap(), /**
3221
+ * Handles the process referred to in the EventSource specification as "failing a connection".
3222
+ *
3223
+ * @param error - The error causing the connection to fail
3224
+ * @internal
3225
+ */
3226
+ failConnection_fn = function(error, code) {
3227
+ var _a;
3228
+ __privateGet(this, _readyState) !== this.CLOSED && __privateSet(this, _readyState, this.CLOSED);
3229
+ const errorEvent = new ErrorEvent("error");
3230
+ errorEvent.code = code, errorEvent.message = error, (_a = __privateGet(this, _onError)) == null || _a.call(this, errorEvent), this.dispatchEvent(errorEvent);
3231
+ }, /**
3232
+ * Schedules a reconnection attempt against the EventSource endpoint.
3233
+ *
3234
+ * @internal
3235
+ */
3236
+ scheduleReconnect_fn = function() {
3237
+ var _a;
3238
+ if (__privateGet(this, _readyState) === this.CLOSED)
3239
+ return;
3240
+ __privateSet(this, _readyState, this.CONNECTING);
3241
+ const errorEvent = new ErrorEvent("error");
3242
+ (_a = __privateGet(this, _onError)) == null || _a.call(this, errorEvent), this.dispatchEvent(errorEvent), __privateSet(this, _reconnectTimer, setTimeout(__privateGet(this, _reconnect), __privateGet(this, _reconnectInterval)));
3243
+ }, _reconnect = /* @__PURE__ */ new WeakMap(), /**
3244
+ * ReadyState representing an EventSource currently trying to connect
3245
+ *
3246
+ * @public
3247
+ */
3248
+ EventSource$1.CONNECTING = 0, /**
3249
+ * ReadyState representing an EventSource connection that is open (eg connected)
3250
+ *
3251
+ * @public
3252
+ */
3253
+ EventSource$1.OPEN = 1, /**
3254
+ * ReadyState representing an EventSource connection that is closed (eg disconnected)
3255
+ *
3256
+ * @public
3257
+ */
3258
+ EventSource$1.CLOSED = 2;
3259
+ function getBaseURL() {
3260
+ const doc = "document" in globalThis ? globalThis.document : void 0;
3261
+ return doc && typeof doc == "object" && "baseURI" in doc && typeof doc.baseURI == "string" ? doc.baseURI : void 0;
3262
+ }
3263
+
3264
+ var index = /*#__PURE__*/Object.freeze({
4034
3265
  __proto__: null,
4035
- default: browser
3266
+ ErrorEvent: ErrorEvent,
3267
+ EventSource: EventSource$1
4036
3268
  });
4037
3269
 
4038
3270
  exports.BasePatch = BasePatch;