@earthyscience/netcdf4-wasm 0.3.0 → 0.4.0
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/CONTRIBUTING.md +29 -22
- package/README.md +12 -10
- package/dist/constants.d.ts +165 -146
- package/dist/constants.d.ts.map +1 -1
- package/dist/constants.js +48 -60
- package/dist/constants.js.map +1 -1
- package/dist/dimension.js +1 -1
- package/dist/errors.d.ts +3 -0
- package/dist/errors.d.ts.map +1 -0
- package/dist/errors.js +15 -0
- package/dist/errors.js.map +1 -0
- package/dist/group.d.ts +4 -5
- package/dist/group.d.ts.map +1 -1
- package/dist/group.js +11 -70
- package/dist/group.js.map +1 -1
- package/dist/index.d.ts +15 -16
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +13 -14
- package/dist/index.js.map +1 -1
- package/dist/netcdf-getters.d.ts +5 -5
- package/dist/netcdf-getters.d.ts.map +1 -1
- package/dist/netcdf-getters.js +78 -50
- package/dist/netcdf-getters.js.map +1 -1
- package/dist/netcdf-worker.js +15 -105
- package/dist/netcdf-worker.js.map +1 -1
- package/dist/netcdf4-wasm.js +2 -2
- package/dist/netcdf4-wasm.wasm +0 -0
- package/dist/netcdf4.d.ts +19 -20
- package/dist/netcdf4.d.ts.map +1 -1
- package/dist/netcdf4.js +201 -518
- package/dist/netcdf4.js.map +1 -1
- package/dist/operations.d.ts +67 -0
- package/dist/operations.d.ts.map +1 -0
- package/dist/operations.js +57 -0
- package/dist/operations.js.map +1 -0
- package/dist/remote-read.d.ts +4 -4
- package/dist/remote-read.d.ts.map +1 -1
- package/dist/remote-read.js +22 -18
- package/dist/remote-read.js.map +1 -1
- package/dist/slice.d.ts.map +1 -1
- package/dist/slice.js.map +1 -1
- package/dist/types.d.ts +27 -414
- package/dist/types.d.ts.map +1 -1
- package/dist/variable.d.ts +1 -1
- package/dist/variable.d.ts.map +1 -1
- package/dist/variable.js +60 -78
- package/dist/variable.js.map +1 -1
- package/dist/wasm-module.d.ts +468 -2
- package/dist/wasm-module.d.ts.map +1 -1
- package/dist/wasm-module.js +331 -251
- package/dist/wasm-module.js.map +1 -1
- package/package.json +17 -14
- package/dist/test-setup.d.ts +0 -13
- package/dist/test-setup.d.ts.map +0 -1
- package/dist/test-setup.js +0 -78
- package/dist/test-setup.js.map +0 -1
package/dist/netcdf-worker.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { toError } from "./errors.js";
|
|
2
|
+
import { isOperationName, runOperation } from "./operations.js";
|
|
3
|
+
import { checkRangeSupport, createRemoteFileNode, RemoteFile, XhrRangeSource, } from "./remote-read.js";
|
|
2
4
|
import { WasmModuleLoader } from "./wasm-module.js";
|
|
3
|
-
import { NC_CONSTANTS } from "./constants.js";
|
|
4
|
-
import { RemoteFile, XhrRangeSource, checkRangeSupport, createRemoteFileNode } from "./remote-read.js";
|
|
5
5
|
let netcdfModule;
|
|
6
6
|
let mod;
|
|
7
7
|
let remoteFile;
|
|
@@ -9,27 +9,26 @@ let remoteFile;
|
|
|
9
9
|
// An async IIFE (rather than `new Promise(async ...)`) so that a failed
|
|
10
10
|
// import or WASM load rejects this promise instead of leaving it pending.
|
|
11
11
|
const waitForModule = (async () => {
|
|
12
|
-
const netcdf4Module = await import(
|
|
12
|
+
const netcdf4Module = await import("./netcdf4-wasm.js");
|
|
13
13
|
const createNetCDF4Module = netcdf4Module.default;
|
|
14
14
|
netcdfModule = await createNetCDF4Module({
|
|
15
15
|
locateFile: (file) => {
|
|
16
|
-
if (file.endsWith(
|
|
16
|
+
if (file.endsWith(".wasm")) {
|
|
17
17
|
const origin = self.location.origin;
|
|
18
|
-
const basePath = process.env.NEXT_PUBLIC_BASE_PATH ??
|
|
18
|
+
const basePath = process.env.NEXT_PUBLIC_BASE_PATH ?? "";
|
|
19
19
|
return `${origin}${basePath}/${file}`;
|
|
20
20
|
}
|
|
21
21
|
return file;
|
|
22
|
-
}
|
|
22
|
+
},
|
|
23
23
|
});
|
|
24
24
|
return netcdfModule;
|
|
25
25
|
})();
|
|
26
|
-
// @ts-ignore worker scope
|
|
27
26
|
self.onmessage = async (e) => {
|
|
28
27
|
const data = e.data;
|
|
29
28
|
const { type, id } = data;
|
|
30
29
|
try {
|
|
31
30
|
// ---------------- INIT ----------------
|
|
32
|
-
if (type ===
|
|
31
|
+
if (type === "init") {
|
|
33
32
|
mod = WasmModuleLoader.wrapModule(await waitForModule);
|
|
34
33
|
const { blob, url, remote, filename } = data;
|
|
35
34
|
if (url) {
|
|
@@ -39,9 +38,9 @@ self.onmessage = async (e) => {
|
|
|
39
38
|
self.postMessage({ id, success: true });
|
|
40
39
|
return;
|
|
41
40
|
}
|
|
42
|
-
const pathParts = filename.split(
|
|
41
|
+
const pathParts = filename.split("/");
|
|
43
42
|
const baseName = pathParts.pop();
|
|
44
|
-
const mountPoint = pathParts.join(
|
|
43
|
+
const mountPoint = pathParts.join("/") || "/";
|
|
45
44
|
// safer for nested paths
|
|
46
45
|
try {
|
|
47
46
|
mod.FS.mkdirTree(mountPoint);
|
|
@@ -53,7 +52,7 @@ self.onmessage = async (e) => {
|
|
|
53
52
|
}, mountPoint);
|
|
54
53
|
}
|
|
55
54
|
catch (err) {
|
|
56
|
-
console.warn("Mount failed (might already be mounted):", err.message);
|
|
55
|
+
console.warn("Mount failed (might already be mounted):", toError(err).message);
|
|
57
56
|
}
|
|
58
57
|
self.postMessage({ id, success: true });
|
|
59
58
|
return;
|
|
@@ -65,104 +64,15 @@ self.onmessage = async (e) => {
|
|
|
65
64
|
// Only report read errors raised by this request
|
|
66
65
|
if (remoteFile)
|
|
67
66
|
remoteFile.lastError = undefined;
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
case 'open': {
|
|
71
|
-
const openResult = mod.nc_open(data.path, data.modeValue);
|
|
72
|
-
if (openResult.result !== NC_CONSTANTS.NC_NOERR) {
|
|
73
|
-
throw new Error('nc_open failed: ' + openResult.result);
|
|
74
|
-
}
|
|
75
|
-
result = openResult.ncid;
|
|
76
|
-
break;
|
|
77
|
-
}
|
|
78
|
-
case 'close': {
|
|
79
|
-
const closeResult = mod.nc_close(data.ncid);
|
|
80
|
-
if (closeResult !== NC_CONSTANTS.NC_NOERR) {
|
|
81
|
-
throw new Error("Failed to close file");
|
|
82
|
-
}
|
|
83
|
-
result = closeResult;
|
|
84
|
-
break;
|
|
85
|
-
}
|
|
86
|
-
// ---- Globals ----
|
|
87
|
-
case 'getGlobalAttributes':
|
|
88
|
-
result = NCGet.getGlobalAttributes(mod, data.ncid, data.groupPath);
|
|
89
|
-
break;
|
|
90
|
-
case 'getFullMetadata':
|
|
91
|
-
result = NCGet.getFullMetadata(mod, data.ncid, data.groupPath);
|
|
92
|
-
break;
|
|
93
|
-
// ---- Dims ----
|
|
94
|
-
case 'getDimCount':
|
|
95
|
-
result = NCGet.getDimCount(mod, data.ncid);
|
|
96
|
-
break;
|
|
97
|
-
case 'getDimIDs':
|
|
98
|
-
result = Array.from(NCGet.getDimIDs(mod, data.ncid));
|
|
99
|
-
break;
|
|
100
|
-
case 'getDim':
|
|
101
|
-
result = NCGet.getDim(mod, data.ncid, data.dimid);
|
|
102
|
-
break;
|
|
103
|
-
case 'getDims':
|
|
104
|
-
result = NCGet.getDims(mod, data.ncid, data.groupPath);
|
|
105
|
-
break;
|
|
106
|
-
// ---- Vars ----
|
|
107
|
-
case 'getGroupVariables':
|
|
108
|
-
// console.log('Worker: getGroupVariables', data.ncid);
|
|
109
|
-
result = NCGet.getGroupVariables(mod, data.ncid, data.groupPath);
|
|
110
|
-
break;
|
|
111
|
-
case 'getVarIDs':
|
|
112
|
-
result = Array.from(NCGet.getVarIDs(mod, data.ncid));
|
|
113
|
-
break;
|
|
114
|
-
case 'getVarCount':
|
|
115
|
-
result = NCGet.getVarCount(mod, data.ncid);
|
|
116
|
-
break;
|
|
117
|
-
case 'getAttributeName':
|
|
118
|
-
result = NCGet.getAttributeName(mod, data.ncid, data.varid, data.attId);
|
|
119
|
-
break;
|
|
120
|
-
case 'getVariableInfo':
|
|
121
|
-
result = NCGet.getVariableInfo(mod, data.ncid, data.variable, data.groupPath);
|
|
122
|
-
break;
|
|
123
|
-
case 'getAttributeValues':
|
|
124
|
-
result = NCGet.getAttributeValues(mod, data.ncid, data.varid, data.attname);
|
|
125
|
-
break;
|
|
126
|
-
case 'getVariableArrayWithSelection':
|
|
127
|
-
result = NCGet.getVariableArrayWithSelection(mod, data.ncid, data.variable, data.selection, data.groupPath, data.options);
|
|
128
|
-
break;
|
|
129
|
-
// ---- Arrays ----
|
|
130
|
-
case 'getVariableArray':
|
|
131
|
-
result = NCGet.getVariableArray(mod, data.ncid, data.variable, data.groupPath);
|
|
132
|
-
break;
|
|
133
|
-
case 'getSlicedVariableArray':
|
|
134
|
-
result = NCGet.getSlicedVariableArray(mod, data.ncid, data.variable, data.start, data.count, data.groupPath);
|
|
135
|
-
break;
|
|
136
|
-
// ---- Groups ----
|
|
137
|
-
case 'getGroups':
|
|
138
|
-
result = NCGet.getGroups(mod, data.ncid);
|
|
139
|
-
break;
|
|
140
|
-
case 'getGroupsRecursive':
|
|
141
|
-
result = NCGet.getGroupsRecursive(mod, data.ncid);
|
|
142
|
-
break;
|
|
143
|
-
case 'getGroupNCID':
|
|
144
|
-
result = NCGet.getGroupNCID(mod, data.ncid, data.groupPath);
|
|
145
|
-
break;
|
|
146
|
-
case 'getGroupName':
|
|
147
|
-
result = NCGet.getGroupName(mod, data.ncid);
|
|
148
|
-
break;
|
|
149
|
-
case 'getGroupPath':
|
|
150
|
-
result = NCGet.getGroupPath(mod, data.ncid);
|
|
151
|
-
break;
|
|
152
|
-
case 'getCompleteHierarchy':
|
|
153
|
-
result = NCGet.getCompleteHierarchy(mod, data.ncid, data.groupPath);
|
|
154
|
-
break;
|
|
155
|
-
case 'getVariables':
|
|
156
|
-
result = NCGet.getVariables(mod, data.ncid);
|
|
157
|
-
break;
|
|
158
|
-
default:
|
|
159
|
-
throw new Error(`Unknown message type: ${type}`);
|
|
67
|
+
if (!isOperationName(type)) {
|
|
68
|
+
throw new Error(`Unknown message type: ${type}`);
|
|
160
69
|
}
|
|
70
|
+
const result = runOperation(mod, type, data.args);
|
|
161
71
|
self.postMessage({ id, success: true, result });
|
|
162
72
|
}
|
|
163
73
|
catch (err) {
|
|
164
74
|
// netCDF-C only sees EIO for a failed remote read; attach the actual cause
|
|
165
|
-
let message = err.message;
|
|
75
|
+
let message = toError(err).message;
|
|
166
76
|
if (remoteFile?.lastError) {
|
|
167
77
|
message += ` (${remoteFile.lastError.message})`;
|
|
168
78
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"netcdf-worker.js","sourceRoot":"","sources":["../src/netcdf-worker.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"netcdf-worker.js","sourceRoot":"","sources":["../src/netcdf-worker.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,aAAa,CAAC;AACtC,OAAO,EAAE,eAAe,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAC;AAChE,OAAO,EACH,iBAAiB,EACjB,oBAAoB,EACpB,UAAU,EACV,cAAc,GACjB,MAAM,kBAAkB,CAAC;AAG1B,OAAO,EAAE,gBAAgB,EAAE,MAAM,kBAAkB,CAAC;AAEpD,IAAI,YAA8B,CAAC;AACnC,IAAI,GAAkB,CAAC;AACvB,IAAI,UAAkC,CAAC;AAEvC,mCAAmC;AACnC,wEAAwE;AACxE,0EAA0E;AAC1E,MAAM,aAAa,GAA8B,CAAC,KAAK,IAAI,EAAE;IACzD,MAAM,aAAa,GAAG,MAAM,MAAM,CAAC,mBAAmB,CAAC,CAAC;IACxD,MAAM,mBAAmB,GAAG,aAAa,CAAC,OAEZ,CAAC;IAE/B,YAAY,GAAG,MAAM,mBAAmB,CAAC;QACrC,UAAU,EAAE,CAAC,IAAY,EAAU,EAAE;YACjC,IAAI,IAAI,CAAC,QAAQ,CAAC,OAAO,CAAC,EAAE,CAAC;gBACzB,MAA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