@loaders.gl/core 5.0.0-beta.1 → 5.0.0-beta.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/README.md +3 -1
- package/dist/cluster-source.cjs +7228 -0
- package/dist/cluster-source.cjs.map +6 -0
- package/dist/cluster-source.d.ts +2 -0
- package/dist/cluster-source.d.ts.map +1 -0
- package/dist/cluster-source.js +2 -0
- package/dist/cluster-source.js.map +1 -0
- package/dist/dist.dev.js +894 -273
- package/dist/dist.min.js +3 -3
- package/dist/federated-table-scan-source.cjs +2677 -0
- package/dist/federated-table-scan-source.cjs.map +6 -0
- package/dist/federated-table-scan-source.d.ts +2 -0
- package/dist/federated-table-scan-source.d.ts.map +1 -0
- package/dist/federated-table-scan-source.js +2 -0
- package/dist/federated-table-scan-source.js.map +1 -0
- package/dist/index.cjs +12 -1045
- package/dist/index.cjs.map +3 -3
- package/dist/lib/init.js +1 -1
- package/dist/loader-utils/index.cjs +43 -1331
- package/dist/loader-utils/index.cjs.map +3 -3
- package/dist/loader-utils/json-loader.js +1 -1
- package/dist/loader-utils/lib/log-utils/log.js +1 -1
- package/dist/null-loader.js +1 -1
- package/dist/null-worker-node.js +169 -79
- package/dist/null-worker.js +166 -55
- package/dist/polyfills/images/encode-image-node.d.ts +18 -15
- package/dist/polyfills/images/encode-image-node.d.ts.map +1 -1
- package/dist/polyfills/images/encode-image-node.js +19 -33
- package/dist/polyfills/images/encode-image-node.js.map +1 -1
- package/dist/polyfills/images/image-codecs-node.d.ts +2 -6
- package/dist/polyfills/images/image-codecs-node.d.ts.map +1 -1
- package/dist/polyfills/images/image-codecs-node.js +2 -24
- package/dist/polyfills/images/image-codecs-node.js.map +1 -1
- package/dist/polyfills/images/load-sharp.d.ts +3 -0
- package/dist/polyfills/images/load-sharp.d.ts.map +1 -0
- package/dist/polyfills/images/load-sharp.js +11 -0
- package/dist/polyfills/images/load-sharp.js.map +1 -0
- package/dist/polyfills/images/node-image-bitmap.d.ts +1 -1
- package/dist/polyfills/images/node-image-bitmap.js +1 -1
- package/dist/polyfills/images/node-image-formats.d.ts +1 -1
- package/dist/polyfills/images/node-image-formats.d.ts.map +1 -1
- package/dist/polyfills/images/node-image-formats.js +10 -4
- package/dist/polyfills/images/node-image-formats.js.map +1 -1
- package/dist/polyfills/images/parse-image-node.d.ts +10 -2
- package/dist/polyfills/images/parse-image-node.d.ts.map +1 -1
- package/dist/polyfills/images/parse-image-node.js +20 -32
- package/dist/polyfills/images/parse-image-node.js.map +1 -1
- package/dist/polyfills/index.cjs +73 -149
- package/dist/vector-table-scan-source.cjs +1703 -0
- package/dist/vector-table-scan-source.cjs.map +6 -0
- package/dist/vector-table-scan-source.d.ts +2 -0
- package/dist/vector-table-scan-source.d.ts.map +1 -0
- package/dist/vector-table-scan-source.js +2 -0
- package/dist/vector-table-scan-source.js.map +1 -0
- package/dist/worker-utils/index.cjs +72 -1225
- package/dist/worker-utils/index.cjs.map +3 -3
- package/dist/worker-utils/lib/async-queue/async-queue.d.ts +1 -31
- package/dist/worker-utils/lib/async-queue/async-queue.d.ts.map +1 -1
- package/dist/worker-utils/lib/async-queue/async-queue.js +1 -87
- package/dist/worker-utils/lib/async-queue/async-queue.js.map +1 -1
- package/dist/worker-utils/lib/env-utils/version.js +1 -1
- package/dist/worker-utils/lib/worker-api/create-worker.d.ts +1 -8
- package/dist/worker-utils/lib/worker-api/create-worker.d.ts.map +1 -1
- package/dist/worker-utils/lib/worker-api/create-worker.js +1 -157
- package/dist/worker-utils/lib/worker-api/create-worker.js.map +1 -1
- package/dist/worker-utils/lib/worker-api/process-on-worker.d.ts +2 -49
- package/dist/worker-utils/lib/worker-api/process-on-worker.d.ts.map +1 -1
- package/dist/worker-utils/lib/worker-api/process-on-worker.js +1 -345
- package/dist/worker-utils/lib/worker-api/process-on-worker.js.map +1 -1
- package/dist/worker-utils/lib/worker-farm/worker-body.d.ts +1 -19
- package/dist/worker-utils/lib/worker-farm/worker-body.d.ts.map +1 -1
- package/dist/worker-utils/lib/worker-farm/worker-body.js +1 -127
- package/dist/worker-utils/lib/worker-farm/worker-body.js.map +1 -1
- package/dist/worker-utils/lib/worker-farm/worker-farm.d.ts +1 -57
- package/dist/worker-utils/lib/worker-farm/worker-farm.d.ts.map +1 -1
- package/dist/worker-utils/lib/worker-farm/worker-farm.js +1 -112
- package/dist/worker-utils/lib/worker-farm/worker-farm.js.map +1 -1
- package/dist/worker-utils/lib/worker-farm/worker-job.d.ts +1 -33
- package/dist/worker-utils/lib/worker-farm/worker-job.d.ts.map +1 -1
- package/dist/worker-utils/lib/worker-farm/worker-job.js +1 -70
- package/dist/worker-utils/lib/worker-farm/worker-job.js.map +1 -1
- package/dist/worker-utils/lib/worker-farm/worker-pool.d.ts +1 -93
- package/dist/worker-utils/lib/worker-farm/worker-pool.d.ts.map +1 -1
- package/dist/worker-utils/lib/worker-farm/worker-pool.js +1 -242
- package/dist/worker-utils/lib/worker-farm/worker-pool.js.map +1 -1
- package/dist/worker-utils/lib/worker-farm/worker-thread.d.ts +1 -66
- package/dist/worker-utils/lib/worker-farm/worker-thread.d.ts.map +1 -1
- package/dist/worker-utils/lib/worker-farm/worker-thread.js +1 -171
- package/dist/worker-utils/lib/worker-farm/worker-thread.js.map +1 -1
- package/dist/worker-utils/null-worker-node.js +234 -144
- package/dist/worker-utils/null-worker-node.js.map +4 -4
- package/dist/worker-utils/null-worker.js +232 -121
- package/dist/worker-utils/null-worker.js.map +4 -4
- package/dist/worker-utils/types.d.ts +1 -99
- package/dist/worker-utils/types.d.ts.map +1 -1
- package/package.json +27 -29
- package/src/cluster-source.ts +1 -0
- package/src/federated-table-scan-source.ts +1 -0
- package/src/polyfills/README.md +2 -2
- package/src/polyfills/images/encode-image-node.ts +44 -37
- package/src/polyfills/images/image-codecs-node.ts +2 -37
- package/src/polyfills/images/load-sharp.ts +13 -0
- package/src/polyfills/images/node-image-bitmap.ts +1 -1
- package/src/polyfills/images/node-image-formats.ts +10 -4
- package/src/polyfills/images/parse-image-node.ts +31 -40
- package/src/vector-table-scan-source.ts +1 -0
- package/src/worker-utils/lib/async-queue/async-queue.ts +1 -96
- package/src/worker-utils/lib/worker-api/create-worker.ts +1 -201
- package/src/worker-utils/lib/worker-api/process-on-worker.ts +8 -464
- package/src/worker-utils/lib/worker-farm/worker-body.ts +1 -141
- package/src/worker-utils/lib/worker-farm/worker-farm.ts +1 -140
- package/src/worker-utils/lib/worker-farm/worker-job.ts +1 -81
- package/src/worker-utils/lib/worker-farm/worker-pool.ts +1 -312
- package/src/worker-utils/lib/worker-farm/worker-thread.ts +1 -202
- package/src/worker-utils/types.ts +14 -144
- package/src/polyfills/images/encode-image.node.ts.disabled +0 -41
- package/src/polyfills/images/parse-image.node.ts.disabled +0 -55
|
@@ -1,67 +1,2 @@
|
|
|
1
|
-
|
|
2
|
-
import { NodeWorkerType } from "../node/worker_threads.js";
|
|
3
|
-
export type WorkerThreadProps = {
|
|
4
|
-
/** Human-readable worker name. */
|
|
5
|
-
name: string;
|
|
6
|
-
/** Inline worker source. */
|
|
7
|
-
source?: string;
|
|
8
|
-
/** Worker script URL. */
|
|
9
|
-
url?: string;
|
|
10
|
-
/** Lazily resolves the classic worker URL used as a fallback. */
|
|
11
|
-
getUrl?: () => string;
|
|
12
|
-
/** Creates a browser Worker directly. */
|
|
13
|
-
loadWorker?: LoadWorker;
|
|
14
|
-
};
|
|
15
|
-
/**
|
|
16
|
-
* Represents one worker thread
|
|
17
|
-
*/
|
|
18
|
-
export default class WorkerThread {
|
|
19
|
-
readonly name: string;
|
|
20
|
-
readonly source: string | undefined;
|
|
21
|
-
readonly url: string | undefined;
|
|
22
|
-
/** Lazily resolves the classic worker URL used as a fallback. */
|
|
23
|
-
readonly getUrl: (() => string) | undefined;
|
|
24
|
-
/** Creates a browser Worker directly. */
|
|
25
|
-
readonly loadWorker: LoadWorker | undefined;
|
|
26
|
-
terminated: boolean;
|
|
27
|
-
worker: Worker | NodeWorkerType;
|
|
28
|
-
onMessage: (message: any) => void;
|
|
29
|
-
onError: (error: Error) => void;
|
|
30
|
-
private _loadableURL;
|
|
31
|
-
/** Checks if workers are supported on this platform */
|
|
32
|
-
static isSupported(): boolean;
|
|
33
|
-
constructor(props: WorkerThreadProps);
|
|
34
|
-
/**
|
|
35
|
-
* Terminate this worker thread
|
|
36
|
-
* @note Can free up significant memory
|
|
37
|
-
*/
|
|
38
|
-
destroy(): void;
|
|
39
|
-
/** Keeps this worker from preventing Node.js process exit while idle. */
|
|
40
|
-
unref(): void;
|
|
41
|
-
/** Keeps this worker alive while it is actively processing a job. */
|
|
42
|
-
ref(): void;
|
|
43
|
-
get isRunning(): boolean;
|
|
44
|
-
/**
|
|
45
|
-
* Send a message to this worker thread
|
|
46
|
-
* @param data any data structure, ideally consisting mostly of transferrable objects
|
|
47
|
-
* @param transferList If not supplied, calculated automatically by traversing data
|
|
48
|
-
*/
|
|
49
|
-
postMessage(data: any, transferList?: any[]): void;
|
|
50
|
-
/**
|
|
51
|
-
* Generate a standard Error from an ErrorEvent
|
|
52
|
-
* @param event
|
|
53
|
-
*/
|
|
54
|
-
_getErrorFromErrorEvent(event: ErrorEvent): Error;
|
|
55
|
-
/**
|
|
56
|
-
* Creates a worker thread on the browser
|
|
57
|
-
*/
|
|
58
|
-
_createBrowserWorker(): Worker;
|
|
59
|
-
/** Attaches protocol handlers to a browser worker. */
|
|
60
|
-
_initializeBrowserWorker(worker: Worker): Worker;
|
|
61
|
-
/**
|
|
62
|
-
* Creates a worker thread in node.js
|
|
63
|
-
* @todo https://nodejs.org/api/async_hooks.html#async-resource-worker-pool
|
|
64
|
-
*/
|
|
65
|
-
_createNodeWorker(): NodeWorkerType;
|
|
66
|
-
}
|
|
1
|
+
export { WorkerThread as default } from '@math.gl/core/tasks';
|
|
67
2
|
//# sourceMappingURL=worker-thread.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"worker-thread.d.ts","sourceRoot":"","sources":["../../../../src/worker-utils/lib/worker-farm/worker-thread.ts"],"names":[],"mappings":"AAIA,OAAO,
|
|
1
|
+
{"version":3,"file":"worker-thread.d.ts","sourceRoot":"","sources":["../../../../src/worker-utils/lib/worker-farm/worker-thread.ts"],"names":[],"mappings":"AAIA,OAAO,EAAC,YAAY,IAAI,OAAO,EAAC,MAAM,qBAAqB,CAAC"}
|
|
@@ -1,175 +1,5 @@
|
|
|
1
1
|
// loaders.gl
|
|
2
2
|
// SPDX-License-Identifier: MIT
|
|
3
3
|
// Copyright (c) vis.gl contributors
|
|
4
|
-
|
|
5
|
-
import { isBrowser } from "../env-utils/globals.js";
|
|
6
|
-
import { assert } from "../env-utils/assert.js";
|
|
7
|
-
import { getLoadableWorkerURL } from "../worker-utils/get-loadable-worker-url.js";
|
|
8
|
-
import { getTransferList } from "../worker-utils/get-transfer-list.js";
|
|
9
|
-
const NOOP = () => { };
|
|
10
|
-
/**
|
|
11
|
-
* Represents one worker thread
|
|
12
|
-
*/
|
|
13
|
-
export default class WorkerThread {
|
|
14
|
-
name;
|
|
15
|
-
source;
|
|
16
|
-
url;
|
|
17
|
-
/** Lazily resolves the classic worker URL used as a fallback. */
|
|
18
|
-
getUrl;
|
|
19
|
-
/** Creates a browser Worker directly. */
|
|
20
|
-
loadWorker;
|
|
21
|
-
terminated = false;
|
|
22
|
-
worker;
|
|
23
|
-
onMessage;
|
|
24
|
-
onError;
|
|
25
|
-
_loadableURL = '';
|
|
26
|
-
/** Checks if workers are supported on this platform */
|
|
27
|
-
static isSupported() {
|
|
28
|
-
return ((typeof Worker !== 'undefined' && isBrowser) ||
|
|
29
|
-
(typeof NodeWorker !== 'undefined' && !isBrowser));
|
|
30
|
-
}
|
|
31
|
-
constructor(props) {
|
|
32
|
-
const { name, source, url, getUrl, loadWorker } = props;
|
|
33
|
-
assert(source || url || getUrl || loadWorker);
|
|
34
|
-
this.name = name;
|
|
35
|
-
this.source = source;
|
|
36
|
-
this.url = url;
|
|
37
|
-
this.getUrl = getUrl;
|
|
38
|
-
this.loadWorker = loadWorker;
|
|
39
|
-
this.onMessage = NOOP;
|
|
40
|
-
this.onError = error => console.log(error); // eslint-disable-line
|
|
41
|
-
this.worker = isBrowser ? this._createBrowserWorker() : this._createNodeWorker();
|
|
42
|
-
}
|
|
43
|
-
/**
|
|
44
|
-
* Terminate this worker thread
|
|
45
|
-
* @note Can free up significant memory
|
|
46
|
-
*/
|
|
47
|
-
destroy() {
|
|
48
|
-
this.onMessage = NOOP;
|
|
49
|
-
this.onError = NOOP;
|
|
50
|
-
this.worker.terminate(); // eslint-disable-line @typescript-eslint/no-floating-promises
|
|
51
|
-
this.terminated = true;
|
|
52
|
-
}
|
|
53
|
-
/** Keeps this worker from preventing Node.js process exit while idle. */
|
|
54
|
-
unref() {
|
|
55
|
-
if (!isBrowser && typeof this.worker.unref === 'function') {
|
|
56
|
-
this.worker.unref();
|
|
57
|
-
}
|
|
58
|
-
}
|
|
59
|
-
/** Keeps this worker alive while it is actively processing a job. */
|
|
60
|
-
ref() {
|
|
61
|
-
if (!isBrowser && typeof this.worker.ref === 'function') {
|
|
62
|
-
this.worker.ref();
|
|
63
|
-
}
|
|
64
|
-
}
|
|
65
|
-
get isRunning() {
|
|
66
|
-
return Boolean(this.onMessage);
|
|
67
|
-
}
|
|
68
|
-
/**
|
|
69
|
-
* Send a message to this worker thread
|
|
70
|
-
* @param data any data structure, ideally consisting mostly of transferrable objects
|
|
71
|
-
* @param transferList If not supplied, calculated automatically by traversing data
|
|
72
|
-
*/
|
|
73
|
-
postMessage(data, transferList) {
|
|
74
|
-
transferList = transferList || getTransferList(data);
|
|
75
|
-
// @ts-ignore
|
|
76
|
-
this.worker.postMessage(data, transferList);
|
|
77
|
-
}
|
|
78
|
-
// PRIVATE
|
|
79
|
-
/**
|
|
80
|
-
* Generate a standard Error from an ErrorEvent
|
|
81
|
-
* @param event
|
|
82
|
-
*/
|
|
83
|
-
_getErrorFromErrorEvent(event) {
|
|
84
|
-
// Note Error object does not have the expected fields if loading failed completely
|
|
85
|
-
// https://developer.mozilla.org/en-US/docs/Web/API/Worker#Event_handlers
|
|
86
|
-
// https://developer.mozilla.org/en-US/docs/Web/API/ErrorEvent
|
|
87
|
-
let message = 'Failed to load ';
|
|
88
|
-
message += `worker ${this.name} from ${this.url || 'built-in worker factory'}. `;
|
|
89
|
-
if (event.message) {
|
|
90
|
-
message += `${event.message} in `;
|
|
91
|
-
}
|
|
92
|
-
// const hasFilename = event.filename && !event.filename.startsWith('blob:');
|
|
93
|
-
// message += hasFilename ? event.filename : this.source.slice(0, 100);
|
|
94
|
-
if (event.lineno) {
|
|
95
|
-
message += `:${event.lineno}:${event.colno}`;
|
|
96
|
-
}
|
|
97
|
-
return new Error(message);
|
|
98
|
-
}
|
|
99
|
-
/**
|
|
100
|
-
* Creates a worker thread on the browser
|
|
101
|
-
*/
|
|
102
|
-
_createBrowserWorker() {
|
|
103
|
-
if (this.loadWorker) {
|
|
104
|
-
try {
|
|
105
|
-
const worker = this.loadWorker();
|
|
106
|
-
if (worker) {
|
|
107
|
-
return this._initializeBrowserWorker(worker);
|
|
108
|
-
}
|
|
109
|
-
}
|
|
110
|
-
catch (error) {
|
|
111
|
-
if (!this.source && !this.url && !this.getUrl) {
|
|
112
|
-
throw error;
|
|
113
|
-
}
|
|
114
|
-
}
|
|
115
|
-
}
|
|
116
|
-
const url = this.url || this.getUrl?.();
|
|
117
|
-
this._loadableURL = getLoadableWorkerURL({ source: this.source, url });
|
|
118
|
-
const worker = new Worker(this._loadableURL, { name: this.name });
|
|
119
|
-
return this._initializeBrowserWorker(worker);
|
|
120
|
-
}
|
|
121
|
-
/** Attaches protocol handlers to a browser worker. */
|
|
122
|
-
_initializeBrowserWorker(worker) {
|
|
123
|
-
worker.onmessage = event => {
|
|
124
|
-
if (!event.data) {
|
|
125
|
-
this.onError(new Error('No data received'));
|
|
126
|
-
}
|
|
127
|
-
else {
|
|
128
|
-
this.onMessage(event.data);
|
|
129
|
-
}
|
|
130
|
-
};
|
|
131
|
-
// This callback represents an uncaught exception in the worker thread
|
|
132
|
-
worker.onerror = (error) => {
|
|
133
|
-
this.onError(this._getErrorFromErrorEvent(error));
|
|
134
|
-
this.terminated = true;
|
|
135
|
-
};
|
|
136
|
-
// TODO - not clear when this would be called, for now just log in case it happens
|
|
137
|
-
worker.onmessageerror = event => console.error(event); // eslint-disable-line
|
|
138
|
-
return worker;
|
|
139
|
-
}
|
|
140
|
-
/**
|
|
141
|
-
* Creates a worker thread in node.js
|
|
142
|
-
* @todo https://nodejs.org/api/async_hooks.html#async-resource-worker-pool
|
|
143
|
-
*/
|
|
144
|
-
_createNodeWorker() {
|
|
145
|
-
let worker;
|
|
146
|
-
if (this.url) {
|
|
147
|
-
// Make sure relative URLs start with './'
|
|
148
|
-
const absolute = this.url.includes(':/') || this.url.startsWith('/');
|
|
149
|
-
const url = absolute ? this.url : `./${this.url}`;
|
|
150
|
-
const workerUrl = url.startsWith('file:') ? new URL(url) : url;
|
|
151
|
-
const type = this.url.endsWith('.ts') || this.url.endsWith('.mjs') ? 'module' : 'commonjs';
|
|
152
|
-
// console.log('Starting work from', url);
|
|
153
|
-
// @ts-expect-error type is not known
|
|
154
|
-
worker = new NodeWorker(workerUrl, { eval: false, type });
|
|
155
|
-
}
|
|
156
|
-
else if (this.source) {
|
|
157
|
-
worker = new NodeWorker(this.source, { eval: true });
|
|
158
|
-
}
|
|
159
|
-
else {
|
|
160
|
-
throw new Error('no worker');
|
|
161
|
-
}
|
|
162
|
-
worker.on('message', data => {
|
|
163
|
-
// console.error('message', data);
|
|
164
|
-
this.onMessage(data);
|
|
165
|
-
});
|
|
166
|
-
worker.on('error', error => {
|
|
167
|
-
this.onError(error);
|
|
168
|
-
});
|
|
169
|
-
worker.on('exit', _code => {
|
|
170
|
-
// console.error('exit', code);
|
|
171
|
-
});
|
|
172
|
-
return worker;
|
|
173
|
-
}
|
|
174
|
-
}
|
|
4
|
+
export { WorkerThread as default } from '@math.gl/core/tasks';
|
|
175
5
|
//# sourceMappingURL=worker-thread.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"worker-thread.js","sourceRoot":"","sources":["../../../../src/worker-utils/lib/worker-farm/worker-thread.ts"],"names":[],"mappings":"AAAA,aAAa;AACb,+BAA+B;AAC/B,oCAAoC;
|
|
1
|
+
{"version":3,"file":"worker-thread.js","sourceRoot":"","sources":["../../../../src/worker-utils/lib/worker-farm/worker-thread.ts"],"names":[],"mappings":"AAAA,aAAa;AACb,+BAA+B;AAC/B,oCAAoC;AAEpC,OAAO,EAAC,YAAY,IAAI,OAAO,EAAC,MAAM,qBAAqB,CAAC"}
|