scratch-storage 2.3.284 → 3.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 (61) hide show
  1. package/.browserslistrc +7 -0
  2. package/CHANGELOG.md +18 -0
  3. package/dist/{web/f6240eab828e6d415177.worker.js → node/chunks/fetch-worker.3bf90a691c26a60b5752.js} +262 -231
  4. package/dist/node/chunks/fetch-worker.3bf90a691c26a60b5752.js.map +1 -0
  5. package/dist/node/scratch-storage.js +4019 -6348
  6. package/dist/node/scratch-storage.js.map +1 -1
  7. package/dist/types/Asset.d.ts +38 -0
  8. package/dist/types/AssetType.d.ts +49 -0
  9. package/dist/types/BuiltinHelper.d.ts +69 -0
  10. package/dist/types/DataFormat.d.ts +15 -0
  11. package/dist/types/FetchTool.d.ts +33 -0
  12. package/dist/types/FetchWorkerTool.d.ts +29 -0
  13. package/dist/types/Helper.d.ts +20 -0
  14. package/dist/types/ProxyTool.d.ts +53 -0
  15. package/dist/types/ScratchStorage.d.ts +202 -0
  16. package/dist/types/Tool.d.ts +13 -0
  17. package/dist/types/WebHelper.d.ts +59 -0
  18. package/dist/types/index.d.ts +11 -0
  19. package/dist/types/log.d.ts +2 -0
  20. package/dist/types/memoizedToString.d.ts +5 -0
  21. package/dist/web/chunks/fetch-worker.42ee2f0bc3b8de590472.js +2 -0
  22. package/dist/web/chunks/fetch-worker.42ee2f0bc3b8de590472.js.map +1 -0
  23. package/dist/web/chunks/fetch-worker.cd3a909d7b876aabf94a.js +782 -0
  24. package/dist/web/chunks/fetch-worker.cd3a909d7b876aabf94a.js.map +1 -0
  25. package/dist/web/scratch-storage.js +2143 -2798
  26. package/dist/web/scratch-storage.js.map +1 -1
  27. package/dist/web/scratch-storage.min.js +2 -6398
  28. package/dist/web/scratch-storage.min.js.LICENSE.txt +18 -0
  29. package/dist/web/scratch-storage.min.js.map +1 -1
  30. package/jest.config.js +32 -0
  31. package/package.json +19 -14
  32. package/src/.eslintrc.js +13 -1
  33. package/src/Asset.ts +100 -0
  34. package/src/{AssetType.js → AssetType.ts} +10 -5
  35. package/src/{BuiltinHelper.js → BuiltinHelper.ts} +44 -35
  36. package/src/{DataFormat.js → DataFormat.ts} +3 -3
  37. package/src/{FetchTool.js → FetchTool.ts} +8 -9
  38. package/src/{FetchWorkerTool.js → FetchWorkerTool.ts} +47 -22
  39. package/src/{Helper.js → Helper.ts} +10 -5
  40. package/src/{ProxyTool.js → ProxyTool.ts} +32 -29
  41. package/src/{ScratchStorage.js → ScratchStorage.ts} +57 -34
  42. package/src/Tool.ts +10 -0
  43. package/src/{WebHelper.js → WebHelper.ts} +42 -15
  44. package/src/index.ts +19 -0
  45. package/src/log.ts +4 -0
  46. package/src/{Asset.js → memoizedToString.ts} +16 -76
  47. package/src/scratchFetch.js +10 -15
  48. package/src/types.d.ts +3 -0
  49. package/test/integration/download-known-assets.test.js +1 -1
  50. package/test/unit/add-helper.test.js +1 -1
  51. package/test/unit/fetch-tool.test.js +1 -1
  52. package/test/unit/load-default-assets.test.js +1 -1
  53. package/test/unit/metadata.test.js +6 -6
  54. package/tsconfig.json +29 -0
  55. package/tsconfig.test.json +11 -0
  56. package/webpack.config.js +63 -67
  57. package/dist/node/ce8a01e629587e4f90e4.worker.js +0 -4274
  58. package/dist/node/ce8a01e629587e4f90e4.worker.js.map +0 -1
  59. package/dist/web/f6240eab828e6d415177.worker.js.map +0 -1
  60. package/src/index.js +0 -7
  61. package/src/log.js +0 -4
