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