scratch-storage 2.2.0 → 2.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.circleci/config.yml +1 -1
- package/dist/node/scratch-storage.js +125 -57
- package/dist/node/scratch-storage.js.map +1 -1
- package/dist/web/scratch-storage.js +125 -57
- package/dist/web/scratch-storage.js.map +1 -1
- package/dist/web/scratch-storage.min.js +125 -57
- package/dist/web/scratch-storage.min.js.map +1 -1
- package/jest.config.js +5 -0
- package/package.json +10 -8
- package/src/BuiltinHelper.js +3 -3
- package/src/FetchWorkerTool.js +8 -1
- package/src/ScratchStorage.js +9 -0
- package/src/scratchFetch.js +51 -11
- package/test/.eslintrc.js +5 -1
- package/test/{mocks/mockFetch.js → __mocks__/cross-fetch.js} +30 -16
- package/test/fixtures/.gitattributes +3 -0
- package/test/fixtures/assets/117504922.json +196 -0
- package/test/fixtures/assets/66895930177178ea01d9e610917f8acf.png +0 -0
- package/test/fixtures/assets/6e8bd9ae68fdb02b7e1e3df656a75635.svg +37 -0
- package/test/fixtures/assets/7e24c99c1b853e52f8e7f9004416fa34.png +0 -0
- package/test/fixtures/assets/83c36d806dc92327b9e7049a565c6bff.wav +0 -0
- package/test/fixtures/assets/f88bf1935daea28f8ca098462a31dbb0.svg +35 -0
- package/test/fixtures/assets/fe5e3566965f9de793beeffce377d054.jpg +0 -0
- package/test/fixtures/known-assets.js +60 -0
- package/test/integration/download-known-assets.test.js +141 -0
- package/test/transformers/.eslintrc.js +8 -0
- package/test/transformers/arraybuffer-loader.js +11 -0
- package/test/unit/{add-helper.js → add-helper.test.js} +16 -20
- package/test/unit/fetch-tool.test.js +56 -0
- package/test/unit/load-default-assets.test.js +59 -0
- package/test/unit/metadata.test.js +129 -0
- package/webpack.config.js +4 -0
- package/.nyc_output/c826ae6b-4ae2-4d8e-bdb2-162df5761fa7.json +0 -1
- package/.nyc_output/ec2d52a1-5131-4dd0-9c23-59106f297082.json +0 -1
- package/.nyc_output/processinfo/c826ae6b-4ae2-4d8e-bdb2-162df5761fa7.json +0 -1
- package/.nyc_output/processinfo/ec2d52a1-5131-4dd0-9c23-59106f297082.json +0 -1
- package/.nyc_output/processinfo/index.json +0 -1
- package/test/integration/download-known-assets.js +0 -111
- package/test/unit/fetch-tool.js +0 -60
- package/test/unit/load-default-assets.js +0 -48
- package/test/unit/metadata.js +0 -136
|
@@ -471,39 +471,6 @@ module.exports = _unsupportedIterableToArray, module.exports.__esModule = true,
|
|
|
471
471
|
|
|
472
472
|
/***/ }),
|
|
473
473
|
|
|
474
|
-
/***/ "./node_modules/arraybuffer-loader/index.js!./src/builtins/defaultBitmap.png":
|
|
475
|
-
/*!**************************************************************************!*\
|
|
476
|
-
!*** ./node_modules/arraybuffer-loader!./src/builtins/defaultBitmap.png ***!
|
|
477
|
-
\**************************************************************************/
|
|
478
|
-
/*! no static exports found */
|
|
479
|
-
/***/ (function(module, exports, __webpack_require__) {
|
|
480
|
-
|
|
481
|
-
module.exports = __webpack_require__(/*! ../../node_modules/arraybuffer-loader/lib/to-array-buffer.js */ "./node_modules/arraybuffer-loader/lib/to-array-buffer.js")("iVBORw0KGgoAAAANSUhEUgAAAIAAAACACAAAAADmVT4XAAADZElEQVR42u3a70vbQBgH8O/7vOibvsmbFUEEWUGGUhQ25nDuhSKIUFDxlYi0SAd94atRmFiHCH2x4W8iiNtwowXRgd1QipJYY3N/1F4kTQ6XLKS9yyHcvWyO8MnT5y53Tw5EcIMESIAESIAESIAESIAEPFVAq/6l8G4oAQCp4aniwbUVJ6BVzafwqKXy1VZMgNb+CHzbyK4ZB+Bi0nnk0VyhsDiSoAmvvnMHmGUVAF6UG+0ffsxRhsRHky/AyCsAUpumX0wAAIs6T4CxDADDtcdZsal6gjmdH8AsAEC6+s8Fa48SFExeAKusAEju+V367AmUCi9ANQ0AU3pwcOw2cMEH0FwAAKz5X228pRLR5AI4TgIAtIDL24oLUE94AB6W7LsH/cONN14Ilh44AOqD9s2LQR1KHiB9zgGgOSGeuA3ocPrME1Q4ANaceyePAzrcjHmAZYs9IBeW4/fzHiAwTCwAgTle9ACZK44ALDT9e6x7gL4aT0BQCHb4AqgA5/1TTOMLoJ7vZSMM0H/GHnCeDnu+CrU8vGYPcN5FADBYD0vCaYPDy+i0p337GSMsS1Z4vA3t9QgAZTt0IuIxFRPSKicAQHlvhk3FXF5GhBByMa8qo/sBO6BarwuYbYrYnFKDYEvE7phKgcxvEQBqnvhgiQCUOgoAO4C3JOS3L/hv23UXxVldBECfcueAqpAa0WGy/QeULREAY6aTXRFDgBuA13+ElOncAERMAGaA9hBQD4gQQHsIRE1AZoD2xrgQS5nOZyHgFKmWDSIG4GRAVidiAE4GRB6AzAB2AKIPQFaA5myHA5AV4ESNugZhC7BLR50lIBPAebrzBGQCKAFQNSIMcDvRTQIwAHxNApM3RBygGK0uyhxwOwGsPAgEnPWj5ycRCNiJtBHlAChGKQVwANzPY+CXSMDNWISiLA9AfRA5IhJQ68UnoQAt+AtOPIBKhJosF8B6UM0yLkAxQk2WCyDX9SiUh1gkQAIkoCuAvjGuquMbuijAtwG7MPL8yBICOHSPk3W8Ne8KcEUdmBi6FADYos+QleIH0N/ogOxd7AD6uAS6WRU8WcBdlgZMG/EnYUlwEpLLoQ4PjzGbiA5UsRMRsbQ+5ziDJmYqJuR6NaMomdXuFuZyPSABEiABEiABEiABEiAc8Bd6VyvCEKGqcQAAAABJRU5ErkJggg==")
|
|
482
|
-
|
|
483
|
-
/***/ }),
|
|
484
|
-
|
|
485
|
-
/***/ "./node_modules/arraybuffer-loader/index.js!./src/builtins/defaultSound.wav":
|
|
486
|
-
/*!*************************************************************************!*\
|
|
487
|
-
!*** ./node_modules/arraybuffer-loader!./src/builtins/defaultSound.wav ***!
|
|
488
|
-
\*************************************************************************/
|
|
489
|
-
/*! no static exports found */
|
|
490
|
-
/***/ (function(module, exports, __webpack_require__) {
|
|
491
|
-
|
|
492
|
-
module.exports = __webpack_require__(/*! ../../node_modules/arraybuffer-loader/lib/to-array-buffer.js */ "./node_modules/arraybuffer-loader/lib/to-array-buffer.js")("UklGRiYAAABXQVZFZm10IBAAAAABAAEAIlYAAESsAAACABAAZGF0YQIAAAAAAA==")
|
|
493
|
-
|
|
494
|
-
/***/ }),
|
|
495
|
-
|
|
496
|
-
/***/ "./node_modules/arraybuffer-loader/index.js!./src/builtins/defaultVector.svg":
|
|
497
|
-
/*!**************************************************************************!*\
|
|
498
|
-
!*** ./node_modules/arraybuffer-loader!./src/builtins/defaultVector.svg ***!
|
|
499
|
-
\**************************************************************************/
|
|
500
|
-
/*! no static exports found */
|
|
501
|
-
/***/ (function(module, exports, __webpack_require__) {
|
|
502
|
-
|
|
503
|
-
module.exports = __webpack_require__(/*! ../../node_modules/arraybuffer-loader/lib/to-array-buffer.js */ "./node_modules/arraybuffer-loader/lib/to-array-buffer.js")("PD94bWwgdmVyc2lvbj0iMS4wIj8+Cjxzdmcgd2lkdGg9IjEyOCIgaGVpZ2h0PSIxMjgiIHhtbG5zPSJodHRwOi8vd3d3LnczLm9yZy8yMDAwL3N2ZyIgeG1sbnM6c3ZnPSJodHRwOi8vd3d3LnczLm9yZy8yMDAwL3N2ZyI+CiA8Zz4KICA8cmVjdCBmaWxsPSIjQ0NDIiBoZWlnaHQ9IjEyOCIgd2lkdGg9IjEyOCIvPgogIDx0ZXh0IGZpbGw9ImJsYWNrIiB5PSIxMDciIHg9IjM1LjUiIGZvbnQtc2l6ZT0iMTI4Ij4/PC90ZXh0PgogPC9nPgo8L3N2Zz4K")
|
|
504
|
-
|
|
505
|
-
/***/ }),
|
|
506
|
-
|
|
507
474
|
/***/ "./node_modules/arraybuffer-loader/lib/to-array-buffer.js":
|
|
508
475
|
/*!****************************************************************!*\
|
|
509
476
|
!*** ./node_modules/arraybuffer-loader/lib/to-array-buffer.js ***!
|
|
@@ -5072,19 +5039,19 @@ var DefaultAssets = [{
|
|
|
5072
5039
|
type: AssetType.ImageBitmap,
|
|
5073
5040
|
format: DataFormat.PNG,
|
|
5074
5041
|
id: null,
|
|
5075
|
-
data: Buffer.from(__webpack_require__(/*!
|
|
5042
|
+
data: Buffer.from(__webpack_require__(/*! ./builtins/defaultBitmap.png */ "./src/builtins/defaultBitmap.png") // eslint-disable-line global-require
|
|
5076
5043
|
)
|
|
5077
5044
|
}, {
|
|
5078
5045
|
type: AssetType.Sound,
|
|
5079
5046
|
format: DataFormat.WAV,
|
|
5080
5047
|
id: null,
|
|
5081
|
-
data: Buffer.from(__webpack_require__(/*!
|
|
5048
|
+
data: Buffer.from(__webpack_require__(/*! ./builtins/defaultSound.wav */ "./src/builtins/defaultSound.wav") // eslint-disable-line global-require
|
|
5082
5049
|
)
|
|
5083
5050
|
}, {
|
|
5084
5051
|
type: AssetType.ImageVector,
|
|
5085
5052
|
format: DataFormat.SVG,
|
|
5086
5053
|
id: null,
|
|
5087
|
-
data: Buffer.from(__webpack_require__(/*!
|
|
5054
|
+
data: Buffer.from(__webpack_require__(/*! ./builtins/defaultVector.svg */ "./src/builtins/defaultVector.svg") // eslint-disable-line global-require
|
|
5088
5055
|
)
|
|
5089
5056
|
}];
|
|
5090
5057
|
/**
|
|
@@ -5397,6 +5364,7 @@ function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o =
|
|
|
5397
5364
|
function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) { arr2[i] = arr[i]; } return arr2; }
|
|
5398
5365
|
|
|
5399
5366
|
var _require = __webpack_require__(/*! ./scratchFetch */ "./src/scratchFetch.js"),
|
|
5367
|
+
Headers = _require.Headers,
|
|
5400
5368
|
applyMetadata = _require.applyMetadata;
|
|
5401
5369
|
/**
|
|
5402
5370
|
* Get and send assets with a worker that uses fetch.
|
|
@@ -5515,7 +5483,14 @@ var PrivateFetchWorkerTool = /*#__PURE__*/function () {
|
|
|
5515
5483
|
var id = Math.random().toString(16).substring(2);
|
|
5516
5484
|
var augmentedOptions = applyMetadata(Object.assign({
|
|
5517
5485
|
method: 'GET'
|
|
5518
|
-
}, options));
|
|
5486
|
+
}, options)); // the Fetch spec says options.headers could be:
|
|
5487
|
+
// "A Headers object, an object literal, or an array of two-item arrays to set request's headers."
|
|
5488
|
+
// structured clone (postMessage) doesn't support Headers objects
|
|
5489
|
+
// so turn it into an array of two-item arrays to make it to the worker intact
|
|
5490
|
+
|
|
5491
|
+
if (augmentedOptions && augmentedOptions.headers instanceof Headers) {
|
|
5492
|
+
augmentedOptions.headers = Array.from(augmentedOptions.headers.entries());
|
|
5493
|
+
}
|
|
5519
5494
|
|
|
5520
5495
|
_this2.worker.postMessage({
|
|
5521
5496
|
id: id,
|
|
@@ -5869,6 +5844,8 @@ var _AssetType = __webpack_require__(/*! ./AssetType */ "./src/AssetType.js");
|
|
|
5869
5844
|
|
|
5870
5845
|
var _DataFormat = __webpack_require__(/*! ./DataFormat */ "./src/DataFormat.js");
|
|
5871
5846
|
|
|
5847
|
+
var _scratchFetch = __webpack_require__(/*! ./scratchFetch */ "./src/scratchFetch.js");
|
|
5848
|
+
|
|
5872
5849
|
var ScratchStorage = /*#__PURE__*/function () {
|
|
5873
5850
|
"use strict";
|
|
5874
5851
|
|
|
@@ -5918,6 +5895,16 @@ var ScratchStorage = /*#__PURE__*/function () {
|
|
|
5918
5895
|
get: function get() {
|
|
5919
5896
|
return _DataFormat;
|
|
5920
5897
|
}
|
|
5898
|
+
/**
|
|
5899
|
+
* Access the `scratchFetch` module within this library.
|
|
5900
|
+
* @return {module} the scratchFetch module, with properties for `scratchFetch`, `setMetadata`, etc.
|
|
5901
|
+
*/
|
|
5902
|
+
|
|
5903
|
+
}, {
|
|
5904
|
+
key: "scratchFetch",
|
|
5905
|
+
get: function get() {
|
|
5906
|
+
return _scratchFetch;
|
|
5907
|
+
}
|
|
5921
5908
|
/**
|
|
5922
5909
|
* @deprecated Please use the `Asset` member of a storage instance instead.
|
|
5923
5910
|
* @return {Asset} - the `Asset` class constructor.
|
|
@@ -6391,6 +6378,39 @@ module.exports = WebHelper;
|
|
|
6391
6378
|
|
|
6392
6379
|
/***/ }),
|
|
6393
6380
|
|
|
6381
|
+
/***/ "./src/builtins/defaultBitmap.png":
|
|
6382
|
+
/*!****************************************!*\
|
|
6383
|
+
!*** ./src/builtins/defaultBitmap.png ***!
|
|
6384
|
+
\****************************************/
|
|
6385
|
+
/*! no static exports found */
|
|
6386
|
+
/***/ (function(module, exports, __webpack_require__) {
|
|
6387
|
+
|
|
6388
|
+
module.exports = __webpack_require__(/*! ../../node_modules/arraybuffer-loader/lib/to-array-buffer.js */ "./node_modules/arraybuffer-loader/lib/to-array-buffer.js")("iVBORw0KGgoAAAANSUhEUgAAAIAAAACACAAAAADmVT4XAAADZElEQVR42u3a70vbQBgH8O/7vOibvsmbFUEEWUGGUhQ25nDuhSKIUFDxlYi0SAd94atRmFiHCH2x4W8iiNtwowXRgd1QipJYY3N/1F4kTQ6XLKS9yyHcvWyO8MnT5y53Tw5EcIMESIAESIAESIAESIAEPFVAq/6l8G4oAQCp4aniwbUVJ6BVzafwqKXy1VZMgNb+CHzbyK4ZB+Bi0nnk0VyhsDiSoAmvvnMHmGUVAF6UG+0ffsxRhsRHky/AyCsAUpumX0wAAIs6T4CxDADDtcdZsal6gjmdH8AsAEC6+s8Fa48SFExeAKusAEju+V367AmUCi9ANQ0AU3pwcOw2cMEH0FwAAKz5X228pRLR5AI4TgIAtIDL24oLUE94AB6W7LsH/cONN14Ilh44AOqD9s2LQR1KHiB9zgGgOSGeuA3ocPrME1Q4ANaceyePAzrcjHmAZYs9IBeW4/fzHiAwTCwAgTle9ACZK44ALDT9e6x7gL4aT0BQCHb4AqgA5/1TTOMLoJ7vZSMM0H/GHnCeDnu+CrU8vGYPcN5FADBYD0vCaYPDy+i0p337GSMsS1Z4vA3t9QgAZTt0IuIxFRPSKicAQHlvhk3FXF5GhBByMa8qo/sBO6BarwuYbYrYnFKDYEvE7phKgcxvEQBqnvhgiQCUOgoAO4C3JOS3L/hv23UXxVldBECfcueAqpAa0WGy/QeULREAY6aTXRFDgBuA13+ElOncAERMAGaA9hBQD4gQQHsIRE1AZoD2xrgQS5nOZyHgFKmWDSIG4GRAVidiAE4GRB6AzAB2AKIPQFaA5myHA5AV4ESNugZhC7BLR50lIBPAebrzBGQCKAFQNSIMcDvRTQIwAHxNApM3RBygGK0uyhxwOwGsPAgEnPWj5ycRCNiJtBHlAChGKQVwANzPY+CXSMDNWISiLA9AfRA5IhJQ68UnoQAt+AtOPIBKhJosF8B6UM0yLkAxQk2WCyDX9SiUh1gkQAIkoCuAvjGuquMbuijAtwG7MPL8yBICOHSPk3W8Ne8KcEUdmBi6FADYos+QleIH0N/ogOxd7AD6uAS6WRU8WcBdlgZMG/EnYUlwEpLLoQ4PjzGbiA5UsRMRsbQ+5ziDJmYqJuR6NaMomdXuFuZyPSABEiABEiABEiABEiAc8Bd6VyvCEKGqcQAAAABJRU5ErkJggg==")
|
|
6389
|
+
|
|
6390
|
+
/***/ }),
|
|
6391
|
+
|
|
6392
|
+
/***/ "./src/builtins/defaultSound.wav":
|
|
6393
|
+
/*!***************************************!*\
|
|
6394
|
+
!*** ./src/builtins/defaultSound.wav ***!
|
|
6395
|
+
\***************************************/
|
|
6396
|
+
/*! no static exports found */
|
|
6397
|
+
/***/ (function(module, exports, __webpack_require__) {
|
|
6398
|
+
|
|
6399
|
+
module.exports = __webpack_require__(/*! ../../node_modules/arraybuffer-loader/lib/to-array-buffer.js */ "./node_modules/arraybuffer-loader/lib/to-array-buffer.js")("UklGRiYAAABXQVZFZm10IBAAAAABAAEAIlYAAESsAAACABAAZGF0YQIAAAAAAA==")
|
|
6400
|
+
|
|
6401
|
+
/***/ }),
|
|
6402
|
+
|
|
6403
|
+
/***/ "./src/builtins/defaultVector.svg":
|
|
6404
|
+
/*!****************************************!*\
|
|
6405
|
+
!*** ./src/builtins/defaultVector.svg ***!
|
|
6406
|
+
\****************************************/
|
|
6407
|
+
/*! no static exports found */
|
|
6408
|
+
/***/ (function(module, exports, __webpack_require__) {
|
|
6409
|
+
|
|
6410
|
+
module.exports = __webpack_require__(/*! ../../node_modules/arraybuffer-loader/lib/to-array-buffer.js */ "./node_modules/arraybuffer-loader/lib/to-array-buffer.js")("PD94bWwgdmVyc2lvbj0iMS4wIj8+Cjxzdmcgd2lkdGg9IjEyOCIgaGVpZ2h0PSIxMjgiIHhtbG5zPSJodHRwOi8vd3d3LnczLm9yZy8yMDAwL3N2ZyIgeG1sbnM6c3ZnPSJodHRwOi8vd3d3LnczLm9yZy8yMDAwL3N2ZyI+CiA8Zz4KICA8cmVjdCBmaWxsPSIjQ0NDIiBoZWlnaHQ9IjEyOCIgd2lkdGg9IjEyOCIvPgogIDx0ZXh0IGZpbGw9ImJsYWNrIiB5PSIxMDciIHg9IjM1LjUiIGZvbnQtc2l6ZT0iMTI4Ij4/PC90ZXh0PgogPC9nPgo8L3N2Zz4K")
|
|
6411
|
+
|
|
6412
|
+
/***/ }),
|
|
6413
|
+
|
|
6394
6414
|
/***/ "./src/index.js":
|
|
6395
6415
|
/*!**********************!*\
|
|
6396
6416
|
!*** ./src/index.js ***!
|
|
@@ -6438,9 +6458,7 @@ function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o =
|
|
|
6438
6458
|
|
|
6439
6459
|
function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) { arr2[i] = arr[i]; } return arr2; }
|
|
6440
6460
|
|
|
6441
|
-
var
|
|
6442
|
-
fetch = _require.fetch,
|
|
6443
|
-
Headers = _require.Headers;
|
|
6461
|
+
var crossFetch = __webpack_require__(/*! cross-fetch */ "./node_modules/cross-fetch/dist/browser-ponyfill.js");
|
|
6444
6462
|
/**
|
|
6445
6463
|
* Metadata header names
|
|
6446
6464
|
* @enum {string} The enum value is the name of the associated header.
|
|
@@ -6450,17 +6468,48 @@ var _require = __webpack_require__(/*! cross-fetch */ "./node_modules/cross-fetc
|
|
|
6450
6468
|
|
|
6451
6469
|
var RequestMetadata = {
|
|
6452
6470
|
/** The ID of the project associated with this request */
|
|
6453
|
-
ProjectId: 'X-
|
|
6471
|
+
ProjectId: 'X-Project-ID',
|
|
6454
6472
|
|
|
6455
6473
|
/** The ID of the project run associated with this request */
|
|
6456
|
-
RunId: 'X-
|
|
6474
|
+
RunId: 'X-Run-ID'
|
|
6457
6475
|
};
|
|
6458
6476
|
/**
|
|
6459
|
-
* Metadata for requests
|
|
6460
|
-
* @type {
|
|
6477
|
+
* Metadata headers for requests
|
|
6478
|
+
* @type {Headers}
|
|
6461
6479
|
*/
|
|
6462
6480
|
|
|
6463
|
-
var metadata = new
|
|
6481
|
+
var metadata = new crossFetch.Headers();
|
|
6482
|
+
/**
|
|
6483
|
+
* Check if there is any metadata to apply.
|
|
6484
|
+
* @returns {boolean} true if `metadata` has contents, or false if it is empty.
|
|
6485
|
+
*/
|
|
6486
|
+
|
|
6487
|
+
var hasMetadata = function hasMetadata() {
|
|
6488
|
+
/* global self */
|
|
6489
|
+
var searchParams = typeof self !== 'undefined' && self && self.location && self.location.search && self.location.search.split(/[?&]/) || [];
|
|
6490
|
+
|
|
6491
|
+
if (!searchParams.includes('scratchMetadata=1')) {
|
|
6492
|
+
// for now, disable this feature unless scratchMetadata=1
|
|
6493
|
+
// TODO: remove this check once we're sure the feature works correctly in production
|
|
6494
|
+
return false;
|
|
6495
|
+
}
|
|
6496
|
+
|
|
6497
|
+
var _iterator = _createForOfIteratorHelper(metadata),
|
|
6498
|
+
_step;
|
|
6499
|
+
|
|
6500
|
+
try {
|
|
6501
|
+
for (_iterator.s(); !(_step = _iterator.n()).done;) {
|
|
6502
|
+
var _ = _step.value;
|
|
6503
|
+
return true;
|
|
6504
|
+
}
|
|
6505
|
+
} catch (err) {
|
|
6506
|
+
_iterator.e(err);
|
|
6507
|
+
} finally {
|
|
6508
|
+
_iterator.f();
|
|
6509
|
+
}
|
|
6510
|
+
|
|
6511
|
+
return false;
|
|
6512
|
+
};
|
|
6464
6513
|
/**
|
|
6465
6514
|
* Non-destructively merge any metadata state (if any) with the provided options object (if any).
|
|
6466
6515
|
* If there is metadata state but no options object is provided, make a new object.
|
|
@@ -6471,29 +6520,33 @@ var metadata = new Map();
|
|
|
6471
6520
|
* @returns {RequestInit|undefined} the provided options parameter without modification, or a new options object.
|
|
6472
6521
|
*/
|
|
6473
6522
|
|
|
6523
|
+
|
|
6474
6524
|
var applyMetadata = function applyMetadata(options) {
|
|
6475
|
-
if (
|
|
6525
|
+
if (hasMetadata()) {
|
|
6476
6526
|
var augmentedOptions = Object.assign({}, options);
|
|
6477
|
-
augmentedOptions.headers = new Headers(
|
|
6527
|
+
augmentedOptions.headers = new crossFetch.Headers(metadata);
|
|
6478
6528
|
|
|
6479
6529
|
if (options && options.headers) {
|
|
6480
|
-
|
|
6530
|
+
// the Fetch spec says options.headers could be:
|
|
6531
|
+
// "A Headers object, an object literal, or an array of two-item arrays to set request's headers."
|
|
6532
|
+
// turn it into a Headers object to be sure of how to interact with it
|
|
6533
|
+
var overrideHeaders = options.headers instanceof crossFetch.Headers ? options.headers : new crossFetch.Headers(options.headers);
|
|
6481
6534
|
|
|
6482
|
-
var
|
|
6483
|
-
|
|
6535
|
+
var _iterator2 = _createForOfIteratorHelper(overrideHeaders.entries()),
|
|
6536
|
+
_step2;
|
|
6484
6537
|
|
|
6485
6538
|
try {
|
|
6486
|
-
for (
|
|
6487
|
-
var
|
|
6488
|
-
name =
|
|
6489
|
-
value =
|
|
6539
|
+
for (_iterator2.s(); !(_step2 = _iterator2.n()).done;) {
|
|
6540
|
+
var _step2$value = _slicedToArray(_step2.value, 2),
|
|
6541
|
+
name = _step2$value[0],
|
|
6542
|
+
value = _step2$value[1];
|
|
6490
6543
|
|
|
6491
6544
|
augmentedOptions.headers.set(name, value);
|
|
6492
6545
|
}
|
|
6493
6546
|
} catch (err) {
|
|
6494
|
-
|
|
6547
|
+
_iterator2.e(err);
|
|
6495
6548
|
} finally {
|
|
6496
|
-
|
|
6549
|
+
_iterator2.f();
|
|
6497
6550
|
}
|
|
6498
6551
|
}
|
|
6499
6552
|
|
|
@@ -6514,7 +6567,7 @@ var applyMetadata = function applyMetadata(options) {
|
|
|
6514
6567
|
|
|
6515
6568
|
var scratchFetch = function scratchFetch(resource, options) {
|
|
6516
6569
|
var augmentedOptions = applyMetadata(options);
|
|
6517
|
-
return fetch(resource, augmentedOptions);
|
|
6570
|
+
return crossFetch.fetch(resource, augmentedOptions);
|
|
6518
6571
|
};
|
|
6519
6572
|
/**
|
|
6520
6573
|
* Set the value of a named request metadata item.
|
|
@@ -6540,6 +6593,7 @@ var unsetMetadata = function unsetMetadata(name) {
|
|
|
6540
6593
|
|
|
6541
6594
|
module.exports = {
|
|
6542
6595
|
default: scratchFetch,
|
|
6596
|
+
Headers: crossFetch.Headers,
|
|
6543
6597
|
RequestMetadata: RequestMetadata,
|
|
6544
6598
|
applyMetadata: applyMetadata,
|
|
6545
6599
|
scratchFetch: scratchFetch,
|
|
@@ -6547,6 +6601,20 @@ module.exports = {
|
|
|
6547
6601
|
unsetMetadata: unsetMetadata
|
|
6548
6602
|
};
|
|
6549
6603
|
|
|
6604
|
+
if (true) {
|
|
6605
|
+
/**
|
|
6606
|
+
* Retrieve a named request metadata item.
|
|
6607
|
+
* Only for use in tests.
|
|
6608
|
+
* @param {RequestMetadata} name The name of the metadata item to retrieve.
|
|
6609
|
+
* @returns {any} value The value of the metadata item, or `undefined` if it was not found.
|
|
6610
|
+
*/
|
|
6611
|
+
var getMetadata = function getMetadata(name) {
|
|
6612
|
+
return metadata.get(name);
|
|
6613
|
+
};
|
|
6614
|
+
|
|
6615
|
+
module.exports.getMetadata = getMetadata;
|
|
6616
|
+
}
|
|
6617
|
+
|
|
6550
6618
|
/***/ })
|
|
6551
6619
|
|
|
6552
6620
|
/******/ });
|