@sanity/client 6.22.3 → 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.
- package/dist/_chunks-cjs/resolveEditInfo.cjs +1 -2
- package/dist/_chunks-cjs/resolveEditInfo.cjs.map +1 -1
- package/dist/_chunks-cjs/stegaClean.cjs +1 -2
- package/dist/_chunks-cjs/stegaClean.cjs.map +1 -1
- package/dist/_chunks-cjs/stegaEncodeSourceMap.cjs +3 -3
- package/dist/_chunks-cjs/stegaEncodeSourceMap.cjs.map +1 -1
- package/dist/_chunks-es/resolveEditInfo.js +1 -2
- package/dist/_chunks-es/resolveEditInfo.js.map +1 -1
- package/dist/_chunks-es/stegaClean.js +1 -2
- package/dist/_chunks-es/stegaClean.js.map +1 -1
- package/dist/_chunks-es/stegaEncodeSourceMap.js +3 -3
- package/dist/_chunks-es/stegaEncodeSourceMap.js.map +1 -1
- package/dist/csm.cjs +1 -2
- package/dist/csm.cjs.map +1 -1
- package/dist/csm.js +1 -2
- package/dist/csm.js.map +1 -1
- package/dist/index.browser.cjs +3 -4
- package/dist/index.browser.cjs.map +1 -1
- package/dist/index.browser.js +3 -4
- package/dist/index.browser.js.map +1 -1
- package/dist/index.cjs +4 -5
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +4 -5
- package/dist/index.js.map +1 -1
- package/package.json +3 -3
- package/src/data/listen.ts +3 -3
- package/src/data/live.ts +1 -1
- package/src/stega/filterDefault.ts +3 -2
- package/umd/sanityClient.js +321 -1088
- package/umd/sanityClient.min.js +1 -6
package/umd/sanityClient.js
CHANGED
|
@@ -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 {
|
|
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
|
|
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,
|
|
@@ -2812,7 +2810,7 @@ ${selectionOpts}`);
|
|
|
2812
2810
|
if (isValidDate(value) || isValidURL(value))
|
|
2813
2811
|
return !1;
|
|
2814
2812
|
const endPath = sourcePath.at(-1);
|
|
2815
|
-
return !(sourcePath.at(-2) === "slug" && endPath === "current" || typeof endPath == "string" && endPath.startsWith("_") || typeof endPath == "number" && sourcePath.at(-2) === "marks" || endPath === "href" && typeof sourcePath.at(-2) == "number" && sourcePath.at(-3) === "markDefs" || endPath === "style" || endPath === "listItem" || sourcePath.some(
|
|
2813
|
+
return !(sourcePath.at(-2) === "slug" && endPath === "current" || typeof endPath == "string" && (endPath.startsWith("_") || endPath.endsWith("Id")) || typeof endPath == "number" && sourcePath.at(-2) === "marks" || endPath === "href" && typeof sourcePath.at(-2) == "number" && sourcePath.at(-3) === "markDefs" || endPath === "style" || endPath === "listItem" || sourcePath.some(
|
|
2816
2814
|
(path) => path === "meta" || path === "metadata" || path === "openGraph" || path === "seo"
|
|
2817
2815
|
) || hasTypeLike(sourcePath) || hasTypeLike(resultPath) || typeof endPath == "string" && denylist.has(endPath));
|
|
2818
2816
|
}, denylist = /* @__PURE__ */ new Set([
|
|
@@ -2849,6 +2847,7 @@ ${selectionOpts}`);
|
|
|
2849
2847
|
"template",
|
|
2850
2848
|
"theme",
|
|
2851
2849
|
"type",
|
|
2850
|
+
"textTheme",
|
|
2852
2851
|
"unit",
|
|
2853
2852
|
"url",
|
|
2854
2853
|
"username",
|
|
@@ -2907,8 +2906,7 @@ ${selectionOpts}`);
|
|
|
2907
2906
|
const { baseUrl, workspace, tool } = resolveStudioBaseRoute(
|
|
2908
2907
|
typeof config.studioUrl == "function" ? config.studioUrl(sourceDocument) : config.studioUrl
|
|
2909
2908
|
);
|
|
2910
|
-
if (!baseUrl)
|
|
2911
|
-
return value;
|
|
2909
|
+
if (!baseUrl) return value;
|
|
2912
2910
|
const { _id: id, _type: type, _projectId: projectId, _dataset: dataset } = sourceDocument;
|
|
2913
2911
|
return C(
|
|
2914
2912
|
value,
|
|
@@ -2958,1080 +2956,315 @@ ${selectionOpts}`);
|
|
|
2958
2956
|
stegaEncodeSourceMap$1: stegaEncodeSourceMap$1
|
|
2959
2957
|
});
|
|
2960
2958
|
|
|
2961
|
-
|
|
2962
|
-
|
|
2963
|
-
|
|
2964
|
-
|
|
2965
|
-
|
|
2966
|
-
|
|
2967
|
-
|
|
2968
|
-
|
|
2969
|
-
|
|
2970
|
-
|
|
2971
|
-
|
|
2972
|
-
|
|
2973
|
-
|
|
2974
|
-
|
|
2975
|
-
|
|
2976
|
-
|
|
2977
|
-
|
|
2978
|
-
|
|
2979
|
-
|
|
2980
|
-
|
|
2981
|
-
|
|
2982
|
-
|
|
2983
|
-
|
|
2984
|
-
|
|
2985
|
-
|
|
2986
|
-
|
|
2987
|
-
|
|
2988
|
-
|
|
2989
|
-
|
|
2990
|
-
|
|
2991
|
-
|
|
2992
|
-
|
|
2993
|
-
|
|
2994
|
-
|
|
2995
|
-
|
|
2996
|
-
|
|
2997
|
-
|
|
2998
|
-
|
|
2999
|
-
|
|
3000
|
-
|
|
3001
|
-
|
|
3002
|
-
|
|
3003
|
-
|
|
3004
|
-
|
|
3005
|
-
|
|
3006
|
-
|
|
3007
|
-
|
|
3008
|
-
|
|
3009
|
-
|
|
3010
|
-
|
|
3011
|
-
|
|
3012
|
-
|
|
3013
|
-
|
|
3014
|
-
|
|
3015
|
-
|
|
3016
|
-
|
|
3017
|
-
|
|
3018
|
-
|
|
3019
|
-
|
|
3020
|
-
|
|
3021
|
-
|
|
3022
|
-
|
|
3023
|
-
|
|
3024
|
-
|
|
3025
|
-
|
|
3026
|
-
|
|
3027
|
-
|
|
3028
|
-
|
|
3029
|
-
|
|
3030
|
-
|
|
3031
|
-
|
|
3032
|
-
|
|
3033
|
-
|
|
3034
|
-
|
|
3035
|
-
|
|
3036
|
-
|
|
3037
|
-
|
|
3038
|
-
|
|
3039
|
-
|
|
3040
|
-
|
|
3041
|
-
|
|
3042
|
-
|
|
3043
|
-
|
|
3044
|
-
|
|
3045
|
-
|
|
3046
|
-
|
|
3047
|
-
|
|
3048
|
-
|
|
3049
|
-
|
|
3050
|
-
|
|
3051
|
-
|
|
3052
|
-
|
|
3053
|
-
|
|
3054
|
-
|
|
3055
|
-
|
|
3056
|
-
|
|
3057
|
-
|
|
3058
|
-
|
|
3059
|
-
|
|
3060
|
-
|
|
3061
|
-
|
|
3062
|
-
|
|
3063
|
-
|
|
3064
|
-
|
|
3065
|
-
|
|
3066
|
-
|
|
3067
|
-
|
|
3068
|
-
|
|
3069
|
-
|
|
3070
|
-
|
|
3071
|
-
|
|
3072
|
-
|
|
3073
|
-
|
|
3074
|
-
|
|
3075
|
-
|
|
3076
|
-
|
|
3077
|
-
|
|
3078
|
-
|
|
3079
|
-
|
|
3080
|
-
|
|
3081
|
-
|
|
3082
|
-
|
|
3083
|
-
|
|
3084
|
-
|
|
3085
|
-
|
|
3086
|
-
|
|
3087
|
-
|
|
3088
|
-
|
|
3089
|
-
|
|
3090
|
-
|
|
3091
|
-
|
|
3092
|
-
|
|
3093
|
-
|
|
3094
|
-
|
|
3095
|
-
|
|
3096
|
-
|
|
3097
|
-
|
|
3098
|
-
|
|
3099
|
-
|
|
3100
|
-
|
|
3101
|
-
|
|
3102
|
-
|
|
3103
|
-
|
|
3104
|
-
|
|
3105
|
-
|
|
3106
|
-
|
|
3107
|
-
|
|
3108
|
-
|
|
3109
|
-
|
|
3110
|
-
|
|
3111
|
-
|
|
3112
|
-
|
|
3113
|
-
|
|
3114
|
-
|
|
3115
|
-
|
|
3116
|
-
|
|
3117
|
-
|
|
3118
|
-
|
|
3119
|
-
|
|
3120
|
-
|
|
3121
|
-
|
|
3122
|
-
|
|
3123
|
-
|
|
3124
|
-
|
|
3125
|
-
|
|
3126
|
-
|
|
3127
|
-
|
|
3128
|
-
|
|
3129
|
-
|
|
3130
|
-
|
|
3131
|
-
|
|
3132
|
-
|
|
3133
|
-
|
|
3134
|
-
|
|
3135
|
-
|
|
3136
|
-
|
|
3137
|
-
|
|
3138
|
-
|
|
3139
|
-
|
|
3140
|
-
|
|
3141
|
-
|
|
3142
|
-
|
|
3143
|
-
|
|
3144
|
-
|
|
3145
|
-
|
|
3146
|
-
|
|
3147
|
-
|
|
3148
|
-
|
|
3149
|
-
|
|
3150
|
-
|
|
3151
|
-
|
|
3152
|
-
|
|
3153
|
-
|
|
3154
|
-
|
|
3155
|
-
|
|
3156
|
-
|
|
3157
|
-
|
|
3158
|
-
|
|
3159
|
-
|
|
3160
|
-
|
|
3161
|
-
|
|
3162
|
-
|
|
3163
|
-
|
|
3164
|
-
|
|
3165
|
-
|
|
3166
|
-
|
|
3167
|
-
|
|
3168
|
-
|
|
3169
|
-
|
|
3170
|
-
|
|
3171
|
-
|
|
3172
|
-
|
|
3173
|
-
|
|
3174
|
-
|
|
3175
|
-
|
|
3176
|
-
|
|
3177
|
-
|
|
3178
|
-
|
|
3179
|
-
|
|
3180
|
-
|
|
3181
|
-
|
|
3182
|
-
|
|
3183
|
-
|
|
3184
|
-
|
|
3185
|
-
|
|
3186
|
-
|
|
3187
|
-
|
|
3188
|
-
|
|
3189
|
-
|
|
3190
|
-
|
|
3191
|
-
|
|
3192
|
-
|
|
3193
|
-
|
|
3194
|
-
|
|
3195
|
-
|
|
3196
|
-
|
|
3197
|
-
|
|
3198
|
-
|
|
3199
|
-
|
|
3200
|
-
|
|
3201
|
-
|
|
3202
|
-
|
|
3203
|
-
|
|
3204
|
-
|
|
3205
|
-
|
|
3206
|
-
|
|
3207
|
-
|
|
3208
|
-
|
|
3209
|
-
|
|
3210
|
-
|
|
3211
|
-
|
|
3212
|
-
|
|
3213
|
-
|
|
3214
|
-
|
|
3215
|
-
|
|
3216
|
-
|
|
3217
|
-
|
|
3218
|
-
|
|
3219
|
-
|
|
3220
|
-
|
|
3221
|
-
|
|
3222
|
-
|
|
3223
|
-
|
|
3224
|
-
|
|
3225
|
-
|
|
3226
|
-
|
|
3227
|
-
|
|
3228
|
-
|
|
3229
|
-
|
|
3230
|
-
|
|
3231
|
-
|
|
3232
|
-
|
|
3233
|
-
|
|
3234
|
-
|
|
3235
|
-
|
|
3236
|
-
|
|
3237
|
-
|
|
3238
|
-
|
|
3239
|
-
|
|
3240
|
-
|
|
3241
|
-
|
|
3242
|
-
|
|
3243
|
-
|
|
3244
|
-
|
|
3245
|
-
|
|
3246
|
-
|
|
3247
|
-
|
|
3248
|
-
|
|
3249
|
-
|
|
3250
|
-
|
|
3251
|
-
|
|
3252
|
-
|
|
3253
|
-
|
|
3254
|
-
|
|
3255
|
-
|
|
3256
|
-
|
|
3257
|
-
|
|
3258
|
-
|
|
3259
|
-
|
|
3260
|
-
|
|
3261
|
-
|
|
3262
|
-
|
|
3263
|
-
|
|
3264
|
-
|
|
3265
|
-
|
|
3266
|
-
|
|
3267
|
-
}
|
|
3268
|
-
that.readyState = 3;
|
|
3269
|
-
that.responseText = responseText;
|
|
3270
|
-
that.onprogress();
|
|
3271
|
-
}
|
|
3272
|
-
};
|
|
3273
|
-
var onFinish = function (type, event) {
|
|
3274
|
-
if (event == null || event.preventDefault == null) {
|
|
3275
|
-
event = {
|
|
3276
|
-
preventDefault: k
|
|
3277
|
-
};
|
|
3278
|
-
}
|
|
3279
|
-
// Firefox 52 fires "readystatechange" (xhr.readyState === 4) without final "readystatechange" (xhr.readyState === 3)
|
|
3280
|
-
// IE 8 fires "onload" without "onprogress"
|
|
3281
|
-
onProgress();
|
|
3282
|
-
if (state === 1 || state === 2 || state === 3) {
|
|
3283
|
-
state = 4;
|
|
3284
|
-
if (timeout !== 0) {
|
|
3285
|
-
clearTimeout(timeout);
|
|
3286
|
-
timeout = 0;
|
|
3287
|
-
}
|
|
3288
|
-
that.readyState = 4;
|
|
3289
|
-
if (type === "load") {
|
|
3290
|
-
that.onload(event);
|
|
3291
|
-
} else if (type === "error") {
|
|
3292
|
-
that.onerror(event);
|
|
3293
|
-
} else if (type === "abort") {
|
|
3294
|
-
that.onabort(event);
|
|
3295
|
-
} else {
|
|
3296
|
-
throw new TypeError();
|
|
3297
|
-
}
|
|
3298
|
-
that.onreadystatechange();
|
|
3299
|
-
}
|
|
3300
|
-
};
|
|
3301
|
-
var onReadyStateChange = function (event) {
|
|
3302
|
-
if (xhr != undefined) { // Opera 12
|
|
3303
|
-
if (xhr.readyState === 4) {
|
|
3304
|
-
if (!("onload" in xhr) || !("onerror" in xhr) || !("onabort" in xhr)) {
|
|
3305
|
-
onFinish(xhr.responseText === "" ? "error" : "load", event);
|
|
3306
|
-
}
|
|
3307
|
-
} else if (xhr.readyState === 3) {
|
|
3308
|
-
if (!("onprogress" in xhr)) { // testing XMLHttpRequest#responseText too many times is too slow in IE 11
|
|
3309
|
-
// and in Firefox 3.6
|
|
3310
|
-
onProgress();
|
|
3311
|
-
}
|
|
3312
|
-
} else if (xhr.readyState === 2) {
|
|
3313
|
-
onStart();
|
|
3314
|
-
}
|
|
3315
|
-
}
|
|
3316
|
-
};
|
|
3317
|
-
var onTimeout = function () {
|
|
3318
|
-
timeout = setTimeout(function () {
|
|
3319
|
-
onTimeout();
|
|
3320
|
-
}, 500);
|
|
3321
|
-
if (xhr.readyState === 3) {
|
|
3322
|
-
onProgress();
|
|
3323
|
-
}
|
|
3324
|
-
};
|
|
3325
|
-
|
|
3326
|
-
// XDomainRequest#abort removes onprogress, onerror, onload
|
|
3327
|
-
if ("onload" in xhr) {
|
|
3328
|
-
xhr.onload = function (event) {
|
|
3329
|
-
onFinish("load", event);
|
|
3330
|
-
};
|
|
3331
|
-
}
|
|
3332
|
-
if ("onerror" in xhr) {
|
|
3333
|
-
xhr.onerror = function (event) {
|
|
3334
|
-
onFinish("error", event);
|
|
3335
|
-
};
|
|
3336
|
-
}
|
|
3337
|
-
// improper fix to match Firefox behaviour, but it is better than just ignore abort
|
|
3338
|
-
// see https://bugzilla.mozilla.org/show_bug.cgi?id=768596
|
|
3339
|
-
// https://bugzilla.mozilla.org/show_bug.cgi?id=880200
|
|
3340
|
-
// https://code.google.com/p/chromium/issues/detail?id=153570
|
|
3341
|
-
// IE 8 fires "onload" without "onprogress
|
|
3342
|
-
if ("onabort" in xhr) {
|
|
3343
|
-
xhr.onabort = function (event) {
|
|
3344
|
-
onFinish("abort", event);
|
|
3345
|
-
};
|
|
3346
|
-
}
|
|
3347
|
-
|
|
3348
|
-
if ("onprogress" in xhr) {
|
|
3349
|
-
xhr.onprogress = onProgress;
|
|
3350
|
-
}
|
|
3351
|
-
|
|
3352
|
-
// IE 8 - 9 (XMLHTTPRequest)
|
|
3353
|
-
// Opera < 12
|
|
3354
|
-
// Firefox < 3.5
|
|
3355
|
-
// Firefox 3.5 - 3.6 - ? < 9.0
|
|
3356
|
-
// onprogress is not fired sometimes or delayed
|
|
3357
|
-
// see also #64 (significant lag in IE 11)
|
|
3358
|
-
if ("onreadystatechange" in xhr) {
|
|
3359
|
-
xhr.onreadystatechange = function (event) {
|
|
3360
|
-
onReadyStateChange(event);
|
|
3361
|
-
};
|
|
3362
|
-
}
|
|
3363
|
-
|
|
3364
|
-
if ("contentType" in xhr || !("ontimeout" in XMLHttpRequest.prototype)) {
|
|
3365
|
-
url += (url.indexOf("?") === -1 ? "?" : "&") + "padding=true";
|
|
3366
|
-
}
|
|
3367
|
-
xhr.open(method, url, true);
|
|
3368
|
-
|
|
3369
|
-
if ("readyState" in xhr) {
|
|
3370
|
-
// workaround for Opera 12 issue with "progress" events
|
|
3371
|
-
// #91 (XMLHttpRequest onprogress not fired for streaming response in Edge 14-15-?)
|
|
3372
|
-
timeout = setTimeout(function () {
|
|
3373
|
-
onTimeout();
|
|
3374
|
-
}, 0);
|
|
3375
|
-
}
|
|
3376
|
-
};
|
|
3377
|
-
XHRWrapper.prototype.abort = function () {
|
|
3378
|
-
this._abort(false);
|
|
3379
|
-
};
|
|
3380
|
-
XHRWrapper.prototype.getResponseHeader = function (name) {
|
|
3381
|
-
return this._contentType;
|
|
3382
|
-
};
|
|
3383
|
-
XHRWrapper.prototype.setRequestHeader = function (name, value) {
|
|
3384
|
-
var xhr = this._xhr;
|
|
3385
|
-
if ("setRequestHeader" in xhr) {
|
|
3386
|
-
xhr.setRequestHeader(name, value);
|
|
3387
|
-
}
|
|
3388
|
-
};
|
|
3389
|
-
XHRWrapper.prototype.getAllResponseHeaders = function () {
|
|
3390
|
-
// XMLHttpRequest#getAllResponseHeaders returns null for CORS requests in Firefox 3.6.28
|
|
3391
|
-
return this._xhr.getAllResponseHeaders != undefined ? this._xhr.getAllResponseHeaders() || "" : "";
|
|
3392
|
-
};
|
|
3393
|
-
XHRWrapper.prototype.send = function () {
|
|
3394
|
-
// loading indicator in Safari < ? (6), Chrome < 14, Firefox
|
|
3395
|
-
// https://bugzilla.mozilla.org/show_bug.cgi?id=736723
|
|
3396
|
-
if ((!("ontimeout" in XMLHttpRequest.prototype) || (!("sendAsBinary" in XMLHttpRequest.prototype) && !("mozAnon" in XMLHttpRequest.prototype))) &&
|
|
3397
|
-
document != undefined &&
|
|
3398
|
-
document.readyState != undefined &&
|
|
3399
|
-
document.readyState !== "complete") {
|
|
3400
|
-
var that = this;
|
|
3401
|
-
that._sendTimeout = setTimeout(function () {
|
|
3402
|
-
that._sendTimeout = 0;
|
|
3403
|
-
that.send();
|
|
3404
|
-
}, 4);
|
|
3405
|
-
return;
|
|
3406
|
-
}
|
|
3407
|
-
|
|
3408
|
-
var xhr = this._xhr;
|
|
3409
|
-
// withCredentials should be set after "open" for Safari and Chrome (< 19 ?)
|
|
3410
|
-
if ("withCredentials" in xhr) {
|
|
3411
|
-
xhr.withCredentials = this.withCredentials;
|
|
3412
|
-
}
|
|
3413
|
-
try {
|
|
3414
|
-
// xhr.send(); throws "Not enough arguments" in Firefox 3.0
|
|
3415
|
-
xhr.send(undefined);
|
|
3416
|
-
} catch (error1) {
|
|
3417
|
-
// Safari 5.1.7, Opera 12
|
|
3418
|
-
throw error1;
|
|
3419
|
-
}
|
|
3420
|
-
};
|
|
3421
|
-
|
|
3422
|
-
function toLowerCase(name) {
|
|
3423
|
-
return name.replace(/[A-Z]/g, function (c) {
|
|
3424
|
-
return String.fromCharCode(c.charCodeAt(0) + 0x20);
|
|
3425
|
-
});
|
|
3426
|
-
}
|
|
3427
|
-
|
|
3428
|
-
function HeadersPolyfill(all) {
|
|
3429
|
-
// Get headers: implemented according to mozilla's example code: https://developer.mozilla.org/en-US/docs/Web/API/XMLHttpRequest/getAllResponseHeaders#Example
|
|
3430
|
-
var map = Object.create(null);
|
|
3431
|
-
var array = all.split("\r\n");
|
|
3432
|
-
for (var i = 0; i < array.length; i += 1) {
|
|
3433
|
-
var line = array[i];
|
|
3434
|
-
var parts = line.split(": ");
|
|
3435
|
-
var name = parts.shift();
|
|
3436
|
-
var value = parts.join(": ");
|
|
3437
|
-
map[toLowerCase(name)] = value;
|
|
3438
|
-
}
|
|
3439
|
-
this._map = map;
|
|
3440
|
-
}
|
|
3441
|
-
HeadersPolyfill.prototype.get = function (name) {
|
|
3442
|
-
return this._map[toLowerCase(name)];
|
|
3443
|
-
};
|
|
3444
|
-
|
|
3445
|
-
if (XMLHttpRequest != null && XMLHttpRequest.HEADERS_RECEIVED == null) { // IE < 9, Firefox 3.6
|
|
3446
|
-
XMLHttpRequest.HEADERS_RECEIVED = 2;
|
|
3447
|
-
}
|
|
3448
|
-
|
|
3449
|
-
function XHRTransport() {
|
|
3450
|
-
}
|
|
3451
|
-
|
|
3452
|
-
XHRTransport.prototype.open = function (xhr, onStartCallback, onProgressCallback, onFinishCallback, url, withCredentials, headers) {
|
|
3453
|
-
xhr.open("GET", url);
|
|
3454
|
-
var offset = 0;
|
|
3455
|
-
xhr.onprogress = function () {
|
|
3456
|
-
var responseText = xhr.responseText;
|
|
3457
|
-
var chunk = responseText.slice(offset);
|
|
3458
|
-
offset += chunk.length;
|
|
3459
|
-
onProgressCallback(chunk);
|
|
3460
|
-
};
|
|
3461
|
-
xhr.onerror = function (event) {
|
|
3462
|
-
event.preventDefault();
|
|
3463
|
-
onFinishCallback(new Error("NetworkError"));
|
|
3464
|
-
};
|
|
3465
|
-
xhr.onload = function () {
|
|
3466
|
-
onFinishCallback(null);
|
|
3467
|
-
};
|
|
3468
|
-
xhr.onabort = function () {
|
|
3469
|
-
onFinishCallback(null);
|
|
3470
|
-
};
|
|
3471
|
-
xhr.onreadystatechange = function () {
|
|
3472
|
-
if (xhr.readyState === XMLHttpRequest.HEADERS_RECEIVED) {
|
|
3473
|
-
var status = xhr.status;
|
|
3474
|
-
var statusText = xhr.statusText;
|
|
3475
|
-
var contentType = xhr.getResponseHeader("Content-Type");
|
|
3476
|
-
var headers = xhr.getAllResponseHeaders();
|
|
3477
|
-
onStartCallback(status, statusText, contentType, new HeadersPolyfill(headers));
|
|
3478
|
-
}
|
|
3479
|
-
};
|
|
3480
|
-
xhr.withCredentials = withCredentials;
|
|
3481
|
-
for (var name in headers) {
|
|
3482
|
-
if (Object.prototype.hasOwnProperty.call(headers, name)) {
|
|
3483
|
-
xhr.setRequestHeader(name, headers[name]);
|
|
3484
|
-
}
|
|
3485
|
-
}
|
|
3486
|
-
xhr.send();
|
|
3487
|
-
return xhr;
|
|
3488
|
-
};
|
|
3489
|
-
|
|
3490
|
-
function HeadersWrapper(headers) {
|
|
3491
|
-
this._headers = headers;
|
|
3492
|
-
}
|
|
3493
|
-
HeadersWrapper.prototype.get = function (name) {
|
|
3494
|
-
return this._headers.get(name);
|
|
3495
|
-
};
|
|
3496
|
-
|
|
3497
|
-
function FetchTransport() {
|
|
3498
|
-
}
|
|
3499
|
-
|
|
3500
|
-
FetchTransport.prototype.open = function (xhr, onStartCallback, onProgressCallback, onFinishCallback, url, withCredentials, headers) {
|
|
3501
|
-
var reader = null;
|
|
3502
|
-
var controller = new AbortController();
|
|
3503
|
-
var signal = controller.signal;
|
|
3504
|
-
var textDecoder = new TextDecoder();
|
|
3505
|
-
fetch(url, {
|
|
3506
|
-
headers: headers,
|
|
3507
|
-
credentials: withCredentials ? "include" : "same-origin",
|
|
3508
|
-
signal: signal,
|
|
3509
|
-
cache: "no-store"
|
|
3510
|
-
}).then(function (response) {
|
|
3511
|
-
reader = response.body.getReader();
|
|
3512
|
-
onStartCallback(response.status, response.statusText, response.headers.get("Content-Type"), new HeadersWrapper(response.headers));
|
|
3513
|
-
// see https://github.com/promises-aplus/promises-spec/issues/179
|
|
3514
|
-
return new Promise(function (resolve, reject) {
|
|
3515
|
-
var readNextChunk = function () {
|
|
3516
|
-
reader.read().then(function (result) {
|
|
3517
|
-
if (result.done) {
|
|
3518
|
-
//Note: bytes in textDecoder are ignored
|
|
3519
|
-
resolve(undefined);
|
|
3520
|
-
} else {
|
|
3521
|
-
var chunk = textDecoder.decode(result.value, {stream: true});
|
|
3522
|
-
onProgressCallback(chunk);
|
|
3523
|
-
readNextChunk();
|
|
3524
|
-
}
|
|
3525
|
-
})["catch"](function (error) {
|
|
3526
|
-
reject(error);
|
|
3527
|
-
});
|
|
3528
|
-
};
|
|
3529
|
-
readNextChunk();
|
|
3530
|
-
});
|
|
3531
|
-
})["catch"](function (error) {
|
|
3532
|
-
if (error.name === "AbortError") {
|
|
3533
|
-
return undefined;
|
|
3534
|
-
} else {
|
|
3535
|
-
return error;
|
|
3536
|
-
}
|
|
3537
|
-
}).then(function (error) {
|
|
3538
|
-
onFinishCallback(error);
|
|
3539
|
-
});
|
|
3540
|
-
return {
|
|
3541
|
-
abort: function () {
|
|
3542
|
-
if (reader != null) {
|
|
3543
|
-
reader.cancel(); // https://bugzilla.mozilla.org/show_bug.cgi?id=1583815
|
|
3544
|
-
}
|
|
3545
|
-
controller.abort();
|
|
3546
|
-
}
|
|
3547
|
-
};
|
|
3548
|
-
};
|
|
3549
|
-
|
|
3550
|
-
function EventTarget() {
|
|
3551
|
-
this._listeners = Object.create(null);
|
|
3552
|
-
}
|
|
3553
|
-
|
|
3554
|
-
function throwError(e) {
|
|
3555
|
-
setTimeout(function () {
|
|
3556
|
-
throw e;
|
|
3557
|
-
}, 0);
|
|
3558
|
-
}
|
|
3559
|
-
|
|
3560
|
-
EventTarget.prototype.dispatchEvent = function (event) {
|
|
3561
|
-
event.target = this;
|
|
3562
|
-
var typeListeners = this._listeners[event.type];
|
|
3563
|
-
if (typeListeners != undefined) {
|
|
3564
|
-
var length = typeListeners.length;
|
|
3565
|
-
for (var i = 0; i < length; i += 1) {
|
|
3566
|
-
var listener = typeListeners[i];
|
|
3567
|
-
try {
|
|
3568
|
-
if (typeof listener.handleEvent === "function") {
|
|
3569
|
-
listener.handleEvent(event);
|
|
3570
|
-
} else {
|
|
3571
|
-
listener.call(this, event);
|
|
3572
|
-
}
|
|
3573
|
-
} catch (e) {
|
|
3574
|
-
throwError(e);
|
|
3575
|
-
}
|
|
3576
|
-
}
|
|
3577
|
-
}
|
|
3578
|
-
};
|
|
3579
|
-
EventTarget.prototype.addEventListener = function (type, listener) {
|
|
3580
|
-
type = String(type);
|
|
3581
|
-
var listeners = this._listeners;
|
|
3582
|
-
var typeListeners = listeners[type];
|
|
3583
|
-
if (typeListeners == undefined) {
|
|
3584
|
-
typeListeners = [];
|
|
3585
|
-
listeners[type] = typeListeners;
|
|
3586
|
-
}
|
|
3587
|
-
var found = false;
|
|
3588
|
-
for (var i = 0; i < typeListeners.length; i += 1) {
|
|
3589
|
-
if (typeListeners[i] === listener) {
|
|
3590
|
-
found = true;
|
|
3591
|
-
}
|
|
3592
|
-
}
|
|
3593
|
-
if (!found) {
|
|
3594
|
-
typeListeners.push(listener);
|
|
3595
|
-
}
|
|
3596
|
-
};
|
|
3597
|
-
EventTarget.prototype.removeEventListener = function (type, listener) {
|
|
3598
|
-
type = String(type);
|
|
3599
|
-
var listeners = this._listeners;
|
|
3600
|
-
var typeListeners = listeners[type];
|
|
3601
|
-
if (typeListeners != undefined) {
|
|
3602
|
-
var filtered = [];
|
|
3603
|
-
for (var i = 0; i < typeListeners.length; i += 1) {
|
|
3604
|
-
if (typeListeners[i] !== listener) {
|
|
3605
|
-
filtered.push(typeListeners[i]);
|
|
3606
|
-
}
|
|
3607
|
-
}
|
|
3608
|
-
if (filtered.length === 0) {
|
|
3609
|
-
delete listeners[type];
|
|
3610
|
-
} else {
|
|
3611
|
-
listeners[type] = filtered;
|
|
3612
|
-
}
|
|
3613
|
-
}
|
|
3614
|
-
};
|
|
3615
|
-
|
|
3616
|
-
function Event(type) {
|
|
3617
|
-
this.type = type;
|
|
3618
|
-
this.target = undefined;
|
|
3619
|
-
}
|
|
3620
|
-
|
|
3621
|
-
function MessageEvent(type, options) {
|
|
3622
|
-
Event.call(this, type);
|
|
3623
|
-
this.data = options.data;
|
|
3624
|
-
this.lastEventId = options.lastEventId;
|
|
3625
|
-
}
|
|
3626
|
-
|
|
3627
|
-
MessageEvent.prototype = Object.create(Event.prototype);
|
|
3628
|
-
|
|
3629
|
-
function ConnectionEvent(type, options) {
|
|
3630
|
-
Event.call(this, type);
|
|
3631
|
-
this.status = options.status;
|
|
3632
|
-
this.statusText = options.statusText;
|
|
3633
|
-
this.headers = options.headers;
|
|
3634
|
-
}
|
|
3635
|
-
|
|
3636
|
-
ConnectionEvent.prototype = Object.create(Event.prototype);
|
|
3637
|
-
|
|
3638
|
-
function ErrorEvent(type, options) {
|
|
3639
|
-
Event.call(this, type);
|
|
3640
|
-
this.error = options.error;
|
|
3641
|
-
}
|
|
3642
|
-
|
|
3643
|
-
ErrorEvent.prototype = Object.create(Event.prototype);
|
|
3644
|
-
|
|
3645
|
-
var WAITING = -1;
|
|
3646
|
-
var CONNECTING = 0;
|
|
3647
|
-
var OPEN = 1;
|
|
3648
|
-
var CLOSED = 2;
|
|
3649
|
-
|
|
3650
|
-
var AFTER_CR = -1;
|
|
3651
|
-
var FIELD_START = 0;
|
|
3652
|
-
var FIELD = 1;
|
|
3653
|
-
var VALUE_START = 2;
|
|
3654
|
-
var VALUE = 3;
|
|
3655
|
-
|
|
3656
|
-
var contentTypeRegExp = /^text\/event\-stream(;.*)?$/i;
|
|
3657
|
-
|
|
3658
|
-
var MINIMUM_DURATION = 1000;
|
|
3659
|
-
var MAXIMUM_DURATION = 18000000;
|
|
3660
|
-
|
|
3661
|
-
var parseDuration = function (value, def) {
|
|
3662
|
-
var n = value == null ? def : parseInt(value, 10);
|
|
3663
|
-
if (n !== n) {
|
|
3664
|
-
n = def;
|
|
3665
|
-
}
|
|
3666
|
-
return clampDuration(n);
|
|
3667
|
-
};
|
|
3668
|
-
var clampDuration = function (n) {
|
|
3669
|
-
return Math.min(Math.max(n, MINIMUM_DURATION), MAXIMUM_DURATION);
|
|
3670
|
-
};
|
|
3671
|
-
|
|
3672
|
-
var fire = function (that, f, event) {
|
|
3673
|
-
try {
|
|
3674
|
-
if (typeof f === "function") {
|
|
3675
|
-
f.call(that, event);
|
|
3676
|
-
}
|
|
3677
|
-
} catch (e) {
|
|
3678
|
-
throwError(e);
|
|
3679
|
-
}
|
|
3680
|
-
};
|
|
3681
|
-
|
|
3682
|
-
function EventSourcePolyfill(url, options) {
|
|
3683
|
-
EventTarget.call(this);
|
|
3684
|
-
options = options || {};
|
|
3685
|
-
|
|
3686
|
-
this.onopen = undefined;
|
|
3687
|
-
this.onmessage = undefined;
|
|
3688
|
-
this.onerror = undefined;
|
|
3689
|
-
|
|
3690
|
-
this.url = undefined;
|
|
3691
|
-
this.readyState = undefined;
|
|
3692
|
-
this.withCredentials = undefined;
|
|
3693
|
-
this.headers = undefined;
|
|
3694
|
-
|
|
3695
|
-
this._close = undefined;
|
|
3696
|
-
|
|
3697
|
-
start(this, url, options);
|
|
3698
|
-
}
|
|
3699
|
-
|
|
3700
|
-
function getBestXHRTransport() {
|
|
3701
|
-
return (XMLHttpRequest != undefined && ("withCredentials" in XMLHttpRequest.prototype)) || XDomainRequest == undefined
|
|
3702
|
-
? new XMLHttpRequest()
|
|
3703
|
-
: new XDomainRequest();
|
|
3704
|
-
}
|
|
3705
|
-
|
|
3706
|
-
var isFetchSupported = fetch != undefined && Response != undefined && "body" in Response.prototype;
|
|
3707
|
-
|
|
3708
|
-
function start(es, url, options) {
|
|
3709
|
-
url = String(url);
|
|
3710
|
-
var withCredentials = Boolean(options.withCredentials);
|
|
3711
|
-
var lastEventIdQueryParameterName = options.lastEventIdQueryParameterName || "lastEventId";
|
|
3712
|
-
|
|
3713
|
-
var initialRetry = clampDuration(1000);
|
|
3714
|
-
var heartbeatTimeout = parseDuration(options.heartbeatTimeout, 45000);
|
|
3715
|
-
|
|
3716
|
-
var lastEventId = "";
|
|
3717
|
-
var retry = initialRetry;
|
|
3718
|
-
var wasActivity = false;
|
|
3719
|
-
var textLength = 0;
|
|
3720
|
-
var headers = options.headers || {};
|
|
3721
|
-
var TransportOption = options.Transport;
|
|
3722
|
-
var xhr = isFetchSupported && TransportOption == undefined ? undefined : new XHRWrapper(TransportOption != undefined ? new TransportOption() : getBestXHRTransport());
|
|
3723
|
-
var transport = TransportOption != null && typeof TransportOption !== "string" ? new TransportOption() : (xhr == undefined ? new FetchTransport() : new XHRTransport());
|
|
3724
|
-
var abortController = undefined;
|
|
3725
|
-
var timeout = 0;
|
|
3726
|
-
var currentState = WAITING;
|
|
3727
|
-
var dataBuffer = "";
|
|
3728
|
-
var lastEventIdBuffer = "";
|
|
3729
|
-
var eventTypeBuffer = "";
|
|
3730
|
-
|
|
3731
|
-
var textBuffer = "";
|
|
3732
|
-
var state = FIELD_START;
|
|
3733
|
-
var fieldStart = 0;
|
|
3734
|
-
var valueStart = 0;
|
|
3735
|
-
|
|
3736
|
-
var onStart = function (status, statusText, contentType, headers) {
|
|
3737
|
-
if (currentState === CONNECTING) {
|
|
3738
|
-
if (status === 200 && contentType != undefined && contentTypeRegExp.test(contentType)) {
|
|
3739
|
-
currentState = OPEN;
|
|
3740
|
-
wasActivity = Date.now();
|
|
3741
|
-
retry = initialRetry;
|
|
3742
|
-
es.readyState = OPEN;
|
|
3743
|
-
var event = new ConnectionEvent("open", {
|
|
3744
|
-
status: status,
|
|
3745
|
-
statusText: statusText,
|
|
3746
|
-
headers: headers
|
|
3747
|
-
});
|
|
3748
|
-
es.dispatchEvent(event);
|
|
3749
|
-
fire(es, es.onopen, event);
|
|
3750
|
-
} else {
|
|
3751
|
-
var message = "";
|
|
3752
|
-
if (status !== 200) {
|
|
3753
|
-
if (statusText) {
|
|
3754
|
-
statusText = statusText.replace(/\s+/g, " ");
|
|
3755
|
-
}
|
|
3756
|
-
message = "EventSource's response has a status " + status + " " + statusText + " that is not 200. Aborting the connection.";
|
|
3757
|
-
} else {
|
|
3758
|
-
message = "EventSource's response has a Content-Type specifying an unsupported type: " + (contentType == undefined ? "-" : contentType.replace(/\s+/g, " ")) + ". Aborting the connection.";
|
|
3759
|
-
}
|
|
3760
|
-
close();
|
|
3761
|
-
var event = new ConnectionEvent("error", {
|
|
3762
|
-
status: status,
|
|
3763
|
-
statusText: statusText,
|
|
3764
|
-
headers: headers
|
|
3765
|
-
});
|
|
3766
|
-
es.dispatchEvent(event);
|
|
3767
|
-
fire(es, es.onerror, event);
|
|
3768
|
-
console.error(message);
|
|
3769
|
-
}
|
|
3770
|
-
}
|
|
3771
|
-
};
|
|
3772
|
-
|
|
3773
|
-
var onProgress = function (textChunk) {
|
|
3774
|
-
if (currentState === OPEN) {
|
|
3775
|
-
var n = -1;
|
|
3776
|
-
for (var i = 0; i < textChunk.length; i += 1) {
|
|
3777
|
-
var c = textChunk.charCodeAt(i);
|
|
3778
|
-
if (c === "\n".charCodeAt(0) || c === "\r".charCodeAt(0)) {
|
|
3779
|
-
n = i;
|
|
3780
|
-
}
|
|
3781
|
-
}
|
|
3782
|
-
var chunk = (n !== -1 ? textBuffer : "") + textChunk.slice(0, n + 1);
|
|
3783
|
-
textBuffer = (n === -1 ? textBuffer : "") + textChunk.slice(n + 1);
|
|
3784
|
-
if (textChunk !== "") {
|
|
3785
|
-
wasActivity = Date.now();
|
|
3786
|
-
textLength += textChunk.length;
|
|
3787
|
-
}
|
|
3788
|
-
for (var position = 0; position < chunk.length; position += 1) {
|
|
3789
|
-
var c = chunk.charCodeAt(position);
|
|
3790
|
-
if (state === AFTER_CR && c === "\n".charCodeAt(0)) {
|
|
3791
|
-
state = FIELD_START;
|
|
3792
|
-
} else {
|
|
3793
|
-
if (state === AFTER_CR) {
|
|
3794
|
-
state = FIELD_START;
|
|
3795
|
-
}
|
|
3796
|
-
if (c === "\r".charCodeAt(0) || c === "\n".charCodeAt(0)) {
|
|
3797
|
-
if (state !== FIELD_START) {
|
|
3798
|
-
if (state === FIELD) {
|
|
3799
|
-
valueStart = position + 1;
|
|
3800
|
-
}
|
|
3801
|
-
var field = chunk.slice(fieldStart, valueStart - 1);
|
|
3802
|
-
var value = chunk.slice(valueStart + (valueStart < position && chunk.charCodeAt(valueStart) === " ".charCodeAt(0) ? 1 : 0), position);
|
|
3803
|
-
if (field === "data") {
|
|
3804
|
-
dataBuffer += "\n";
|
|
3805
|
-
dataBuffer += value;
|
|
3806
|
-
} else if (field === "id") {
|
|
3807
|
-
lastEventIdBuffer = value;
|
|
3808
|
-
} else if (field === "event") {
|
|
3809
|
-
eventTypeBuffer = value;
|
|
3810
|
-
} else if (field === "retry") {
|
|
3811
|
-
initialRetry = parseDuration(value, initialRetry);
|
|
3812
|
-
retry = initialRetry;
|
|
3813
|
-
} else if (field === "heartbeatTimeout") {
|
|
3814
|
-
heartbeatTimeout = parseDuration(value, heartbeatTimeout);
|
|
3815
|
-
if (timeout !== 0) {
|
|
3816
|
-
clearTimeout(timeout);
|
|
3817
|
-
timeout = setTimeout(function () {
|
|
3818
|
-
onTimeout();
|
|
3819
|
-
}, heartbeatTimeout);
|
|
3820
|
-
}
|
|
3821
|
-
}
|
|
3822
|
-
}
|
|
3823
|
-
if (state === FIELD_START) {
|
|
3824
|
-
if (dataBuffer !== "") {
|
|
3825
|
-
lastEventId = lastEventIdBuffer;
|
|
3826
|
-
if (eventTypeBuffer === "") {
|
|
3827
|
-
eventTypeBuffer = "message";
|
|
3828
|
-
}
|
|
3829
|
-
var event = new MessageEvent(eventTypeBuffer, {
|
|
3830
|
-
data: dataBuffer.slice(1),
|
|
3831
|
-
lastEventId: lastEventIdBuffer
|
|
3832
|
-
});
|
|
3833
|
-
es.dispatchEvent(event);
|
|
3834
|
-
if (eventTypeBuffer === "open") {
|
|
3835
|
-
fire(es, es.onopen, event);
|
|
3836
|
-
} else if (eventTypeBuffer === "message") {
|
|
3837
|
-
fire(es, es.onmessage, event);
|
|
3838
|
-
} else if (eventTypeBuffer === "error") {
|
|
3839
|
-
fire(es, es.onerror, event);
|
|
3840
|
-
}
|
|
3841
|
-
if (currentState === CLOSED) {
|
|
3842
|
-
return;
|
|
3843
|
-
}
|
|
3844
|
-
}
|
|
3845
|
-
dataBuffer = "";
|
|
3846
|
-
eventTypeBuffer = "";
|
|
3847
|
-
}
|
|
3848
|
-
state = c === "\r".charCodeAt(0) ? AFTER_CR : FIELD_START;
|
|
3849
|
-
} else {
|
|
3850
|
-
if (state === FIELD_START) {
|
|
3851
|
-
fieldStart = position;
|
|
3852
|
-
state = FIELD;
|
|
3853
|
-
}
|
|
3854
|
-
if (state === FIELD) {
|
|
3855
|
-
if (c === ":".charCodeAt(0)) {
|
|
3856
|
-
valueStart = position + 1;
|
|
3857
|
-
state = VALUE_START;
|
|
3858
|
-
}
|
|
3859
|
-
} else if (state === VALUE_START) {
|
|
3860
|
-
state = VALUE;
|
|
3861
|
-
}
|
|
3862
|
-
}
|
|
3863
|
-
}
|
|
3864
|
-
}
|
|
3865
|
-
}
|
|
3866
|
-
};
|
|
3867
|
-
|
|
3868
|
-
var onFinish = function (error) {
|
|
3869
|
-
if (currentState === OPEN || currentState === CONNECTING) {
|
|
3870
|
-
currentState = WAITING;
|
|
3871
|
-
if (timeout !== 0) {
|
|
3872
|
-
clearTimeout(timeout);
|
|
3873
|
-
timeout = 0;
|
|
3874
|
-
}
|
|
3875
|
-
timeout = setTimeout(function () {
|
|
3876
|
-
onTimeout();
|
|
3877
|
-
}, retry);
|
|
3878
|
-
retry = clampDuration(Math.min(initialRetry * 16, retry * 2));
|
|
3879
|
-
|
|
3880
|
-
es.readyState = CONNECTING;
|
|
3881
|
-
var event = new ErrorEvent("error", {error: error});
|
|
3882
|
-
es.dispatchEvent(event);
|
|
3883
|
-
fire(es, es.onerror, event);
|
|
3884
|
-
if (error != undefined) {
|
|
3885
|
-
console.error(error);
|
|
3886
|
-
}
|
|
3887
|
-
}
|
|
3888
|
-
};
|
|
3889
|
-
|
|
3890
|
-
var close = function () {
|
|
3891
|
-
currentState = CLOSED;
|
|
3892
|
-
if (abortController != undefined) {
|
|
3893
|
-
abortController.abort();
|
|
3894
|
-
abortController = undefined;
|
|
3895
|
-
}
|
|
3896
|
-
if (timeout !== 0) {
|
|
3897
|
-
clearTimeout(timeout);
|
|
3898
|
-
timeout = 0;
|
|
3899
|
-
}
|
|
3900
|
-
es.readyState = CLOSED;
|
|
3901
|
-
};
|
|
3902
|
-
|
|
3903
|
-
var onTimeout = function () {
|
|
3904
|
-
timeout = 0;
|
|
3905
|
-
|
|
3906
|
-
if (currentState !== WAITING) {
|
|
3907
|
-
if (!wasActivity && abortController != undefined) {
|
|
3908
|
-
onFinish(new Error("No activity within " + heartbeatTimeout + " milliseconds." + " " + (currentState === CONNECTING ? "No response received." : textLength + " chars received.") + " " + "Reconnecting."));
|
|
3909
|
-
if (abortController != undefined) {
|
|
3910
|
-
abortController.abort();
|
|
3911
|
-
abortController = undefined;
|
|
3912
|
-
}
|
|
3913
|
-
} else {
|
|
3914
|
-
var nextHeartbeat = Math.max((wasActivity || Date.now()) + heartbeatTimeout - Date.now(), 1);
|
|
3915
|
-
wasActivity = false;
|
|
3916
|
-
timeout = setTimeout(function () {
|
|
3917
|
-
onTimeout();
|
|
3918
|
-
}, nextHeartbeat);
|
|
3919
|
-
}
|
|
3920
|
-
return;
|
|
3921
|
-
}
|
|
3922
|
-
|
|
3923
|
-
wasActivity = false;
|
|
3924
|
-
textLength = 0;
|
|
3925
|
-
timeout = setTimeout(function () {
|
|
3926
|
-
onTimeout();
|
|
3927
|
-
}, heartbeatTimeout);
|
|
3928
|
-
|
|
3929
|
-
currentState = CONNECTING;
|
|
3930
|
-
dataBuffer = "";
|
|
3931
|
-
eventTypeBuffer = "";
|
|
3932
|
-
lastEventIdBuffer = lastEventId;
|
|
3933
|
-
textBuffer = "";
|
|
3934
|
-
fieldStart = 0;
|
|
3935
|
-
valueStart = 0;
|
|
3936
|
-
state = FIELD_START;
|
|
3937
|
-
|
|
3938
|
-
// https://bugzilla.mozilla.org/show_bug.cgi?id=428916
|
|
3939
|
-
// Request header field Last-Event-ID is not allowed by Access-Control-Allow-Headers.
|
|
3940
|
-
var requestURL = url;
|
|
3941
|
-
if (url.slice(0, 5) !== "data:" && url.slice(0, 5) !== "blob:") {
|
|
3942
|
-
if (lastEventId !== "") {
|
|
3943
|
-
// Remove the lastEventId parameter if it's already part of the request URL.
|
|
3944
|
-
var i = url.indexOf("?");
|
|
3945
|
-
requestURL = i === -1 ? url : url.slice(0, i + 1) + url.slice(i + 1).replace(/(?:^|&)([^=&]*)(?:=[^&]*)?/g, function (p, paramName) {
|
|
3946
|
-
return paramName === lastEventIdQueryParameterName ? '' : p;
|
|
3947
|
-
});
|
|
3948
|
-
// Append the current lastEventId to the request URL.
|
|
3949
|
-
requestURL += (url.indexOf("?") === -1 ? "?" : "&") + lastEventIdQueryParameterName +"=" + encodeURIComponent(lastEventId);
|
|
3950
|
-
}
|
|
3951
|
-
}
|
|
3952
|
-
var withCredentials = es.withCredentials;
|
|
3953
|
-
var requestHeaders = {};
|
|
3954
|
-
requestHeaders["Accept"] = "text/event-stream";
|
|
3955
|
-
var headers = es.headers;
|
|
3956
|
-
if (headers != undefined) {
|
|
3957
|
-
for (var name in headers) {
|
|
3958
|
-
if (Object.prototype.hasOwnProperty.call(headers, name)) {
|
|
3959
|
-
requestHeaders[name] = headers[name];
|
|
3960
|
-
}
|
|
3961
|
-
}
|
|
3962
|
-
}
|
|
3963
|
-
try {
|
|
3964
|
-
abortController = transport.open(xhr, onStart, onProgress, onFinish, requestURL, withCredentials, requestHeaders);
|
|
3965
|
-
} catch (error) {
|
|
3966
|
-
close();
|
|
3967
|
-
throw error;
|
|
3968
|
-
}
|
|
3969
|
-
};
|
|
3970
|
-
|
|
3971
|
-
es.url = url;
|
|
3972
|
-
es.readyState = CONNECTING;
|
|
3973
|
-
es.withCredentials = withCredentials;
|
|
3974
|
-
es.headers = headers;
|
|
3975
|
-
es._close = close;
|
|
3976
|
-
|
|
3977
|
-
onTimeout();
|
|
3978
|
-
}
|
|
3979
|
-
|
|
3980
|
-
EventSourcePolyfill.prototype = Object.create(EventTarget.prototype);
|
|
3981
|
-
EventSourcePolyfill.prototype.CONNECTING = CONNECTING;
|
|
3982
|
-
EventSourcePolyfill.prototype.OPEN = OPEN;
|
|
3983
|
-
EventSourcePolyfill.prototype.CLOSED = CLOSED;
|
|
3984
|
-
EventSourcePolyfill.prototype.close = function () {
|
|
3985
|
-
this._close();
|
|
3986
|
-
};
|
|
3987
|
-
|
|
3988
|
-
EventSourcePolyfill.CONNECTING = CONNECTING;
|
|
3989
|
-
EventSourcePolyfill.OPEN = OPEN;
|
|
3990
|
-
EventSourcePolyfill.CLOSED = CLOSED;
|
|
3991
|
-
EventSourcePolyfill.prototype.withCredentials = undefined;
|
|
3992
|
-
|
|
3993
|
-
var R = NativeEventSource;
|
|
3994
|
-
if (XMLHttpRequest != undefined && (NativeEventSource == undefined || !("withCredentials" in NativeEventSource.prototype))) {
|
|
3995
|
-
// Why replace a native EventSource ?
|
|
3996
|
-
// https://bugzilla.mozilla.org/show_bug.cgi?id=444328
|
|
3997
|
-
// https://bugzilla.mozilla.org/show_bug.cgi?id=831392
|
|
3998
|
-
// https://code.google.com/p/chromium/issues/detail?id=260144
|
|
3999
|
-
// https://code.google.com/p/chromium/issues/detail?id=225654
|
|
4000
|
-
// ...
|
|
4001
|
-
R = EventSourcePolyfill;
|
|
4002
|
-
}
|
|
4003
|
-
|
|
4004
|
-
(function (factory) {
|
|
4005
|
-
{
|
|
4006
|
-
var v = factory(exports);
|
|
4007
|
-
if (v !== undefined) module.exports = v;
|
|
4008
|
-
}
|
|
4009
|
-
})(function (exports) {
|
|
4010
|
-
exports.EventSourcePolyfill = EventSourcePolyfill;
|
|
4011
|
-
exports.NativeEventSource = NativeEventSource;
|
|
4012
|
-
exports.EventSource = R;
|
|
4013
|
-
});
|
|
4014
|
-
}(typeof globalThis === 'undefined' ? (typeof window !== 'undefined' ? window : typeof self !== 'undefined' ? self : eventsource) : globalThis));
|
|
4015
|
-
} (eventsource$1, eventsource$1.exports));
|
|
4016
|
-
return eventsource$1.exports;
|
|
4017
|
-
}
|
|
4018
|
-
|
|
4019
|
-
var browser$2;
|
|
4020
|
-
var hasRequiredBrowser;
|
|
4021
|
-
|
|
4022
|
-
function requireBrowser () {
|
|
4023
|
-
if (hasRequiredBrowser) return browser$2;
|
|
4024
|
-
hasRequiredBrowser = 1;
|
|
4025
|
-
browser$2 = requireEventsource().EventSourcePolyfill;
|
|
4026
|
-
return browser$2;
|
|
4027
|
-
}
|
|
4028
|
-
|
|
4029
|
-
var browserExports = /*@__PURE__*/ requireBrowser();
|
|
4030
|
-
var browser = /*@__PURE__*/getDefaultExportFromCjs(browserExports);
|
|
4031
|
-
|
|
4032
|
-
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({
|
|
4033
3265
|
__proto__: null,
|
|
4034
|
-
|
|
3266
|
+
ErrorEvent: ErrorEvent,
|
|
3267
|
+
EventSource: EventSource$1
|
|
4035
3268
|
});
|
|
4036
3269
|
|
|
4037
3270
|
exports.BasePatch = BasePatch;
|