@loaders.gl/json 4.0.1 → 4.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/geojson-worker.js +32 -24
- package/package.json +5 -5
package/dist/geojson-worker.js
CHANGED
|
@@ -36,61 +36,69 @@
|
|
|
36
36
|
}
|
|
37
37
|
|
|
38
38
|
// ../worker-utils/src/lib/worker-farm/worker-body.ts
|
|
39
|
-
function getParentPort() {
|
|
39
|
+
async function getParentPort() {
|
|
40
40
|
let parentPort;
|
|
41
41
|
try {
|
|
42
42
|
eval("globalThis.parentPort = require('worker_threads').parentPort");
|
|
43
43
|
parentPort = globalThis.parentPort;
|
|
44
44
|
} catch {
|
|
45
|
+
try {
|
|
46
|
+
eval("globalThis.workerThreadsPromise = import('worker_threads')");
|
|
47
|
+
const workerThreads = await globalThis.workerThreadsPromise;
|
|
48
|
+
parentPort = workerThreads.parentPort;
|
|
49
|
+
} catch (error) {
|
|
50
|
+
console.error(error.message);
|
|
51
|
+
}
|
|
45
52
|
}
|
|
46
53
|
return parentPort;
|
|
47
54
|
}
|
|
48
55
|
var onMessageWrapperMap = /* @__PURE__ */ new Map();
|
|
49
56
|
var WorkerBody = class {
|
|
50
57
|
/** Check that we are actually in a worker thread */
|
|
51
|
-
static inWorkerThread() {
|
|
52
|
-
return typeof self !== "undefined" || Boolean(getParentPort());
|
|
58
|
+
static async inWorkerThread() {
|
|
59
|
+
return typeof self !== "undefined" || Boolean(await getParentPort());
|
|
53
60
|
}
|
|
54
61
|
/*
|
|
55
62
|
* (type: WorkerMessageType, payload: WorkerMessagePayload) => any
|
|
56
63
|
*/
|
|
57
64
|
static set onmessage(onMessage) {
|
|
58
|
-
function handleMessage(message) {
|
|
59
|
-
const
|
|
60
|
-
const { type, payload } =
|
|
65
|
+
async function handleMessage(message) {
|
|
66
|
+
const parentPort2 = await getParentPort();
|
|
67
|
+
const { type, payload } = parentPort2 ? message : message.data;
|
|
61
68
|
onMessage(type, payload);
|
|
62
69
|
}
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
+
getParentPort().then((parentPort2) => {
|
|
71
|
+
if (parentPort2) {
|
|
72
|
+
parentPort2.on("message", handleMessage);
|
|
73
|
+
parentPort2.on("exit", () => console.debug("Node worker closing"));
|
|
74
|
+
} else {
|
|
75
|
+
globalThis.onmessage = handleMessage;
|
|
76
|
+
}
|
|
77
|
+
});
|
|
70
78
|
}
|
|
71
|
-
static addEventListener(onMessage) {
|
|
79
|
+
static async addEventListener(onMessage) {
|
|
72
80
|
let onMessageWrapper = onMessageWrapperMap.get(onMessage);
|
|
73
81
|
if (!onMessageWrapper) {
|
|
74
|
-
onMessageWrapper = (message) => {
|
|
82
|
+
onMessageWrapper = async (message) => {
|
|
75
83
|
if (!isKnownMessage(message)) {
|
|
76
84
|
return;
|
|
77
85
|
}
|
|
78
|
-
const parentPort3 = getParentPort();
|
|
86
|
+
const parentPort3 = await getParentPort();
|
|
79
87
|
const { type, payload } = parentPort3 ? message : message.data;
|
|
80
88
|
onMessage(type, payload);
|
|
81
89
|
};
|
|
82
90
|
}
|
|
83
|
-
const parentPort2 = getParentPort();
|
|
91
|
+
const parentPort2 = await getParentPort();
|
|
84
92
|
if (parentPort2) {
|
|
85
93
|
console.error("not implemented");
|
|
86
94
|
} else {
|
|
87
95
|
globalThis.addEventListener("message", onMessageWrapper);
|
|
88
96
|
}
|
|
89
97
|
}
|
|
90
|
-
static removeEventListener(onMessage) {
|
|
98
|
+
static async removeEventListener(onMessage) {
|
|
91
99
|
const onMessageWrapper = onMessageWrapperMap.get(onMessage);
|
|
92
100
|
onMessageWrapperMap.delete(onMessage);
|
|
93
|
-
const parentPort2 = getParentPort();
|
|
101
|
+
const parentPort2 = await getParentPort();
|
|
94
102
|
if (parentPort2) {
|
|
95
103
|
console.error("not implemented");
|
|
96
104
|
} else {
|
|
@@ -102,10 +110,10 @@
|
|
|
102
110
|
* @param type
|
|
103
111
|
* @param payload
|
|
104
112
|
*/
|
|
105
|
-
static postMessage(type, payload) {
|
|
113
|
+
static async postMessage(type, payload) {
|
|
106
114
|
const data = { source: "loaders.gl", type, payload };
|
|
107
115
|
const transferList = getTransferList(payload);
|
|
108
|
-
const parentPort2 = getParentPort();
|
|
116
|
+
const parentPort2 = await getParentPort();
|
|
109
117
|
if (parentPort2) {
|
|
110
118
|
parentPort2.postMessage(data, transferList);
|
|
111
119
|
} else {
|
|
@@ -120,8 +128,8 @@
|
|
|
120
128
|
|
|
121
129
|
// ../loader-utils/src/lib/worker-loader-utils/create-loader-worker.ts
|
|
122
130
|
var requestId = 0;
|
|
123
|
-
function createLoaderWorker(loader) {
|
|
124
|
-
if (!WorkerBody.inWorkerThread()) {
|
|
131
|
+
async function createLoaderWorker(loader) {
|
|
132
|
+
if (!await WorkerBody.inWorkerThread()) {
|
|
125
133
|
return;
|
|
126
134
|
}
|
|
127
135
|
WorkerBody.onmessage = async (type, payload) => {
|
|
@@ -2417,7 +2425,7 @@ Char: ${this.c}`;
|
|
|
2417
2425
|
}
|
|
2418
2426
|
|
|
2419
2427
|
// src/geojson-loader.ts
|
|
2420
|
-
var VERSION = true ? "4.0.
|
|
2428
|
+
var VERSION = true ? "4.0.2" : "latest";
|
|
2421
2429
|
var GeoJSONWorkerLoader = {
|
|
2422
2430
|
name: "GeoJSON",
|
|
2423
2431
|
id: "geojson",
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@loaders.gl/json",
|
|
3
|
-
"version": "4.0.
|
|
3
|
+
"version": "4.0.2",
|
|
4
4
|
"description": "Framework-independent loader for JSON and streaming JSON formats",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"type": "module",
|
|
@@ -43,9 +43,9 @@
|
|
|
43
43
|
"build-worker": "esbuild src/workers/geojson-worker.ts --bundle --outfile=dist/geojson-worker.js --define:__VERSION__=\\\"$npm_package_version\\\""
|
|
44
44
|
},
|
|
45
45
|
"dependencies": {
|
|
46
|
-
"@loaders.gl/gis": "4.0.
|
|
47
|
-
"@loaders.gl/loader-utils": "4.0.
|
|
48
|
-
"@loaders.gl/schema": "4.0.
|
|
46
|
+
"@loaders.gl/gis": "4.0.2",
|
|
47
|
+
"@loaders.gl/loader-utils": "4.0.2",
|
|
48
|
+
"@loaders.gl/schema": "4.0.2"
|
|
49
49
|
},
|
|
50
|
-
"gitHead": "
|
|
50
|
+
"gitHead": "471058d109d5652f28c32c1f296fd632f9a5c806"
|
|
51
51
|
}
|