@loaders.gl/loader-utils 4.0.0-alpha.23 → 4.0.0-alpha.25
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/json-loader.js +1 -1
- package/dist/es5/lib/file-provider/file-handle.js +14 -20
- package/dist/es5/lib/file-provider/file-handle.js.map +1 -1
- package/dist/es5/lib/filesystems/filesystem.js.map +1 -1
- package/dist/es5/lib/filesystems/node-filesystem.browser.js +172 -0
- package/dist/es5/lib/filesystems/node-filesystem.browser.js.map +1 -0
- package/dist/es5/lib/filesystems/node-filesystem.js.map +1 -1
- package/dist/es5/lib/node/fs.browser.js +9 -0
- package/dist/es5/lib/node/fs.browser.js.map +1 -0
- package/dist/es5/lib/node/fs.js +25 -37
- package/dist/es5/lib/node/fs.js.map +1 -1
- package/dist/es5/lib/node/stream.browser.js +9 -0
- package/dist/es5/lib/node/stream.browser.js.map +1 -0
- package/dist/es5/lib/node/stream.js +6 -7
- package/dist/es5/lib/node/stream.js.map +1 -1
- package/dist/es5/lib/option-utils/merge-loader-options.js +1 -1
- package/dist/es5/lib/option-utils/merge-loader-options.js.map +1 -1
- package/dist/es5/loader-types.js.map +1 -1
- package/dist/es5/writer-types.js.map +1 -1
- package/dist/esm/json-loader.js +1 -1
- package/dist/esm/lib/file-provider/file-handle.js +6 -10
- package/dist/esm/lib/file-provider/file-handle.js.map +1 -1
- package/dist/esm/lib/filesystems/filesystem.js.map +1 -1
- package/dist/esm/lib/filesystems/node-filesystem.browser.js +42 -0
- package/dist/esm/lib/filesystems/node-filesystem.browser.js.map +1 -0
- package/dist/esm/lib/filesystems/node-filesystem.js.map +1 -1
- package/dist/esm/lib/node/fs.browser.js +2 -0
- package/dist/esm/lib/node/fs.browser.js.map +1 -0
- package/dist/esm/lib/node/fs.js +16 -31
- package/dist/esm/lib/node/fs.js.map +1 -1
- package/dist/esm/lib/node/stream.browser.js +2 -0
- package/dist/esm/lib/node/stream.browser.js.map +1 -0
- package/dist/esm/lib/node/stream.js +2 -5
- package/dist/esm/lib/node/stream.js.map +1 -1
- package/dist/esm/lib/option-utils/merge-loader-options.js +1 -1
- package/dist/esm/lib/option-utils/merge-loader-options.js.map +1 -1
- package/dist/esm/loader-types.js.map +1 -1
- package/dist/esm/writer-types.js.map +1 -1
- package/dist/lib/file-provider/file-handle.d.ts +2 -2
- package/dist/lib/file-provider/file-handle.d.ts.map +1 -1
- package/dist/lib/filesystems/filesystem.d.ts +1 -2
- package/dist/lib/filesystems/filesystem.d.ts.map +1 -1
- package/dist/lib/filesystems/node-filesystem.browser.d.ts +39 -0
- package/dist/lib/filesystems/node-filesystem.browser.d.ts.map +1 -0
- package/dist/lib/filesystems/node-filesystem.d.ts +1 -1
- package/dist/lib/filesystems/node-filesystem.d.ts.map +1 -1
- package/dist/lib/node/fs.browser.d.ts +2 -0
- package/dist/lib/node/fs.browser.d.ts.map +1 -0
- package/dist/lib/node/fs.d.ts +19 -16
- package/dist/lib/node/fs.d.ts.map +1 -1
- package/dist/lib/node/stream.browser.d.ts +2 -0
- package/dist/lib/node/stream.browser.d.ts.map +1 -0
- package/dist/lib/node/stream.d.ts +4 -1
- package/dist/lib/node/stream.d.ts.map +1 -1
- package/dist/loader-types.d.ts +2 -2
- package/dist/loader-types.d.ts.map +1 -1
- package/dist/writer-types.d.ts +4 -6
- package/dist/writer-types.d.ts.map +1 -1
- package/package.json +9 -5
- package/src/lib/file-provider/file-handle.ts +17 -12
- package/src/lib/filesystems/filesystem.ts +1 -1
- package/src/lib/filesystems/node-filesystem.browser.ts +61 -0
- package/src/lib/filesystems/node-filesystem.ts +1 -1
- package/src/lib/node/fs.browser.ts +1 -0
- package/src/lib/node/fs.ts +20 -54
- package/src/lib/node/stream.browser.ts +1 -0
- package/src/lib/node/stream.ts +3 -11
- package/src/lib/option-utils/merge-loader-options.ts +1 -1
- package/src/loader-types.ts +2 -2
- package/src/writer-types.ts +11 -16
- package/dist/index.js +0 -135
- package/dist/json-loader.js +0 -27
- package/dist/lib/binary-utils/array-buffer-utils.js +0 -84
- package/dist/lib/binary-utils/dataview-copy-utils.js +0 -97
- package/dist/lib/binary-utils/get-first-characters.js +0 -45
- package/dist/lib/binary-utils/memory-conversion-utils.js +0 -73
- package/dist/lib/binary-utils/memory-copy-utils.js +0 -61
- package/dist/lib/env-utils/assert.js +0 -13
- package/dist/lib/env-utils/globals.js +0 -30
- package/dist/lib/file-provider/data-view-file.js +0 -63
- package/dist/lib/file-provider/file-handle-file.js +0 -92
- package/dist/lib/file-provider/file-handle.js +0 -55
- package/dist/lib/file-provider/file-provider.js +0 -13
- package/dist/lib/filesystems/filesystem.js +0 -37
- package/dist/lib/filesystems/node-filesystem.js +0 -74
- package/dist/lib/filesystems/readable-file.js +0 -25
- package/dist/lib/filesystems/writable-file.js +0 -48
- package/dist/lib/iterators/async-iteration.js +0 -53
- package/dist/lib/iterators/text-iterators.js +0 -61
- package/dist/lib/node/buffer.browser.js +0 -22
- package/dist/lib/node/buffer.js +0 -36
- package/dist/lib/node/fs.js +0 -51
- package/dist/lib/node/promisify.js +0 -22
- package/dist/lib/node/stream.js +0 -17
- package/dist/lib/option-utils/merge-loader-options.js +0 -27
- package/dist/lib/parser-utils/parse-json.js +0 -16
- package/dist/lib/path-utils/file-aliases.js +0 -47
- package/dist/lib/path-utils/get-cwd.js +0 -12
- package/dist/lib/path-utils/path.js +0 -178
- package/dist/lib/request-utils/request-scheduler.js +0 -142
- package/dist/lib/worker-loader-utils/create-loader-worker.js +0 -99
- package/dist/lib/worker-loader-utils/encode-with-worker.js +0 -21
- package/dist/lib/worker-loader-utils/parse-with-worker.js +0 -81
- package/dist/loader-types.js +0 -36
- package/dist/types.js +0 -3
- package/dist/workers/json-worker.js +0 -5
- package/dist/writer-types.js +0 -3
|
@@ -1,47 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
// Simple file alias mechanisms for tests.
|
|
3
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
-
exports.resolvePath = exports.addAliases = exports.getPathPrefix = exports.setPathPrefix = void 0;
|
|
5
|
-
let pathPrefix = '';
|
|
6
|
-
const fileAliases = {};
|
|
7
|
-
/*
|
|
8
|
-
* Set a relative path prefix
|
|
9
|
-
*/
|
|
10
|
-
function setPathPrefix(prefix) {
|
|
11
|
-
pathPrefix = prefix;
|
|
12
|
-
}
|
|
13
|
-
exports.setPathPrefix = setPathPrefix;
|
|
14
|
-
/*
|
|
15
|
-
* Get the relative path prefix
|
|
16
|
-
*/
|
|
17
|
-
function getPathPrefix() {
|
|
18
|
-
return pathPrefix;
|
|
19
|
-
}
|
|
20
|
-
exports.getPathPrefix = getPathPrefix;
|
|
21
|
-
/**
|
|
22
|
-
*
|
|
23
|
-
* @param aliases
|
|
24
|
-
*
|
|
25
|
-
* Note: addAliases are an experimental export, they are only for testing of loaders.gl loaders
|
|
26
|
-
* not intended as a generic aliasing mechanism
|
|
27
|
-
*/
|
|
28
|
-
function addAliases(aliases) {
|
|
29
|
-
Object.assign(fileAliases, aliases);
|
|
30
|
-
}
|
|
31
|
-
exports.addAliases = addAliases;
|
|
32
|
-
/**
|
|
33
|
-
* Resolves aliases and adds path-prefix to paths
|
|
34
|
-
*/
|
|
35
|
-
function resolvePath(filename) {
|
|
36
|
-
for (const alias in fileAliases) {
|
|
37
|
-
if (filename.startsWith(alias)) {
|
|
38
|
-
const replacement = fileAliases[alias];
|
|
39
|
-
filename = filename.replace(alias, replacement);
|
|
40
|
-
}
|
|
41
|
-
}
|
|
42
|
-
if (!filename.startsWith('http://') && !filename.startsWith('https://')) {
|
|
43
|
-
filename = `${pathPrefix}${filename}`;
|
|
44
|
-
}
|
|
45
|
-
return filename;
|
|
46
|
-
}
|
|
47
|
-
exports.resolvePath = resolvePath;
|
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
// loaders.gl MIT license
|
|
3
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
-
exports.getCWD = void 0;
|
|
5
|
-
function getCWD() {
|
|
6
|
-
if (typeof process !== 'undefined' && typeof process.cwd !== 'undefined') {
|
|
7
|
-
return process.cwd();
|
|
8
|
-
}
|
|
9
|
-
const pathname = window.location?.pathname;
|
|
10
|
-
return pathname?.slice(0, pathname.lastIndexOf('/') + 1) || '';
|
|
11
|
-
}
|
|
12
|
-
exports.getCWD = getCWD;
|
|
@@ -1,178 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
// Beginning of a minimal implementation of the Node.js path API, that doesn't pull in big polyfills.
|
|
3
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
-
exports.resolve = exports.join = exports.dirname = exports.filename = void 0;
|
|
5
|
-
const get_cwd_1 = require("./get-cwd");
|
|
6
|
-
/**
|
|
7
|
-
* Replacement for Node.js path.filename
|
|
8
|
-
* @param url
|
|
9
|
-
*/
|
|
10
|
-
function filename(url) {
|
|
11
|
-
const slashIndex = url ? url.lastIndexOf('/') : -1;
|
|
12
|
-
return slashIndex >= 0 ? url.substr(slashIndex + 1) : '';
|
|
13
|
-
}
|
|
14
|
-
exports.filename = filename;
|
|
15
|
-
/**
|
|
16
|
-
* Replacement for Node.js path.dirname
|
|
17
|
-
* @param url
|
|
18
|
-
*/
|
|
19
|
-
function dirname(url) {
|
|
20
|
-
const slashIndex = url ? url.lastIndexOf('/') : -1;
|
|
21
|
-
return slashIndex >= 0 ? url.substr(0, slashIndex) : '';
|
|
22
|
-
}
|
|
23
|
-
exports.dirname = dirname;
|
|
24
|
-
/**
|
|
25
|
-
* Replacement for Node.js path.join
|
|
26
|
-
* @param parts
|
|
27
|
-
*/
|
|
28
|
-
function join(...parts) {
|
|
29
|
-
const separator = '/';
|
|
30
|
-
parts = parts.map((part, index) => {
|
|
31
|
-
if (index) {
|
|
32
|
-
part = part.replace(new RegExp(`^${separator}`), '');
|
|
33
|
-
}
|
|
34
|
-
if (index !== parts.length - 1) {
|
|
35
|
-
part = part.replace(new RegExp(`${separator}$`), '');
|
|
36
|
-
}
|
|
37
|
-
return part;
|
|
38
|
-
});
|
|
39
|
-
return parts.join(separator);
|
|
40
|
-
}
|
|
41
|
-
exports.join = join;
|
|
42
|
-
/* eslint-disable no-continue */
|
|
43
|
-
/**
|
|
44
|
-
* https://nodejs.org/api/path.html#path_path_resolve_paths
|
|
45
|
-
* @param paths A sequence of paths or path segments.
|
|
46
|
-
* @return resolved path
|
|
47
|
-
* Forked from BTOdell/path-resolve under MIT license
|
|
48
|
-
* @see https://github.com/BTOdell/path-resolve/blob/master/LICENSE
|
|
49
|
-
*/
|
|
50
|
-
function resolve(...components) {
|
|
51
|
-
const paths = [];
|
|
52
|
-
for (let _i = 0; _i < components.length; _i++) {
|
|
53
|
-
paths[_i] = components[_i];
|
|
54
|
-
}
|
|
55
|
-
let resolvedPath = '';
|
|
56
|
-
let resolvedAbsolute = false;
|
|
57
|
-
let cwd;
|
|
58
|
-
for (let i = paths.length - 1; i >= -1 && !resolvedAbsolute; i--) {
|
|
59
|
-
let path;
|
|
60
|
-
if (i >= 0) {
|
|
61
|
-
path = paths[i];
|
|
62
|
-
}
|
|
63
|
-
else {
|
|
64
|
-
if (cwd === undefined) {
|
|
65
|
-
cwd = (0, get_cwd_1.getCWD)();
|
|
66
|
-
}
|
|
67
|
-
path = cwd;
|
|
68
|
-
}
|
|
69
|
-
// Skip empty entries
|
|
70
|
-
if (path.length === 0) {
|
|
71
|
-
continue;
|
|
72
|
-
}
|
|
73
|
-
resolvedPath = `${path}/${resolvedPath}`;
|
|
74
|
-
resolvedAbsolute = path.charCodeAt(0) === SLASH;
|
|
75
|
-
}
|
|
76
|
-
// At this point the path should be resolved to a full absolute path, but
|
|
77
|
-
// handle relative paths to be safe (might happen when process.cwd() fails)
|
|
78
|
-
// Normalize the path (removes leading slash)
|
|
79
|
-
resolvedPath = normalizeStringPosix(resolvedPath, !resolvedAbsolute);
|
|
80
|
-
if (resolvedAbsolute) {
|
|
81
|
-
return `/${resolvedPath}`;
|
|
82
|
-
}
|
|
83
|
-
else if (resolvedPath.length > 0) {
|
|
84
|
-
return resolvedPath;
|
|
85
|
-
}
|
|
86
|
-
return '.';
|
|
87
|
-
}
|
|
88
|
-
exports.resolve = resolve;
|
|
89
|
-
const SLASH = 47;
|
|
90
|
-
const DOT = 46;
|
|
91
|
-
/**
|
|
92
|
-
* Resolves . and .. elements in a path with directory names
|
|
93
|
-
* Forked from BTOdell/path-resolve under MIT license
|
|
94
|
-
* @see https://github.com/BTOdell/path-resolve/blob/master/LICENSE
|
|
95
|
-
*/
|
|
96
|
-
/* eslint-disable max-depth */
|
|
97
|
-
// eslint-disable-next-line complexity, max-statements
|
|
98
|
-
function normalizeStringPosix(path, allowAboveRoot) {
|
|
99
|
-
let res = '';
|
|
100
|
-
let lastSlash = -1;
|
|
101
|
-
let dots = 0;
|
|
102
|
-
let code;
|
|
103
|
-
let isAboveRoot = false;
|
|
104
|
-
for (let i = 0; i <= path.length; ++i) {
|
|
105
|
-
if (i < path.length) {
|
|
106
|
-
code = path.charCodeAt(i);
|
|
107
|
-
}
|
|
108
|
-
else if (code === SLASH) {
|
|
109
|
-
break;
|
|
110
|
-
}
|
|
111
|
-
else {
|
|
112
|
-
code = SLASH;
|
|
113
|
-
}
|
|
114
|
-
if (code === SLASH) {
|
|
115
|
-
if (lastSlash === i - 1 || dots === 1) {
|
|
116
|
-
// NOOP
|
|
117
|
-
}
|
|
118
|
-
else if (lastSlash !== i - 1 && dots === 2) {
|
|
119
|
-
if (res.length < 2 ||
|
|
120
|
-
!isAboveRoot ||
|
|
121
|
-
res.charCodeAt(res.length - 1) !== DOT ||
|
|
122
|
-
res.charCodeAt(res.length - 2) !== DOT) {
|
|
123
|
-
if (res.length > 2) {
|
|
124
|
-
const start = res.length - 1;
|
|
125
|
-
let j = start;
|
|
126
|
-
for (; j >= 0; --j) {
|
|
127
|
-
if (res.charCodeAt(j) === SLASH) {
|
|
128
|
-
break;
|
|
129
|
-
}
|
|
130
|
-
}
|
|
131
|
-
if (j !== start) {
|
|
132
|
-
res = j === -1 ? '' : res.slice(0, j);
|
|
133
|
-
lastSlash = i;
|
|
134
|
-
dots = 0;
|
|
135
|
-
isAboveRoot = false;
|
|
136
|
-
continue;
|
|
137
|
-
}
|
|
138
|
-
}
|
|
139
|
-
else if (res.length === 2 || res.length === 1) {
|
|
140
|
-
res = '';
|
|
141
|
-
lastSlash = i;
|
|
142
|
-
dots = 0;
|
|
143
|
-
isAboveRoot = false;
|
|
144
|
-
continue;
|
|
145
|
-
}
|
|
146
|
-
}
|
|
147
|
-
if (allowAboveRoot) {
|
|
148
|
-
if (res.length > 0) {
|
|
149
|
-
res += '/..';
|
|
150
|
-
}
|
|
151
|
-
else {
|
|
152
|
-
res = '..';
|
|
153
|
-
}
|
|
154
|
-
isAboveRoot = true;
|
|
155
|
-
}
|
|
156
|
-
}
|
|
157
|
-
else {
|
|
158
|
-
const slice = path.slice(lastSlash + 1, i);
|
|
159
|
-
if (res.length > 0) {
|
|
160
|
-
res += `/${slice}`;
|
|
161
|
-
}
|
|
162
|
-
else {
|
|
163
|
-
res = slice;
|
|
164
|
-
}
|
|
165
|
-
isAboveRoot = false;
|
|
166
|
-
}
|
|
167
|
-
lastSlash = i;
|
|
168
|
-
dots = 0;
|
|
169
|
-
}
|
|
170
|
-
else if (code === DOT && dots !== -1) {
|
|
171
|
-
++dots;
|
|
172
|
-
}
|
|
173
|
-
else {
|
|
174
|
-
dots = -1;
|
|
175
|
-
}
|
|
176
|
-
}
|
|
177
|
-
return res;
|
|
178
|
-
}
|
|
@@ -1,142 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
const stats_1 = require("@probe.gl/stats");
|
|
4
|
-
const STAT_QUEUED_REQUESTS = 'Queued Requests';
|
|
5
|
-
const STAT_ACTIVE_REQUESTS = 'Active Requests';
|
|
6
|
-
const STAT_CANCELLED_REQUESTS = 'Cancelled Requests';
|
|
7
|
-
const STAT_QUEUED_REQUESTS_EVER = 'Queued Requests Ever';
|
|
8
|
-
const STAT_ACTIVE_REQUESTS_EVER = 'Active Requests Ever';
|
|
9
|
-
const DEFAULT_PROPS = {
|
|
10
|
-
id: 'request-scheduler',
|
|
11
|
-
// Specifies if the request scheduler should throttle incoming requests, mainly for comparative testing
|
|
12
|
-
throttleRequests: true,
|
|
13
|
-
// The maximum number of simultaneous active requests. Un-throttled requests do not observe this limit.
|
|
14
|
-
maxRequests: 6
|
|
15
|
-
};
|
|
16
|
-
/**
|
|
17
|
-
* Used to issue a request, without having them "deeply queued" by the browser.
|
|
18
|
-
* @todo - Track requests globally, across multiple servers
|
|
19
|
-
*/
|
|
20
|
-
class RequestScheduler {
|
|
21
|
-
constructor(props = {}) {
|
|
22
|
-
this.activeRequestCount = 0;
|
|
23
|
-
/** Tracks the number of active requests and prioritizes/cancels queued requests. */
|
|
24
|
-
this.requestQueue = [];
|
|
25
|
-
this.requestMap = new Map();
|
|
26
|
-
this.deferredUpdate = null;
|
|
27
|
-
this.props = { ...DEFAULT_PROPS, ...props };
|
|
28
|
-
// Returns the statistics used by the request scheduler.
|
|
29
|
-
this.stats = new stats_1.Stats({ id: this.props.id });
|
|
30
|
-
this.stats.get(STAT_QUEUED_REQUESTS);
|
|
31
|
-
this.stats.get(STAT_ACTIVE_REQUESTS);
|
|
32
|
-
this.stats.get(STAT_CANCELLED_REQUESTS);
|
|
33
|
-
this.stats.get(STAT_QUEUED_REQUESTS_EVER);
|
|
34
|
-
this.stats.get(STAT_ACTIVE_REQUESTS_EVER);
|
|
35
|
-
}
|
|
36
|
-
/**
|
|
37
|
-
* Called by an application that wants to issue a request, without having it deeply queued by the browser
|
|
38
|
-
*
|
|
39
|
-
* When the returned promise resolved, it is OK for the application to issue a request.
|
|
40
|
-
* The promise resolves to an object that contains a `done` method.
|
|
41
|
-
* When the application's request has completed (or failed), the application must call the `done` function
|
|
42
|
-
*
|
|
43
|
-
* @param handle
|
|
44
|
-
* @param getPriority will be called when request "slots" open up,
|
|
45
|
-
* allowing the caller to update priority or cancel the request
|
|
46
|
-
* Highest priority executes first, priority < 0 cancels the request
|
|
47
|
-
* @returns a promise
|
|
48
|
-
* - resolves to a object (with a `done` field) when the request can be issued without queueing,
|
|
49
|
-
* - resolves to `null` if the request has been cancelled (by the callback return < 0).
|
|
50
|
-
* In this case the application should not issue the request
|
|
51
|
-
*/
|
|
52
|
-
scheduleRequest(handle, getPriority = () => 0) {
|
|
53
|
-
// Allows throttling to be disabled
|
|
54
|
-
if (!this.props.throttleRequests) {
|
|
55
|
-
return Promise.resolve({ done: () => { } });
|
|
56
|
-
}
|
|
57
|
-
// dedupe
|
|
58
|
-
if (this.requestMap.has(handle)) {
|
|
59
|
-
return this.requestMap.get(handle);
|
|
60
|
-
}
|
|
61
|
-
const request = { handle, priority: 0, getPriority };
|
|
62
|
-
const promise = new Promise((resolve) => {
|
|
63
|
-
// @ts-ignore
|
|
64
|
-
request.resolve = resolve;
|
|
65
|
-
return request;
|
|
66
|
-
});
|
|
67
|
-
this.requestQueue.push(request);
|
|
68
|
-
this.requestMap.set(handle, promise);
|
|
69
|
-
this._issueNewRequests();
|
|
70
|
-
return promise;
|
|
71
|
-
}
|
|
72
|
-
// PRIVATE
|
|
73
|
-
_issueRequest(request) {
|
|
74
|
-
const { handle, resolve } = request;
|
|
75
|
-
let isDone = false;
|
|
76
|
-
const done = () => {
|
|
77
|
-
// can only be called once
|
|
78
|
-
if (!isDone) {
|
|
79
|
-
isDone = true;
|
|
80
|
-
// Stop tracking a request - it has completed, failed, cancelled etc
|
|
81
|
-
this.requestMap.delete(handle);
|
|
82
|
-
this.activeRequestCount--;
|
|
83
|
-
// A slot just freed up, see if any queued requests are waiting
|
|
84
|
-
this._issueNewRequests();
|
|
85
|
-
}
|
|
86
|
-
};
|
|
87
|
-
// Track this request
|
|
88
|
-
this.activeRequestCount++;
|
|
89
|
-
return resolve ? resolve({ done }) : Promise.resolve({ done });
|
|
90
|
-
}
|
|
91
|
-
/** We check requests asynchronously, to prevent multiple updates */
|
|
92
|
-
_issueNewRequests() {
|
|
93
|
-
if (!this.deferredUpdate) {
|
|
94
|
-
this.deferredUpdate = setTimeout(() => this._issueNewRequestsAsync(), 0);
|
|
95
|
-
}
|
|
96
|
-
}
|
|
97
|
-
/** Refresh all requests */
|
|
98
|
-
_issueNewRequestsAsync() {
|
|
99
|
-
// TODO - shouldn't we clear the timeout?
|
|
100
|
-
this.deferredUpdate = null;
|
|
101
|
-
const freeSlots = Math.max(this.props.maxRequests - this.activeRequestCount, 0);
|
|
102
|
-
if (freeSlots === 0) {
|
|
103
|
-
return;
|
|
104
|
-
}
|
|
105
|
-
this._updateAllRequests();
|
|
106
|
-
// Resolve pending promises for the top-priority requests
|
|
107
|
-
for (let i = 0; i < freeSlots; ++i) {
|
|
108
|
-
const request = this.requestQueue.shift();
|
|
109
|
-
if (request) {
|
|
110
|
-
this._issueRequest(request); // eslint-disable-line @typescript-eslint/no-floating-promises
|
|
111
|
-
}
|
|
112
|
-
}
|
|
113
|
-
// Uncomment to debug
|
|
114
|
-
// console.log(`${freeSlots} free slots, ${this.requestQueue.length} queued requests`);
|
|
115
|
-
}
|
|
116
|
-
/** Ensure all requests have updated priorities, and that no longer valid requests are cancelled */
|
|
117
|
-
_updateAllRequests() {
|
|
118
|
-
const requestQueue = this.requestQueue;
|
|
119
|
-
for (let i = 0; i < requestQueue.length; ++i) {
|
|
120
|
-
const request = requestQueue[i];
|
|
121
|
-
if (!this._updateRequest(request)) {
|
|
122
|
-
// Remove the element and make sure to adjust the counter to account for shortened array
|
|
123
|
-
requestQueue.splice(i, 1);
|
|
124
|
-
this.requestMap.delete(request.handle);
|
|
125
|
-
i--;
|
|
126
|
-
}
|
|
127
|
-
}
|
|
128
|
-
// Sort the remaining requests based on priority
|
|
129
|
-
requestQueue.sort((a, b) => a.priority - b.priority);
|
|
130
|
-
}
|
|
131
|
-
/** Update a single request by calling the callback */
|
|
132
|
-
_updateRequest(request) {
|
|
133
|
-
request.priority = request.getPriority(request.handle); // eslint-disable-line callback-return
|
|
134
|
-
// by returning a negative priority, the callback cancels the request
|
|
135
|
-
if (request.priority < 0) {
|
|
136
|
-
request.resolve(null);
|
|
137
|
-
return false;
|
|
138
|
-
}
|
|
139
|
-
return true;
|
|
140
|
-
}
|
|
141
|
-
}
|
|
142
|
-
exports.default = RequestScheduler;
|
|
@@ -1,99 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.createLoaderWorker = void 0;
|
|
4
|
-
const worker_utils_1 = require("@loaders.gl/worker-utils");
|
|
5
|
-
// import {validateLoaderVersion} from './validate-loader-version';
|
|
6
|
-
let requestId = 0;
|
|
7
|
-
/**
|
|
8
|
-
* Set up a WebWorkerGlobalScope to talk with the main thread
|
|
9
|
-
* @param loader
|
|
10
|
-
*/
|
|
11
|
-
function createLoaderWorker(loader) {
|
|
12
|
-
// Check that we are actually in a worker thread
|
|
13
|
-
if (!worker_utils_1.WorkerBody.inWorkerThread()) {
|
|
14
|
-
return;
|
|
15
|
-
}
|
|
16
|
-
worker_utils_1.WorkerBody.onmessage = async (type, payload) => {
|
|
17
|
-
switch (type) {
|
|
18
|
-
case 'process':
|
|
19
|
-
try {
|
|
20
|
-
// validateLoaderVersion(loader, data.source.split('@')[1]);
|
|
21
|
-
const { input, options = {}, context = {} } = payload;
|
|
22
|
-
const result = await parseData({
|
|
23
|
-
loader,
|
|
24
|
-
arrayBuffer: input,
|
|
25
|
-
options,
|
|
26
|
-
// @ts-expect-error fetch missing
|
|
27
|
-
context: {
|
|
28
|
-
...context,
|
|
29
|
-
_parse: parseOnMainThread
|
|
30
|
-
}
|
|
31
|
-
});
|
|
32
|
-
worker_utils_1.WorkerBody.postMessage('done', { result });
|
|
33
|
-
}
|
|
34
|
-
catch (error) {
|
|
35
|
-
const message = error instanceof Error ? error.message : '';
|
|
36
|
-
worker_utils_1.WorkerBody.postMessage('error', { error: message });
|
|
37
|
-
}
|
|
38
|
-
break;
|
|
39
|
-
default:
|
|
40
|
-
}
|
|
41
|
-
};
|
|
42
|
-
}
|
|
43
|
-
exports.createLoaderWorker = createLoaderWorker;
|
|
44
|
-
function parseOnMainThread(arrayBuffer, loader, options, context) {
|
|
45
|
-
return new Promise((resolve, reject) => {
|
|
46
|
-
const id = requestId++;
|
|
47
|
-
/**
|
|
48
|
-
*/
|
|
49
|
-
const onMessage = (type, payload) => {
|
|
50
|
-
if (payload.id !== id) {
|
|
51
|
-
// not ours
|
|
52
|
-
return;
|
|
53
|
-
}
|
|
54
|
-
switch (type) {
|
|
55
|
-
case 'done':
|
|
56
|
-
worker_utils_1.WorkerBody.removeEventListener(onMessage);
|
|
57
|
-
resolve(payload.result);
|
|
58
|
-
break;
|
|
59
|
-
case 'error':
|
|
60
|
-
worker_utils_1.WorkerBody.removeEventListener(onMessage);
|
|
61
|
-
reject(payload.error);
|
|
62
|
-
break;
|
|
63
|
-
default:
|
|
64
|
-
// ignore
|
|
65
|
-
}
|
|
66
|
-
};
|
|
67
|
-
worker_utils_1.WorkerBody.addEventListener(onMessage);
|
|
68
|
-
// Ask the main thread to decode data
|
|
69
|
-
const payload = { id, input: arrayBuffer, options };
|
|
70
|
-
worker_utils_1.WorkerBody.postMessage('process', payload);
|
|
71
|
-
});
|
|
72
|
-
}
|
|
73
|
-
// TODO - Support byteOffset and byteLength (enabling parsing of embedded binaries without copies)
|
|
74
|
-
// TODO - Why not support async loader.parse* funcs here?
|
|
75
|
-
// TODO - Why not reuse a common function instead of reimplementing loader.parse* selection logic? Keeping loader small?
|
|
76
|
-
// TODO - Lack of appropriate parser functions can be detected when we create worker, no need to wait until parse
|
|
77
|
-
async function parseData({ loader, arrayBuffer, options, context }) {
|
|
78
|
-
let data;
|
|
79
|
-
let parser;
|
|
80
|
-
if (loader.parseSync || loader.parse) {
|
|
81
|
-
data = arrayBuffer;
|
|
82
|
-
parser = loader.parseSync || loader.parse;
|
|
83
|
-
}
|
|
84
|
-
else if (loader.parseTextSync) {
|
|
85
|
-
const textDecoder = new TextDecoder();
|
|
86
|
-
data = textDecoder.decode(arrayBuffer);
|
|
87
|
-
parser = loader.parseTextSync;
|
|
88
|
-
}
|
|
89
|
-
else {
|
|
90
|
-
throw new Error(`Could not load data with ${loader.name} loader`);
|
|
91
|
-
}
|
|
92
|
-
// TODO - proper merge in of loader options...
|
|
93
|
-
options = {
|
|
94
|
-
...options,
|
|
95
|
-
modules: (loader && loader.options && loader.options.modules) || {},
|
|
96
|
-
worker: false
|
|
97
|
-
};
|
|
98
|
-
return await parser(data, { ...options }, context, loader);
|
|
99
|
-
}
|
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.canEncodeWithWorker = void 0;
|
|
4
|
-
const worker_utils_1 = require("@loaders.gl/worker-utils");
|
|
5
|
-
const globals_1 = require("../env-utils/globals");
|
|
6
|
-
/**
|
|
7
|
-
* Determines if a loader can parse with worker
|
|
8
|
-
* @param loader
|
|
9
|
-
* @param options
|
|
10
|
-
*/
|
|
11
|
-
function canEncodeWithWorker(writer, options) {
|
|
12
|
-
if (!worker_utils_1.WorkerFarm.isSupported()) {
|
|
13
|
-
return false;
|
|
14
|
-
}
|
|
15
|
-
// Node workers are still experimental
|
|
16
|
-
if (!globals_1.isBrowser && !options?._nodeWorkers) {
|
|
17
|
-
return false;
|
|
18
|
-
}
|
|
19
|
-
return writer.worker && options?.worker;
|
|
20
|
-
}
|
|
21
|
-
exports.canEncodeWithWorker = canEncodeWithWorker;
|
|
@@ -1,81 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.parseWithWorker = exports.canParseWithWorker = void 0;
|
|
4
|
-
const worker_utils_1 = require("@loaders.gl/worker-utils");
|
|
5
|
-
const worker_utils_2 = require("@loaders.gl/worker-utils");
|
|
6
|
-
/**
|
|
7
|
-
* Determines if a loader can parse with worker
|
|
8
|
-
* @param loader
|
|
9
|
-
* @param options
|
|
10
|
-
*/
|
|
11
|
-
function canParseWithWorker(loader, options) {
|
|
12
|
-
if (!worker_utils_2.WorkerFarm.isSupported()) {
|
|
13
|
-
return false;
|
|
14
|
-
}
|
|
15
|
-
// Node workers are still experimental
|
|
16
|
-
if (!worker_utils_1.isBrowser && !options?._nodeWorkers) {
|
|
17
|
-
return false;
|
|
18
|
-
}
|
|
19
|
-
return loader.worker && options?.worker;
|
|
20
|
-
}
|
|
21
|
-
exports.canParseWithWorker = canParseWithWorker;
|
|
22
|
-
/**
|
|
23
|
-
* this function expects that the worker function sends certain messages,
|
|
24
|
-
* this can be automated if the worker is wrapper by a call to createLoaderWorker in @loaders.gl/loader-utils.
|
|
25
|
-
*/
|
|
26
|
-
async function parseWithWorker(loader, data, options, context, parseOnMainThread) {
|
|
27
|
-
const name = loader.id; // TODO
|
|
28
|
-
const url = (0, worker_utils_2.getWorkerURL)(loader, options);
|
|
29
|
-
const workerFarm = worker_utils_2.WorkerFarm.getWorkerFarm(options);
|
|
30
|
-
const workerPool = workerFarm.getWorkerPool({ name, url });
|
|
31
|
-
// options.log object contains functions which cannot be transferred
|
|
32
|
-
// context.fetch & context.parse functions cannot be transferred
|
|
33
|
-
// TODO - decide how to handle logging on workers
|
|
34
|
-
options = JSON.parse(JSON.stringify(options));
|
|
35
|
-
context = JSON.parse(JSON.stringify(context || {}));
|
|
36
|
-
const job = await workerPool.startJob('process-on-worker',
|
|
37
|
-
// @ts-expect-error
|
|
38
|
-
onMessage.bind(null, parseOnMainThread) // eslint-disable-line @typescript-eslint/no-misused-promises
|
|
39
|
-
);
|
|
40
|
-
job.postMessage('process', {
|
|
41
|
-
// @ts-ignore
|
|
42
|
-
input: data,
|
|
43
|
-
options,
|
|
44
|
-
context
|
|
45
|
-
});
|
|
46
|
-
const result = await job.result;
|
|
47
|
-
// TODO - what is going on here?
|
|
48
|
-
return await result.result;
|
|
49
|
-
}
|
|
50
|
-
exports.parseWithWorker = parseWithWorker;
|
|
51
|
-
/**
|
|
52
|
-
* Handle worker's responses to the main thread
|
|
53
|
-
* @param job
|
|
54
|
-
* @param type
|
|
55
|
-
* @param payload
|
|
56
|
-
*/
|
|
57
|
-
async function onMessage(parseOnMainThread, job, type, payload) {
|
|
58
|
-
switch (type) {
|
|
59
|
-
case 'done':
|
|
60
|
-
job.done(payload);
|
|
61
|
-
break;
|
|
62
|
-
case 'error':
|
|
63
|
-
job.error(new Error(payload.error));
|
|
64
|
-
break;
|
|
65
|
-
case 'process':
|
|
66
|
-
// Worker is asking for main thread to parseO
|
|
67
|
-
const { id, input, options } = payload;
|
|
68
|
-
try {
|
|
69
|
-
const result = await parseOnMainThread(input, options);
|
|
70
|
-
job.postMessage('done', { id, result });
|
|
71
|
-
}
|
|
72
|
-
catch (error) {
|
|
73
|
-
const message = error instanceof Error ? error.message : 'unknown error';
|
|
74
|
-
job.postMessage('error', { id, error: message });
|
|
75
|
-
}
|
|
76
|
-
break;
|
|
77
|
-
default:
|
|
78
|
-
// eslint-disable-next-line
|
|
79
|
-
console.warn(`parse-with-worker unknown message ${type}`);
|
|
80
|
-
}
|
|
81
|
-
}
|
package/dist/loader-types.js
DELETED
|
@@ -1,36 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
// loaders.gl, MIT license
|
|
3
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
-
exports.parseInBatchesFromContext = exports.parseSyncFromContext = exports.parseFromContext = void 0;
|
|
5
|
-
/**
|
|
6
|
-
* Parses `data` using a specified loader
|
|
7
|
-
* @param data
|
|
8
|
-
* @param loaders
|
|
9
|
-
* @param options
|
|
10
|
-
* @param context
|
|
11
|
-
*/
|
|
12
|
-
// implementation signature
|
|
13
|
-
async function parseFromContext(data, loaders, options, context) {
|
|
14
|
-
return context._parse(data, loaders, options, context);
|
|
15
|
-
}
|
|
16
|
-
exports.parseFromContext = parseFromContext;
|
|
17
|
-
/**
|
|
18
|
-
* Parses `data` synchronously using the specified loader, parse function provided via the loader context
|
|
19
|
-
*/
|
|
20
|
-
function parseSyncFromContext(data, loader, options, context) {
|
|
21
|
-
if (!context._parseSync) {
|
|
22
|
-
throw new Error('parseSync');
|
|
23
|
-
}
|
|
24
|
-
return context._parseSync(data, loader, options, context);
|
|
25
|
-
}
|
|
26
|
-
exports.parseSyncFromContext = parseSyncFromContext;
|
|
27
|
-
/**
|
|
28
|
-
* Parses `data` synchronously using a specified loader, parse function provided via the loader context
|
|
29
|
-
*/
|
|
30
|
-
async function parseInBatchesFromContext(data, loader, options, context) {
|
|
31
|
-
if (!context._parseInBatches) {
|
|
32
|
-
throw new Error('parseInBatches');
|
|
33
|
-
}
|
|
34
|
-
return context._parseInBatches(data, loader, options, context);
|
|
35
|
-
}
|
|
36
|
-
exports.parseInBatchesFromContext = parseInBatchesFromContext;
|
package/dist/types.js
DELETED
|
@@ -1,5 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
const create_loader_worker_1 = require("../lib/worker-loader-utils/create-loader-worker");
|
|
4
|
-
const json_loader_1 = require("../json-loader");
|
|
5
|
-
(0, create_loader_worker_1.createLoaderWorker)(json_loader_1.JSONLoader);
|
package/dist/writer-types.js
DELETED