scratch-storage 2.0.2 → 2.2.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 (32) hide show
  1. package/.circleci/config.yml +70 -0
  2. package/.nyc_output/c826ae6b-4ae2-4d8e-bdb2-162df5761fa7.json +1 -0
  3. package/.nyc_output/ec2d52a1-5131-4dd0-9c23-59106f297082.json +1 -0
  4. package/.nyc_output/processinfo/c826ae6b-4ae2-4d8e-bdb2-162df5761fa7.json +1 -0
  5. package/.nyc_output/processinfo/ec2d52a1-5131-4dd0-9c23-59106f297082.json +1 -0
  6. package/.nyc_output/processinfo/index.json +1 -0
  7. package/README.md +2 -1
  8. package/dist/node/8c63ecb0448dfbb8e804.worker.js +4187 -0
  9. package/dist/node/8c63ecb0448dfbb8e804.worker.js.map +1 -0
  10. package/dist/node/scratch-storage.js +2933 -142
  11. package/dist/node/scratch-storage.js.map +1 -1
  12. package/dist/web/90c5db0dff5ca2a36ff6.worker.js +743 -0
  13. package/dist/web/90c5db0dff5ca2a36ff6.worker.js.map +1 -0
  14. package/dist/web/scratch-storage.js +1149 -85
  15. package/dist/web/scratch-storage.js.map +1 -1
  16. package/dist/web/scratch-storage.min.js +1149 -85
  17. package/dist/web/scratch-storage.min.js.map +1 -1
  18. package/package.json +9 -4
  19. package/src/FetchTool.js +17 -13
  20. package/src/FetchWorkerTool.js +14 -7
  21. package/src/FetchWorkerTool.worker.js +6 -10
  22. package/src/scratchFetch.js +86 -0
  23. package/test/integration/download-known-assets.js +27 -30
  24. package/test/mocks/mockFetch.js +64 -0
  25. package/test/unit/fetch-tool.js +27 -44
  26. package/test/unit/metadata.js +136 -0
  27. package/webpack.config.js +9 -8
  28. package/.travis.yml +0 -24
  29. package/dist/node/f98711f696b187f5e007.worker.js +0 -1906
  30. package/dist/node/f98711f696b187f5e007.worker.js.map +0 -1
  31. package/dist/web/01b4fbd4d14a4f22cab8.worker.js +0 -190
  32. package/dist/web/01b4fbd4d14a4f22cab8.worker.js.map +0 -1
