@versatiles/versatiles-rs 3.0.2 → 3.0.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/README.md CHANGED
@@ -10,6 +10,7 @@ Node.js bindings for [VersaTiles](https://github.com/versatiles-org/versatiles-r
10
10
  - 📊 **Metadata Access** - Read TileJSON and inspect container details
11
11
  - 🌍 **Coordinate Utils** - Convert between tile and geographic coordinates
12
12
  - ⚡ **Async API** - Non-blocking operations with Promise-based interface
13
+ - 📦 **Dual Format** - Supports both ESM and CommonJS
13
14
 
14
15
  ## Installation
15
16
 
@@ -23,16 +24,16 @@ Pre-built binaries are available for:
23
24
 
24
25
  - macOS (arm64, x64)
25
26
  - Linux (x64, arm64, musl)
26
- - Windows (x64)
27
+ - Windows (x64, arm64)
27
28
 
28
29
  ## Quick Start
29
30
 
30
31
  ### Convert Tiles
31
32
 
32
33
  ```javascript
33
- const { convertTiles } = require('@versatiles/versatiles-rs');
34
+ import { convert } from '@versatiles/versatiles-rs';
34
35
 
35
- await convertTiles('input.mbtiles', 'output.versatiles', {
36
+ await convert('input.mbtiles', 'output.versatiles', {
36
37
  minZoom: 0,
37
38
  maxZoom: 14,
38
39
  bbox: [-180, -85, 180, 85],
@@ -43,10 +44,10 @@ await convertTiles('input.mbtiles', 'output.versatiles', {
43
44
  ### Serve Tiles
44
45
 
45
46
  ```javascript
46
- const { TileServer } = require('@versatiles/versatiles-rs');
47
+ import { TileServer } from '@versatiles/versatiles-rs';
47
48
 
48
49
  const server = new TileServer({ port: 8080 });
49
- await server.addTileSource('osm', 'tiles.mbtiles');
50
+ await server.addTileSourceFromPath('osm', 'tiles.mbtiles');
50
51
  await server.start();
51
52
 
52
53
  console.log(`Server running at http://localhost:${await server.port}`);
@@ -55,40 +56,44 @@ console.log(`Server running at http://localhost:${await server.port}`);
55
56
  ### Read Tiles
56
57
 
57
58
  ```javascript
58
- const { ContainerReader } = require('@versatiles/versatiles-rs');
59
+ import { TileSource } from '@versatiles/versatiles-rs';
59
60
 
60
- const reader = await ContainerReader.open('tiles.mbtiles');
61
+ const source = await TileSource.open('tiles.mbtiles');
61
62
 
62
63
  // Get a single tile
63
- const tile = await reader.getTile(5, 16, 10);
64
+ const tile = await source.getTile(5, 16, 10);
64
65
  if (tile) {
65
66
  console.log('Tile size:', tile.length, 'bytes');
66
67
  }
67
68
 
68
69
  // Get metadata
69
- const tileJSON = JSON.parse(await reader.tileJSON);
70
- console.log('Format:', tileJSON.tile_format);
70
+ const metadata = source.metadata();
71
+ console.log('Format:', metadata.tileFormat);
72
+ console.log('Zoom levels:', metadata.minZoom, '-', metadata.maxZoom);
71
73
 
72
- const params = await reader.parameters;
73
- console.log('Zoom levels:', params.minZoom, '-', params.maxZoom);
74
+ // Get TileJSON
75
+ const tileJSON = source.tileJson();
76
+ console.log('Bounds:', tileJSON.bounds);
74
77
  ```
75
78
 
76
79
  ### Probe Container
77
80
 
78
81
  ```javascript
79
- const { probeTiles } = require('@versatiles/versatiles-rs');
82
+ import { TileSource } from '@versatiles/versatiles-rs';
80
83
 
81
- const info = await probeTiles('tiles.mbtiles');
82
- console.log('Container:', info.containerName);
83
- console.log('Source:', info.sourceName);
84
- console.log('Format:', info.parameters.tileFormat);
85
- console.log('Compression:', info.parameters.tileCompression);
84
+ const source = await TileSource.open('tiles.mbtiles');
85
+ const sourceType = source.sourceType();
86
+ const metadata = source.metadata();
87
+
88
+ console.log('Type:', sourceType.kind);
89
+ console.log('Format:', metadata.tileFormat);
90
+ console.log('Compression:', metadata.tileCompression);
86
91
  ```
87
92
 
88
93
  ### Coordinate Conversion
89
94
 
90
95
  ```javascript
91
- const { TileCoord } = require('@versatiles/versatiles-rs');
96
+ import { TileCoord } from '@versatiles/versatiles-rs';
92
97
 
93
98
  // Geographic to tile coordinates
94
99
  const coord = TileCoord.fromGeo(13.4, 52.5, 10);
@@ -104,9 +109,17 @@ const bbox = tile.toGeoBbox();
104
109
  console.log('BBox:', bbox); // [west, south, east, north]
105
110
  ```
106
111
 
112
+ ### CommonJS Support
113
+
114
+ The package also supports CommonJS:
115
+
116
+ ```javascript
117
+ const { convert, TileSource, TileServer, TileCoord } = require('@versatiles/versatiles-rs');
118
+ ```
119
+
107
120
  ## API Reference
108
121
 
109
- ### `convertTiles(input, output, options?)`
122
+ ### `convert(input, output, options?, onProgress?, onMessage?)`
110
123
 
111
124
  Convert tiles from one format to another.
112
125
 
@@ -114,7 +127,7 @@ Convert tiles from one format to another.
114
127
 
115
128
  - `input` (string): Input file path (.versatiles, .mbtiles, .pmtiles, .tar, directory)
116
129
  - `output` (string): Output file path
117
- - `options` (object, optional):
130
+ - `options` (ConvertOptions, optional):
118
131
  - `minZoom` (number): Minimum zoom level
119
132
  - `maxZoom` (number): Maximum zoom level
120
133
  - `bbox` (array): Bounding box `[west, south, east, north]`
@@ -122,42 +135,35 @@ Convert tiles from one format to another.
122
135
  - `compress` (string): Compression `"gzip"`, `"brotli"`, or `"uncompressed"`
123
136
  - `flipY` (boolean): Flip tiles vertically
124
137
  - `swapXy` (boolean): Swap x and y coordinates
138
+ - `onProgress` (function, optional): Progress callback `(data: ProgressData) => void`
139
+ - `onMessage` (function, optional): Message callback `(data: MessageData) => void`
125
140
 
126
141
  **Returns:** `Promise<void>`
127
142
 
128
- ### `probeTiles(path, depth?)`
143
+ ### `class TileSource`
129
144
 
130
- Inspect a tile container.
145
+ #### `TileSource.open(path)`
131
146
 
132
- **Parameters:**
133
-
134
- - `path` (string): Container file path
135
- - `depth` (string, optional): Probe depth - currently not implemented
147
+ Open a tile container.
136
148
 
137
- **Returns:** `Promise<ProbeResult>`
149
+ **Parameters:**
138
150
 
139
- ```typescript
140
- interface ProbeResult {
141
- sourceName: string;
142
- containerName: string;
143
- tileJson: string;
144
- parameters: ReaderParameters;
145
- }
146
- ```
151
+ - `path` (string): File path or URL
147
152
 
148
- ### `class ContainerReader`
153
+ **Returns:** `Promise<TileSource>`
149
154
 
150
- #### `ContainerReader.open(path)`
155
+ #### `TileSource.fromVpl(vpl, basePath?)`
151
156
 
152
- Open a tile container.
157
+ Create a tile source from VPL (VersaTiles Pipeline Language).
153
158
 
154
159
  **Parameters:**
155
160
 
156
- - `path` (string): File path or URL
161
+ - `vpl` (string): VPL query string
162
+ - `basePath` (string, optional): Base path for resolving relative paths
157
163
 
158
- **Returns:** `Promise<ContainerReader>`
164
+ **Returns:** `Promise<TileSource>`
159
165
 
160
- #### `reader.getTile(z, x, y)`
166
+ #### `source.getTile(z, x, y)`
161
167
 
162
168
  Get a single tile.
163
169
 
@@ -169,20 +175,32 @@ Get a single tile.
169
175
 
170
176
  **Returns:** `Promise<Buffer | null>`
171
177
 
172
- #### `reader.tileJSON`
178
+ #### `source.tileJson()`
179
+
180
+ Get TileJSON metadata.
173
181
 
174
- Get TileJSON metadata (getter).
182
+ **Returns:** `TileJSON`
175
183
 
176
- **Returns:** `Promise<string>`
184
+ ```typescript
185
+ interface TileJSON {
186
+ tilejson: string;
187
+ tiles?: string[];
188
+ vector_layers?: VectorLayer[];
189
+ attribution?: string;
190
+ bounds?: [number, number, number, number];
191
+ center?: [number, number, number];
192
+ // ... and more
193
+ }
194
+ ```
177
195
 
178
- #### `reader.parameters`
196
+ #### `source.metadata()`
179
197
 
180
- Get reader parameters (getter).
198
+ Get source metadata.
181
199
 
182
- **Returns:** `Promise<ReaderParameters>`
200
+ **Returns:** `SourceMetadata`
183
201
 
184
202
  ```typescript
185
- interface ReaderParameters {
203
+ interface SourceMetadata {
186
204
  tileFormat: string;
187
205
  tileCompression: string;
188
206
  minZoom: number;
@@ -190,39 +208,25 @@ interface ReaderParameters {
190
208
  }
191
209
  ```
192
210
 
193
- #### `reader.sourceName`
194
-
195
- Get source name (getter).
196
-
197
- **Returns:** `Promise<string>`
198
-
199
- #### `reader.containerName`
211
+ #### `source.sourceType()`
200
212
 
201
- Get container type (getter).
213
+ Get source type information.
202
214
 
203
- **Returns:** `Promise<string>`
215
+ **Returns:** `SourceType`
204
216
 
205
- #### `reader.convertTo(output, options?)`
217
+ #### `source.convertTo(output, options?, onProgress?, onMessage?)`
206
218
 
207
- Convert this container to another format.
219
+ Convert this source to another format.
208
220
 
209
221
  **Parameters:**
210
222
 
211
223
  - `output` (string): Output file path
212
- - `options` (ConvertOptions, optional): Same as `convertTiles`
224
+ - `options` (ConvertOptions, optional): Same as `convert()`
225
+ - `onProgress` (function, optional): Progress callback
226
+ - `onMessage` (function, optional): Message callback
213
227
 
214
228
  **Returns:** `Promise<void>`
215
229
 
216
- #### `reader.probe(depth?)`
217
-
218
- Probe container details.
219
-
220
- **Parameters:**
221
-
222
- - `depth` (string, optional): Probe depth
223
-
224
- **Returns:** `Promise<ProbeResult>`
225
-
226
230
  ### `class TileServer`
227
231
 
228
232
  #### `new TileServer(options?)`
@@ -236,9 +240,9 @@ Create a new tile server.
236
240
  - `port` (number): Port number (default: `8080`)
237
241
  - `minimalRecompression` (boolean): Use minimal recompression
238
242
 
239
- #### `server.addTileSource(name, path)`
243
+ #### `server.addTileSourceFromPath(name, path)`
240
244
 
241
- Add a tile source.
245
+ Add a tile source from a file path.
242
246
 
243
247
  **Parameters:**
244
248
 
@@ -247,6 +251,27 @@ Add a tile source.
247
251
 
248
252
  **Returns:** `Promise<void>`
249
253
 
254
+ #### `server.addTileSource(name, source)`
255
+
256
+ Add a tile source from a TileSource instance.
257
+
258
+ **Parameters:**
259
+
260
+ - `name` (string): Source name
261
+ - `source` (TileSource): TileSource instance
262
+
263
+ **Returns:** `Promise<void>`
264
+
265
+ #### `server.removeTileSource(name)`
266
+
267
+ Remove a tile source.
268
+
269
+ **Parameters:**
270
+
271
+ - `name` (string): Source name to remove
272
+
273
+ **Returns:** `Promise<void>`
274
+
250
275
  #### `server.addStaticSource(path, urlPrefix?)`
251
276
 
252
277
  Add static file source.
@@ -336,10 +361,17 @@ Get JSON representation.
336
361
 
337
362
  See the [examples](./examples) directory for more usage examples:
338
363
 
339
- - [convert.js](./examples/convert.js) - Format conversion
340
- - [probe.js](./examples/probe.js) - Container inspection
341
- - [serve.js](./examples/serve.js) - Tile server
342
- - [read-tiles.js](./examples/read-tiles.js) - Reading tiles
364
+ - [convert.ts](./examples/convert.ts) - Format conversion with various options
365
+ - [convert-with-progress.ts](./examples/convert-with-progress.ts) - Conversion with progress monitoring
366
+ - [probe.ts](./examples/probe.ts) - Container inspection
367
+ - [serve.ts](./examples/serve.ts) - HTTP tile server
368
+ - [read-tiles.ts](./examples/read-tiles.ts) - Reading tiles and coordinate conversion
369
+
370
+ All examples use TypeScript and can be run with:
371
+
372
+ ```bash
373
+ npx tsx examples/<filename>.ts
374
+ ```
343
375
 
344
376
  ## Development
345
377