geolibre-wasm 0.4.2 → 0.4.3

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/geolibre-cli.wasm CHANGED
Binary file
Binary file
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "geolibre-wasm",
3
3
  "type": "module",
4
- "version": "0.4.2",
4
+ "version": "0.4.3",
5
5
  "description": "Pure-Rust geospatial toolkit (whitebox_next_gen) compiled to WebAssembly (WASI) for GeoLibre's in-browser tool execution",
6
6
  "license": "MIT",
7
7
  "repository": {
package/tools.d.ts CHANGED
@@ -13,8 +13,10 @@ export interface ToolResult {
13
13
  export interface RunToolOptions {
14
14
  /** CLI args, e.g. ["--input=/work/dem.tif", "--output=/work/out.tif", "--units=degrees"]. */
15
15
  args?: string[];
16
- /** Input files placed under /work, keyed by filename. */
17
- input?: Record<string, Uint8Array>;
16
+ /** Input files placed under /work, keyed by filename. Each value is the file
17
+ * bytes (Uint8Array/ArrayBuffer) or an http(s) URL string that is fetched
18
+ * (whole file, no range reads). Works for raster and vector inputs alike. */
19
+ input?: Record<string, Uint8Array | ArrayBuffer | string>;
18
20
  }
19
21
 
20
22
  /** A single parameter in a tool manifest. */
package/tools.mjs CHANGED
@@ -34,11 +34,26 @@ export async function initTools(source) {
34
34
  return _module;
35
35
  }
36
36
 
37
+ // Resolve one input value to bytes: a Uint8Array/ArrayBuffer as-is, or an
38
+ // http(s) URL string to fetch. Format-agnostic (raster or vector).
39
+ async function materializeInput(value) {
40
+ if (typeof value === "string") {
41
+ if (!/^https?:\/\//i.test(value))
42
+ throw new Error(`input string must be an http(s) URL, got: ${value}`);
43
+ // A User-Agent helps with CDNs that reject non-browser agents (browsers
44
+ // ignore this header and send their own; Node/undici honors it).
45
+ const resp = await fetch(value, { headers: { "User-Agent": "Mozilla/5.0 (geolibre-wasm)" } });
46
+ return new Uint8Array(await resp.arrayBuffer());
47
+ }
48
+ return new Uint8Array(value);
49
+ }
50
+
37
51
  async function exec(argv, inputFiles) {
38
52
  const mod = await initTools();
39
53
  const inNames = new Set(Object.keys(inputFiles));
40
- const contents = new Map(
41
- Object.entries(inputFiles).map(([k, v]) => [k, new File(new Uint8Array(v))]));
54
+ const entries = await Promise.all(
55
+ Object.entries(inputFiles).map(async ([k, v]) => [k, new File(await materializeInput(v))]));
56
+ const contents = new Map(entries);
42
57
  const work = new PreopenDirectory("/work", contents);
43
58
  const stdout = [];
44
59
  const fds = [