scratch-storage 5.0.11 → 6.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (37) hide show
  1. package/.github/workflows/ci-cd.yml +10 -3
  2. package/dist/node/chunks/fetch-worker.7afe4ade866d6f6a3cb3.js +383 -0
  3. package/dist/node/chunks/fetch-worker.7afe4ade866d6f6a3cb3.js.map +1 -0
  4. package/dist/node/scratch-storage.js +316 -821
  5. package/dist/node/scratch-storage.js.map +1 -1
  6. package/dist/types/HostQueues.d.ts +20 -0
  7. package/dist/types/ScratchStorage.d.ts +2 -15
  8. package/dist/types/scratchFetch.d.ts +37 -15
  9. package/dist/web/chunks/fetch-worker.9fbe108071a9c5d6e70b.js +2 -0
  10. package/dist/web/chunks/{fetch-worker.4277f33a97fe995aa7dd.js.map → fetch-worker.9fbe108071a9c5d6e70b.js.map} +1 -1
  11. package/dist/web/chunks/fetch-worker.efebf27d479ab0f0d98c.js +394 -0
  12. package/dist/web/chunks/fetch-worker.efebf27d479ab0f0d98c.js.map +1 -0
  13. package/dist/web/scratch-storage.js +316 -821
  14. package/dist/web/scratch-storage.js.map +1 -1
  15. package/dist/web/scratch-storage.min.js +1 -1
  16. package/package.json +7 -5
  17. package/src/FetchTool.ts +3 -2
  18. package/src/FetchWorkerTool.worker.ts +94 -0
  19. package/src/HostQueues.ts +33 -0
  20. package/src/ScratchStorage.ts +1 -1
  21. package/src/{scratchFetch.js → scratchFetch.ts} +53 -34
  22. package/src/types.d.ts +4 -3
  23. package/test/build/api.test.js +60 -0
  24. package/test/build/scratchFetch.test.js +40 -0
  25. package/test/fixtures/known-assets.js +30 -2
  26. package/test/{__mocks__/cross-fetch.js → fixtures/mockFetch.js} +18 -17
  27. package/test/integration/download-known-assets.test.js +6 -3
  28. package/test/unit/fetch-tool.test.js +8 -7
  29. package/test/unit/metadata.test.js +9 -8
  30. package/tsconfig.json +0 -1
  31. package/tsconfig.test.json +1 -0
  32. package/dist/node/chunks/fetch-worker.56da39b0f4bad6747138.js +0 -809
  33. package/dist/node/chunks/fetch-worker.56da39b0f4bad6747138.js.map +0 -1
  34. package/dist/web/chunks/fetch-worker.4277f33a97fe995aa7dd.js +0 -2
  35. package/dist/web/chunks/fetch-worker.c813c32be403f91001ba.js +0 -820
  36. package/dist/web/chunks/fetch-worker.c813c32be403f91001ba.js.map +0 -1
  37. package/src/FetchWorkerTool.worker.js +0 -67