@@ -0,0 +1,743 @@
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
+ var crossFetch = __webpack_require__(/*! cross-fetch */ "./node_modules/cross-fetch/dist/browser-ponyfill.js").default;
98
+
99
+ var jobsActive = 0;
100
+ var complete = [];
101
+ var intervalId = null;
102
+ /**
103
+ * Register a step function.
104
+ *
105
+ * Step checks if there are completed jobs and if there are sends them to the
106
+ * parent. Then it checks the jobs count. If there are no further jobs, clear
107
+ * the step.
108
+ */
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(), // Instruct postMessage that these buffers in the sent message
116
+ // should use their Transferable trait. After the postMessage
117
+ // call the "buffers" will still be in complete if you looked,
118
+ // but they will all be length 0 as the data they reference has
119
+ // been sent to the window. This lets us send a lot of data
120
+ // without the normal postMessage behaviour of making a copy of
121
+ // all of the data for the window.
122
+ complete.map(function (response) {
123
+ return response.buffer;
124
+ }).filter(Boolean));
125
+ complete.length = 0;
126
+ }
127
+
128
+ if (jobsActive === 0) {
129
+ clearInterval(intervalId);
130
+ intervalId = null;
131
+ }
132
+ }, 1);
133
+ };
134
+ /**
135
+ * Receive a job from the parent and fetch the requested data.
136
+ * @param {object} options.job A job id, url, and options descriptor to perform.
137
+ */
138
+
139
+
140
+ var onMessage = function onMessage(_ref) {
141
+ var job = _ref.data;
142
+
143
+ if (jobsActive === 0 && !intervalId) {
144
+ registerStep();
145
+ }
146
+
147
+ jobsActive++;
148
+ crossFetch(job.url, job.options).then(function (result) {
149
+ if (result.ok) return result.arrayBuffer();
150
+ if (result.status === 404) return null;
151
+ return Promise.reject(result.status);
152
+ }).then(function (buffer) {
153
+ return complete.push({
154
+ id: job.id,
155
+ buffer: buffer
156
+ });
157
+ }).catch(function (error) {
158
+ return complete.push({
159
+ id: job.id,
160
+ error: error && error.message || "Failed request: ".concat(job.url)
161
+ });
162
+ }).then(function () {
163
+ return jobsActive--;
164
+ });
165
+ }; // crossFetch means "fetch" is now always supported
166
+
167
+
168
+ postMessage({
169
+ support: {
170
+ fetch: true
171
+ }
172
+ });
173
+ self.addEventListener('message', onMessage);
174
+
175
+ /***/ }),
176
+
177
+ /***/ "./node_modules/cross-fetch/dist/browser-ponyfill.js":
178
+ /*!***********************************************************!*\
179
+ !*** ./node_modules/cross-fetch/dist/browser-ponyfill.js ***!
180
+ \***********************************************************/
181
+ /*! no static exports found */
182
+ /***/ (function(module, exports) {
183
+
184
+ var global = typeof self !== 'undefined' ? self : this;
185
+ var __self__ = (function () {
186
+ function F() {
187
+ this.fetch = false;
188
+ this.DOMException = global.DOMException
189
+ }
190
+ F.prototype = global;
191
+ return new F();
192
+ })();
193
+ (function(self) {
194
+
195
+ var irrelevant = (function (exports) {
196
+
197
+ var support = {
198
+ searchParams: 'URLSearchParams' in self,
199
+ iterable: 'Symbol' in self && 'iterator' in Symbol,
200
+ blob:
201
+ 'FileReader' in self &&
202
+ 'Blob' in self &&
203
+ (function() {
204
+ try {
205
+ new Blob();
206
+ return true
207
+ } catch (e) {
208
+ return false
209
+ }
210
+ })(),
211
+ formData: 'FormData' in self,
212
+ arrayBuffer: 'ArrayBuffer' in self
213
+ };
214
+
215
+ function isDataView(obj) {
216
+ return obj && DataView.prototype.isPrototypeOf(obj)
217
+ }
218
+
219
+ if (support.arrayBuffer) {
220
+ var viewClasses = [
221
+ '[object Int8Array]',
222
+ '[object Uint8Array]',
223
+ '[object Uint8ClampedArray]',
224
+ '[object Int16Array]',
225
+ '[object Uint16Array]',
226
+ '[object Int32Array]',
227
+ '[object Uint32Array]',
228
+ '[object Float32Array]',
229
+ '[object Float64Array]'
230
+ ];
231
+
232
+ var isArrayBufferView =
233
+ ArrayBuffer.isView ||
234
+ function(obj) {
235
+ return obj && viewClasses.indexOf(Object.prototype.toString.call(obj)) > -1
236
+ };
237
+ }
238
+
239
+ function normalizeName(name) {
240
+ if (typeof name !== 'string') {
241
+ name = String(name);
242
+ }
243
+ if (/[^a-z0-9\-#$%&'*+.^_`|~]/i.test(name)) {
244
+ throw new TypeError('Invalid character in header field name')
245
+ }
246
+ return name.toLowerCase()
247
+ }
248
+
249
+ function normalizeValue(value) {
250
+ if (typeof value !== 'string') {
251
+ value = String(value);
252
+ }
253
+ return value
254
+ }
255
+
256
+ // Build a destructive iterator for the value list
257
+ function iteratorFor(items) {
258
+ var iterator = {
259
+ next: function() {
260
+ var value = items.shift();
261
+ return {done: value === undefined, value: value}
262
+ }
263
+ };
264
+
265
+ if (support.iterable) {
266
+ iterator[Symbol.iterator] = function() {
267
+ return iterator
268
+ };
269
+ }
270
+
271
+ return iterator
272
+ }
273
+
274
+ function Headers(headers) {
275
+ this.map = {};
276
+
277
+ if (headers instanceof Headers) {
278
+ headers.forEach(function(value, name) {
279
+ this.append(name, value);
280
+ }, this);
281
+ } else if (Array.isArray(headers)) {
282
+ headers.forEach(function(header) {
283
+ this.append(header[0], header[1]);
284
+ }, this);
285
+ } else if (headers) {
286
+ Object.getOwnPropertyNames(headers).forEach(function(name) {
287
+ this.append(name, headers[name]);
288
+ }, this);
289
+ }
290
+ }
291
+
292
+ Headers.prototype.append = function(name, value) {
293
+ name = normalizeName(name);
294
+ value = normalizeValue(value);
295
+ var oldValue = this.map[name];
296
+ this.map[name] = oldValue ? oldValue + ', ' + value : value;
297
+ };
298
+
299
+ Headers.prototype['delete'] = function(name) {
300
+ delete this.map[normalizeName(name)];
301
+ };
302
+
303
+ Headers.prototype.get = function(name) {
304
+ name = normalizeName(name);
305
+ return this.has(name) ? this.map[name] : null
306
+ };
307
+
308
+ Headers.prototype.has = function(name) {
309
+ return this.map.hasOwnProperty(normalizeName(name))
310
+ };
311
+
312
+ Headers.prototype.set = function(name, value) {
313
+ this.map[normalizeName(name)] = normalizeValue(value);
314
+ };
315
+
316
+ Headers.prototype.forEach = function(callback, thisArg) {
317
+ for (var name in this.map) {
318
+ if (this.map.hasOwnProperty(name)) {
319
+ callback.call(thisArg, this.map[name], name, this);
320
+ }
321
+ }
322
+ };
323
+
324
+ Headers.prototype.keys = function() {
325
+ var items = [];
326
+ this.forEach(function(value, name) {
327
+ items.push(name);
328
+ });
329
+ return iteratorFor(items)
330
+ };
331
+
332
+ Headers.prototype.values = function() {
333
+ var items = [];
334
+ this.forEach(function(value) {
335
+ items.push(value);
336
+ });
337
+ return iteratorFor(items)
338
+ };
339
+
340
+ Headers.prototype.entries = function() {
341
+ var items = [];
342
+ this.forEach(function(value, name) {
343
+ items.push([name, value]);
344
+ });
345
+ return iteratorFor(items)
346
+ };
347
+
348
+ if (support.iterable) {
349
+ Headers.prototype[Symbol.iterator] = Headers.prototype.entries;
350
+ }
351
+
352
+ function consumed(body) {
353
+ if (body.bodyUsed) {
354
+ return Promise.reject(new TypeError('Already read'))
355
+ }
356
+ body.bodyUsed = true;
357
+ }
358
+
359
+ function fileReaderReady(reader) {
360
+ return new Promise(function(resolve, reject) {
361
+ reader.onload = function() {
362
+ resolve(reader.result);
363
+ };
364
+ reader.onerror = function() {
365
+ reject(reader.error);
366
+ };
367
+ })
368
+ }
369
+
370
+ function readBlobAsArrayBuffer(blob) {
371
+ var reader = new FileReader();
372
+ var promise = fileReaderReady(reader);
373
+ reader.readAsArrayBuffer(blob);
374
+ return promise
375
+ }
376
+
377
+ function readBlobAsText(blob) {
378
+ var reader = new FileReader();
379
+ var promise = fileReaderReady(reader);
380
+ reader.readAsText(blob);
381
+ return promise
382
+ }
383
+
384
+ function readArrayBufferAsText(buf) {
385
+ var view = new Uint8Array(buf);
386
+ var chars = new Array(view.length);
387
+
388
+ for (var i = 0; i < view.length; i++) {
389
+ chars[i] = String.fromCharCode(view[i]);
390
+ }
391
+ return chars.join('')
392
+ }
393
+
394
+ function bufferClone(buf) {
395
+ if (buf.slice) {
396
+ return buf.slice(0)
397
+ } else {
398
+ var view = new Uint8Array(buf.byteLength);
399
+ view.set(new Uint8Array(buf));
400
+ return view.buffer
401
+ }
402
+ }
403
+
404
+ function Body() {
405
+ this.bodyUsed = false;
406
+
407
+ this._initBody = function(body) {
408
+ this._bodyInit = body;
409
+ if (!body) {
410
+ this._bodyText = '';
411
+ } else if (typeof body === 'string') {
412
+ this._bodyText = body;
413
+ } else if (support.blob && Blob.prototype.isPrototypeOf(body)) {
414
+ this._bodyBlob = body;
415
+ } else if (support.formData && FormData.prototype.isPrototypeOf(body)) {
416
+ this._bodyFormData = body;
417
+ } else if (support.searchParams && URLSearchParams.prototype.isPrototypeOf(body)) {
418
+ this._bodyText = body.toString();
419
+ } else if (support.arrayBuffer && support.blob && isDataView(body)) {
420
+ this._bodyArrayBuffer = bufferClone(body.buffer);
421
+ // IE 10-11 can't handle a DataView body.
422
+ this._bodyInit = new Blob([this._bodyArrayBuffer]);
423
+ } else if (support.arrayBuffer && (ArrayBuffer.prototype.isPrototypeOf(body) || isArrayBufferView(body))) {
424
+ this._bodyArrayBuffer = bufferClone(body);
425
+ } else {
426
+ this._bodyText = body = Object.prototype.toString.call(body);
427
+ }
428
+
429
+ if (!this.headers.get('content-type')) {
430
+ if (typeof body === 'string') {
431
+ this.headers.set('content-type', 'text/plain;charset=UTF-8');
432
+ } else if (this._bodyBlob && this._bodyBlob.type) {
433
+ this.headers.set('content-type', this._bodyBlob.type);
434
+ } else if (support.searchParams && URLSearchParams.prototype.isPrototypeOf(body)) {
435
+ this.headers.set('content-type', 'application/x-www-form-urlencoded;charset=UTF-8');
436
+ }
437
+ }
438
+ };
439
+
440
+ if (support.blob) {
441
+ this.blob = function() {
442
+ var rejected = consumed(this);
443
+ if (rejected) {
444
+ return rejected
445
+ }
446
+
447
+ if (this._bodyBlob) {
448
+ return Promise.resolve(this._bodyBlob)
449
+ } else if (this._bodyArrayBuffer) {
450
+ return Promise.resolve(new Blob([this._bodyArrayBuffer]))
451
+ } else if (this._bodyFormData) {
452
+ throw new Error('could not read FormData body as blob')
453
+ } else {
454
+ return Promise.resolve(new Blob([this._bodyText]))
455
+ }
456
+ };
457
+
458
+ this.arrayBuffer = function() {
459
+ if (this._bodyArrayBuffer) {
460
+ return consumed(this) || Promise.resolve(this._bodyArrayBuffer)
461
+ } else {
462
+ return this.blob().then(readBlobAsArrayBuffer)
463
+ }
464
+ };
465
+ }
466
+
467
+ this.text = function() {
468
+ var rejected = consumed(this);
469
+ if (rejected) {
470
+ return rejected
471
+ }
472
+
473
+ if (this._bodyBlob) {
474
+ return readBlobAsText(this._bodyBlob)
475
+ } else if (this._bodyArrayBuffer) {
476
+ return Promise.resolve(readArrayBufferAsText(this._bodyArrayBuffer))
477
+ } else if (this._bodyFormData) {
478
+ throw new Error('could not read FormData body as text')
479
+ } else {
480
+ return Promise.resolve(this._bodyText)
481
+ }
482
+ };
483
+
484
+ if (support.formData) {
485
+ this.formData = function() {
486
+ return this.text().then(decode)
487
+ };
488
+ }
489
+
490
+ this.json = function() {
491
+ return this.text().then(JSON.parse)
492
+ };
493
+
494
+ return this
495
+ }
496
+
497
+ // HTTP methods whose capitalization should be normalized
498
+ var methods = ['DELETE', 'GET', 'HEAD', 'OPTIONS', 'POST', 'PUT'];
499
+
500
+ function normalizeMethod(method) {
501
+ var upcased = method.toUpperCase();
502
+ return methods.indexOf(upcased) > -1 ? upcased : method
503
+ }
504
+
505
+ function Request(input, options) {
506
+ options = options || {};
507
+ var body = options.body;
508
+
509
+ if (input instanceof Request) {
510
+ if (input.bodyUsed) {
511
+ throw new TypeError('Already read')
512
+ }
513
+ this.url = input.url;
514
+ this.credentials = input.credentials;
515
+ if (!options.headers) {
516
+ this.headers = new Headers(input.headers);
517
+ }
518
+ this.method = input.method;
519
+ this.mode = input.mode;
520
+ this.signal = input.signal;
521
+ if (!body && input._bodyInit != null) {
522
+ body = input._bodyInit;
523
+ input.bodyUsed = true;
524
+ }
525
+ } else {
526
+ this.url = String(input);
527
+ }
528
+
529
+ this.credentials = options.credentials || this.credentials || 'same-origin';
530
+ if (options.headers || !this.headers) {
531
+ this.headers = new Headers(options.headers);
532
+ }
533
+ this.method = normalizeMethod(options.method || this.method || 'GET');
534
+ this.mode = options.mode || this.mode || null;
535
+ this.signal = options.signal || this.signal;
536
+ this.referrer = null;
537
+
538
+ if ((this.method === 'GET' || this.method === 'HEAD') && body) {
539
+ throw new TypeError('Body not allowed for GET or HEAD requests')
540
+ }
541
+ this._initBody(body);
542
+ }
543
+
544
+ Request.prototype.clone = function() {
545
+ return new Request(this, {body: this._bodyInit})
546
+ };
547
+
548
+ function decode(body) {
549
+ var form = new FormData();
550
+ body
551
+ .trim()
552
+ .split('&')
553
+ .forEach(function(bytes) {
554
+ if (bytes) {
555
+ var split = bytes.split('=');
556
+ var name = split.shift().replace(/\+/g, ' ');
557
+ var value = split.join('=').replace(/\+/g, ' ');
558
+ form.append(decodeURIComponent(name), decodeURIComponent(value));
559
+ }
560
+ });
561
+ return form
562
+ }
563
+
564
+ function parseHeaders(rawHeaders) {
565
+ var headers = new Headers();
566
+ // Replace instances of \r\n and \n followed by at least one space or horizontal tab with a space
567
+ // https://tools.ietf.org/html/rfc7230#section-3.2
568
+ var preProcessedHeaders = rawHeaders.replace(/\r?\n[\t ]+/g, ' ');
569
+ preProcessedHeaders.split(/\r?\n/).forEach(function(line) {
570
+ var parts = line.split(':');
571
+ var key = parts.shift().trim();
572
+ if (key) {
573
+ var value = parts.join(':').trim();
574
+ headers.append(key, value);
575
+ }
576
+ });
577
+ return headers
578
+ }
579
+
580
+ Body.call(Request.prototype);
581
+
582
+ function Response(bodyInit, options) {
583
+ if (!options) {
584
+ options = {};
585
+ }
586
+
587
+ this.type = 'default';
588
+ this.status = options.status === undefined ? 200 : options.status;
589
+ this.ok = this.status >= 200 && this.status < 300;
590
+ this.statusText = 'statusText' in options ? options.statusText : 'OK';
591
+ this.headers = new Headers(options.headers);
592
+ this.url = options.url || '';
593
+ this._initBody(bodyInit);
594
+ }
595
+
596
+ Body.call(Response.prototype);
597
+
598
+ Response.prototype.clone = function() {
599
+ return new Response(this._bodyInit, {
600
+ status: this.status,
601
+ statusText: this.statusText,
602
+ headers: new Headers(this.headers),
603
+ url: this.url
604
+ })
605
+ };
606
+
607
+ Response.error = function() {
608
+ var response = new Response(null, {status: 0, statusText: ''});
609
+ response.type = 'error';
610
+ return response
611
+ };
612
+
613
+ var redirectStatuses = [301, 302, 303, 307, 308];
614
+
615
+ Response.redirect = function(url, status) {
616
+ if (redirectStatuses.indexOf(status) === -1) {
617
+ throw new RangeError('Invalid status code')
618
+ }
619
+
620
+ return new Response(null, {status: status, headers: {location: url}})
621
+ };
622
+
623
+ exports.DOMException = self.DOMException;
624
+ try {
625
+ new exports.DOMException();
626
+ } catch (err) {
627
+ exports.DOMException = function(message, name) {
628
+ this.message = message;
629
+ this.name = name;
630
+ var error = Error(message);
631
+ this.stack = error.stack;
632
+ };
633
+ exports.DOMException.prototype = Object.create(Error.prototype);
634
+ exports.DOMException.prototype.constructor = exports.DOMException;
635
+ }
636
+
637
+ function fetch(input, init) {
638
+ return new Promise(function(resolve, reject) {
639
+ var request = new Request(input, init);
640
+
641
+ if (request.signal && request.signal.aborted) {
642
+ return reject(new exports.DOMException('Aborted', 'AbortError'))
643
+ }
644
+
645
+ var xhr = new XMLHttpRequest();
646
+
647
+ function abortXhr() {
648
+ xhr.abort();
649
+ }
650
+
651
+ xhr.onload = function() {
652
+ var options = {
653
+ status: xhr.status,
654
+ statusText: xhr.statusText,
655
+ headers: parseHeaders(xhr.getAllResponseHeaders() || '')
656
+ };
657
+ options.url = 'responseURL' in xhr ? xhr.responseURL : options.headers.get('X-Request-URL');
658
+ var body = 'response' in xhr ? xhr.response : xhr.responseText;
659
+ resolve(new Response(body, options));
660
+ };
661
+
662
+ xhr.onerror = function() {
663
+ reject(new TypeError('Network request failed'));
664
+ };
665
+
666
+ xhr.ontimeout = function() {
667
+ reject(new TypeError('Network request failed'));
668
+ };
669
+
670
+ xhr.onabort = function() {
671
+ reject(new exports.DOMException('Aborted', 'AbortError'));
672
+ };
673
+
674
+ xhr.open(request.method, request.url, true);
675
+
676
+ if (request.credentials === 'include') {
677
+ xhr.withCredentials = true;
678
+ } else if (request.credentials === 'omit') {
679
+ xhr.withCredentials = false;
680
+ }
681
+
682
+ if ('responseType' in xhr && support.blob) {
683
+ xhr.responseType = 'blob';
684
+ }
685
+
686
+ request.headers.forEach(function(value, name) {
687
+ xhr.setRequestHeader(name, value);
688
+ });
689
+
690
+ if (request.signal) {
691
+ request.signal.addEventListener('abort', abortXhr);
692
+
693
+ xhr.onreadystatechange = function() {
694
+ // DONE (success or failure)
695
+ if (xhr.readyState === 4) {
696
+ request.signal.removeEventListener('abort', abortXhr);
697
+ }
698
+ };
699
+ }
700
+
701
+ xhr.send(typeof request._bodyInit === 'undefined' ? null : request._bodyInit);
702
+ })
703
+ }
704
+
705
+ fetch.polyfill = true;
706
+
707
+ if (!self.fetch) {
708
+ self.fetch = fetch;
709
+ self.Headers = Headers;
710
+ self.Request = Request;
711
+ self.Response = Response;
712
+ }
713
+
714
+ exports.Headers = Headers;
715
+ exports.Request = Request;
716
+ exports.Response = Response;
717
+ exports.fetch = fetch;
718
+
719
+ Object.defineProperty(exports, '__esModule', { value: true });
720
+
721
+ return exports;
722
+
723
+ })({});
724
+ })(__self__);
725
+ __self__.fetch.ponyfill = true;
726
+ // Remove "polyfill" property added by whatwg-fetch
727
+ delete __self__.fetch.polyfill;
728
+ // Choose between native implementation (global) or custom implementation (__self__)
729
+ // var ctx = global.fetch ? global : __self__;
730
+ var ctx = __self__; // this line disable service worker support temporarily
731
+ exports = ctx.fetch // To enable: import fetch from 'cross-fetch'
732
+ exports.default = ctx.fetch // For TypeScript consumers without esModuleInterop.
733
+ exports.fetch = ctx.fetch // To enable: import {fetch} from 'cross-fetch'
734
+ exports.Headers = ctx.Headers
735
+ exports.Request = ctx.Request
736
+ exports.Response = ctx.Response
737
+ module.exports = exports
738
+
739
+
740
+ /***/ })
741
+
742
+ /******/ });
743
+ //# sourceMappingURL=90c5db0dff5ca2a36ff6.worker.js.map