scratch-storage 2.2.0 → 2.2.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.
@@ -5397,6 +5397,7 @@ function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o =
5397
5397
  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
5398
 
5399
5399
  var _require = __webpack_require__(/*! ./scratchFetch */ "./src/scratchFetch.js"),
5400
+ Headers = _require.Headers,
5400
5401
  applyMetadata = _require.applyMetadata;
5401
5402
  /**
5402
5403
  * Get and send assets with a worker that uses fetch.
@@ -5515,7 +5516,14 @@ var PrivateFetchWorkerTool = /*#__PURE__*/function () {
5515
5516
  var id = Math.random().toString(16).substring(2);
5516
5517
  var augmentedOptions = applyMetadata(Object.assign({
5517
5518
  method: 'GET'
5518
- }, options));
5519
+ }, options)); // the Fetch spec says options.headers could be:
5520
+ // "A Headers object, an object literal, or an array of two-item arrays to set request's headers."
5521
+ // structured clone (postMessage) doesn't support Headers objects
5522
+ // so turn it into an array of two-item arrays to make it to the worker intact
5523
+
5524
+ if (augmentedOptions && augmentedOptions.headers instanceof Headers) {
5525
+ augmentedOptions.headers = Array.from(augmentedOptions.headers.entries());
5526
+ }
5519
5527
 
