scratch-storage 1.3.6 → 2.0.2
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/dist/node/{d6e0e9d8aacfc3e11565.worker.js → f98711f696b187f5e007.worker.js} +7 -5
- package/dist/node/f98711f696b187f5e007.worker.js.map +1 -0
- package/dist/node/scratch-storage.js +29 -16
- package/dist/node/scratch-storage.js.map +1 -1
- package/dist/web/{3325b91e8645157f8dc6.worker.js → 01b4fbd4d14a4f22cab8.worker.js} +7 -5
- package/dist/web/{3325b91e8645157f8dc6.worker.js.map → 01b4fbd4d14a4f22cab8.worker.js.map} +1 -1
- package/dist/web/scratch-storage.js +29 -16
- package/dist/web/scratch-storage.js.map +1 -1
- package/dist/web/scratch-storage.min.js +29 -16
- package/dist/web/scratch-storage.min.js.map +1 -1
- package/package.json +2 -2
- package/src/FetchTool.js +5 -2
- package/src/FetchWorkerTool.js +2 -1
- package/src/FetchWorkerTool.worker.js +7 -3
- package/src/ScratchStorage.js +4 -4
- package/src/WebHelper.js +15 -4
- package/test/unit/fetch-tool.js +53 -5
- package/dist/node/d6e0e9d8aacfc3e11565.worker.js.map +0 -1
|
@@ -3790,7 +3790,7 @@ module.exports = g;
|
|
|
3790
3790
|
/***/ (function(module, exports, __webpack_require__) {
|
|
3791
3791
|
|
|
3792
3792
|
module.exports = function() {
|
|
3793
|
-
return __webpack_require__(/*! !./node_modules/worker-loader/dist/workers/InlineWorker.js */ "./node_modules/worker-loader/dist/workers/InlineWorker.js")("/******/ (function(modules) { // webpackBootstrap\n/******/ \t// The module cache\n/******/ \tvar installedModules = {};\n/******/\n/******/ \t// The require function\n/******/ \tfunction __webpack_require__(moduleId) {\n/******/\n/******/ \t\t// Check if module is in cache\n/******/ \t\tif(installedModules[moduleId]) {\n/******/ \t\t\treturn installedModules[moduleId].exports;\n/******/ \t\t}\n/******/ \t\t// Create a new module (and put it into the cache)\n/******/ \t\tvar module = installedModules[moduleId] = {\n/******/ \t\t\ti: moduleId,\n/******/ \t\t\tl: false,\n/******/ \t\t\texports: {}\n/******/ \t\t};\n/******/\n/******/ \t\t// Execute the module function\n/******/ \t\tmodules[moduleId].call(module.exports, module, module.exports, __webpack_require__);\n/******/\n/******/ \t\t// Flag the module as loaded\n/******/ \t\tmodule.l = true;\n/******/\n/******/ \t\t// Return the exports of the module\n/******/ \t\treturn module.exports;\n/******/ \t}\n/******/\n/******/\n/******/ \t// expose the modules object (__webpack_modules__)\n/******/ \t__webpack_require__.m = modules;\n/******/\n/******/ \t// expose the module cache\n/******/ \t__webpack_require__.c = installedModules;\n/******/\n/******/ \t// define getter function for harmony exports\n/******/ \t__webpack_require__.d = function(exports, name, getter) {\n/******/ \t\tif(!__webpack_require__.o(exports, name)) {\n/******/ \t\t\tObject.defineProperty(exports, name, { enumerable: true, get: getter });\n/******/ \t\t}\n/******/ \t};\n/******/\n/******/ \t// define __esModule on exports\n/******/ \t__webpack_require__.r = function(exports) {\n/******/ \t\tif(typeof Symbol !== 'undefined' && Symbol.toStringTag) {\n/******/ \t\t\tObject.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });\n/******/ \t\t}\n/******/ \t\tObject.defineProperty(exports, '__esModule', { value: true });\n/******/ \t};\n/******/\n/******/ \t// create a fake namespace object\n/******/ \t// mode & 1: value is a module id, require it\n/******/ \t// mode & 2: merge all properties of value into the ns\n/******/ \t// mode & 4: return value when already ns object\n/******/ \t// mode & 8|1: behave like require\n/******/ \t__webpack_require__.t = function(value, mode) {\n/******/ \t\tif(mode & 1) value = __webpack_require__(value);\n/******/ \t\tif(mode & 8) return value;\n/******/ \t\tif((mode & 4) && typeof value === 'object' && value && value.__esModule) return value;\n/******/ \t\tvar ns = Object.create(null);\n/******/ \t\t__webpack_require__.r(ns);\n/******/ \t\tObject.defineProperty(ns, 'default', { enumerable: true, value: value });\n/******/ \t\tif(mode & 2 && typeof value != 'string') for(var key in value) __webpack_require__.d(ns, key, function(key) { return value[key]; }.bind(null, key));\n/******/ \t\treturn ns;\n/******/ \t};\n/******/\n/******/ \t// getDefaultExport function for compatibility with non-harmony modules\n/******/ \t__webpack_require__.n = function(module) {\n/******/ \t\tvar getter = module && module.__esModule ?\n/******/ \t\t\tfunction getDefault() { return module['default']; } :\n/******/ \t\t\tfunction getModuleExports() { return module; };\n/******/ \t\t__webpack_require__.d(getter, 'a', getter);\n/******/ \t\treturn getter;\n/******/ \t};\n/******/\n/******/ \t// Object.prototype.hasOwnProperty.call\n/******/ \t__webpack_require__.o = function(object, property) { return Object.prototype.hasOwnProperty.call(object, property); };\n/******/\n/******/ \t// __webpack_public_path__\n/******/ \t__webpack_require__.p = \"\";\n/******/\n/******/\n/******/ \t// Load entry module and return exports\n/******/ \treturn __webpack_require__(__webpack_require__.s = \"./node_modules/babel-loader/lib/index.js?!./src/FetchWorkerTool.worker.js\");\n/******/ })\n/************************************************************************/\n/******/ ({\n\n/***/ \"./node_modules/babel-loader/lib/index.js?!./src/FetchWorkerTool.worker.js\":\n/*!*******************************************************************************!*\\\n !*** ./node_modules/babel-loader/lib??ref--4!./src/FetchWorkerTool.worker.js ***!\n \\*******************************************************************************/\n/*! no static exports found */\n/***/ (function(module, exports) {\n\n/* eslint-env worker */\nvar jobsActive = 0;\nvar complete = [];\nvar intervalId = null;\n/**\n * Register a step function.\n *\n * Step checks if there are completed jobs and if there are sends them to the\n * parent. Then it checks the jobs count. If there are no further jobs, clear\n * the step.\n */\n\nvar registerStep = function registerStep() {\n intervalId = setInterval(function () {\n if (complete.length) {\n // Send our chunk of completed requests and instruct postMessage to\n // transfer the buffers instead of copying them.\n postMessage(complete.slice(), // Instruct postMessage that these buffers in the sent message\n // should use their Transferable trait. After the postMessage\n // call the \"buffers\" will still be in complete if you looked,\n // but they will all be length 0 as the data they reference has\n // been sent to the window. This lets us send a lot of data\n // without the normal postMessage behaviour of making a copy of\n // all of the data for the window.\n complete.map(function (response) {\n return response.buffer;\n }).filter(Boolean));\n complete.length = 0;\n }\n\n if (jobsActive === 0) {\n clearInterval(intervalId);\n intervalId = null;\n }\n }, 1);\n};\n/**\n * Receive a job from the parent and fetch the requested data.\n * @param {object} options.job A job id, url, and options descriptor to perform.\n */\n\n\nvar onMessage = function onMessage(_ref) {\n var job = _ref.data;\n\n if (jobsActive === 0 && !intervalId) {\n registerStep();\n }\n\n jobsActive++;\n fetch(job.url, job.options).then(function (
|
|
3793
|
+
return __webpack_require__(/*! !./node_modules/worker-loader/dist/workers/InlineWorker.js */ "./node_modules/worker-loader/dist/workers/InlineWorker.js")("/******/ (function(modules) { // webpackBootstrap\n/******/ \t// The module cache\n/******/ \tvar installedModules = {};\n/******/\n/******/ \t// The require function\n/******/ \tfunction __webpack_require__(moduleId) {\n/******/\n/******/ \t\t// Check if module is in cache\n/******/ \t\tif(installedModules[moduleId]) {\n/******/ \t\t\treturn installedModules[moduleId].exports;\n/******/ \t\t}\n/******/ \t\t// Create a new module (and put it into the cache)\n/******/ \t\tvar module = installedModules[moduleId] = {\n/******/ \t\t\ti: moduleId,\n/******/ \t\t\tl: false,\n/******/ \t\t\texports: {}\n/******/ \t\t};\n/******/\n/******/ \t\t// Execute the module function\n/******/ \t\tmodules[moduleId].call(module.exports, module, module.exports, __webpack_require__);\n/******/\n/******/ \t\t// Flag the module as loaded\n/******/ \t\tmodule.l = true;\n/******/\n/******/ \t\t// Return the exports of the module\n/******/ \t\treturn module.exports;\n/******/ \t}\n/******/\n/******/\n/******/ \t// expose the modules object (__webpack_modules__)\n/******/ \t__webpack_require__.m = modules;\n/******/\n/******/ \t// expose the module cache\n/******/ \t__webpack_require__.c = installedModules;\n/******/\n/******/ \t// define getter function for harmony exports\n/******/ \t__webpack_require__.d = function(exports, name, getter) {\n/******/ \t\tif(!__webpack_require__.o(exports, name)) {\n/******/ \t\t\tObject.defineProperty(exports, name, { enumerable: true, get: getter });\n/******/ \t\t}\n/******/ \t};\n/******/\n/******/ \t// define __esModule on exports\n/******/ \t__webpack_require__.r = function(exports) {\n/******/ \t\tif(typeof Symbol !== 'undefined' && Symbol.toStringTag) {\n/******/ \t\t\tObject.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });\n/******/ \t\t}\n/******/ \t\tObject.defineProperty(exports, '__esModule', { value: true });\n/******/ \t};\n/******/\n/******/ \t// create a fake namespace object\n/******/ \t// mode & 1: value is a module id, require it\n/******/ \t// mode & 2: merge all properties of value into the ns\n/******/ \t// mode & 4: return value when already ns object\n/******/ \t// mode & 8|1: behave like require\n/******/ \t__webpack_require__.t = function(value, mode) {\n/******/ \t\tif(mode & 1) value = __webpack_require__(value);\n/******/ \t\tif(mode & 8) return value;\n/******/ \t\tif((mode & 4) && typeof value === 'object' && value && value.__esModule) return value;\n/******/ \t\tvar ns = Object.create(null);\n/******/ \t\t__webpack_require__.r(ns);\n/******/ \t\tObject.defineProperty(ns, 'default', { enumerable: true, value: value });\n/******/ \t\tif(mode & 2 && typeof value != 'string') for(var key in value) __webpack_require__.d(ns, key, function(key) { return value[key]; }.bind(null, key));\n/******/ \t\treturn ns;\n/******/ \t};\n/******/\n/******/ \t// getDefaultExport function for compatibility with non-harmony modules\n/******/ \t__webpack_require__.n = function(module) {\n/******/ \t\tvar getter = module && module.__esModule ?\n/******/ \t\t\tfunction getDefault() { return module['default']; } :\n/******/ \t\t\tfunction getModuleExports() { return module; };\n/******/ \t\t__webpack_require__.d(getter, 'a', getter);\n/******/ \t\treturn getter;\n/******/ \t};\n/******/\n/******/ \t// Object.prototype.hasOwnProperty.call\n/******/ \t__webpack_require__.o = function(object, property) { return Object.prototype.hasOwnProperty.call(object, property); };\n/******/\n/******/ \t// __webpack_public_path__\n/******/ \t__webpack_require__.p = \"\";\n/******/\n/******/\n/******/ \t// Load entry module and return exports\n/******/ \treturn __webpack_require__(__webpack_require__.s = \"./node_modules/babel-loader/lib/index.js?!./src/FetchWorkerTool.worker.js\");\n/******/ })\n/************************************************************************/\n/******/ ({\n\n/***/ \"./node_modules/babel-loader/lib/index.js?!./src/FetchWorkerTool.worker.js\":\n/*!*******************************************************************************!*\\\n !*** ./node_modules/babel-loader/lib??ref--4!./src/FetchWorkerTool.worker.js ***!\n \\*******************************************************************************/\n/*! no static exports found */\n/***/ (function(module, exports) {\n\n/* eslint-env worker */\nvar jobsActive = 0;\nvar complete = [];\nvar intervalId = null;\n/**\n * Register a step function.\n *\n * Step checks if there are completed jobs and if there are sends them to the\n * parent. Then it checks the jobs count. If there are no further jobs, clear\n * the step.\n */\n\nvar registerStep = function registerStep() {\n intervalId = setInterval(function () {\n if (complete.length) {\n // Send our chunk of completed requests and instruct postMessage to\n // transfer the buffers instead of copying them.\n postMessage(complete.slice(), // Instruct postMessage that these buffers in the sent message\n // should use their Transferable trait. After the postMessage\n // call the \"buffers\" will still be in complete if you looked,\n // but they will all be length 0 as the data they reference has\n // been sent to the window. This lets us send a lot of data\n // without the normal postMessage behaviour of making a copy of\n // all of the data for the window.\n complete.map(function (response) {\n return response.buffer;\n }).filter(Boolean));\n complete.length = 0;\n }\n\n if (jobsActive === 0) {\n clearInterval(intervalId);\n intervalId = null;\n }\n }, 1);\n};\n/**\n * Receive a job from the parent and fetch the requested data.\n * @param {object} options.job A job id, url, and options descriptor to perform.\n */\n\n\nvar onMessage = function onMessage(_ref) {\n var job = _ref.data;\n\n if (jobsActive === 0 && !intervalId) {\n registerStep();\n }\n\n jobsActive++;\n fetch(job.url, job.options).then(function (result) {\n if (result.ok) return result.arrayBuffer();\n if (result.status === 404) return null;\n return Promise.reject(result.status);\n }).then(function (buffer) {\n return complete.push({\n id: job.id,\n buffer: buffer\n });\n }).catch(function (error) {\n return complete.push({\n id: job.id,\n error: error && error.message || \"Failed request: \".concat(job.url)\n });\n }).then(function () {\n return jobsActive--;\n });\n};\n\nif (self.fetch) {\n postMessage({\n support: {\n fetch: true\n }\n });\n self.addEventListener('message', onMessage);\n} else {\n postMessage({\n support: {\n fetch: false\n }\n });\n self.addEventListener('message', function (_ref2) {\n var job = _ref2.data;\n postMessage([{\n id: job.id,\n error: 'fetch is unavailable'\n }]);\n });\n}\n\n/***/ })\n\n/******/ });\n//# sourceMappingURL=01b4fbd4d14a4f22cab8.worker.js.map", __webpack_require__.p + "01b4fbd4d14a4f22cab8.worker.js");
|
|
3794
3794
|
};
|
|
3795
3795
|
|
|
3796
3796
|
/***/ }),
|
|
@@ -4389,9 +4389,11 @@ var FetchTool = /*#__PURE__*/function () {
|
|
|
4389
4389
|
return fetch(url, Object.assign({
|
|
4390
4390
|
method: 'GET'
|
|
4391
4391
|
}, options)).then(function (result) {
|
|
4392
|
-
return result.arrayBuffer()
|
|
4393
|
-
|
|
4394
|
-
|
|
4392
|
+
if (result.ok) return result.arrayBuffer().then(function (b) {
|
|
4393
|
+
return new Uint8Array(b);
|
|
4394
|
+
});
|
|
4395
|
+
if (result.status === 404) return null;
|
|
4396
|
+
return Promise.reject(result.status);
|
|
4395
4397
|
});
|
|
4396
4398
|
}
|
|
4397
4399
|
/**
|
|
@@ -4584,8 +4586,10 @@ var PrivateFetchWorkerTool = /*#__PURE__*/function () {
|
|
|
4584
4586
|
resolve: resolve,
|
|
4585
4587
|
reject: reject
|
|
4586
4588
|
};
|
|
4587
|
-
})
|
|
4588
|
-
|
|
4589
|
+
})
|
|
4590
|
+
/* eslint no-confusing-arrow: ["error", {"allowParens": true}] */
|
|
4591
|
+
.then(function (body) {
|
|
4592
|
+
return body ? new Uint8Array(body) : null;
|
|
4589
4593
|
});
|
|
4590
4594
|
}
|
|
4591
4595
|
/**
|
|
@@ -5099,7 +5103,7 @@ var ScratchStorage = /*#__PURE__*/function () {
|
|
|
5099
5103
|
* @param {string} assetId - The ID of the asset to fetch: a project ID, MD5, etc.
|
|
5100
5104
|
* @param {DataFormat} [dataFormat] - Optional: load this format instead of the AssetType's default.
|
|
5101
5105
|
* @return {Promise.<Asset>} A promise for the requested Asset.
|
|
5102
|
-
* If the promise is resolved with non-null, the value is the requested asset
|
|
5106
|
+
* If the promise is resolved with non-null, the value is the requested asset.
|
|
5103
5107
|
* If the promise is resolved with null, the desired asset could not be found with the current asset sources.
|
|
5104
5108
|
* If the promise is rejected, there was an error on at least one asset source. HTTP 404 does not count as an
|
|
5105
5109
|
* error here, but (for example) HTTP 403 does.
|
|
@@ -5120,6 +5124,7 @@ var ScratchStorage = /*#__PURE__*/function () {
|
|
|
5120
5124
|
|
|
5121
5125
|
var tryNextHelper = function tryNextHelper(err) {
|
|
5122
5126
|
if (err) {
|
|
5127
|
+
// Track the error, but continue looking
|
|
5123
5128
|
errors.push(err);
|
|
5124
5129
|
}
|
|
5125
5130
|
|
|
@@ -5136,8 +5141,8 @@ var ScratchStorage = /*#__PURE__*/function () {
|
|
|
5136
5141
|
return loading // TODO: maybe some types of error should prevent trying the next helper?
|
|
5137
5142
|
.catch(tryNextHelper);
|
|
5138
5143
|
} else if (errors.length > 0) {
|
|
5139
|
-
//
|
|
5140
|
-
//
|
|
5144
|
+
// We looked through all the helpers and couldn't find the asset, AND
|
|
5145
|
+
// at least one thing went wrong while we were looking.
|
|
5141
5146
|
return Promise.reject(errors);
|
|
5142
5147
|
} // Nothing went wrong but we couldn't find the asset.
|
|
5143
5148
|
|
|
@@ -5338,7 +5343,8 @@ var WebHelper = /*#__PURE__*/function (_Helper) {
|
|
|
5338
5343
|
var errors = [];
|
|
5339
5344
|
var stores = this.stores.slice().filter(function (store) {
|
|
5340
5345
|
return store.types.indexOf(assetType.name) >= 0;
|
|
5341
|
-
});
|
|
5346
|
+
}); // New empty asset but it doesn't have data yet
|
|
5347
|
+
|
|
5342
5348
|
var asset = new Asset(assetType, assetId, dataFormat);
|
|
5343
5349
|
var tool = this.assetTool;
|
|
5344
5350
|
|
|
@@ -5348,11 +5354,15 @@ var WebHelper = /*#__PURE__*/function (_Helper) {
|
|
|
5348
5354
|
|
|
5349
5355
|
var storeIndex = 0;
|
|
5350
5356
|
|
|
5351
|
-
var tryNextSource = function tryNextSource() {
|
|
5357
|
+
var tryNextSource = function tryNextSource(err) {
|
|
5358
|
+
if (err) {
|
|
5359
|
+
errors.push(err);
|
|
5360
|
+
}
|
|
5361
|
+
|
|
5352
5362
|
var store = stores[storeIndex++];
|
|
5353
5363
|
/** @type {UrlFunction} */
|
|
5354
5364
|
|
|
5355
|
-
var reqConfigFunction = store.get;
|
|
5365
|
+
var reqConfigFunction = store && store.get;
|
|
5356
5366
|
|
|
5357
5367
|
if (reqConfigFunction) {
|
|
5358
5368
|
var reqConfig = ensureRequestConfig(reqConfigFunction(asset));
|
|
@@ -5362,7 +5372,12 @@ var WebHelper = /*#__PURE__*/function (_Helper) {
|
|
|
5362
5372
|
}
|
|
5363
5373
|
|
|
5364
5374
|
return tool.get(reqConfig).then(function (body) {
|
|
5365
|
-
|
|
5375
|
+
if (body) {
|
|
5376
|
+
asset.setData(body, dataFormat);
|
|
5377
|
+
return asset;
|
|
5378
|
+
}
|
|
5379
|
+
|
|
5380
|
+
return tryNextSource();
|
|
5366
5381
|
}).catch(tryNextSource);
|
|
5367
5382
|
} else if (errors.length > 0) {
|
|
5368
5383
|
return Promise.reject(errors);
|
|
@@ -5372,9 +5387,7 @@ var WebHelper = /*#__PURE__*/function (_Helper) {
|
|
|
5372
5387
|
return Promise.resolve(null);
|
|
5373
5388
|
};
|
|
5374
5389
|
|
|
5375
|
-
return tryNextSource()
|
|
5376
|
-
return asset;
|
|
5377
|
-
});
|
|
5390
|
+
return tryNextSource();
|
|
5378
5391
|
}
|
|
5379
5392
|
/**
|
|
5380
5393
|
* Create or update an asset with provided data. The create function is called if no asset id is provided
|