@@ -0,0 +1,7 @@
1
+ # See https://scratch.mit.edu/faq
2
+ Chrome >= 63
3
+ Edge >= 15
4
+ Firefox >= 57
5
+ Safari >= 11
6
+ Android >= 63
7
+ iOS >= 11
package/CHANGELOG.md CHANGED
@@ -3,6 +3,24 @@
3
3
  All notable changes to this project will be documented in this file. See
4
4
  [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
5
5
 
6
+ ## [3.0.1](https://github.com/scratchfoundation/scratch-storage/compare/v3.0.0...v3.0.1) (2024-10-23)
7
+
8
+
9
+ ### Bug Fixes
10
+
11
+ * fix web worker usage in scratch-vm integration tests ([78b2c66](https://github.com/scratchfoundation/scratch-storage/commit/78b2c66140dbee8f8cbde9dc546ccd075642858b))
12
+
13
+ # [3.0.0](https://github.com/scratchfoundation/scratch-storage/compare/v2.3.284...v3.0.0) (2024-10-23)
14
+
15
+
16
+ * chore!: can't have a default and non-default exports in commonjs ([ff5b428](https://github.com/scratchfoundation/scratch-storage/commit/ff5b428e7152b97671262da1d7ac08f3abfe7259))
17
+
18
+
19
+ ### BREAKING CHANGES
20
+
21
+ * The ScratchStorage constructor is now exported
22
+ as a named export instead of a default export.
23
+
6
24
  ## [2.3.284](https://github.com/scratchfoundation/scratch-storage/compare/v2.3.283...v2.3.284) (2024-10-23)
7
25
 
8
26
 
@@ -1,202 +1,40 @@
1
- /******/ (function(modules) { // webpackBootstrap
2
- /******/ // The module cache
3
- /******/ var installedModules = {};
4
- /******/
5
- /******/ // The require function
6
- /******/ function __webpack_require__(moduleId) {
7
- /******/
8
- /******/ // Check if module is in cache
9
- /******/ if(installedModules[moduleId]) {
10
- /******/ return installedModules[moduleId].exports;
11
- /******/ }
12
- /******/ // Create a new module (and put it into the cache)
13
- /******/ var module = installedModules[moduleId] = {
14
- /******/ i: moduleId,
15
- /******/ l: false,
16
- /******/ exports: {}
17
- /******/ };
18
- /******/
19
- /******/ // Execute the module function
20
- /******/ modules[moduleId].call(module.exports, module, module.exports, __webpack_require__);
21
- /******/
22
- /******/ // Flag the module as loaded
23
- /******/ module.l = true;
24
- /******/
25
- /******/ // Return the exports of the module
26
- /******/ return module.exports;
27
- /******/ }
28
- /******/
29
- /******/
30
- /******/ // expose the modules object (__webpack_modules__)
31
- /******/ __webpack_require__.m = modules;
32
- /******/
33
- /******/ // expose the module cache
34
- /******/ __webpack_require__.c = installedModules;
35
- /******/
36
- /******/ // define getter function for harmony exports
37
- /******/ __webpack_require__.d = function(exports, name, getter) {
38
- /******/ if(!__webpack_require__.o(exports, name)) {
39
- /******/ Object.defineProperty(exports, name, { enumerable: true, get: getter });
40
- /******/ }
41
- /******/ };
42
- /******/
43
- /******/ // define __esModule on exports
44
- /******/ __webpack_require__.r = function(exports) {
45
- /******/ if(typeof Symbol !== 'undefined' && Symbol.toStringTag) {
46
- /******/ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
47
- /******/ }
48
- /******/ Object.defineProperty(exports, '__esModule', { value: true });
49
- /******/ };
50
- /******/
51
- /******/ // create a fake namespace object
52
- /******/ // mode & 1: value is a module id, require it
53
- /******/ // mode & 2: merge all properties of value into the ns
54
- /******/ // mode & 4: return value when already ns object
55
- /******/ // mode & 8|1: behave like require
56
- /******/ __webpack_require__.t = function(value, mode) {
57
- /******/ if(mode & 1) value = __webpack_require__(value);
58
- /******/ if(mode & 8) return value;
59
- /******/ if((mode & 4) && typeof value === 'object' && value && value.__esModule) return value;
60
- /******/ var ns = Object.create(null);
61
- /******/ __webpack_require__.r(ns);
62
- /******/ Object.defineProperty(ns, 'default', { enumerable: true, value: value });
63
- /******/ if(mode & 2 && typeof value != 'string') for(var key in value) __webpack_require__.d(ns, key, function(key) { return value[key]; }.bind(null, key));
64
- /******/ return ns;
65
- /******/ };
66
- /******/
67
- /******/ // getDefaultExport function for compatibility with non-harmony modules
68
- /******/ __webpack_require__.n = function(module) {
69
- /******/ var getter = module && module.__esModule ?
70
- /******/ function getDefault() { return module['default']; } :
71
- /******/ function getModuleExports() { return module; };
72
- /******/ __webpack_require__.d(getter, 'a', getter);
73
- /******/ return getter;
74
- /******/ };
75
- /******/
76
- /******/ // Object.prototype.hasOwnProperty.call
77
- /******/ __webpack_require__.o = function(object, property) { return Object.prototype.hasOwnProperty.call(object, property); };
78
- /******/
79
- /******/ // __webpack_public_path__
80
- /******/ __webpack_require__.p = "";
81
- /******/
82
- /******/
83
- /******/ // Load entry module and return exports
84
- /******/ return __webpack_require__(__webpack_require__.s = "./node_modules/babel-loader/lib/index.js?!./src/FetchWorkerTool.worker.js");
85
- /******/ })
86
- /************************************************************************/
87
- /******/ ({
88
-
89
- /***/ "./node_modules/babel-loader/lib/index.js?!./src/FetchWorkerTool.worker.js":
90
- /*!*******************************************************************************!*\
91
- !*** ./node_modules/babel-loader/lib??ref--4!./src/FetchWorkerTool.worker.js ***!
92
- \*******************************************************************************/
93
- /*! no static exports found */
94
- /***/ (function(module, exports, __webpack_require__) {
95
-
96
- /* eslint-env worker */
97
-
98
- var crossFetch = __webpack_require__(/*! cross-fetch */ "./node_modules/cross-fetch/dist/browser-ponyfill.js").default;
99
- var jobsActive = 0;
100
- var complete = [];
101
- var intervalId = null;
102
-
103
- /**
104
- * Register a step function.
105
- *
106
- * Step checks if there are completed jobs and if there are sends them to the
107
- * parent. Then it checks the jobs count. If there are no further jobs, clear
108
- * the step.
109
- */
110
- var registerStep = function registerStep() {
111
- intervalId = setInterval(function () {
112
- if (complete.length) {
113
- // Send our chunk of completed requests and instruct postMessage to
114
- // transfer the buffers instead of copying them.
115
- postMessage(complete.slice(),
116
- // Instruct postMessage that these buffers in the sent message
117
- // should use their Transferable trait. After the postMessage
118
- // call the "buffers" will still be in complete if you looked,
119
- // but they will all be length 0 as the data they reference has
120
- // been sent to the window. This lets us send a lot of data
121
- // without the normal postMessage behaviour of making a copy of
122
- // all of the data for the window.
123
- complete.map(function (response) {
124
- return response.buffer;
125
- }).filter(Boolean));
126
- complete.length = 0;
127
- }
128
- if (jobsActive === 0) {
129
- clearInterval(intervalId);
130
- intervalId = null;
131
- }
132
- }, 1);
133
- };
134
-
135
- /**
136
- * Receive a job from the parent and fetch the requested data.
137
- * @param {object} options.job A job id, url, and options descriptor to perform.
138
- */
139
- var onMessage = function onMessage(_ref) {
140
- var job = _ref.data;
141
- if (jobsActive === 0 && !intervalId) {
142
- registerStep();
143
- }
144
- jobsActive++;
145
- crossFetch(job.url, job.options).then(function (result) {
146
- if (result.ok) return result.arrayBuffer();
147
- if (result.status === 404) return null;
148
- return Promise.reject(result.status);
149
- }).then(function (buffer) {
150
- return complete.push({
151
- id: job.id,
152
- buffer: buffer
153
- });
154
- }).catch(function (error) {
155
- return complete.push({
156
- id: job.id,
157
- error: error && error.message || "Failed request: ".concat(job.url)
158
- });
159
- }).then(function () {
160
- return jobsActive--;
161
- });
162
- };
163
-
164
- // crossFetch means "fetch" is now always supported
165
- postMessage({
166
- support: {
167
- fetch: true
168
- }
169
- });
170
- self.addEventListener('message', onMessage);
171
-
172
- /***/ }),
173
-
174
- /***/ "./node_modules/cross-fetch/dist/browser-ponyfill.js":
175
- /*!***********************************************************!*\
176
- !*** ./node_modules/cross-fetch/dist/browser-ponyfill.js ***!
177
- \***********************************************************/
178
- /*! no static exports found */
179
- /***/ (function(module, exports) {
180
-
181
- var global = typeof self !== 'undefined' ? self : this;
182
- var __self__ = (function () {
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 () {
183
14
  function F() {
184
15
  this.fetch = false;
185
- this.DOMException = global.DOMException
16
+ this.DOMException = __global__.DOMException
186
17
  }
187
- F.prototype = global;
18
+ F.prototype = __global__; // Needed for feature detection on whatwg-fetch's code
188
19
  return new F();
189
20
  })();
190
- (function(self) {
21
+ // Wraps whatwg-fetch with a function scope to hijack the global object
22
+ // "globalThis" that's going to be patched
23
+ (function(globalThis) {
191
24
 
192
25
  var irrelevant = (function (exports) {
193
26
 
27
+ var global =
28
+ (typeof globalThis !== 'undefined' && globalThis) ||
29
+ (typeof self !== 'undefined' && self) ||
30
+ (typeof global !== 'undefined' && global);
31
+
194
32
  var support = {
195
- searchParams: 'URLSearchParams' in self,
196
- iterable: 'Symbol' in self && 'iterator' in Symbol,
33
+ searchParams: 'URLSearchParams' in global,
34
+ iterable: 'Symbol' in global && 'iterator' in Symbol,
197
35
  blob:
198
- 'FileReader' in self &&
199
- 'Blob' in self &&
36
+ 'FileReader' in global &&
37
+ 'Blob' in global &&
200
38
  (function() {
201
39
  try {
202
40
  new Blob();
@@ -205,8 +43,8 @@ var irrelevant = (function (exports) {
205
43
  return false
206
44
  }
207
45
  })(),
208
- formData: 'FormData' in self,
209
- arrayBuffer: 'ArrayBuffer' in self
46
+ formData: 'FormData' in global,
47
+ arrayBuffer: 'ArrayBuffer' in global
210
48
  };
211
49
 
212
50
  function isDataView(obj) {
@@ -237,8 +75,8 @@ var irrelevant = (function (exports) {
237
75
  if (typeof name !== 'string') {
238
76
  name = String(name);
239
77
  }
240
- if (/[^a-z0-9\-#$%&'*+.^_`|~]/i.test(name)) {
241
- throw new TypeError('Invalid character in header field name')
78
+ if (/[^a-z0-9\-#$%&'*+.^_`|~!]/i.test(name) || name === '') {
79
+ throw new TypeError('Invalid character in header field name: "' + name + '"')
242
80
  }
243
81
  return name.toLowerCase()
244
82
  }
@@ -402,6 +240,17 @@ var irrelevant = (function (exports) {
402
240
  this.bodyUsed = false;
403
241
 
404
242
  this._initBody = function(body) {
243
+ /*
244
+ fetch-mock wraps the Response object in an ES6 Proxy to
245
+ provide useful test harness features such as flush. However, on
246
+ ES5 browsers without fetch or Proxy support pollyfills must be used;
247
+ the proxy-pollyfill is unable to proxy an attribute unless it exists
248
+ on the object before the Proxy is created. This change ensures
249
+ Response.bodyUsed exists on the instance, while maintaining the
250
+ semantic of setting Request.bodyUsed in the constructor before
251
+ _initBody is called.
252
+ */
253
+ this.bodyUsed = this.bodyUsed;
405
254
  this._bodyInit = body;
406
255
  if (!body) {
407
256
  this._bodyText = '';
@@ -454,7 +303,20 @@ var irrelevant = (function (exports) {
454
303
 
455
304
  this.arrayBuffer = function() {
456
305
  if (this._bodyArrayBuffer) {
457
- return consumed(this) || Promise.resolve(this._bodyArrayBuffer)
306
+ var isConsumed = consumed(this);
307
+ if (isConsumed) {
308
+ return isConsumed
309
+ }
310
+ if (ArrayBuffer.isView(this._bodyArrayBuffer)) {
311
+ return Promise.resolve(
312
+ this._bodyArrayBuffer.buffer.slice(
313
+ this._bodyArrayBuffer.byteOffset,
314
+ this._bodyArrayBuffer.byteOffset + this._bodyArrayBuffer.byteLength
315
+ )
316
+ )
317
+ } else {
318
+ return Promise.resolve(this._bodyArrayBuffer)
319
+ }
458
320
  } else {
459
321
  return this.blob().then(readBlobAsArrayBuffer)
460
322
  }
@@ -500,6 +362,10 @@ var irrelevant = (function (exports) {
500
362
  }
501
363
 
502
364
  function Request(input, options) {
365
+ if (!(this instanceof Request)) {
366
+ throw new TypeError('Please use the "new" operator, this DOM object constructor cannot be called as a function.')
367
+ }
368
+
503
369
  options = options || {};
504
370
  var body = options.body;
505
371
 
@@ -536,6 +402,21 @@ var irrelevant = (function (exports) {
536
402
  throw new TypeError('Body not allowed for GET or HEAD requests')
537
403
  }
538
404
  this._initBody(body);
405
+
406
+ if (this.method === 'GET' || this.method === 'HEAD') {
407
+ if (options.cache === 'no-store' || options.cache === 'no-cache') {
408
+ // Search for a '_' parameter in the query string
409
+ var reParamSearch = /([?&])_=[^&]*/;
410
+ if (reParamSearch.test(this.url)) {
411
+ // If it already exists then set the value with the current time
412
+ this.url = this.url.replace(reParamSearch, '$1_=' + new Date().getTime());
413
+ } else {
414
+ // Otherwise add a new '_' parameter to the end with the current time
415
+ var reQueryString = /\?/;
416
+ this.url += (reQueryString.test(this.url) ? '&' : '?') + '_=' + new Date().getTime();
417
+ }
418
+ }
419
+ }
539
420
  }
540
421
 
541
422
  Request.prototype.clone = function() {
@@ -563,20 +444,31 @@ var irrelevant = (function (exports) {
563
444
  // Replace instances of \r\n and \n followed by at least one space or horizontal tab with a space
564
445
  // https://tools.ietf.org/html/rfc7230#section-3.2
565
446
  var preProcessedHeaders = rawHeaders.replace(/\r?\n[\t ]+/g, ' ');
566
- preProcessedHeaders.split(/\r?\n/).forEach(function(line) {
567
- var parts = line.split(':');
568
- var key = parts.shift().trim();
569
- if (key) {
570
- var value = parts.join(':').trim();
571
- headers.append(key, value);
572
- }
573
- });
447
+ // Avoiding split via regex to work around a common IE11 bug with the core-js 3.6.0 regex polyfill
448
+ // https://github.com/github/fetch/issues/748
449
+ // https://github.com/zloirock/core-js/issues/751
450
+ preProcessedHeaders
451
+ .split('\r')
452
+ .map(function(header) {
453
+ return header.indexOf('\n') === 0 ? header.substr(1, header.length) : header
454
+ })
455
+ .forEach(function(line) {
456
+ var parts = line.split(':');
457
+ var key = parts.shift().trim();
458
+ if (key) {
459
+ var value = parts.join(':').trim();
460
+ headers.append(key, value);
461
+ }
462
+ });
574
463
  return headers
575
464
  }
576
465
 
577
466
  Body.call(Request.prototype);
578
467
 
579
468
  function Response(bodyInit, options) {
469
+ if (!(this instanceof Response)) {
470
+ throw new TypeError('Please use the "new" operator, this DOM object constructor cannot be called as a function.')
471
+ }
580
472
  if (!options) {
581
473
  options = {};
582
474
  }
@@ -584,7 +476,7 @@ var irrelevant = (function (exports) {
584
476
  this.type = 'default';
585
477
  this.status = options.status === undefined ? 200 : options.status;
586
478
  this.ok = this.status >= 200 && this.status < 300;
587
- this.statusText = 'statusText' in options ? options.statusText : 'OK';
479
+ this.statusText = options.statusText === undefined ? '' : '' + options.statusText;
588
480
  this.headers = new Headers(options.headers);
589
481
  this.url = options.url || '';
590
482
  this._initBody(bodyInit);
@@ -617,7 +509,7 @@ var irrelevant = (function (exports) {
617
509
  return new Response(null, {status: status, headers: {location: url}})
618
510
  };
619
511
 
620
- exports.DOMException = self.DOMException;
512
+ exports.DOMException = global.DOMException;
621
513
  try {
622
514
  new exports.DOMException();
623
515
  } catch (err) {
@@ -653,22 +545,38 @@ var irrelevant = (function (exports) {
653
545
  };
654
546
  options.url = 'responseURL' in xhr ? xhr.responseURL : options.headers.get('X-Request-URL');
655
547
  var body = 'response' in xhr ? xhr.response : xhr.responseText;
656
- resolve(new Response(body, options));
548
+ setTimeout(function() {
549
+ resolve(new Response(body, options));
550
+ }, 0);
657
551
  };
658
552
 
659
553
  xhr.onerror = function() {
660
- reject(new TypeError('Network request failed'));
554
+ setTimeout(function() {
555
+ reject(new TypeError('Network request failed'));
556
+ }, 0);
661
557
  };
662
558
 
663
559
  xhr.ontimeout = function() {
664
- reject(new TypeError('Network request failed'));
560
+ setTimeout(function() {
561
+ reject(new TypeError('Network request failed'));
562
+ }, 0);
665
563
  };
666
564
 
667
565
  xhr.onabort = function() {
668
- reject(new exports.DOMException('Aborted', 'AbortError'));
566
+ setTimeout(function() {
567
+ reject(new exports.DOMException('Aborted', 'AbortError'));
568
+ }, 0);
669
569
  };
670
570
 
671
- xhr.open(request.method, request.url, true);
571
+ function fixUrl(url) {
572
+ try {
573
+ return url === '' && global.location.href ? global.location.href : url
574
+ } catch (e) {
575
+ return url
576
+ }
577
+ }
578
+
579
+ xhr.open(request.method, fixUrl(request.url), true);
672
580
 
673
581
  if (request.credentials === 'include') {
674
582
  xhr.withCredentials = true;
@@ -676,13 +584,27 @@ var irrelevant = (function (exports) {
676
584
  xhr.withCredentials = false;
677
585
  }
678
586
 
679
- if ('responseType' in xhr && support.blob) {
680
- xhr.responseType = 'blob';
587
+ if ('responseType' in xhr) {
588
+ if (support.blob) {
589
+ xhr.responseType = 'blob';
590
+ } else if (
591
+ support.arrayBuffer &&
592
+ request.headers.get('Content-Type') &&
593
+ request.headers.get('Content-Type').indexOf('application/octet-stream') !== -1
594
+ ) {
595
+ xhr.responseType = 'arraybuffer';
596
+ }
681
597
  }
682
598
 
683
- request.headers.forEach(function(value, name) {
684
- xhr.setRequestHeader(name, value);
685
- });
599
+ if (init && typeof init.headers === 'object' && !(init.headers instanceof Headers)) {
600
+ Object.getOwnPropertyNames(init.headers).forEach(function(name) {
601
+ xhr.setRequestHeader(name, normalizeValue(init.headers[name]));
602
+ });
603
+ } else {
604
+ request.headers.forEach(function(value, name) {
605
+ xhr.setRequestHeader(name, value);
606
+ });
607
+ }
686
608
 
687
609
  if (request.signal) {
688
610
  request.signal.addEventListener('abort', abortXhr);
@@ -701,11 +623,11 @@ var irrelevant = (function (exports) {
701
623
 
702
624
  fetch.polyfill = true;
703
625
 
704
- if (!self.fetch) {
705
- self.fetch = fetch;
706
- self.Headers = Headers;
707
- self.Request = Request;
708
- self.Response = Response;
626
+ if (!global.fetch) {
627
+ global.fetch = fetch;
628
+ global.Headers = Headers;
629
+ global.Request = Request;
630
+ global.Response = Response;
709
631
  }
710
632
 
711
633
  exports.Headers = Headers;
@@ -713,20 +635,17 @@ var irrelevant = (function (exports) {
713
635
  exports.Response = Response;
714
636
  exports.fetch = fetch;
715
637
 
716
- Object.defineProperty(exports, '__esModule', { value: true });
717
-
718
638
  return exports;
719
639
 
720
640
  })({});
721
- })(__self__);
722
- __self__.fetch.ponyfill = true;
723
- // Remove "polyfill" property added by whatwg-fetch
724
- delete __self__.fetch.polyfill;
725
- // Choose between native implementation (global) or custom implementation (__self__)
726
- // var ctx = global.fetch ? global : __self__;
727
- var ctx = __self__; // this line disable service worker support temporarily
641
+ })(__globalThis__);
642
+ // This is a ponyfill, so...
643
+ __globalThis__.fetch.ponyfill = true;
644
+ delete __globalThis__.fetch.polyfill;
645
+ // Choose between native implementation (__global__) or custom implementation (__globalThis__)
646
+ var ctx = __global__.fetch ? __global__ : __globalThis__;
728
647
  exports = ctx.fetch // To enable: import fetch from 'cross-fetch'
729
- exports.default = ctx.fetch // For TypeScript consumers without esModuleInterop.
648
+ exports["default"] = ctx.fetch // For TypeScript consumers without esModuleInterop.
730
649
  exports.fetch = ctx.fetch // To enable: import {fetch} from 'cross-fetch'
731
650
  exports.Headers = ctx.Headers
732
651
  exports.Request = ctx.Request
@@ -736,5 +655,117 @@ module.exports = exports
736
655
 
737
656
  /***/ })
738
657
 
739
- /******/ });
740
- //# sourceMappingURL=f6240eab828e6d415177.worker.js.map
658
+ /******/ });
659
+ /************************************************************************/
660
+ /******/ // The module cache
661
+ /******/ var __webpack_module_cache__ = {};
662
+ /******/
663
+ /******/ // The require function
664
+ /******/ function __webpack_require__(moduleId) {
665
+ /******/ // Check if module is in cache
666
+ /******/ var cachedModule = __webpack_module_cache__[moduleId];
667
+ /******/ if (cachedModule !== undefined) {
668
+ /******/ return cachedModule.exports;
669
+ /******/ }
670
+ /******/ // Create a new module (and put it into the cache)
671
+ /******/ var module = __webpack_module_cache__[moduleId] = {
672
+ /******/ // no module.id needed
673
+ /******/ // no module.loaded needed
674
+ /******/ exports: {}
675
+ /******/ };
676
+ /******/
677
+ /******/ // Execute the module function
678
+ /******/ __webpack_modules__[moduleId](module, module.exports, __webpack_require__);
679
+ /******/
680
+ /******/ // Return the exports of the module
681
+ /******/ return module.exports;
682
+ /******/ }
683
+ /******/
684
+ /************************************************************************/
685
+ /******/ /* webpack/runtime/global */
686
+ /******/ (() => {
687
+ /******/ __webpack_require__.g = (function() {
688
+ /******/ if (typeof globalThis === 'object') return globalThis;
689
+ /******/ try {
690
+ /******/ return this || new Function('return this')();
691
+ /******/ } catch (e) {
692
+ /******/ if (typeof window === 'object') return window;
693
+ /******/ }
694
+ /******/ })();
695
+ /******/ })();
696
+ /******/
697
+ /************************************************************************/
698
+ var __webpack_exports__ = {};
699
+ /* eslint-env worker */
700
+
701
+ const crossFetch = (__webpack_require__(945)["default"]);
702
+ let jobsActive = 0;
703
+ const complete = [];
704
+ let intervalId = null;
705
+
706
+ /**
707
+ * Register a step function.
708
+ *
709
+ * Step checks if there are completed jobs and if there are sends them to the
710
+ * parent. Then it checks the jobs count. If there are no further jobs, clear
711
+ * the step.
712
+ */
713
+ const registerStep = function registerStep() {
714
+ intervalId = setInterval(() => {
715
+ if (complete.length) {
716
+ // Send our chunk of completed requests and instruct postMessage to
717
+ // transfer the buffers instead of copying them.
718
+ postMessage(complete.slice(),
719
+ // Instruct postMessage that these buffers in the sent message
720
+ // should use their Transferable trait. After the postMessage
721
+ // call the "buffers" will still be in complete if you looked,
722
+ // but they will all be length 0 as the data they reference has
723
+ // been sent to the window. This lets us send a lot of data
724
+ // without the normal postMessage behaviour of making a copy of
725
+ // all of the data for the window.
726
+ complete.map(response => response.buffer).filter(Boolean));
727
+ complete.length = 0;
728
+ }
729
+ if (jobsActive === 0) {
730
+ clearInterval(intervalId);
731
+ intervalId = null;
732
+ }
733
+ }, 1);
734
+ };
735
+
736
+ /**
737
+ * Receive a job from the parent and fetch the requested data.
738
+ * @param {object} options.job A job id, url, and options descriptor to perform.
739
+ */
740
+ const onMessage = _ref => {
741
+ let {
742
+ data: job
743
+ } = _ref;
744
+ if (jobsActive === 0 && !intervalId) {
745
+ registerStep();
746
+ }
747
+ jobsActive++;
748
+ crossFetch(job.url, job.options).then(result => {
749
+ if (result.ok) return result.arrayBuffer();
750
+ if (result.status === 404) return null;
751
+ return Promise.reject(result.status);
752
+ }).then(buffer => complete.push({
753
+ id: job.id,
754
+ buffer
755
+ })).catch(error => complete.push({
756
+ id: job.id,
757
+ error: error && error.message || "Failed request: ".concat(job.url)
758
+ })).then(() => jobsActive--);
759
+ };
760
+
761
+ // crossFetch means "fetch" is now always supported
762
+ postMessage({
763
+ support: {
764
+ fetch: true
765
+ }
766
+ });
767
+ self.addEventListener('message', onMessage);
768
+ module.exports = __webpack_exports__;
769
+ /******/ })()
770
+ ;
771
+ //# sourceMappingURL=fetch-worker.3bf90a691c26a60b5752.js.map