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
package/.circleci/config.yml
CHANGED
|
@@ -462,39 +462,6 @@ module.exports = _unsupportedIterableToArray, module.exports.__esModule = true,
|
|
|
462
462
|
|
|
463
463
|
/***/ }),
|
|
464
464
|
|
|
465
|
-
/***/ "./node_modules/arraybuffer-loader/index.js!./src/builtins/defaultBitmap.png":
|
|
466
|
-
/*!**************************************************************************!*\
|
|
467
|
-
!*** ./node_modules/arraybuffer-loader!./src/builtins/defaultBitmap.png ***!
|
|
468
|
-
\**************************************************************************/
|
|
469
|
-
/*! no static exports found */
|
|
470
|
-
/***/ (function(module, exports, __webpack_require__) {
|
|
471
|
-
|
|
472
|
-
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==")
|
|
473
|
-
|
|
474
|
-
/***/ }),
|
|
475
|
-
|
|
476
|
-
/***/ "./node_modules/arraybuffer-loader/index.js!./src/builtins/defaultSound.wav":
|
|
477
|
-
/*!*************************************************************************!*\
|
|
478
|
-
!*** ./node_modules/arraybuffer-loader!./src/builtins/defaultSound.wav ***!
|
|
479
|
-
\*************************************************************************/
|
|
480
|
-
/*! no static exports found */
|
|
481
|
-
/***/ (function(module, exports, __webpack_require__) {
|
|
482
|
-
|
|
483
|
-
module.exports = __webpack_require__(/*! ../../node_modules/arraybuffer-loader/lib/to-array-buffer.js */ "./node_modules/arraybuffer-loader/lib/to-array-buffer.js")("UklGRiYAAABXQVZFZm10IBAAAAABAAEAIlYAAESsAAACABAAZGF0YQIAAAAAAA==")
|
|
484
|
-
|
|
485
|
-
/***/ }),
|
|
486
|
-
|
|
487
|
-
/***/ "./node_modules/arraybuffer-loader/index.js!./src/builtins/defaultVector.svg":
|
|
488
|
-
/*!**************************************************************************!*\
|
|
489
|
-
!*** ./node_modules/arraybuffer-loader!./src/builtins/defaultVector.svg ***!
|
|
490
|
-
\**************************************************************************/
|
|
491
|
-
/*! no static exports found */
|
|
492
|
-
/***/ (function(module, exports, __webpack_require__) {
|
|
493
|
-
|
|
494
|
-
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")
|
|
495
|
-
|
|
496
|
-
/***/ }),
|
|
497
|
-
|
|
498
465
|
/***/ "./node_modules/arraybuffer-loader/lib/to-array-buffer.js":
|
|
499
466
|
/*!****************************************************************!*\
|
|
500
467
|
!*** ./node_modules/arraybuffer-loader/lib/to-array-buffer.js ***!
|
|
@@ -5677,19 +5644,19 @@ var DefaultAssets = [{
|
|
|
5677
5644
|
type: AssetType.ImageBitmap,
|
|
5678
5645
|
format: DataFormat.PNG,
|
|
5679
5646
|
id: null,
|
|
5680
|
-
data: Buffer.from(__webpack_require__(/*!
|
|
5647
|
+
data: Buffer.from(__webpack_require__(/*! ./builtins/defaultBitmap.png */ "./src/builtins/defaultBitmap.png") // eslint-disable-line global-require
|
|
5681
5648
|
)
|
|
5682
5649
|
}, {
|
|
5683
5650
|
type: AssetType.Sound,
|
|
5684
5651
|
format: DataFormat.WAV,
|
|
5685
5652
|
id: null,
|
|
5686
|
-
data: Buffer.from(__webpack_require__(/*!
|
|
5653
|
+
data: Buffer.from(__webpack_require__(/*! ./builtins/defaultSound.wav */ "./src/builtins/defaultSound.wav") // eslint-disable-line global-require
|
|
5687
5654
|
)
|
|
5688
5655
|
}, {
|
|
5689
5656
|
type: AssetType.ImageVector,
|
|
5690
5657
|
format: DataFormat.SVG,
|
|
5691
5658
|
id: null,
|
|
5692
|
-
data: Buffer.from(__webpack_require__(/*!
|
|
5659
|
+
data: Buffer.from(__webpack_require__(/*! ./builtins/defaultVector.svg */ "./src/builtins/defaultVector.svg") // eslint-disable-line global-require
|
|
5693
5660
|
)
|
|
5694
5661
|
}];
|
|
5695
5662
|
/**
|
|
@@ -6001,6 +5968,7 @@ function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o =
|
|
|
6001
5968
|
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; }
|
|
6002
5969
|
|
|
6003
5970
|
var _require = __webpack_require__(/*! ./scratchFetch */ "./src/scratchFetch.js"),
|
|
5971
|
+
Headers = _require.Headers,
|
|
6004
5972
|
applyMetadata = _require.applyMetadata;
|
|
6005
5973
|
/**
|
|
6006
5974
|
* Get and send assets with a worker that uses fetch.
|
|
@@ -6119,7 +6087,14 @@ var PrivateFetchWorkerTool = /*#__PURE__*/function () {
|
|
|
6119
6087
|
var id = Math.random().toString(16).substring(2);
|
|
6120
6088
|
var augmentedOptions = applyMetadata(Object.assign({
|
|
6121
6089
|
method: 'GET'
|
|
6122
|
-
}, options));
|
|
6090
|
+
}, options)); // the Fetch spec says options.headers could be:
|
|
6091
|
+
// "A Headers object, an object literal, or an array of two-item arrays to set request's headers."
|
|
6092
|
+
// structured clone (postMessage) doesn't support Headers objects
|
|
6093
|
+
// so turn it into an array of two-item arrays to make it to the worker intact
|
|
6094
|
+
|
|
6095
|
+
if (augmentedOptions && augmentedOptions.headers instanceof Headers) {
|
|
6096
|
+
augmentedOptions.headers = Array.from(augmentedOptions.headers.entries());
|
|
6097
|
+
}
|
|
6123
6098
|
|
|
6124
6099
|
_this2.worker.postMessage({
|
|
6125
6100
|
id: id,
|
|
@@ -6473,6 +6448,8 @@ var _AssetType = __webpack_require__(/*! ./AssetType */ "./src/AssetType.js");
|
|
|
6473
6448
|
|
|
6474
6449
|
var _DataFormat = __webpack_require__(/*! ./DataFormat */ "./src/DataFormat.js");
|
|
6475
6450
|
|
|
6451
|
+
var _scratchFetch = __webpack_require__(/*! ./scratchFetch */ "./src/scratchFetch.js");
|
|
6452
|
+
|
|
6476
6453
|
var ScratchStorage = /*#__PURE__*/function () {
|
|
6477
6454
|
"use strict";
|
|
6478
6455
|
|
|
@@ -6522,6 +6499,16 @@ var ScratchStorage = /*#__PURE__*/function () {
|
|
|
6522
6499
|
get: function get() {
|
|
6523
6500
|
return _DataFormat;
|
|
6524
6501
|
}
|
|
6502
|
+
/**
|
|
6503
|
+
* Access the `scratchFetch` module within this library.
|
|
6504
|
+
* @return {module} the scratchFetch module, with properties for `scratchFetch`, `setMetadata`, etc.
|
|
6505
|
+
*/
|
|
6506
|
+
|
|
6507
|
+
}, {
|
|
6508
|
+
key: "scratchFetch",
|
|
6509
|
+
get: function get() {
|
|
6510
|
+
return _scratchFetch;
|
|
6511
|
+
}
|
|
6525
6512
|
/**
|
|
6526
6513
|
* @deprecated Please use the `Asset` member of a storage instance instead.
|
|
6527
6514
|
* @return {Asset} - the `Asset` class constructor.
|
|
@@ -6995,6 +6982,39 @@ module.exports = WebHelper;
|
|
|
6995
6982
|
|
|
6996
6983
|
/***/ }),
|
|
6997
6984
|
|
|
6985
|
+
/***/ "./src/builtins/defaultBitmap.png":
|
|
6986
|
+
/*!****************************************!*\
|
|
6987
|
+
!*** ./src/builtins/defaultBitmap.png ***!
|
|
6988
|
+
\****************************************/
|
|
6989
|
+
/*! no static exports found */
|
|
6990
|
+
/***/ (function(module, exports, __webpack_require__) {
|
|
6991
|
+
|
|
6992
|
+
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==")
|
|
6993
|
+
|
|
6994
|
+
/***/ }),
|
|
6995
|
+
|
|
6996
|
+
/***/ "./src/builtins/defaultSound.wav":
|
|
6997
|
+
/*!***************************************!*\
|
|
6998
|
+
!*** ./src/builtins/defaultSound.wav ***!
|
|
6999
|
+
\***************************************/
|
|
7000
|
+
/*! no static exports found */
|
|
7001
|
+
/***/ (function(module, exports, __webpack_require__) {
|
|
7002
|
+
|
|
7003
|
+
module.exports = __webpack_require__(/*! ../../node_modules/arraybuffer-loader/lib/to-array-buffer.js */ "./node_modules/arraybuffer-loader/lib/to-array-buffer.js")("UklGRiYAAABXQVZFZm10IBAAAAABAAEAIlYAAESsAAACABAAZGF0YQIAAAAAAA==")
|
|
7004
|
+
|
|
7005
|
+
/***/ }),
|
|
7006
|
+
|
|
7007
|
+
/***/ "./src/builtins/defaultVector.svg":
|
|
7008
|
+
/*!****************************************!*\
|
|
7009
|
+
!*** ./src/builtins/defaultVector.svg ***!
|
|
7010
|
+
\****************************************/
|
|
7011
|
+
/*! no static exports found */
|
|
7012
|
+
/***/ (function(module, exports, __webpack_require__) {
|
|
7013
|
+
|
|
7014
|
+
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")
|
|
7015
|
+
|
|
7016
|
+
/***/ }),
|
|
7017
|
+
|
|
6998
7018
|
/***/ "./src/index.js":
|
|
6999
7019
|
/*!**********************!*\
|
|
7000
7020
|
!*** ./src/index.js ***!
|
|
@@ -7042,9 +7062,7 @@ function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o =
|
|
|
7042
7062
|
|
|
7043
7063
|
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; }
|
|
7044
7064
|
|
|
7045
|
-
var
|
|
7046
|
-
fetch = _require.fetch,
|
|
7047
|
-
Headers = _require.Headers;
|
|
7065
|
+
var crossFetch = __webpack_require__(/*! cross-fetch */ "./node_modules/cross-fetch/dist/node-ponyfill.js");
|
|
7048
7066
|
/**
|
|
7049
7067
|
* Metadata header names
|
|
7050
7068
|
* @enum {string} The enum value is the name of the associated header.
|
|
@@ -7054,17 +7072,48 @@ var _require = __webpack_require__(/*! cross-fetch */ "./node_modules/cross-fetc
|
|
|
7054
7072
|
|
|
7055
7073
|
var RequestMetadata = {
|
|
7056
7074
|
/** The ID of the project associated with this request */
|
|
7057
|
-
ProjectId: 'X-
|
|
7075
|
+
ProjectId: 'X-Project-ID',
|
|
7058
7076
|
|
|
7059
7077
|
/** The ID of the project run associated with this request */
|
|
7060
|
-
RunId: 'X-
|
|
7078
|
+
RunId: 'X-Run-ID'
|
|
7061
7079
|
};
|
|
7062
7080
|
/**
|
|
7063
|
-
* Metadata for requests
|
|
7064
|
-
* @type {
|
|
7081
|
+
* Metadata headers for requests
|
|
7082
|
+
* @type {Headers}
|
|
7083
|
+
*/
|
|
7084
|
+
|
|
7085
|
+
var metadata = new crossFetch.Headers();
|
|
7086
|
+
/**
|
|
7087
|
+
* Check if there is any metadata to apply.
|
|
7088
|
+
* @returns {boolean} true if `metadata` has contents, or false if it is empty.
|
|
7065
7089
|
*/
|
|
7066
7090
|
|
|
7067
|
-
var
|
|
7091
|
+
var hasMetadata = function hasMetadata() {
|
|
7092
|
+
/* global self */
|
|
7093
|
+
var searchParams = typeof self !== 'undefined' && self && self.location && self.location.search && self.location.search.split(/[?&]/) || [];
|
|
7094
|
+
|
|
7095
|
+
if (!searchParams.includes('scratchMetadata=1')) {
|
|
7096
|
+
// for now, disable this feature unless scratchMetadata=1
|
|
7097
|
+
// TODO: remove this check once we're sure the feature works correctly in production
|
|
7098
|
+
return false;
|
|
7099
|
+
}
|
|
7100
|
+
|
|
7101
|
+
var _iterator = _createForOfIteratorHelper(metadata),
|
|
7102
|
+
_step;
|
|
7103
|
+
|
|
7104
|
+
try {
|
|
7105
|
+
for (_iterator.s(); !(_step = _iterator.n()).done;) {
|
|
7106
|
+
var _ = _step.value;
|
|
7107
|
+
return true;
|
|
7108
|
+
}
|
|
7109
|
+
} catch (err) {
|
|
7110
|
+
_iterator.e(err);
|
|
7111
|
+
} finally {
|
|
7112
|
+
_iterator.f();
|
|
7113
|
+
}
|
|
7114
|
+
|
|
7115
|
+
return false;
|
|
7116
|
+
};
|
|
7068
7117
|
/**
|
|
7069
7118
|
* Non-destructively merge any metadata state (if any) with the provided options object (if any).
|
|
7070
7119
|
* If there is metadata state but no options object is provided, make a new object.
|
|
@@ -7075,29 +7124,33 @@ var metadata = new Map();
|
|
|
7075
7124
|
* @returns {RequestInit|undefined} the provided options parameter without modification, or a new options object.
|
|
7076
7125
|
*/
|
|
7077
7126
|
|
|
7127
|
+
|
|
7078
7128
|
var applyMetadata = function applyMetadata(options) {
|
|
7079
|
-
if (
|
|
7129
|
+
if (hasMetadata()) {
|
|
7080
7130
|
var augmentedOptions = Object.assign({}, options);
|
|
7081
|
-
augmentedOptions.headers = new Headers(
|
|
7131
|
+
augmentedOptions.headers = new crossFetch.Headers(metadata);
|
|
7082
7132
|
|
|
7083
7133
|
if (options && options.headers) {
|
|
7084
|
-
|
|
7134
|
+
// the Fetch spec says options.headers could be:
|
|
7135
|
+
// "A Headers object, an object literal, or an array of two-item arrays to set request's headers."
|
|
7136
|
+
// turn it into a Headers object to be sure of how to interact with it
|
|
7137
|
+
var overrideHeaders = options.headers instanceof crossFetch.Headers ? options.headers : new crossFetch.Headers(options.headers);
|
|
7085
7138
|
|
|
7086
|
-
var
|
|
7087
|
-
|
|
7139
|
+
var _iterator2 = _createForOfIteratorHelper(overrideHeaders.entries()),
|
|
7140
|
+
_step2;
|
|
7088
7141
|
|
|
7089
7142
|
try {
|
|
7090
|
-
for (
|
|
7091
|
-
var
|
|
7092
|
-
name =
|
|
7093
|
-
value =
|
|
7143
|
+
for (_iterator2.s(); !(_step2 = _iterator2.n()).done;) {
|
|
7144
|
+
var _step2$value = _slicedToArray(_step2.value, 2),
|
|
7145
|
+
name = _step2$value[0],
|
|
7146
|
+
value = _step2$value[1];
|
|
7094
7147
|
|
|
7095
7148
|
augmentedOptions.headers.set(name, value);
|
|
7096
7149
|
}
|
|
7097
7150
|
} catch (err) {
|
|
7098
|
-
|
|
7151
|
+
_iterator2.e(err);
|
|
7099
7152
|
} finally {
|
|
7100
|
-
|
|
7153
|
+
_iterator2.f();
|
|
7101
7154
|
}
|
|
7102
7155
|
}
|
|
7103
7156
|
|
|
@@ -7118,7 +7171,7 @@ var applyMetadata = function applyMetadata(options) {
|
|
|
7118
7171
|
|
|
7119
7172
|
var scratchFetch = function scratchFetch(resource, options) {
|
|
7120
7173
|
var augmentedOptions = applyMetadata(options);
|
|
7121
|
-
return fetch(resource, augmentedOptions);
|
|
7174
|
+
return crossFetch.fetch(resource, augmentedOptions);
|
|
7122
7175
|
};
|
|
7123
7176
|
/**
|
|
7124
7177
|
* Set the value of a named request metadata item.
|
|
@@ -7144,6 +7197,7 @@ var unsetMetadata = function unsetMetadata(name) {
|
|
|
7144
7197
|
|
|
7145
7198
|
module.exports = {
|
|
7146
7199
|
default: scratchFetch,
|
|
7200
|
+
Headers: crossFetch.Headers,
|
|
7147
7201
|
RequestMetadata: RequestMetadata,
|
|
7148
7202
|
applyMetadata: applyMetadata,
|
|
7149
7203
|
scratchFetch: scratchFetch,
|
|
@@ -7151,6 +7205,20 @@ module.exports = {
|
|
|
7151
7205
|
unsetMetadata: unsetMetadata
|
|
7152
7206
|
};
|
|
7153
7207
|
|
|
7208
|
+
if (true) {
|
|
7209
|
+
/**
|
|
7210
|
+
* Retrieve a named request metadata item.
|
|
7211
|
+
* Only for use in tests.
|
|
7212
|
+
* @param {RequestMetadata} name The name of the metadata item to retrieve.
|
|
7213
|
+
* @returns {any} value The value of the metadata item, or `undefined` if it was not found.
|
|
7214
|
+
*/
|
|
7215
|
+
var getMetadata = function getMetadata(name) {
|
|
7216
|
+
return metadata.get(name);
|
|
7217
|
+
};
|
|
7218
|
+
|
|
7219
|
+
module.exports.getMetadata = getMetadata;
|
|
7220
|
+
}
|
|
7221
|
+
|
|
7154
7222
|
/***/ }),
|
|
7155
7223
|
|
|
7156
7224
|
/***/ "base64-js":
|