@@ -1,820 +0,0 @@
1
- (function webpackUniversalModuleDefinition(root, factory) {
2
- if(typeof exports === 'object' && typeof module === 'object')
3
- module.exports = factory();
4
- else if(typeof define === 'function' && define.amd)
5
- define([], factory);
6
- else if(typeof exports === 'object')
7
- exports["ScratchStorage"] = factory();
8
- else
9
- root["ScratchStorage"] = factory();
10
- })(self, () => {
11
- return /******/ (() => { // webpackBootstrap
12
- /******/ var __webpack_modules__ = ({
13
-
14
- /***/ 945
15
- (module, exports, __webpack_require__) {
16
-
17
- // Save global object in a variable
18
- var __global__ =
19
- (typeof globalThis !== 'undefined' && globalThis) ||
20
- (typeof self !== 'undefined' && self) ||
21
- (typeof __webpack_require__.g !== 'undefined' && __webpack_require__.g);
22
- // Create an object that extends from __global__ without the fetch function
23
- var __globalThis__ = (function () {
24
- function F() {
25
- this.fetch = false;
26
- this.DOMException = __global__.DOMException
27
- }
28
- F.prototype = __global__; // Needed for feature detection on whatwg-fetch's code
29
- return new F();
30
- })();
31
- // Wraps whatwg-fetch with a function scope to hijack the global object
32
- // "globalThis" that's going to be patched
33
- (function(globalThis) {
34
-
35
- var irrelevant = (function (exports) {
36
-
37
- /* eslint-disable no-prototype-builtins */
38
- var g =
39
- (typeof globalThis !== 'undefined' && globalThis) ||
40
- (typeof self !== 'undefined' && self) ||
41
- // eslint-disable-next-line no-undef
42
- (typeof __webpack_require__.g !== 'undefined' && __webpack_require__.g) ||
43
- {};
44
-
45
- var support = {
46
- searchParams: 'URLSearchParams' in g,
47
- iterable: 'Symbol' in g && 'iterator' in Symbol,
48
- blob:
49
- 'FileReader' in g &&
50
- 'Blob' in g &&
51
- (function() {
52
- try {
53
- new Blob();
54
- return true
55
- } catch (e) {
56
- return false
57
- }
58
- })(),
59
- formData: 'FormData' in g,
60
- arrayBuffer: 'ArrayBuffer' in g
61
- };
62
-
63
- function isDataView(obj) {
64
- return obj && DataView.prototype.isPrototypeOf(obj)
65
- }
66
-
67
- if (support.arrayBuffer) {
68
- var viewClasses = [
69
- '[object Int8Array]',
70
- '[object Uint8Array]',
71
- '[object Uint8ClampedArray]',
72
- '[object Int16Array]',
73
- '[object Uint16Array]',
74
- '[object Int32Array]',
75
- '[object Uint32Array]',
76
- '[object Float32Array]',
77
- '[object Float64Array]'
78
- ];
79
-
80
- var isArrayBufferView =
81
- ArrayBuffer.isView ||
82
- function(obj) {
83
- return obj && viewClasses.indexOf(Object.prototype.toString.call(obj)) > -1
84
- };
85
- }
86
-
87
- function normalizeName(name) {
88
- if (typeof name !== 'string') {
89
- name = String(name);
90
- }
91
- if (/[^a-z0-9\-#$%&'*+.^_`|~!]/i.test(name) || name === '') {
92
- throw new TypeError('Invalid character in header field name: "' + name + '"')
93
- }
94
- return name.toLowerCase()
95
- }
96
-
97
- function normalizeValue(value) {
98
- if (typeof value !== 'string') {
99
- value = String(value);
100
- }
101
- return value
102
- }
103
-
104
- // Build a destructive iterator for the value list
105
- function iteratorFor(items) {
106
- var iterator = {
107
- next: function() {
108
- var value = items.shift();
109
- return {done: value === undefined, value: value}
110
- }
111
- };
112
-
113
- if (support.iterable) {
114
- iterator[Symbol.iterator] = function() {
115
- return iterator
116
- };
117
- }
118
-
119
- return iterator
120
- }
121
-
122
- function Headers(headers) {
123
- this.map = {};
124
-
125
- if (headers instanceof Headers) {
126
- headers.forEach(function(value, name) {
127
- this.append(name, value);
128
- }, this);
129
- } else if (Array.isArray(headers)) {
130
- headers.forEach(function(header) {
131
- if (header.length != 2) {
132
- throw new TypeError('Headers constructor: expected name/value pair to be length 2, found' + header.length)
133
- }
134
- this.append(header[0], header[1]);
135
- }, this);
136
- } else if (headers) {
137
- Object.getOwnPropertyNames(headers).forEach(function(name) {
138
- this.append(name, headers[name]);
139
- }, this);
140
- }
141
- }
142
-
143
- Headers.prototype.append = function(name, value) {
144
- name = normalizeName(name);
145
- value = normalizeValue(value);
146
- var oldValue = this.map[name];
147
- this.map[name] = oldValue ? oldValue + ', ' + value : value;
148
- };
149
-
150
- Headers.prototype['delete'] = function(name) {
151
- delete this.map[normalizeName(name)];
152
- };
153
-
154
- Headers.prototype.get = function(name) {
155
- name = normalizeName(name);
156
- return this.has(name) ? this.map[name] : null
157
- };
158
-
159
- Headers.prototype.has = function(name) {
160
- return this.map.hasOwnProperty(normalizeName(name))
161
- };
162
-
163
- Headers.prototype.set = function(name, value) {
164
- this.map[normalizeName(name)] = normalizeValue(value);
165
- };
166
-
167
- Headers.prototype.forEach = function(callback, thisArg) {
168
- for (var name in this.map) {
169
- if (this.map.hasOwnProperty(name)) {
170
- callback.call(thisArg, this.map[name], name, this);
171
- }
172
- }
173
- };
174
-
175
- Headers.prototype.keys = function() {
176
- var items = [];
177
- this.forEach(function(value, name) {
178
- items.push(name);
179
- });
180
- return iteratorFor(items)
181
- };
182
-
183
- Headers.prototype.values = function() {
184
- var items = [];
185
- this.forEach(function(value) {
186
- items.push(value);
187
- });
188
- return iteratorFor(items)
189
- };
190
-
191
- Headers.prototype.entries = function() {
192
- var items = [];
193
- this.forEach(function(value, name) {
194
- items.push([name, value]);
195
- });
196
- return iteratorFor(items)
197
- };
198
-
199
- if (support.iterable) {
200
- Headers.prototype[Symbol.iterator] = Headers.prototype.entries;
201
- }
202
-
203
- function consumed(body) {
204
- if (body._noBody) return
205
- if (body.bodyUsed) {
206
- return Promise.reject(new TypeError('Already read'))
207
- }
208
- body.bodyUsed = true;
209
- }
210
-
211
- function fileReaderReady(reader) {
212
- return new Promise(function(resolve, reject) {
213
- reader.onload = function() {
214
- resolve(reader.result);
215
- };
216
- reader.onerror = function() {
217
- reject(reader.error);
218
- };
219
- })
220
- }
221
-
222
- function readBlobAsArrayBuffer(blob) {
223
- var reader = new FileReader();
224
- var promise = fileReaderReady(reader);
225
- reader.readAsArrayBuffer(blob);
226
- return promise
227
- }
228
-
229
- function readBlobAsText(blob) {
230
- var reader = new FileReader();
231
- var promise = fileReaderReady(reader);
232
- var match = /charset=([A-Za-z0-9_-]+)/.exec(blob.type);
233
- var encoding = match ? match[1] : 'utf-8';
234
- reader.readAsText(blob, encoding);
235
- return promise
236
- }
237
-
238
- function readArrayBufferAsText(buf) {
239
- var view = new Uint8Array(buf);
240
- var chars = new Array(view.length);
241
-
242
- for (var i = 0; i < view.length; i++) {
243
- chars[i] = String.fromCharCode(view[i]);
244
- }
245
- return chars.join('')
246
- }
247
-
248
- function bufferClone(buf) {
249
- if (buf.slice) {
250
- return buf.slice(0)
251
- } else {
252
- var view = new Uint8Array(buf.byteLength);
253
- view.set(new Uint8Array(buf));
254
- return view.buffer
255
- }
256
- }
257
-
258
- function Body() {
259
- this.bodyUsed = false;
260
-
261
- this._initBody = function(body) {
262
- /*
263
- fetch-mock wraps the Response object in an ES6 Proxy to
264
- provide useful test harness features such as flush. However, on
265
- ES5 browsers without fetch or Proxy support pollyfills must be used;
266
- the proxy-pollyfill is unable to proxy an attribute unless it exists
267
- on the object before the Proxy is created. This change ensures
268
- Response.bodyUsed exists on the instance, while maintaining the
269
- semantic of setting Request.bodyUsed in the constructor before
270
- _initBody is called.
271
- */
272
- // eslint-disable-next-line no-self-assign
273
- this.bodyUsed = this.bodyUsed;
274
- this._bodyInit = body;
275
- if (!body) {
276
- this._noBody = true;
277
- this._bodyText = '';
278
- } else if (typeof body === 'string') {
279
- this._bodyText = body;
280
- } else if (support.blob && Blob.prototype.isPrototypeOf(body)) {
281
- this._bodyBlob = body;
282
- } else if (support.formData && FormData.prototype.isPrototypeOf(body)) {
283
- this._bodyFormData = body;
284
- } else if (support.searchParams && URLSearchParams.prototype.isPrototypeOf(body)) {
285
- this._bodyText = body.toString();
286
- } else if (support.arrayBuffer && support.blob && isDataView(body)) {
287
- this._bodyArrayBuffer = bufferClone(body.buffer);
288
- // IE 10-11 can't handle a DataView body.
289
- this._bodyInit = new Blob([this._bodyArrayBuffer]);
290
- } else if (support.arrayBuffer && (ArrayBuffer.prototype.isPrototypeOf(body) || isArrayBufferView(body))) {
291
- this._bodyArrayBuffer = bufferClone(body);
292
- } else {
293
- this._bodyText = body = Object.prototype.toString.call(body);
294
- }
295
-
296
- if (!this.headers.get('content-type')) {
297
- if (typeof body === 'string') {
298
- this.headers.set('content-type', 'text/plain;charset=UTF-8');
299
- } else if (this._bodyBlob && this._bodyBlob.type) {
300
- this.headers.set('content-type', this._bodyBlob.type);
301
- } else if (support.searchParams && URLSearchParams.prototype.isPrototypeOf(body)) {
302
- this.headers.set('content-type', 'application/x-www-form-urlencoded;charset=UTF-8');
303
- }
304
- }
305
- };
306
-
307
- if (support.blob) {
308
- this.blob = function() {
309
- var rejected = consumed(this);
310
- if (rejected) {
311
- return rejected
312
- }
313
-
314
- if (this._bodyBlob) {
315
- return Promise.resolve(this._bodyBlob)
316
- } else if (this._bodyArrayBuffer) {
317
- return Promise.resolve(new Blob([this._bodyArrayBuffer]))
318
- } else if (this._bodyFormData) {
319
- throw new Error('could not read FormData body as blob')
320
- } else {
321
- return Promise.resolve(new Blob([this._bodyText]))
322
- }
323
- };
324
- }
325
-
326
- this.arrayBuffer = function() {
327
- if (this._bodyArrayBuffer) {
328
- var isConsumed = consumed(this);
329
- if (isConsumed) {
330
- return isConsumed
331
- } else if (ArrayBuffer.isView(this._bodyArrayBuffer)) {
332
- return Promise.resolve(
333
- this._bodyArrayBuffer.buffer.slice(
334
- this._bodyArrayBuffer.byteOffset,
335
- this._bodyArrayBuffer.byteOffset + this._bodyArrayBuffer.byteLength
336
- )
337
- )
338
- } else {
339
- return Promise.resolve(this._bodyArrayBuffer)
340
- }
341
- } else if (support.blob) {
342
- return this.blob().then(readBlobAsArrayBuffer)
343
- } else {
344
- throw new Error('could not read as ArrayBuffer')
345
- }
346
- };
347
-
348
- this.text = function() {
349
- var rejected = consumed(this);
350
- if (rejected) {
351
- return rejected
352
- }
353
-
354
- if (this._bodyBlob) {
355
- return readBlobAsText(this._bodyBlob)
356
- } else if (this._bodyArrayBuffer) {
357
- return Promise.resolve(readArrayBufferAsText(this._bodyArrayBuffer))
358
- } else if (this._bodyFormData) {
359
- throw new Error('could not read FormData body as text')
360
- } else {
361
- return Promise.resolve(this._bodyText)
362
- }
363
- };
364
-
365
- if (support.formData) {
366
- this.formData = function() {
367
- return this.text().then(decode)
368
- };
369
- }
370
-
371
- this.json = function() {
372
- return this.text().then(JSON.parse)
373
- };
374
-
375
- return this
376
- }
377
-
378
- // HTTP methods whose capitalization should be normalized
379
- var methods = ['CONNECT', 'DELETE', 'GET', 'HEAD', 'OPTIONS', 'PATCH', 'POST', 'PUT', 'TRACE'];
380
-
381
- function normalizeMethod(method) {
382
- var upcased = method.toUpperCase();
383
- return methods.indexOf(upcased) > -1 ? upcased : method
384
- }
385
-
386
- function Request(input, options) {
387
- if (!(this instanceof Request)) {
388
- throw new TypeError('Please use the "new" operator, this DOM object constructor cannot be called as a function.')
389
- }
390
-
391
- options = options || {};
392
- var body = options.body;
393
-
394
- if (input instanceof Request) {
395
- if (input.bodyUsed) {
396
- throw new TypeError('Already read')
397
- }
398
- this.url = input.url;
399
- this.credentials = input.credentials;
400
- if (!options.headers) {
401
- this.headers = new Headers(input.headers);
402
- }
403
- this.method = input.method;
404
- this.mode = input.mode;
405
- this.signal = input.signal;
406
- if (!body && input._bodyInit != null) {
407
- body = input._bodyInit;
408
- input.bodyUsed = true;
409
- }
410
- } else {
411
- this.url = String(input);
412
- }
413
-
414
- this.credentials = options.credentials || this.credentials || 'same-origin';
415
- if (options.headers || !this.headers) {
416
- this.headers = new Headers(options.headers);
417
- }
418
- this.method = normalizeMethod(options.method || this.method || 'GET');
419
- this.mode = options.mode || this.mode || null;
420
- this.signal = options.signal || this.signal || (function () {
421
- if ('AbortController' in g) {
422
- var ctrl = new AbortController();
423
- return ctrl.signal;
424
- }
425
- }());
426
- this.referrer = null;
427
-
428
- if ((this.method === 'GET' || this.method === 'HEAD') && body) {
429
- throw new TypeError('Body not allowed for GET or HEAD requests')
430
- }
431
- this._initBody(body);
432
-
433
- if (this.method === 'GET' || this.method === 'HEAD') {
434
- if (options.cache === 'no-store' || options.cache === 'no-cache') {
435
- // Search for a '_' parameter in the query string
436
- var reParamSearch = /([?&])_=[^&]*/;
437
- if (reParamSearch.test(this.url)) {
438
- // If it already exists then set the value with the current time
439
- this.url = this.url.replace(reParamSearch, '$1_=' + new Date().getTime());
440
- } else {
441
- // Otherwise add a new '_' parameter to the end with the current time
442
- var reQueryString = /\?/;
443
- this.url += (reQueryString.test(this.url) ? '&' : '?') + '_=' + new Date().getTime();
444
- }
445
- }
446
- }
447
- }
448
-
449
- Request.prototype.clone = function() {
450
- return new Request(this, {body: this._bodyInit})
451
- };
452
-
453
- function decode(body) {
454
- var form = new FormData();
455
- body
456
- .trim()
457
- .split('&')
458
- .forEach(function(bytes) {
459
- if (bytes) {
460
- var split = bytes.split('=');
461
- var name = split.shift().replace(/\+/g, ' ');
462
- var value = split.join('=').replace(/\+/g, ' ');
463
- form.append(decodeURIComponent(name), decodeURIComponent(value));
464
- }
465
- });
466
- return form
467
- }
468
-
469
- function parseHeaders(rawHeaders) {
470
- var headers = new Headers();
471
- // Replace instances of \r\n and \n followed by at least one space or horizontal tab with a space
472
- // https://tools.ietf.org/html/rfc7230#section-3.2
473
- var preProcessedHeaders = rawHeaders.replace(/\r?\n[\t ]+/g, ' ');
474
- // Avoiding split via regex to work around a common IE11 bug with the core-js 3.6.0 regex polyfill
475
- // https://github.com/github/fetch/issues/748
476
- // https://github.com/zloirock/core-js/issues/751
477
- preProcessedHeaders
478
- .split('\r')
479
- .map(function(header) {
480
- return header.indexOf('\n') === 0 ? header.substr(1, header.length) : header
481
- })
482
- .forEach(function(line) {
483
- var parts = line.split(':');
484
- var key = parts.shift().trim();
485
- if (key) {
486
- var value = parts.join(':').trim();
487
- try {
488
- headers.append(key, value);
489
- } catch (error) {
490
- console.warn('Response ' + error.message);
491
- }
492
- }
493
- });
494
- return headers
495
- }
496
-
497
- Body.call(Request.prototype);
498
-
499
- function Response(bodyInit, options) {
500
- if (!(this instanceof Response)) {
501
- throw new TypeError('Please use the "new" operator, this DOM object constructor cannot be called as a function.')
502
- }
503
- if (!options) {
504
- options = {};
505
- }
506
-
507
- this.type = 'default';
508
- this.status = options.status === undefined ? 200 : options.status;
509
- if (this.status < 200 || this.status > 599) {
510
- throw new RangeError("Failed to construct 'Response': The status provided (0) is outside the range [200, 599].")
511
- }
512
- this.ok = this.status >= 200 && this.status < 300;
513
- this.statusText = options.statusText === undefined ? '' : '' + options.statusText;
514
- this.headers = new Headers(options.headers);
515
- this.url = options.url || '';
516
- this._initBody(bodyInit);
517
- }
518
-
519
- Body.call(Response.prototype);
520
-
521
- Response.prototype.clone = function() {
522
- return new Response(this._bodyInit, {
523
- status: this.status,
524
- statusText: this.statusText,
525
- headers: new Headers(this.headers),
526
- url: this.url
527
- })
528
- };
529
-
530
- Response.error = function() {
531
- var response = new Response(null, {status: 200, statusText: ''});
532
- response.ok = false;
533
- response.status = 0;
534
- response.type = 'error';
535
- return response
536
- };
537
-
538
- var redirectStatuses = [301, 302, 303, 307, 308];
539
-
540
- Response.redirect = function(url, status) {
541
- if (redirectStatuses.indexOf(status) === -1) {
542
- throw new RangeError('Invalid status code')
543
- }
544
-
545
- return new Response(null, {status: status, headers: {location: url}})
546
- };
547
-
548
- exports.DOMException = g.DOMException;
549
- try {
550
- new exports.DOMException();
551
- } catch (err) {
552
- exports.DOMException = function(message, name) {
553
- this.message = message;
554
- this.name = name;
555
- var error = Error(message);
556
- this.stack = error.stack;
557
- };
558
- exports.DOMException.prototype = Object.create(Error.prototype);
559
- exports.DOMException.prototype.constructor = exports.DOMException;
560
- }
561
-
562
- function fetch(input, init) {
563
- return new Promise(function(resolve, reject) {
564
- var request = new Request(input, init);
565
-
566
- if (request.signal && request.signal.aborted) {
567
- return reject(new exports.DOMException('Aborted', 'AbortError'))
568
- }
569
-
570
- var xhr = new XMLHttpRequest();
571
-
572
- function abortXhr() {
573
- xhr.abort();
574
- }
575
-
576
- xhr.onload = function() {
577
- var options = {
578
- statusText: xhr.statusText,
579
- headers: parseHeaders(xhr.getAllResponseHeaders() || '')
580
- };
581
- // This check if specifically for when a user fetches a file locally from the file system
582
- // Only if the status is out of a normal range
583
- if (request.url.indexOf('file://') === 0 && (xhr.status < 200 || xhr.status > 599)) {
584
- options.status = 200;
585
- } else {
586
- options.status = xhr.status;
587
- }
588
- options.url = 'responseURL' in xhr ? xhr.responseURL : options.headers.get('X-Request-URL');
589
- var body = 'response' in xhr ? xhr.response : xhr.responseText;
590
- setTimeout(function() {
591
- resolve(new Response(body, options));
592
- }, 0);
593
- };
594
-
595
- xhr.onerror = function() {
596
- setTimeout(function() {
597
- reject(new TypeError('Network request failed'));
598
- }, 0);
599
- };
600
-
601
- xhr.ontimeout = function() {
602
- setTimeout(function() {
603
- reject(new TypeError('Network request timed out'));
604
- }, 0);
605
- };
606
-
607
- xhr.onabort = function() {
608
- setTimeout(function() {
609
- reject(new exports.DOMException('Aborted', 'AbortError'));
610
- }, 0);
611
- };
612
-
613
- function fixUrl(url) {
614
- try {
615
- return url === '' && g.location.href ? g.location.href : url
616
- } catch (e) {
617
- return url
618
- }
619
- }
620
-
621
- xhr.open(request.method, fixUrl(request.url), true);
622
-
623
- if (request.credentials === 'include') {
624
- xhr.withCredentials = true;
625
- } else if (request.credentials === 'omit') {
626
- xhr.withCredentials = false;
627
- }
628
-
629
- if ('responseType' in xhr) {
630
- if (support.blob) {
631
- xhr.responseType = 'blob';
632
- } else if (
633
- support.arrayBuffer
634
- ) {
635
- xhr.responseType = 'arraybuffer';
636
- }
637
- }
638
-
639
- if (init && typeof init.headers === 'object' && !(init.headers instanceof Headers || (g.Headers && init.headers instanceof g.Headers))) {
640
- var names = [];
641
- Object.getOwnPropertyNames(init.headers).forEach(function(name) {
642
- names.push(normalizeName(name));
643
- xhr.setRequestHeader(name, normalizeValue(init.headers[name]));
644
- });
645
- request.headers.forEach(function(value, name) {
646
- if (names.indexOf(name) === -1) {
647
- xhr.setRequestHeader(name, value);
648
- }
649
- });
650
- } else {
651
- request.headers.forEach(function(value, name) {
652
- xhr.setRequestHeader(name, value);
653
- });
654
- }
655
-
656
- if (request.signal) {
657
- request.signal.addEventListener('abort', abortXhr);
658
-
659
- xhr.onreadystatechange = function() {
660
- // DONE (success or failure)
661
- if (xhr.readyState === 4) {
662
- request.signal.removeEventListener('abort', abortXhr);
663
- }
664
- };
665
- }
666
-
667
- xhr.send(typeof request._bodyInit === 'undefined' ? null : request._bodyInit);
668
- })
669
- }
670
-
671
- fetch.polyfill = true;
672
-
673
- if (!g.fetch) {
674
- g.fetch = fetch;
675
- g.Headers = Headers;
676
- g.Request = Request;
677
- g.Response = Response;
678
- }
679
-
680
- exports.Headers = Headers;
681
- exports.Request = Request;
682
- exports.Response = Response;
683
- exports.fetch = fetch;
684
-
685
- return exports;
686
-
687
- })({});
688
- })(__globalThis__);
689
- // This is a ponyfill, so...
690
- __globalThis__.fetch.ponyfill = true;
691
- delete __globalThis__.fetch.polyfill;
692
- // Choose between native implementation (__global__) or custom implementation (__globalThis__)
693
- var ctx = __global__.fetch ? __global__ : __globalThis__;
694
- exports = ctx.fetch // To enable: import fetch from 'cross-fetch'
695
- exports["default"] = ctx.fetch // For TypeScript consumers without esModuleInterop.
696
- exports.fetch = ctx.fetch // To enable: import {fetch} from 'cross-fetch'
697
- exports.Headers = ctx.Headers
698
- exports.Request = ctx.Request
699
- exports.Response = ctx.Response
700
- module.exports = exports
701
-
702
-
703
- /***/ }
704
-
705
- /******/ });
706
- /************************************************************************/
707
- /******/ // The module cache
708
- /******/ var __webpack_module_cache__ = {};
709
- /******/
710
- /******/ // The require function
711
- /******/ function __webpack_require__(moduleId) {
712
- /******/ // Check if module is in cache
713
- /******/ var cachedModule = __webpack_module_cache__[moduleId];
714
- /******/ if (cachedModule !== undefined) {
715
- /******/ return cachedModule.exports;
716
- /******/ }
717
- /******/ // Create a new module (and put it into the cache)
718
- /******/ var module = __webpack_module_cache__[moduleId] = {
719
- /******/ // no module.id needed
720
- /******/ // no module.loaded needed
721
- /******/ exports: {}
722
- /******/ };
723
- /******/
724
- /******/ // Execute the module function
725
- /******/ __webpack_modules__[moduleId](module, module.exports, __webpack_require__);
726
- /******/
727
- /******/ // Return the exports of the module
728
- /******/ return module.exports;
729
- /******/ }
730
- /******/
731
- /************************************************************************/
732
- /******/ /* webpack/runtime/global */
733
- /******/ (() => {
734
- /******/ __webpack_require__.g = (function() {
735
- /******/ if (typeof globalThis === 'object') return globalThis;
736
- /******/ try {
737
- /******/ return this || new Function('return this')();
738
- /******/ } catch (e) {
739
- /******/ if (typeof window === 'object') return window;
740
- /******/ }
741
- /******/ })();
742
- /******/ })();
743
- /******/
744
- /************************************************************************/
745
- var __webpack_exports__ = {};
746
- /* eslint-env worker */
747
-
748
- const crossFetch = (__webpack_require__(945)["default"]);
749
- let jobsActive = 0;
750
- const complete = [];
751
- let intervalId = null;
752
-
753
- /**
754
- * Register a step function.
755
- *
756
- * Step checks if there are completed jobs and if there are sends them to the
757
- * parent. Then it checks the jobs count. If there are no further jobs, clear
758
- * the step.
759
- */
760
- const registerStep = function registerStep() {
761
- intervalId = setInterval(() => {
762
- if (complete.length) {
763
- // Send our chunk of completed requests and instruct postMessage to
764
- // transfer the buffers instead of copying them.
765
- postMessage(complete.slice(),
766
- // Instruct postMessage that these buffers in the sent message
767
- // should use their Transferable trait. After the postMessage
768
- // call the "buffers" will still be in complete if you looked,
769
- // but they will all be length 0 as the data they reference has
770
- // been sent to the window. This lets us send a lot of data
771
- // without the normal postMessage behaviour of making a copy of
772
- // all of the data for the window.
773
- complete.map(response => response.buffer).filter(Boolean));
774
- complete.length = 0;
775
- }
776
- if (jobsActive === 0) {
777
- clearInterval(intervalId);
778
- intervalId = null;
779
- }
780
- }, 1);
781
- };
782
-
783
- /**
784
- * Receive a job from the parent and fetch the requested data.
785
- * @param {object} message The message from the parent.
786
- * @param {object} message.data A job id, url, and options descriptor to perform.
787
- */
788
- const onMessage = _ref => {
789
- let {
790
- data: job
791
- } = _ref;
792
- if (jobsActive === 0 && !intervalId) {
793
- registerStep();
794
- }
795
- jobsActive++;
796
- crossFetch(job.url, job.options).then(result => {
797
- if (result.ok) return result.arrayBuffer();
798
- if (result.status === 404) return null;
799
- return Promise.reject(result.status);
800
- }).then(buffer => complete.push({
801
- id: job.id,
802
- buffer
803
- })).catch(error => complete.push({
804
- id: job.id,
805
- error: error && error.message || "Failed request: ".concat(job.url)
806
- })).then(() => jobsActive--);
807
- };
808
-
809
- // crossFetch means "fetch" is now always supported
810
- postMessage({
811
- support: {
812
- fetch: true
813
- }
814
- });
815
- self.addEventListener('message', onMessage);
816
- /******/ return __webpack_exports__;
817
- /******/ })()
818
- ;
819
- });
820
- //# sourceMappingURL=fetch-worker.c813c32be403f91001ba.js.map