5520
5528
  _this2.worker.postMessage({
5521
5529
  id: id,
@@ -5869,6 +5877,8 @@ var _AssetType = __webpack_require__(/*! ./AssetType */ "./src/AssetType.js");
5869
5877
 
5870
5878
  var _DataFormat = __webpack_require__(/*! ./DataFormat */ "./src/DataFormat.js");
5871
5879
 
5880
+ var _scratchFetch = __webpack_require__(/*! ./scratchFetch */ "./src/scratchFetch.js");
5881
+
5872
5882
  var ScratchStorage = /*#__PURE__*/function () {
5873
5883
  "use strict";
5874
5884
 
@@ -5918,6 +5928,16 @@ var ScratchStorage = /*#__PURE__*/function () {
5918
5928
  get: function get() {
5919
5929
  return _DataFormat;
5920
5930
  }
5931
+ /**
5932
+ * Access the `scratchFetch` module within this library.
5933
+ * @return {module} the scratchFetch module, with properties for `scratchFetch`, `setMetadata`, etc.
5934
+ */
5935
+
5936
+ }, {
5937
+ key: "scratchFetch",
5938
+ get: function get() {
5939
+ return _scratchFetch;
5940
+ }
5921
5941
  /**
5922
5942
  * @deprecated Please use the `Asset` member of a storage instance instead.
5923
5943
  * @return {Asset} - the `Asset` class constructor.
@@ -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 _require = __webpack_require__(/*! cross-fetch */ "./node_modules/cross-fetch/dist/browser-ponyfill.js"),
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,39 @@ 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-ProjectId',
6471
+ ProjectId: 'X-Project-ID',
6454
6472
 
6455
6473
  /** The ID of the project run associated with this request */
6456
- RunId: 'X-RunId'
6474
+ RunId: 'X-Run-ID'
6457
6475
  };
6458
6476
  /**
6459
- * Metadata for requests
6460
- * @type {Map<string, string>}
6477
+ * Metadata headers for requests
6478
+ * @type {Headers}
6461
6479
  */
6462
6480
 
6463
- var metadata = new Map();
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
+ var _iterator = _createForOfIteratorHelper(metadata),
6489
+ _step;
6490
+
6491
+ try {
6492
+ for (_iterator.s(); !(_step = _iterator.n()).done;) {
6493
+ var _ = _step.value;
6494
+ return true;
6495
+ }
6496
+ } catch (err) {
6497
+ _iterator.e(err);
6498
+ } finally {
6499
+ _iterator.f();
6500
+ }
6501
+
6502
+ return false;
6503
+ };
6464
6504
  /**
6465
6505
  * Non-destructively merge any metadata state (if any) with the provided options object (if any).
6466
6506
  * If there is metadata state but no options object is provided, make a new object.
@@ -6471,29 +6511,33 @@ var metadata = new Map();
6471
6511
  * @returns {RequestInit|undefined} the provided options parameter without modification, or a new options object.
6472
6512
  */
6473
6513
 
6514
+
6474
6515
  var applyMetadata = function applyMetadata(options) {
6475
- if (metadata.size > 0) {
6516
+ if (hasMetadata()) {
6476
6517
  var augmentedOptions = Object.assign({}, options);
6477
- augmentedOptions.headers = new Headers(Array.from(metadata));
6518
+ augmentedOptions.headers = new crossFetch.Headers(metadata);
6478
6519
 
6479
6520
  if (options && options.headers) {
6480
- var overrideHeaders = options.headers instanceof Headers ? options.headers : new Headers(options.headers);
6521
+ // the Fetch spec says options.headers could be:
6522
+ // "A Headers object, an object literal, or an array of two-item arrays to set request's headers."
6523
+ // turn it into a Headers object to be sure of how to interact with it
6524
+ var overrideHeaders = options.headers instanceof crossFetch.Headers ? options.headers : new crossFetch.Headers(options.headers);
6481
6525
 
6482
- var _iterator = _createForOfIteratorHelper(overrideHeaders.entries()),
6483
- _step;
6526
+ var _iterator2 = _createForOfIteratorHelper(overrideHeaders.entries()),
6527
+ _step2;
6484
6528
 
6485
6529
  try {
6486
- for (_iterator.s(); !(_step = _iterator.n()).done;) {
6487
- var _step$value = _slicedToArray(_step.value, 2),
6488
- name = _step$value[0],
6489
- value = _step$value[1];
6530
+ for (_iterator2.s(); !(_step2 = _iterator2.n()).done;) {
6531
+ var _step2$value = _slicedToArray(_step2.value, 2),
6532
+ name = _step2$value[0],
6533
+ value = _step2$value[1];
6490
6534
 
6491
6535
  augmentedOptions.headers.set(name, value);
6492
6536
  }
6493
6537
  } catch (err) {
6494
- _iterator.e(err);
6538
+ _iterator2.e(err);
6495
6539
  } finally {
6496
- _iterator.f();
6540
+ _iterator2.f();
6497
6541
  }
6498
6542
  }
6499
6543
 
@@ -6514,7 +6558,7 @@ var applyMetadata = function applyMetadata(options) {
6514
6558
 
6515
6559
  var scratchFetch = function scratchFetch(resource, options) {
6516
6560
  var augmentedOptions = applyMetadata(options);
6517
- return fetch(resource, augmentedOptions);
6561
+ return crossFetch.fetch(resource, augmentedOptions);
6518
6562
  };
6519
6563
  /**
6520
6564
  * Set the value of a named request metadata item.
@@ -6540,6 +6584,7 @@ var unsetMetadata = function unsetMetadata(name) {
6540
6584
 
6541
6585
  module.exports = {
6542
6586
  default: scratchFetch,
6587
+ Headers: crossFetch.Headers,
6543
6588
  RequestMetadata: RequestMetadata,
6544
6589
  applyMetadata: applyMetadata,
6545
6590
  scratchFetch: scratchFetch,
@@ -6547,6 +6592,20 @@ module.exports = {
6547
6592
  unsetMetadata: unsetMetadata
6548
6593
  };
6549
6594
 
6595
+ if (true) {
6596
+ /**
6597
+ * Retrieve a named request metadata item.
6598
+ * Only for use in tests.
6599
+ * @param {RequestMetadata} name The name of the metadata item to retrieve.
6600
+ * @returns {any} value The value of the metadata item, or `undefined` if it was not found.
6601
+ */
6602
+ var getMetadata = function getMetadata(name) {
6603
+ return metadata.get(name);
6604
+ };
6605
+
6606
+ module.exports.getMetadata = getMetadata;
6607
+ }
6608
+
6550
6609
  /***/ })
6551
6610
 
6552
6611
  /******/ });