@loaders.gl/loader-utils 3.2.12 → 3.3.0-alpha.10
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/es5/index.js +93 -119
- package/dist/es5/index.js.map +1 -1
- package/dist/es5/json-loader.js +2 -9
- package/dist/es5/json-loader.js.map +1 -1
- package/dist/es5/lib/binary-utils/array-buffer-utils.js +6 -26
- package/dist/es5/lib/binary-utils/array-buffer-utils.js.map +1 -1
- package/dist/es5/lib/binary-utils/binary-copy-utils.js +0 -4
- package/dist/es5/lib/binary-utils/binary-copy-utils.js.map +1 -1
- package/dist/es5/lib/binary-utils/buffer-utils.js +1 -9
- package/dist/es5/lib/binary-utils/buffer-utils.js.map +1 -1
- package/dist/es5/lib/binary-utils/encode-utils.js +2 -8
- package/dist/es5/lib/binary-utils/encode-utils.js.map +1 -1
- package/dist/es5/lib/binary-utils/get-first-characters.js +0 -7
- package/dist/es5/lib/binary-utils/get-first-characters.js.map +1 -1
- package/dist/es5/lib/binary-utils/memory-copy-utils.js +1 -4
- package/dist/es5/lib/binary-utils/memory-copy-utils.js.map +1 -1
- package/dist/es5/lib/env-utils/assert.js +0 -1
- package/dist/es5/lib/env-utils/assert.js.map +1 -1
- package/dist/es5/lib/env-utils/globals.js +5 -4
- package/dist/es5/lib/env-utils/globals.js.map +1 -1
- package/dist/es5/lib/filesystems/node-filesystem.js +2 -45
- package/dist/es5/lib/filesystems/node-filesystem.js.map +1 -1
- package/dist/es5/lib/iterators/async-iteration.js +57 -127
- package/dist/es5/lib/iterators/async-iteration.js.map +1 -1
- package/dist/es5/lib/iterators/text-iterators.js +127 -242
- package/dist/es5/lib/iterators/text-iterators.js.map +1 -1
- package/dist/es5/lib/node/buffer.js +0 -6
- package/dist/es5/lib/node/buffer.js.map +1 -1
- package/dist/es5/lib/node/fs.js +9 -16
- package/dist/es5/lib/node/fs.js.map +1 -1
- package/dist/es5/lib/node/util.js +0 -5
- package/dist/es5/lib/node/util.js.map +1 -1
- package/dist/es5/lib/parser-utils/parse-json.js +0 -2
- package/dist/es5/lib/parser-utils/parse-json.js.map +1 -1
- package/dist/es5/lib/path-utils/file-aliases.js +3 -4
- package/dist/es5/lib/path-utils/file-aliases.js.map +1 -1
- package/dist/es5/lib/path-utils/path.js +1 -4
- package/dist/es5/lib/path-utils/path.js.map +1 -1
- package/dist/es5/lib/request-utils/request-scheduler.js +24 -33
- package/dist/es5/lib/request-utils/request-scheduler.js.map +1 -1
- package/dist/es5/lib/worker-loader-utils/create-loader-worker.js +2 -36
- package/dist/es5/lib/worker-loader-utils/create-loader-worker.js.map +1 -1
- package/dist/es5/lib/worker-loader-utils/encode-with-worker.js +0 -4
- package/dist/es5/lib/worker-loader-utils/encode-with-worker.js.map +1 -1
- package/dist/es5/lib/worker-loader-utils/parse-with-worker.js +2 -23
- package/dist/es5/lib/worker-loader-utils/parse-with-worker.js.map +1 -1
- package/dist/es5/types.js.map +1 -1
- package/dist/es5/workers/json-worker.js +0 -2
- package/dist/es5/workers/json-worker.js.map +1 -1
- package/dist/esm/index.js +14 -0
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/json-loader.js +3 -2
- package/dist/esm/json-loader.js.map +1 -1
- package/dist/esm/lib/binary-utils/array-buffer-utils.js +16 -15
- package/dist/esm/lib/binary-utils/array-buffer-utils.js.map +1 -1
- package/dist/esm/lib/binary-utils/binary-copy-utils.js +2 -2
- package/dist/esm/lib/binary-utils/binary-copy-utils.js.map +1 -1
- package/dist/esm/lib/binary-utils/buffer-utils.js +3 -1
- package/dist/esm/lib/binary-utils/buffer-utils.js.map +1 -1
- package/dist/esm/lib/binary-utils/encode-utils.js +2 -4
- package/dist/esm/lib/binary-utils/encode-utils.js.map +1 -1
- package/dist/esm/lib/binary-utils/get-first-characters.js +2 -5
- package/dist/esm/lib/binary-utils/get-first-characters.js.map +1 -1
- package/dist/esm/lib/binary-utils/memory-copy-utils.js +5 -2
- package/dist/esm/lib/binary-utils/memory-copy-utils.js.map +1 -1
- package/dist/esm/lib/env-utils/assert.js +1 -0
- package/dist/esm/lib/env-utils/assert.js.map +1 -1
- package/dist/esm/lib/env-utils/globals.js +7 -1
- package/dist/esm/lib/env-utils/globals.js.map +1 -1
- package/dist/esm/lib/filesystems/node-filesystem.js +10 -16
- package/dist/esm/lib/filesystems/node-filesystem.js.map +1 -1
- package/dist/esm/lib/iterators/async-iteration.js +2 -7
- package/dist/esm/lib/iterators/async-iteration.js.map +1 -1
- package/dist/esm/lib/iterators/text-iterators.js +7 -7
- package/dist/esm/lib/iterators/text-iterators.js.map +1 -1
- package/dist/esm/lib/node/buffer.js +4 -5
- package/dist/esm/lib/node/buffer.js.map +1 -1
- package/dist/esm/lib/node/fs.js +7 -4
- package/dist/esm/lib/node/fs.js.map +1 -1
- package/dist/esm/lib/node/util.js +1 -0
- package/dist/esm/lib/node/util.js.map +1 -1
- package/dist/esm/lib/parser-utils/parse-json.js +1 -0
- package/dist/esm/lib/parser-utils/parse-json.js.map +1 -1
- package/dist/esm/lib/path-utils/file-aliases.js +6 -2
- package/dist/esm/lib/path-utils/file-aliases.js.map +1 -1
- package/dist/esm/lib/path-utils/path.js +8 -3
- package/dist/esm/lib/path-utils/path.js.map +1 -1
- package/dist/esm/lib/request-utils/request-scheduler.js +11 -21
- package/dist/esm/lib/request-utils/request-scheduler.js.map +1 -1
- package/dist/esm/lib/worker-loader-utils/create-loader-worker.js +19 -17
- package/dist/esm/lib/worker-loader-utils/create-loader-worker.js.map +1 -1
- package/dist/esm/lib/worker-loader-utils/encode-with-worker.js +1 -1
- package/dist/esm/lib/worker-loader-utils/encode-with-worker.js.map +1 -1
- package/dist/esm/lib/worker-loader-utils/parse-with-worker.js +6 -7
- package/dist/esm/lib/worker-loader-utils/parse-with-worker.js.map +1 -1
- package/dist/esm/types.js.map +1 -1
- package/dist/esm/workers/json-worker.js.map +1 -1
- package/dist/index.js +5 -1
- package/dist/lib/binary-utils/buffer-utils.js +5 -1
- package/dist/lib/env-utils/globals.d.ts +1 -1
- package/dist/lib/env-utils/globals.d.ts.map +1 -1
- package/dist/lib/filesystems/node-filesystem.d.ts +3 -2
- package/dist/lib/filesystems/node-filesystem.d.ts.map +1 -1
- package/dist/lib/filesystems/node-filesystem.js +5 -1
- package/dist/lib/node/util.js +5 -1
- package/dist/lib/request-utils/request-scheduler.d.ts +6 -6
- package/dist/lib/request-utils/request-scheduler.d.ts.map +1 -1
- package/dist/types.d.ts +29 -29
- package/dist/types.d.ts.map +1 -1
- package/package.json +3 -3
package/dist/es5/lib/node/fs.js
CHANGED
|
@@ -1,26 +1,21 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
3
|
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
-
|
|
5
4
|
Object.defineProperty(exports, "__esModule", {
|
|
6
5
|
value: true
|
|
7
6
|
});
|
|
8
7
|
exports._readToArrayBuffer = _readToArrayBuffer;
|
|
9
|
-
exports.
|
|
10
|
-
|
|
8
|
+
exports.writeFileSync = exports.writeFile = exports.stat = exports.readdir = exports.readFileSync = exports.readFile = exports.read = exports.open = exports.isSupported = exports.fstat = exports.close = void 0;
|
|
11
9
|
var _regenerator = _interopRequireDefault(require("@babel/runtime/regenerator"));
|
|
12
|
-
|
|
13
10
|
var _asyncToGenerator2 = _interopRequireDefault(require("@babel/runtime/helpers/asyncToGenerator"));
|
|
14
|
-
|
|
15
11
|
var _fs = _interopRequireDefault(require("fs"));
|
|
16
|
-
|
|
17
12
|
var _buffer = require("./buffer");
|
|
18
|
-
|
|
19
13
|
var _util = require("./util");
|
|
20
14
|
|
|
21
15
|
var readdir;
|
|
22
16
|
exports.readdir = readdir;
|
|
23
17
|
var stat;
|
|
18
|
+
|
|
24
19
|
exports.stat = stat;
|
|
25
20
|
var readFile;
|
|
26
21
|
exports.readFile = readFile;
|
|
@@ -29,7 +24,9 @@ exports.readFileSync = readFileSync;
|
|
|
29
24
|
var writeFile;
|
|
30
25
|
exports.writeFile = writeFile;
|
|
31
26
|
var writeFileSync;
|
|
27
|
+
|
|
32
28
|
exports.writeFileSync = writeFileSync;
|
|
29
|
+
|
|
33
30
|
var open;
|
|
34
31
|
exports.open = open;
|
|
35
32
|
var close;
|
|
@@ -39,30 +36,31 @@ exports.read = read;
|
|
|
39
36
|
var fstat;
|
|
40
37
|
exports.fstat = fstat;
|
|
41
38
|
var isSupported = Boolean(_fs.default);
|
|
39
|
+
|
|
42
40
|
exports.isSupported = isSupported;
|
|
43
41
|
|
|
44
42
|
try {
|
|
45
43
|
exports.readdir = readdir = (0, _util.promisify)(_fs.default.readdir);
|
|
46
44
|
exports.stat = stat = (0, _util.promisify)(_fs.default.stat);
|
|
45
|
+
|
|
47
46
|
exports.readFile = readFile = (0, _util.promisify)(_fs.default.readFile);
|
|
48
47
|
exports.readFileSync = readFileSync = _fs.default.readFileSync;
|
|
49
48
|
exports.writeFile = writeFile = (0, _util.promisify)(_fs.default.writeFile);
|
|
50
49
|
exports.writeFileSync = writeFileSync = _fs.default.writeFileSync;
|
|
50
|
+
|
|
51
51
|
exports.open = open = (0, _util.promisify)(_fs.default.open);
|
|
52
52
|
exports.close = close = (0, _util.promisify)(_fs.default.close);
|
|
53
53
|
exports.read = read = (0, _util.promisify)(_fs.default.read);
|
|
54
54
|
exports.fstat = fstat = (0, _util.promisify)(_fs.default.fstat);
|
|
55
55
|
exports.isSupported = isSupported = Boolean(_fs.default);
|
|
56
|
-
} catch (_unused) {
|
|
57
|
-
|
|
56
|
+
} catch (_unused) {
|
|
57
|
+
}
|
|
58
58
|
function _readToArrayBuffer(_x, _x2, _x3) {
|
|
59
59
|
return _readToArrayBuffer2.apply(this, arguments);
|
|
60
60
|
}
|
|
61
|
-
|
|
62
61
|
function _readToArrayBuffer2() {
|
|
63
62
|
_readToArrayBuffer2 = (0, _asyncToGenerator2.default)(_regenerator.default.mark(function _callee(fd, start, length) {
|
|
64
63
|
var buffer, _yield$read, bytesRead;
|
|
65
|
-
|
|
66
64
|
return _regenerator.default.wrap(function _callee$(_context) {
|
|
67
65
|
while (1) {
|
|
68
66
|
switch (_context.prev = _context.next) {
|
|
@@ -70,21 +68,16 @@ function _readToArrayBuffer2() {
|
|
|
70
68
|
buffer = Buffer.alloc(length);
|
|
71
69
|
_context.next = 3;
|
|
72
70
|
return read(fd, buffer, 0, length, start);
|
|
73
|
-
|
|
74
71
|
case 3:
|
|
75
72
|
_yield$read = _context.sent;
|
|
76
73
|
bytesRead = _yield$read.bytesRead;
|
|
77
|
-
|
|
78
74
|
if (!(bytesRead !== length)) {
|
|
79
75
|
_context.next = 7;
|
|
80
76
|
break;
|
|
81
77
|
}
|
|
82
|
-
|
|
83
78
|
throw new Error('fs.read failed');
|
|
84
|
-
|
|
85
79
|
case 7:
|
|
86
80
|
return _context.abrupt("return", (0, _buffer.toArrayBuffer)(buffer));
|
|
87
|
-
|
|
88
81
|
case 8:
|
|
89
82
|
case "end":
|
|
90
83
|
return _context.stop();
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
1
|
+
{"version":3,"file":"fs.js","names":["readdir","stat","readFile","readFileSync","writeFile","writeFileSync","open","close","read","fstat","isSupported","Boolean","fs","promisify","_readToArrayBuffer","fd","start","length","buffer","Buffer","alloc","bytesRead","Error","toArrayBuffer"],"sources":["../../../../src/lib/node/fs.ts"],"sourcesContent":["// fs wrapper (promisified fs + avoids bundling fs in browsers)\nimport fs from 'fs';\nimport {toArrayBuffer} from './buffer';\nimport {promisify} from './util';\n\nexport type {Stats} from 'fs';\n\nexport let readdir;\n/** Wrapper for Node.js fs method */\nexport let stat;\n\n/** Wrapper for Node.js fs method */\nexport let readFile;\n/** Wrapper for Node.js fs method */\nexport let readFileSync;\n/** Wrapper for Node.js fs method */\nexport let writeFile;\n/** Wrapper for Node.js fs method */\nexport let writeFileSync;\n\n// file descriptors\n\n/** Wrapper for Node.js fs method */\nexport let open;\n/** Wrapper for Node.js fs method */\nexport let close;\n/** Wrapper for Node.js fs method */\nexport let read;\n/** Wrapper for Node.js fs method */\nexport let fstat;\n\nexport let isSupported = Boolean(fs);\n\n// paths\n\ntry {\n /** Wrapper for Node.js fs method */\n readdir = promisify(fs.readdir);\n /** Wrapper for Node.js fs method */\n stat = promisify(fs.stat);\n\n /** Wrapper for Node.js fs method */\n readFile = promisify(fs.readFile);\n /** Wrapper for Node.js fs method */\n readFileSync = fs.readFileSync;\n /** Wrapper for Node.js fs method */\n writeFile = promisify(fs.writeFile);\n /** Wrapper for Node.js fs method */\n writeFileSync = fs.writeFileSync;\n\n // file descriptors\n\n /** Wrapper for Node.js fs method */\n open = promisify(fs.open);\n /** Wrapper for Node.js fs method */\n close = promisify(fs.close);\n /** Wrapper for Node.js fs method */\n read = promisify(fs.read);\n /** Wrapper for Node.js fs method */\n fstat = promisify(fs.fstat);\n\n isSupported = Boolean(fs);\n} catch {\n // ignore\n}\n\nexport async function _readToArrayBuffer(fd: number, start: number, length: number) {\n const buffer = Buffer.alloc(length);\n const {bytesRead} = await read(fd, buffer, 0, length, start);\n if (bytesRead !== length) {\n throw new Error('fs.read failed');\n }\n return toArrayBuffer(buffer);\n}\n"],"mappings":";;;;;;;;;;AACA;AACA;AACA;;AAIO,IAAIA,OAAO;AAAC;AAEZ,IAAIC,IAAI;;AAAC;AAGT,IAAIC,QAAQ;AAAC;AAEb,IAAIC,YAAY;AAAC;AAEjB,IAAIC,SAAS;AAAC;AAEd,IAAIC,aAAa;;AAAC;;AAKlB,IAAIC,IAAI;AAAC;AAET,IAAIC,KAAK;AAAC;AAEV,IAAIC,IAAI;AAAC;AAET,IAAIC,KAAK;AAAC;AAEV,IAAIC,WAAW,GAAGC,OAAO,CAACC,WAAE,CAAC;;AAAC;;AAIrC,IAAI;EAEF,kBAAAZ,OAAO,GAAG,IAAAa,eAAS,EAACD,WAAE,CAACZ,OAAO,CAAC;EAE/B,eAAAC,IAAI,GAAG,IAAAY,eAAS,EAACD,WAAE,CAACX,IAAI,CAAC;;EAGzB,mBAAAC,QAAQ,GAA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object.defineProperty(exports, "__esModule", {
|
|
6
5
|
value: true
|
|
7
6
|
});
|
|
8
7
|
exports.promisify = void 0;
|
|
9
|
-
|
|
10
8
|
var util = _interopRequireWildcard(require("util"));
|
|
11
|
-
|
|
12
9
|
function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
|
|
13
|
-
|
|
14
10
|
function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || _typeof(obj) !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
|
|
15
|
-
|
|
16
11
|
var promisify = util.promisify;
|
|
17
12
|
exports.promisify = promisify;
|
|
18
13
|
//# sourceMappingURL=util.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
1
|
+
{"version":3,"file":"util.js","names":["promisify","util"],"sources":["../../../../src/lib/node/util.ts"],"sourcesContent":["import * as util from 'util';\n\n/** Wrapper for Node.js promisify */\nexport const promisify = util.promisify;\n"],"mappings":";;;;;;;AAAA;AAA6B;AAAA;AAGtB,IAAMA,SAAS,GAAGC,IAAI,CAACD,SAAS;AAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
1
|
+
{"version":3,"file":"parse-json.js","names":["parseJSON","string","JSON","parse","_","Error","getFirstCharacters"],"sources":["../../../../src/lib/parser-utils/parse-json.ts"],"sourcesContent":["import {getFirstCharacters} from '../binary-utils/get-first-characters';\n\n/**\n * Minimal JSON parser that throws more meaningful error messages\n */\nexport function parseJSON(string: string): any {\n try {\n return JSON.parse(string);\n } catch (_) {\n throw new Error(`Failed to parse JSON from data starting with \"${getFirstCharacters(string)}\"`);\n }\n}\n"],"mappings":";;;;;;AAAA;AAKO,SAASA,SAAS,CAACC,MAAc,EAAO;EAC7C,IAAI;IACF,OAAOC,IAAI,CAACC,KAAK,CAACF,MAAM,CAAC;EAC3B,CAAC,CAAC,OAAOG,CAAC,EAAE;IACV,MAAM,IAAIC,KAAK,0DAAkD,IAAAC,sCAAkB,EAACL,MAAM,CAAC,QAAI;EACjG;AACF"}
|
|
@@ -3,10 +3,11 @@
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
|
-
exports.setPathPrefix = setPathPrefix;
|
|
7
|
-
exports.getPathPrefix = getPathPrefix;
|
|
8
6
|
exports.addAliases = addAliases;
|
|
7
|
+
exports.getPathPrefix = getPathPrefix;
|
|
9
8
|
exports.resolvePath = resolvePath;
|
|
9
|
+
exports.setPathPrefix = setPathPrefix;
|
|
10
|
+
|
|
10
11
|
var pathPrefix = '';
|
|
11
12
|
var fileAliases = {};
|
|
12
13
|
|
|
@@ -29,11 +30,9 @@ function resolvePath(filename) {
|
|
|
29
30
|
filename = filename.replace(alias, replacement);
|
|
30
31
|
}
|
|
31
32
|
}
|
|
32
|
-
|
|
33
33
|
if (!filename.startsWith('http://') && !filename.startsWith('https://')) {
|
|
34
34
|
filename = "".concat(pathPrefix).concat(filename);
|
|
35
35
|
}
|
|
36
|
-
|
|
37
36
|
return filename;
|
|
38
37
|
}
|
|
39
38
|
//# sourceMappingURL=file-aliases.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
1
|
+
{"version":3,"file":"file-aliases.js","names":["pathPrefix","fileAliases","setPathPrefix","prefix","getPathPrefix","addAliases","aliases","Object","assign","resolvePath","filename","alias","startsWith","replacement","replace"],"sources":["../../../../src/lib/path-utils/file-aliases.ts"],"sourcesContent":["// Simple file alias mechanisms for tests.\n\nlet pathPrefix = '';\nconst fileAliases: {[aliasPath: string]: string} = {};\n\n/*\n * Set a relative path prefix\n */\nexport function setPathPrefix(prefix: string): void {\n pathPrefix = prefix;\n}\n\n/*\n * Get the relative path prefix\n */\nexport function getPathPrefix(): string {\n return pathPrefix;\n}\n\n/**\n *\n * @param aliases\n *\n * Note: addAliases are an experimental export, they are only for testing of loaders.gl loaders\n * not intended as a generic aliasing mechanism\n */\nexport function addAliases(aliases: {[aliasPath: string]: string}): void {\n Object.assign(fileAliases, aliases);\n}\n\n/**\n * Resolves aliases and adds path-prefix to paths\n */\nexport function resolvePath(filename: string): string {\n for (const alias in fileAliases) {\n if (filename.startsWith(alias)) {\n const replacement = fileAliases[alias];\n filename = filename.replace(alias, replacement);\n }\n }\n if (!filename.startsWith('http://') && !filename.startsWith('https://')) {\n filename = `${pathPrefix}${filename}`;\n }\n return filename;\n}\n"],"mappings":";;;;;;;;;;AAEA,IAAIA,UAAU,GAAG,EAAE;AACnB,IAAMC,WAA0C,GAAG,CAAC,CAAC;;AAK9C,SAASC,aAAa,CAACC,MAAc,EAAQ;EAClDH,UAAU,GAAGG,MAAM;AACrB;;AAKO,SAASC,aAAa,GAAW;EACtC,OAAOJ,UAAU;AACnB;;AASO,SAASK,UAAU,CAACC,OAAsC,EAAQ;EACvEC,MAAM,CAACC,MAAM,CAACP,WAAW,EAAEK,OAAO,CAAC;AACrC;;AAKO,SAASG,WAAW,CAACC,QAAgB,EAAU;EACpD,KAAK,IAAMC,KAAK,IAAIV,WAAW,EAAE;IAC/B,IAAIS,QAAQ,CAACE,UAAU,CAACD,KAAK,CAAC,EAAE;MAC9B,IAAME,WAAW,GAAGZ,WAAW,CAACU,KAAK,CAAC;MACtCD,QAAQ,GAAGA,QAAQ,CAACI,OAAO,CAACH,KAAK,EAAEE,WAAW,CAAC;IACjD;EACF;EACA,IAAI,CAACH,QAAQ,CAACE,UAAU,CAAC,SAAS,CAAC,IAAI,CAACF,QAAQ,CAACE,UAAU,CAAC,UAAU,CAAC,EAAE;IACvEF,QAAQ,aAAMV,UAAU,SAAGU,QAAQ,CAAE;EACvC;EACA,OAAOA,QAAQ;AACjB"}
|
|
@@ -3,8 +3,8 @@
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
|
-
exports.filename = filename;
|
|
7
6
|
exports.dirname = dirname;
|
|
7
|
+
exports.filename = filename;
|
|
8
8
|
exports.join = join;
|
|
9
9
|
|
|
10
10
|
function filename(url) {
|
|
@@ -21,17 +21,14 @@ function join() {
|
|
|
21
21
|
for (var _len = arguments.length, parts = new Array(_len), _key = 0; _key < _len; _key++) {
|
|
22
22
|
parts[_key] = arguments[_key];
|
|
23
23
|
}
|
|
24
|
-
|
|
25
24
|
var separator = '/';
|
|
26
25
|
parts = parts.map(function (part, index) {
|
|
27
26
|
if (index) {
|
|
28
27
|
part = part.replace(new RegExp("^".concat(separator)), '');
|
|
29
28
|
}
|
|
30
|
-
|
|
31
29
|
if (index !== parts.length - 1) {
|
|
32
30
|
part = part.replace(new RegExp("".concat(separator, "$")), '');
|
|
33
31
|
}
|
|
34
|
-
|
|
35
32
|
return part;
|
|
36
33
|
});
|
|
37
34
|
return parts.join(separator);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
1
|
+
{"version":3,"file":"path.js","names":["filename","url","slashIndex","lastIndexOf","substr","dirname","join","parts","separator","map","part","index","replace","RegExp","length"],"sources":["../../../../src/lib/path-utils/path.ts"],"sourcesContent":["// Beginning of a minimal implementation of the Node.js path API, that doesn't pull in big polyfills.\n\n/**\n * Replacement for Node.js path.filename\n * @param url\n */\nexport function filename(url: string): string {\n const slashIndex = url && url.lastIndexOf('/');\n return slashIndex >= 0 ? url.substr((slashIndex as number) + 1) : '';\n}\n\n/**\n * Replacement for Node.js path.dirname\n * @param url\n */\nexport function dirname(url: string): string {\n const slashIndex = url && url.lastIndexOf('/');\n return slashIndex >= 0 ? url.substr(0, slashIndex as number) : '';\n}\n\n/**\n * Replacement for Node.js path.join\n * @param parts\n */\nexport function join(...parts: string[]): string {\n const separator = '/';\n parts = parts.map((part, index) => {\n if (index) {\n part = part.replace(new RegExp(`^${separator}`), '');\n }\n if (index !== parts.length - 1) {\n part = part.replace(new RegExp(`${separator}$`), '');\n }\n return part;\n });\n return parts.join(separator);\n}\n"],"mappings":";;;;;;;;;AAMO,SAASA,QAAQ,CAACC,GAAW,EAAU;EAC5C,IAAMC,UAAU,GAAGD,GAAG,IAAIA,GAAG,CAACE,WAAW,CAAC,GAAG,CAAC;EAC9C,OAAOD,UAAU,IAAI,CAAC,GAAGD,GAAG,CAACG,MAAM,CAAEF,UAAU,GAAc,CAAC,CAAC,GAAG,EAAE;AACtE;;AAMO,SAASG,OAAO,CAACJ,GAAW,EAAU;EAC3C,IAAMC,UAAU,GAAGD,GAAG,IAAIA,GAAG,CAACE,WAAW,CAAC,GAAG,CAAC;EAC9C,OAAOD,UAAU,IAAI,CAAC,GAAGD,GAAG,CAACG,MAAM,CAAC,CAAC,EAAEF,UAAU,CAAW,GAAG,EAAE;AACnE;;AAMO,SAASI,IAAI,GAA6B;EAAA,kCAAzBC,KAAK;IAALA,KAAK;EAAA;EAC3B,IAAMC,SAAS,GAAG,GAAG;EACrBD,KAAK,GAAGA,KAAK,CAACE,GAAG,CAAC,UAACC,IAAI,EAAEC,KAAK,EAAK;IACjC,IAAIA,KAAK,EAAE;MACTD,IAAI,GAAGA,IAAI,CAACE,OAAO,CAAC,IAAIC,MAAM,YAAKL,SAAS,EAAG,EAAE,EAAE,CAAC;IACtD;IACA,IAAIG,KAAK,KAAKJ,KAAK,CAACO,MAAM,GAAG,CAAC,EAAE;MAC9BJ,IAAI,GAAGA,IAAI,CAACE,OAAO,CAAC,IAAIC,MAAM,WAAIL,SAAS,OAAI,EAAE,EAAE,CAAC;IACtD;IACA,OAAOE,IAAI;EACb,CAAC,CAAC;EACF,OAAOH,KAAK,CAACD,IAAI,CAACE,SAAS,CAAC;AAC9B"}
|
|
@@ -1,24 +1,16 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
3
|
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
-
|
|
5
4
|
Object.defineProperty(exports, "__esModule", {
|
|
6
5
|
value: true
|
|
7
6
|
});
|
|
8
7
|
exports.default = void 0;
|
|
9
|
-
|
|
10
8
|
var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime/helpers/classCallCheck"));
|
|
11
|
-
|
|
12
9
|
var _createClass2 = _interopRequireDefault(require("@babel/runtime/helpers/createClass"));
|
|
13
|
-
|
|
14
10
|
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
|
|
15
|
-
|
|
16
11
|
var _stats = require("@probe.gl/stats");
|
|
17
|
-
|
|
18
|
-
function
|
|
19
|
-
|
|
20
|
-
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(Object(source), true).forEach(function (key) { (0, _defineProperty2.default)(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }
|
|
21
|
-
|
|
12
|
+
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
|
|
13
|
+
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { (0, _defineProperty2.default)(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
|
|
22
14
|
var STAT_QUEUED_REQUESTS = 'Queued Requests';
|
|
23
15
|
var STAT_ACTIVE_REQUESTS = 'Active Requests';
|
|
24
16
|
var STAT_CANCELLED_REQUESTS = 'Cancelled Requests';
|
|
@@ -31,6 +23,7 @@ var DEFAULT_PROPS = {
|
|
|
31
23
|
};
|
|
32
24
|
|
|
33
25
|
var RequestScheduler = function () {
|
|
26
|
+
|
|
34
27
|
function RequestScheduler() {
|
|
35
28
|
var props = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
36
29
|
(0, _classCallCheck2.default)(this, RequestScheduler);
|
|
@@ -41,6 +34,7 @@ var RequestScheduler = function () {
|
|
|
41
34
|
(0, _defineProperty2.default)(this, "requestMap", new Map());
|
|
42
35
|
(0, _defineProperty2.default)(this, "deferredUpdate", null);
|
|
43
36
|
this.props = _objectSpread(_objectSpread({}, DEFAULT_PROPS), props);
|
|
37
|
+
|
|
44
38
|
this.stats = new _stats.Stats({
|
|
45
39
|
id: this.props.id
|
|
46
40
|
});
|
|
@@ -53,11 +47,11 @@ var RequestScheduler = function () {
|
|
|
53
47
|
|
|
54
48
|
(0, _createClass2.default)(RequestScheduler, [{
|
|
55
49
|
key: "scheduleRequest",
|
|
56
|
-
value:
|
|
50
|
+
value:
|
|
51
|
+
function scheduleRequest(handle) {
|
|
57
52
|
var getPriority = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : function () {
|
|
58
53
|
return 0;
|
|
59
54
|
};
|
|
60
|
-
|
|
61
55
|
if (!this.props.throttleRequests) {
|
|
62
56
|
return Promise.resolve({
|
|
63
57
|
done: function done() {}
|
|
@@ -67,7 +61,6 @@ var RequestScheduler = function () {
|
|
|
67
61
|
if (this.requestMap.has(handle)) {
|
|
68
62
|
return this.requestMap.get(handle);
|
|
69
63
|
}
|
|
70
|
-
|
|
71
64
|
var request = {
|
|
72
65
|
handle: handle,
|
|
73
66
|
priority: 0,
|
|
@@ -79,28 +72,25 @@ var RequestScheduler = function () {
|
|
|
79
72
|
});
|
|
80
73
|
this.requestQueue.push(request);
|
|
81
74
|
this.requestMap.set(handle, promise);
|
|
82
|
-
|
|
83
75
|
this._issueNewRequests();
|
|
84
|
-
|
|
85
76
|
return promise;
|
|
86
77
|
}
|
|
78
|
+
|
|
87
79
|
}, {
|
|
88
80
|
key: "_issueRequest",
|
|
89
|
-
value:
|
|
90
|
-
var _this = this;
|
|
81
|
+
value:
|
|
91
82
|
|
|
83
|
+
function _issueRequest(request) {
|
|
84
|
+
var _this = this;
|
|
92
85
|
var handle = request.handle,
|
|
93
|
-
|
|
86
|
+
resolve = request.resolve;
|
|
94
87
|
var isDone = false;
|
|
95
|
-
|
|
96
88
|
var done = function done() {
|
|
97
89
|
if (!isDone) {
|
|
98
90
|
isDone = true;
|
|
99
91
|
|
|
100
92
|
_this.requestMap.delete(handle);
|
|
101
|
-
|
|
102
93
|
_this.activeRequestCount--;
|
|
103
|
-
|
|
104
94
|
_this._issueNewRequests();
|
|
105
95
|
}
|
|
106
96
|
};
|
|
@@ -112,45 +102,46 @@ var RequestScheduler = function () {
|
|
|
112
102
|
done: done
|
|
113
103
|
});
|
|
114
104
|
}
|
|
105
|
+
|
|
115
106
|
}, {
|
|
116
107
|
key: "_issueNewRequests",
|
|
117
|
-
value:
|
|
108
|
+
value:
|
|
109
|
+
function _issueNewRequests() {
|
|
118
110
|
var _this2 = this;
|
|
119
|
-
|
|
120
111
|
if (!this.deferredUpdate) {
|
|
121
112
|
this.deferredUpdate = setTimeout(function () {
|
|
122
113
|
return _this2._issueNewRequestsAsync();
|
|
123
114
|
}, 0);
|
|
124
115
|
}
|
|
125
116
|
}
|
|
117
|
+
|
|
126
118
|
}, {
|
|
127
119
|
key: "_issueNewRequestsAsync",
|
|
128
|
-
value:
|
|
120
|
+
value:
|
|
121
|
+
function _issueNewRequestsAsync() {
|
|
129
122
|
this.deferredUpdate = null;
|
|
130
123
|
var freeSlots = Math.max(this.props.maxRequests - this.activeRequestCount, 0);
|
|
131
|
-
|
|
132
124
|
if (freeSlots === 0) {
|
|
133
125
|
return;
|
|
134
126
|
}
|
|
135
|
-
|
|
136
127
|
this._updateAllRequests();
|
|
137
128
|
|
|
138
129
|
for (var i = 0; i < freeSlots; ++i) {
|
|
139
130
|
var request = this.requestQueue.shift();
|
|
140
|
-
|
|
141
131
|
if (request) {
|
|
142
132
|
this._issueRequest(request);
|
|
143
133
|
}
|
|
144
134
|
}
|
|
135
|
+
|
|
145
136
|
}
|
|
137
|
+
|
|
146
138
|
}, {
|
|
147
139
|
key: "_updateAllRequests",
|
|
148
|
-
value:
|
|
140
|
+
value:
|
|
141
|
+
function _updateAllRequests() {
|
|
149
142
|
var requestQueue = this.requestQueue;
|
|
150
|
-
|
|
151
143
|
for (var i = 0; i < requestQueue.length; ++i) {
|
|
152
144
|
var request = requestQueue[i];
|
|
153
|
-
|
|
154
145
|
if (!this._updateRequest(request)) {
|
|
155
146
|
requestQueue.splice(i, 1);
|
|
156
147
|
this.requestMap.delete(request.handle);
|
|
@@ -162,21 +153,21 @@ var RequestScheduler = function () {
|
|
|
162
153
|
return a.priority - b.priority;
|
|
163
154
|
});
|
|
164
155
|
}
|
|
156
|
+
|
|
165
157
|
}, {
|
|
166
158
|
key: "_updateRequest",
|
|
167
|
-
value:
|
|
159
|
+
value:
|
|
160
|
+
function _updateRequest(request) {
|
|
168
161
|
request.priority = request.getPriority(request.handle);
|
|
169
162
|
|
|
170
163
|
if (request.priority < 0) {
|
|
171
164
|
request.resolve(null);
|
|
172
165
|
return false;
|
|
173
166
|
}
|
|
174
|
-
|
|
175
167
|
return true;
|
|
176
168
|
}
|
|
177
169
|
}]);
|
|
178
170
|
return RequestScheduler;
|
|
179
171
|
}();
|
|
180
|
-
|
|
181
172
|
exports.default = RequestScheduler;
|
|
182
173
|
//# sourceMappingURL=request-scheduler.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../src/lib/request-utils/request-scheduler.ts"],"names":["STAT_QUEUED_REQUESTS","STAT_ACTIVE_REQUESTS","STAT_CANCELLED_REQUESTS","STAT_QUEUED_REQUESTS_EVER","STAT_ACTIVE_REQUESTS_EVER","DEFAULT_PROPS","id","throttleRequests","maxRequests","RequestScheduler","props","Map","stats","Stats","get","handle","getPriority","Promise","resolve","done","requestMap","has","request","priority","promise","requestQueue","push","set","_issueNewRequests","isDone","delete","activeRequestCount","deferredUpdate","setTimeout","_issueNewRequestsAsync","freeSlots","Math","max","_updateAllRequests","i","shift","_issueRequest","length","_updateRequest","splice","sort","a","b"],"mappings":";;;;;;;;;;;;;;;AAAA;;;;;;AAgBA,IAAMA,oBAAoB,GAAG,iBAA7B;AACA,IAAMC,oBAAoB,GAAG,iBAA7B;AACA,IAAMC,uBAAuB,GAAG,oBAAhC;AACA,IAAMC,yBAAyB,GAAG,sBAAlC;AACA,IAAMC,yBAAyB,GAAG,sBAAlC;AAEA,IAAMC,aAA8C,GAAG;AACrDC,EAAAA,EAAE,EAAE,mBADiD;AAGrDC,EAAAA,gBAAgB,EAAE,IAHmC;AAKrDC,EAAAA,WAAW,EAAE;AALwC,CAAvD;;IAoBqBC,gB;AAUnB,8BAA+C;AAAA,QAAnCC,KAAmC,uEAAJ,EAAI;AAAA;AAAA;AAAA;AAAA,8DAPlB,CAOkB;AAAA,wDAJb,EAIa;AAAA,sDAHW,IAAIC,GAAJ,EAGX;AAAA,0DAFjB,IAEiB;AAC7C,SAAKD,KAAL,mCAAiBL,aAAjB,GAAmCK,KAAnC;AAGA,SAAKE,KAAL,GAAa,IAAIC,YAAJ,CAAU;AAACP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AK,IAAIc,CAAC,GAAG,CAAb,EAAgBA,CAAC,GAAGd,YAAY,CAACiB,MAAjC,EAAyC,EAAEH,CAA3C,EAA8C;AAC5C,YAAMjB,OAAO,GAAGG,YAAY,CAACc,CAAD,CAA5B;;AACA,YAAI,CAAC,KAAKI,cAAL,CAAoBrB,OAApB,CAAL,EAAmC;AAEjCG,UAAAA,YAAY,CAACmB,MAAb,CAAoBL,CAApB,EAAuB,CAAvB;AACA,eAAKnB,UAAL,CAAgBU,MAAhB,CAAuBR,OAAO,CAACP,MAA/B;AACAwB,UAAAA,CAAC;AACF;AACF;;AAGDd,MAAAA,YAAY,CAACoB,IAAb,CAAkB,UAACC,CAAD,EAAIC,CAAJ;AAAA,eAAUD,CAAC,CAACvB,QAAF,GAAawB,CAAC,CAACxB,QAAzB;AAAA,OAAlB;AACD;;;WAGD,wBAAeD,OAAf,EAAwB;AACtBA,MAAAA,OAAO,CAACC,QAAR,GAAmBD,OAAO,CAACN,WAAR,CAAoBM,OAAO,CAACP,MAA5B,CAAnB;;AAGA,UAAIO,OAAO,CAACC,QAAR,GAAmB,CAAvB,EAA0B;AACxBD,QAAAA,OAAO,CAACJ,OAAR,CAAgB,IAAhB;AACA,eAAO,KAAP;AACD;;AACD,aAAO,IAAP;AACD","sourcesContent":["import {Stats} from '@probe.gl/stats';\n\ntype Handle = any;\ntype DoneFunction = () => any;\ntype GetPriorityFunction = () => number;\ntype RequestResult = {\n done: DoneFunction;\n} | null;\n\n/** RequestScheduler Options */\nexport type RequestSchedulerProps = {\n id?: string;\n throttleRequests?: boolean;\n maxRequests?: number;\n};\n\nconst STAT_QUEUED_REQUESTS = 'Queued Requests';\nconst STAT_ACTIVE_REQUESTS = 'Active Requests';\nconst STAT_CANCELLED_REQUESTS = 'Cancelled Requests';\nconst STAT_QUEUED_REQUESTS_EVER = 'Queued Requests Ever';\nconst STAT_ACTIVE_REQUESTS_EVER = 'Active Requests Ever';\n\nconst DEFAULT_PROPS: Required<RequestSchedulerProps> = {\n id: 'request-scheduler',\n // Specifies if the request scheduler should throttle incoming requests, mainly for comparative testing\n throttleRequests: true,\n // The maximum number of simultaneous active requests. Un-throttled requests do not observe this limit.\n maxRequests: 6\n};\n\n/** Tracks one request */\ntype Request = {\n handle: Handle;\n priority: number;\n getPriority: GetPriorityFunction;\n resolve?: (value: any) => any;\n};\n\n/**\n * Used to issue a request, without having them \"deeply queued\" by the browser.\n * @todo - Track requests globally, across multiple servers\n */\nexport default class RequestScheduler {\n readonly props: Required<RequestSchedulerProps>;\n readonly stats: Stats;\n activeRequestCount: number = 0;\n\n /** Tracks the number of active requests and prioritizes/cancels queued requests. */\n private requestQueue: Request[] = [];\n private requestMap: Map<Handle, Promise<RequestResult>> = new Map();\n private deferredUpdate: any = null;\n\n constructor(props: RequestSchedulerProps = {}) {\n this.props = {...DEFAULT_PROPS, ...props};\n\n // Returns the statistics used by the request scheduler.\n this.stats = new Stats({id: this.props.id});\n this.stats.get(STAT_QUEUED_REQUESTS);\n this.stats.get(STAT_ACTIVE_REQUESTS);\n this.stats.get(STAT_CANCELLED_REQUESTS);\n this.stats.get(STAT_QUEUED_REQUESTS_EVER);\n this.stats.get(STAT_ACTIVE_REQUESTS_EVER);\n }\n\n /**\n * Called by an application that wants to issue a request, without having it deeply queued by the browser\n *\n * When the returned promise resolved, it is OK for the application to issue a request.\n * The promise resolves to an object that contains a `done` method.\n * When the application's request has completed (or failed), the application must call the `done` function\n *\n * @param handle\n * @param getPriority will be called when request \"slots\" open up,\n * allowing the caller to update priority or cancel the request\n * Highest priority executes first, priority < 0 cancels the request\n * @returns a promise\n * - resolves to a object (with a `done` field) when the request can be issued without queueing,\n * - resolves to `null` if the request has been cancelled (by the callback return < 0).\n * In this case the application should not issue the request\n */\n scheduleRequest(\n handle: Handle,\n getPriority: GetPriorityFunction = () => 0\n ): Promise<RequestResult> {\n // Allows throttling to be disabled\n if (!this.props.throttleRequests) {\n return Promise.resolve({done: () => {}});\n }\n\n // dedupe\n if (this.requestMap.has(handle)) {\n return this.requestMap.get(handle) as Promise<any>;\n }\n\n const request: Request = {handle, priority: 0, getPriority};\n const promise = new Promise<RequestResult>((resolve) => {\n // @ts-ignore\n request.resolve = resolve;\n return request;\n });\n\n this.requestQueue.push(request);\n this.requestMap.set(handle, promise);\n this._issueNewRequests();\n return promise;\n }\n\n // PRIVATE\n\n _issueRequest(request: Request): Promise<any> {\n const {handle, resolve} = request;\n let isDone = false;\n\n const done = () => {\n // can only be called once\n if (!isDone) {\n isDone = true;\n\n // Stop tracking a request - it has completed, failed, cancelled etc\n this.requestMap.delete(handle);\n this.activeRequestCount--;\n // A slot just freed up, see if any queued requests are waiting\n this._issueNewRequests();\n }\n };\n\n // Track this request\n this.activeRequestCount++;\n\n return resolve ? resolve({done}) : Promise.resolve({done});\n }\n\n /** We check requests asynchronously, to prevent multiple updates */\n _issueNewRequests(): void {\n if (!this.deferredUpdate) {\n this.deferredUpdate = setTimeout(() => this._issueNewRequestsAsync(), 0);\n }\n }\n\n /** Refresh all requests */\n _issueNewRequestsAsync() {\n // TODO - shouldn't we clear the timeout?\n this.deferredUpdate = null;\n\n const freeSlots = Math.max(this.props.maxRequests - this.activeRequestCount, 0);\n\n if (freeSlots === 0) {\n return;\n }\n\n this._updateAllRequests();\n\n // Resolve pending promises for the top-priority requests\n for (let i = 0; i < freeSlots; ++i) {\n const request = this.requestQueue.shift();\n if (request) {\n this._issueRequest(request); // eslint-disable-line @typescript-eslint/no-floating-promises\n }\n }\n\n // Uncomment to debug\n // console.log(`${freeSlots} free slots, ${this.requestQueue.length} queued requests`);\n }\n\n /** Ensure all requests have updated priorities, and that no longer valid requests are cancelled */\n _updateAllRequests() {\n const requestQueue = this.requestQueue;\n for (let i = 0; i < requestQueue.length; ++i) {\n const request = requestQueue[i];\n if (!this._updateRequest(request)) {\n // Remove the element and make sure to adjust the counter to account for shortened array\n requestQueue.splice(i, 1);\n this.requestMap.delete(request.handle);\n i--;\n }\n }\n\n // Sort the remaining requests based on priority\n requestQueue.sort((a, b) => a.priority - b.priority);\n }\n\n /** Update a single request by calling the callback */\n _updateRequest(request) {\n request.priority = request.getPriority(request.handle); // eslint-disable-line callback-return\n\n // by returning a negative priority, the callback cancels the request\n if (request.priority < 0) {\n request.resolve(null);\n return false;\n }\n return true;\n }\n}\n"],"file":"request-scheduler.js"}
|
|
1
|
+
{"version":3,"file":"request-scheduler.js","names":["STAT_QUEUED_REQUESTS","STAT_ACTIVE_REQUESTS","STAT_CANCELLED_REQUESTS","STAT_QUEUED_REQUESTS_EVER","STAT_ACTIVE_REQUESTS_EVER","DEFAULT_PROPS","id","throttleRequests","maxRequests","RequestScheduler","props","Map","stats","Stats","get","handle","getPriority","Promise","resolve","done","requestMap","has","request","priority","promise","requestQueue","push","set","_issueNewRequests","isDone","delete","activeRequestCount","deferredUpdate","setTimeout","_issueNewRequestsAsync","freeSlots","Math","max","_updateAllRequests","i","shift","_issueRequest","length","_updateRequest","splice","sort","a","b"],"sources":["../../../../src/lib/request-utils/request-scheduler.ts"],"sourcesContent":["import {Stats} from '@probe.gl/stats';\n\ntype Handle = any;\ntype DoneFunction = () => any;\ntype GetPriorityFunction = () => number;\ntype RequestResult = {\n done: DoneFunction;\n} | null;\n\n/** RequestScheduler Options */\nexport type RequestSchedulerProps = {\n id?: string;\n throttleRequests?: boolean;\n maxRequests?: number;\n};\n\nconst STAT_QUEUED_REQUESTS = 'Queued Requests';\nconst STAT_ACTIVE_REQUESTS = 'Active Requests';\nconst STAT_CANCELLED_REQUESTS = 'Cancelled Requests';\nconst STAT_QUEUED_REQUESTS_EVER = 'Queued Requests Ever';\nconst STAT_ACTIVE_REQUESTS_EVER = 'Active Requests Ever';\n\nconst DEFAULT_PROPS: Required<RequestSchedulerProps> = {\n id: 'request-scheduler',\n // Specifies if the request scheduler should throttle incoming requests, mainly for comparative testing\n throttleRequests: true,\n // The maximum number of simultaneous active requests. Un-throttled requests do not observe this limit.\n maxRequests: 6\n};\n\n/** Tracks one request */\ntype Request = {\n handle: Handle;\n priority: number;\n getPriority: GetPriorityFunction;\n resolve?: (value: any) => any;\n};\n\n/**\n * Used to issue a request, without having them \"deeply queued\" by the browser.\n * @todo - Track requests globally, across multiple servers\n */\nexport default class RequestScheduler {\n readonly props: Required<RequestSchedulerProps>;\n readonly stats: Stats;\n activeRequestCount: number = 0;\n\n /** Tracks the number of active requests and prioritizes/cancels queued requests. */\n private requestQueue: Request[] = [];\n private requestMap: Map<Handle, Promise<RequestResult>> = new Map();\n private deferredUpdate: any = null;\n\n constructor(props: RequestSchedulerProps = {}) {\n this.props = {...DEFAULT_PROPS, ...props};\n\n // Returns the statistics used by the request scheduler.\n this.stats = new Stats({id: this.props.id});\n this.stats.get(STAT_QUEUED_REQUESTS);\n this.stats.get(STAT_ACTIVE_REQUESTS);\n this.stats.get(STAT_CANCELLED_REQUESTS);\n this.stats.get(STAT_QUEUED_REQUESTS_EVER);\n this.stats.get(STAT_ACTIVE_REQUESTS_EVER);\n }\n\n /**\n * Called by an application that wants to issue a request, without having it deeply queued by the browser\n *\n * When the returned promise resolved, it is OK for the application to issue a request.\n * The promise resolves to an object that contains a `done` method.\n * When the application's request has completed (or failed), the application must call the `done` function\n *\n * @param handle\n * @param getPriority will be called when request \"slots\" open up,\n * allowing the caller to update priority or cancel the request\n * Highest priority executes first, priority < 0 cancels the request\n * @returns a promise\n * - resolves to a object (with a `done` field) when the request can be issued without queueing,\n * - resolves to `null` if the request has been cancelled (by the callback return < 0).\n * In this case the application should not issue the request\n */\n scheduleRequest(\n handle: Handle,\n getPriority: GetPriorityFunction = () => 0\n ): Promise<RequestResult> {\n // Allows throttling to be disabled\n if (!this.props.throttleRequests) {\n return Promise.resolve({done: () => {}});\n }\n\n // dedupe\n if (this.requestMap.has(handle)) {\n return this.requestMap.get(handle) as Promise<any>;\n }\n\n const request: Request = {handle, priority: 0, getPriority};\n const promise = new Promise<RequestResult>((resolve) => {\n // @ts-ignore\n request.resolve = resolve;\n return request;\n });\n\n this.requestQueue.push(request);\n this.requestMap.set(handle, promise);\n this._issueNewRequests();\n return promise;\n }\n\n // PRIVATE\n\n _issueRequest(request: Request): Promise<any> {\n const {handle, resolve} = request;\n let isDone = false;\n\n const done = () => {\n // can only be called once\n if (!isDone) {\n isDone = true;\n\n // Stop tracking a request - it has completed, failed, cancelled etc\n this.requestMap.delete(handle);\n this.activeRequestCount--;\n // A slot just freed up, see if any queued requests are waiting\n this._issueNewRequests();\n }\n };\n\n // Track this request\n this.activeRequestCount++;\n\n return resolve ? resolve({done}) : Promise.resolve({done});\n }\n\n /** We check requests asynchronously, to prevent multiple updates */\n _issueNewRequests(): void {\n if (!this.deferredUpdate) {\n this.deferredUpdate = setTimeout(() => this._issueNewRequestsAsync(), 0);\n }\n }\n\n /** Refresh all requests */\n _issueNewRequestsAsync() {\n // TODO - shouldn't we clear the timeout?\n this.deferredUpdate = null;\n\n const freeSlots = Math.max(this.props.maxRequests - this.activeRequestCount, 0);\n\n if (freeSlots === 0) {\n return;\n }\n\n this._updateAllRequests();\n\n // Resolve pending promises for the top-priority requests\n for (let i = 0; i < freeSlots; ++i) {\n const request = this.requestQueue.shift();\n if (request) {\n this._issueRequest(request); // eslint-disable-line @typescript-eslint/no-floating-promises\n }\n }\n\n // Uncomment to debug\n // console.log(`${freeSlots} free slots, ${this.requestQueue.length} queued requests`);\n }\n\n /** Ensure all requests have updated priorities, and that no longer valid requests are cancelled */\n _updateAllRequests() {\n const requestQueue = this.requestQueue;\n for (let i = 0; i < requestQueue.length; ++i) {\n const request = requestQueue[i];\n if (!this._updateRequest(request)) {\n // Remove the element and make sure to adjust the counter to account for shortened array\n requestQueue.splice(i, 1);\n this.requestMap.delete(request.handle);\n i--;\n }\n }\n\n // Sort the remaining requests based on priority\n requestQueue.sort((a, b) => a.priority - b.priority);\n }\n\n /** Update a single request by calling the callback */\n _updateRequest(request) {\n request.priority = request.getPriority(request.handle); // eslint-disable-line callback-return\n\n // by returning a negative priority, the callback cancels the request\n if (request.priority < 0) {\n request.resolve(null);\n return false;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vB,QAAQ,GAAGwB,CAAC,CAACxB,QAAQ;MAAA,EAAC;IACtD;;EAAC;IAAA;IAAA;IAGD,wBAAeD,OAAO,EAAE;MACtBA,OAAO,CAACC,QAAQ,GAAGD,OAAO,CAACN,WAAW,CAACM,OAAO,CAACP,MAAM,CAAC;;MAGtD,IAAIO,OAAO,CAACC,QAAQ,GAAG,CAAC,EAAE;QACxBD,OAAO,CAACJ,OAAO,CAAC,IAAI,CAAC;QACrB,OAAO,KAAK;MACd;MACA,OAAO,IAAI;IACb;EAAC;EAAA;AAAA;AAAA"}
|
|
@@ -1,23 +1,16 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
3
|
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
-
|
|
5
4
|
Object.defineProperty(exports, "__esModule", {
|
|
6
5
|
value: true
|
|
7
6
|
});
|
|
8
7
|
exports.createLoaderWorker = createLoaderWorker;
|
|
9
|
-
|
|
10
8
|
var _regenerator = _interopRequireDefault(require("@babel/runtime/regenerator"));
|
|
11
|
-
|
|
12
9
|
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
|
|
13
|
-
|
|
14
10
|
var _asyncToGenerator2 = _interopRequireDefault(require("@babel/runtime/helpers/asyncToGenerator"));
|
|
15
|
-
|
|
16
11
|
var _workerUtils = require("@loaders.gl/worker-utils");
|
|
17
|
-
|
|
18
|
-
function
|
|
19
|
-
|
|
20
|
-
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(Object(source), true).forEach(function (key) { (0, _defineProperty2.default)(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }
|
|
12
|
+
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
|
|
13
|
+
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { (0, _defineProperty2.default)(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
|
|
21
14
|
|
|
22
15
|
var requestId = 0;
|
|
23
16
|
|
|
@@ -25,11 +18,9 @@ function createLoaderWorker(loader) {
|
|
|
25
18
|
if (!_workerUtils.WorkerBody.inWorkerThread()) {
|
|
26
19
|
return;
|
|
27
20
|
}
|
|
28
|
-
|
|
29
21
|
_workerUtils.WorkerBody.onmessage = function () {
|
|
30
22
|
var _ref = (0, _asyncToGenerator2.default)(_regenerator.default.mark(function _callee(type, payload) {
|
|
31
23
|
var input, _payload$options, options, _payload$context, context, result, message;
|
|
32
|
-
|
|
33
24
|
return _regenerator.default.wrap(function _callee$(_context) {
|
|
34
25
|
while (1) {
|
|
35
26
|
switch (_context.prev = _context.next) {
|
|
@@ -37,7 +28,6 @@ function createLoaderWorker(loader) {
|
|
|
37
28
|
_context.t0 = type;
|
|
38
29
|
_context.next = _context.t0 === 'process' ? 3 : 16;
|
|
39
30
|
break;
|
|
40
|
-
|
|
41
31
|
case 3:
|
|
42
32
|
_context.prev = 3;
|
|
43
33
|
input = payload.input, _payload$options = payload.options, options = _payload$options === void 0 ? {} : _payload$options, _payload$context = payload.context, context = _payload$context === void 0 ? {} : _payload$context;
|
|
@@ -50,29 +40,22 @@ function createLoaderWorker(loader) {
|
|
|
50
40
|
parse: parseOnMainThread
|
|
51
41
|
})
|
|
52
42
|
});
|
|
53
|
-
|
|
54
43
|
case 7:
|
|
55
44
|
result = _context.sent;
|
|
56
|
-
|
|
57
45
|
_workerUtils.WorkerBody.postMessage('done', {
|
|
58
46
|
result: result
|
|
59
47
|
});
|
|
60
|
-
|
|
61
48
|
_context.next = 15;
|
|
62
49
|
break;
|
|
63
|
-
|
|
64
50
|
case 11:
|
|
65
51
|
_context.prev = 11;
|
|
66
52
|
_context.t1 = _context["catch"](3);
|
|
67
53
|
message = _context.t1 instanceof Error ? _context.t1.message : '';
|
|
68
|
-
|
|
69
54
|
_workerUtils.WorkerBody.postMessage('error', {
|
|
70
55
|
error: message
|
|
71
56
|
});
|
|
72
|
-
|
|
73
57
|
case 15:
|
|
74
58
|
return _context.abrupt("break", 16);
|
|
75
|
-
|
|
76
59
|
case 16:
|
|
77
60
|
case "end":
|
|
78
61
|
return _context.stop();
|
|
@@ -80,13 +63,11 @@ function createLoaderWorker(loader) {
|
|
|
80
63
|
}
|
|
81
64
|
}, _callee, null, [[3, 11]]);
|
|
82
65
|
}));
|
|
83
|
-
|
|
84
66
|
return function (_x, _x2) {
|
|
85
67
|
return _ref.apply(this, arguments);
|
|
86
68
|
};
|
|
87
69
|
}();
|
|
88
70
|
}
|
|
89
|
-
|
|
90
71
|
function parseOnMainThread(arrayBuffer, options) {
|
|
91
72
|
return new Promise(function (resolve, reject) {
|
|
92
73
|
var id = requestId++;
|
|
@@ -95,20 +76,15 @@ function parseOnMainThread(arrayBuffer, options) {
|
|
|
95
76
|
if (payload.id !== id) {
|
|
96
77
|
return;
|
|
97
78
|
}
|
|
98
|
-
|
|
99
79
|
switch (type) {
|
|
100
80
|
case 'done':
|
|
101
81
|
_workerUtils.WorkerBody.removeEventListener(onMessage);
|
|
102
|
-
|
|
103
82
|
resolve(payload.result);
|
|
104
83
|
break;
|
|
105
|
-
|
|
106
84
|
case 'error':
|
|
107
85
|
_workerUtils.WorkerBody.removeEventListener(onMessage);
|
|
108
|
-
|
|
109
86
|
reject(payload.error);
|
|
110
87
|
break;
|
|
111
|
-
|
|
112
88
|
default:
|
|
113
89
|
}
|
|
114
90
|
};
|
|
@@ -120,7 +96,6 @@ function parseOnMainThread(arrayBuffer, options) {
|
|
|
120
96
|
input: arrayBuffer,
|
|
121
97
|
options: options
|
|
122
98
|
};
|
|
123
|
-
|
|
124
99
|
_workerUtils.WorkerBody.postMessage('process', payload);
|
|
125
100
|
});
|
|
126
101
|
}
|
|
@@ -128,7 +103,6 @@ function parseOnMainThread(arrayBuffer, options) {
|
|
|
128
103
|
function parseData(_x3) {
|
|
129
104
|
return _parseData.apply(this, arguments);
|
|
130
105
|
}
|
|
131
|
-
|
|
132
106
|
function _parseData() {
|
|
133
107
|
_parseData = (0, _asyncToGenerator2.default)(_regenerator.default.mark(function _callee2(_ref2) {
|
|
134
108
|
var loader, arrayBuffer, options, context, data, parser, textDecoder;
|
|
@@ -137,32 +111,26 @@ function _parseData() {
|
|
|
137
111
|
switch (_context2.prev = _context2.next) {
|
|
138
112
|
case 0:
|
|
139
113
|
loader = _ref2.loader, arrayBuffer = _ref2.arrayBuffer, options = _ref2.options, context = _ref2.context;
|
|
140
|
-
|
|
141
114
|
if (!(loader.parseSync || loader.parse)) {
|
|
142
115
|
_context2.next = 6;
|
|
143
116
|
break;
|
|
144
117
|
}
|
|
145
|
-
|
|
146
118
|
data = arrayBuffer;
|
|
147
119
|
parser = loader.parseSync || loader.parse;
|
|
148
120
|
_context2.next = 13;
|
|
149
121
|
break;
|
|
150
|
-
|
|
151
122
|
case 6:
|
|
152
123
|
if (!loader.parseTextSync) {
|
|
153
124
|
_context2.next = 12;
|
|
154
125
|
break;
|
|
155
126
|
}
|
|
156
|
-
|
|
157
127
|
textDecoder = new TextDecoder();
|
|
158
128
|
data = textDecoder.decode(arrayBuffer);
|
|
159
129
|
parser = loader.parseTextSync;
|
|
160
130
|
_context2.next = 13;
|
|
161
131
|
break;
|
|
162
|
-
|
|
163
132
|
case 12:
|
|
164
133
|
throw new Error("Could not load data with ".concat(loader.name, " loader"));
|
|
165
|
-
|
|
166
134
|
case 13:
|
|
167
135
|
options = _objectSpread(_objectSpread({}, options), {}, {
|
|
168
136
|
modules: loader && loader.options && loader.options.modules || {},
|
|
@@ -170,10 +138,8 @@ function _parseData() {
|
|
|
170
138
|
});
|
|
171
139
|
_context2.next = 16;
|
|
172
140
|
return parser(data, _objectSpread({}, options), context, loader);
|
|
173
|
-
|
|
174
141
|
case 16:
|
|
175
142
|
return _context2.abrupt("return", _context2.sent);
|
|
176
|
-
|
|
177
143
|
case 17:
|
|
178
144
|
case "end":
|
|
179
145
|
return _context2.stop();
|