@versatiles/container 1.1.0 → 1.2.1

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
@@ -1,13 +1,16 @@
1
+ [![Code Coverage](https://codecov.io/gh/versatiles-org/node-versatiles/branch/main/graph/badge.svg?token=IDHAI13M0K)](https://codecov.io/gh/versatiles-org/node-versatiles)
2
+ [![GitHub Workflow Status)](https://img.shields.io/github/actions/workflow/status/versatiles-org/node-versatiles-container/ci.yml)](https://github.com/versatiles-org/node-versatiles-container/actions/workflows/ci.yml)
3
+
1
4
  A client library for [VersaTiles containers](https://github.com/versatiles-org/versatiles-spec).
2
5
 
3
6
  # Install
4
7
 
5
- `npm i versatiles`
8
+ `npm i @versatiles/container"`
6
9
 
7
10
  # Usage Example
8
11
 
9
12
  ```js
10
- import VersaTiles from 'versatiles';
13
+ import VersaTiles from '@versatiles/container"';
11
14
  import fs from 'fs';
12
15
 
13
16
  const container = new VersaTiles('https://example.org/planet.versatiles');
@@ -20,18 +23,16 @@ fs.writeFileSync('tile.' + header.tile_format, tile);
20
23
 
21
24
  <!--- This chapter is generated automatically --->
22
25
 
23
- <details>
26
+ ## Classes
24
27
 
25
- <summary><h2>Class: <code>Container</code><a id="class_container"></a></h2></summary>
28
+ ### Class: `Container`<a id="class_container"></a>
26
29
 
27
30
  The `VersaTiles` class is a wrapper around a `.versatiles` container file. It provides methods\
28
- to access tile data, metadata, and other properties within the container. <sup><a href="https://github.com/versatiles-org/node-versatiles/blob/99b1c91/versatiles-container/src/index.ts#L38">\[src]</a></sup>
29
-
30
- <details>
31
+ to access tile data, metadata, and other properties within the container. <sup><a href="https://github.com/versatiles-org/node-versatiles-container/blob/84e4c84/src/index.ts#L38">\[src]</a></sup>
31
32
 
32
- <summary><h3>Constructor: <code>new Container&#40;source, options&#41;</code></h3></summary>
33
+ #### Constructor: `new Container(source, options)`
33
34
 
34
- Constructs a new instance of the VersaTiles class. <sup><a href="https://github.com/versatiles-org/node-versatiles/blob/99b1c91/versatiles-container/src/index.ts#L61">\[src]</a></sup>
35
+ Constructs a new instance of the VersaTiles class. <sup><a href="https://github.com/versatiles-org/node-versatiles-container/blob/84e4c84/src/index.ts#L59">\[src]</a></sup>
35
36
 
36
37
  **Parameters:**
37
38
 
@@ -41,40 +42,26 @@ Constructs a new instance of the VersaTiles class. <sup><a href="https://github.
41
42
  * <code>options: [OpenOptions](#interface_openoptions)</code> (optional)\
42
43
  Optional settings that configure tile handling.
43
44
 
44
- **Returns:** <code>[Container](#class_container)</code>
45
-
46
- </details>
47
-
48
- <details>
45
+ #### Method: `getHeader()`
49
46
 
50
- <summary><h3>Method: <code>getHeader&#40;&#41;</code></h3></summary>
51
-
52
- Asynchronously retrieves the header information from the `.versatiles` container. <sup><a href="https://github.com/versatiles-org/node-versatiles/blob/99b1c91/versatiles-container/src/index.ts#L85">\[src]</a></sup>
47
+ Asynchronously retrieves the header information from the `.versatiles` container. <sup><a href="https://github.com/versatiles-org/node-versatiles-container/blob/84e4c84/src/index.ts#L81">\[src]</a></sup>
53
48
 
54
49
  **Returns:** <code>Promise<[Header](#interface_header)></code>
55
50
 
56
- </details>
57
-
58
- <details>
59
-
60
- <summary><h3>Method: <code>getMetadata&#40;&#41;</code></h3></summary>
51
+ #### Method: `getMetadata()`
61
52
 
62
53
  Asynchronously retrieves the metadata associated with the `.versatiles` container.\
63
54
  Metadata typically includes information about `vector_layers` for vector tiles.
64
- If the container does not include metadata, this method returns `null`. <sup><a href="https://github.com/versatiles-org/node-versatiles/blob/99b1c91/versatiles-container/src/index.ts#L132">\[src]</a></sup>
55
+ If the container does not include metadata, this method returns `null`. <sup><a href="https://github.com/versatiles-org/node-versatiles-container/blob/84e4c84/src/index.ts#L128">\[src]</a></sup>
65
56
 
66
57
  **Returns:** <code>Promise\<undefined | string></code>
67
58
 
68
- </details>
69
-
70
- <details>
71
-
72
- <summary><h3>Method: <code>getTile&#40;z, x, y&#41;</code></h3></summary>
59
+ #### Method: `getTile(z, x, y)`
73
60
 
74
61
  Asynchronously retrieves a specific tile's data as a Buffer. If the tile data is compressed as\
75
62
  defined in the container header, the returned Buffer will contain the compressed data.
76
63
  To obtain uncompressed data, use the `getTileUncompressed` method.
77
- If the specified tile does not exist, the method returns `null`. <sup><a href="https://github.com/versatiles-org/node-versatiles/blob/99b1c91/versatiles-container/src/index.ts#L159">\[src]</a></sup>
64
+ If the specified tile does not exist, the method returns `null`. <sup><a href="https://github.com/versatiles-org/node-versatiles-container/blob/84e4c84/src/index.ts#L155">\[src]</a></sup>
78
65
 
79
66
  **Parameters:**
80
67
 
@@ -87,16 +74,12 @@ If the specified tile does not exist, the method returns `null`. <sup><a href="h
87
74
 
88
75
  **Returns:** <code>Promise\<null | Buffer></code>
89
76
 
90
- </details>
91
-
92
- <details>
93
-
94
- <summary><h3>Method: <code>getTileUncompressed&#40;z, x, y&#41;</code></h3></summary>
77
+ #### Method: `getTileUncompressed(z, x, y)`
95
78
 
96
79
  Asynchronously retrieves a specific tile's uncompressed data as a Buffer. This method first\
97
80
  retrieves the compressed tile data using `getTile` and then decompresses it based on the
98
81
  compression setting in the container header.
99
- If the specified tile does not exist, the method returns `null`. <sup><a href="https://github.com/versatiles-org/node-versatiles/blob/99b1c91/versatiles-container/src/index.ts#L207">\[src]</a></sup>
82
+ If the specified tile does not exist, the method returns `null`. <sup><a href="https://github.com/versatiles-org/node-versatiles-container/blob/84e4c84/src/index.ts#L203">\[src]</a></sup>
100
83
 
101
84
  **Parameters:**
102
85
 
@@ -109,86 +92,48 @@ If the specified tile does not exist, the method returns `null`. <sup><a href="h
109
92
 
110
93
  **Returns:** <code>Promise\<null | Buffer></code>
111
94
 
112
- </details>
113
-
114
- </details>
115
-
116
- <details>
117
-
118
- <summary><h2>Interface: <code>Header</code><a id="interface_header"></a></h2></summary>
119
-
120
- Interface for the metadata header of a `*.Versatiles` container. <sup><a href="https://github.com/versatiles-org/node-versatiles/blob/99b1c91/versatiles-container/src/interfaces.ts#L57">\[src]</a></sup>
121
-
122
- * <code>magic: string</code>\
123
- Identifier for the container format, usually "versatiles\_v02".
124
- * <code>version: string</code>\
125
- Version of the container format, typically "v02".
126
- * <code>tileFormat: [Format](#type_format)</code>\
127
- The format used for storing tiles.
128
- * <code>tileMime: string</code>\
129
- The MIME type of the tiles.
130
- * <code>tileCompression: [Compression](#type_compression)</code>\
131
- The type of compression applied to tiles.
132
- * <code>zoomMin: number</code>\
133
- The minimum zoom level.
134
- * <code>zoomMax: number</code>\
135
- The maximum zoom level.
136
- * <code>bbox: \[number, number, number, number]</code>\
137
- Bounding box coordinates as \[lon\_min, lat\_min, lon\_max, lat\_max].
138
- * <code>metaOffset: number</code>\
139
- The byte offset for metadata within the container.
140
- * <code>metaLength: number</code>\
141
- The byte size of the metadata. A value of 0 means no metadata.
142
- * <code>blockIndexOffset: number</code>\
143
- The byte offset for the block index within the container.
144
- * <code>blockIndexLength: number</code>\
145
- The byte size of the block index. A value of 0 indicates no tiles in the container.
146
-
147
- </details>
148
-
149
- <details>
150
-
151
- <summary><h2>Interface: <code>OpenOptions</code><a id="interface_openoptions"></a></h2></summary>
152
-
153
- Interface for defining the options available for reading a container. <sup><a href="https://github.com/versatiles-org/node-versatiles/blob/99b1c91/versatiles-container/src/interfaces.ts#L125">\[src]</a></sup>
154
-
155
- * <code>tms: boolean</code>\
156
- If set to true, uses the [TMS (Tile Map Service) tile ordering](https://wiki.openstreetmap.org/wiki/TMS) where y=0 is the southernmost point.
95
+ ## Interfaces
96
+
97
+ ### Interface: `Header`<a id="interface_header"></a>
98
+
99
+ ```typescript
100
+ interface {
101
+ bbox: [number, number, number, number];
102
+ blockIndexLength: number;
103
+ blockIndexOffset: number;
104
+ magic: string;
105
+ metaLength: number;
106
+ metaOffset: number;
107
+ tileCompression: [Compression](#type_compression);
108
+ tileFormat: [Format](#type_format);
109
+ tileMime: string;
110
+ version: string;
111
+ zoomMax: number;
112
+ zoomMin: number;
113
+ }
114
+ ```
157
115
 
158
- </details>
116
+ ### Interface: `OpenOptions`<a id="interface_openoptions"></a>
159
117
 
160
- <details>
118
+ ```typescript
119
+ interface {
120
+ tms: boolean;
121
+ }
122
+ ```
161
123
 
162
- <summary><h2>Type: <code>Compression</code><a id="type_compression"></a></h2></summary>
124
+ ## Type Aliases
163
125
 
164
- Supported compression.\
165
- `null` signifies that the data is uncompressed. <sup><a href="https://github.com/versatiles-org/node-versatiles/blob/99b1c91/versatiles-container/src/interfaces.ts#L5">\[src]</a></sup>
126
+ ### Type: `Compression`<a id="type_compression"></a>
166
127
 
167
128
  **Type:** <code>"br" | "gzip" | "raw"</code>
168
129
 
169
- </details>
170
-
171
- <details>
172
-
173
- <summary><h2>Type: <code>Format</code><a id="type_format"></a></h2></summary>
174
-
175
- Supported tile formats. <sup><a href="https://github.com/versatiles-org/node-versatiles/blob/99b1c91/versatiles-container/src/interfaces.ts#L11">\[src]</a></sup>
176
-
177
- **Type:** <code>"avif" | "bin" | "geojson" | "jpeg" | "json" | "pbf" | "png" | "svg" | "topojson" | "webp"</code>
178
-
179
- </details>
180
-
181
- <details>
182
-
183
- <summary><h2>Type: <code>Reader</code><a id="type_reader"></a></h2></summary>
184
-
185
- Type definition for reading content from a VersaTiles container.
130
+ ### Type: `Format`<a id="type_format"></a>
186
131
 
187
- This is useful for implementing new container readers, e.g. reading over other network protocols. <sup><a href="https://github.com/versatiles-org/node-versatiles/blob/99b1c91/versatiles-container/src/interfaces.ts#L37">\[src]</a></sup>
132
+ **Type:** <code>"avif" | "bin" | "geojson" | "jpg" | "json" | "pbf" | "png" | "svg" | "topojson" | "webp"</code>
188
133
 
189
- **Type:** <code>(position: number, length: number) => Promise<Buffer></code>
134
+ ### Type: `Reader`<a id="type_reader"></a>
190
135
 
191
- </details>
136
+ **Type:** <code>(position: number, length: number) => Promise\<Buffer></code>
192
137
 
193
138
  # License
194
139
 
package/dist/index.d.ts CHANGED
@@ -1,6 +1,6 @@
1
1
  /// <reference types="node" resolution-mode="require"/>
2
- import type { Block, Header, OpenOptions, Reader, TileIndex } from './interfaces.js';
3
- export type { Compression, Format, Header, OpenOptions, Reader } from './interfaces.js';
2
+ import type { Block, Header, OpenOptions, Reader, TileIndex } from './lib/interfaces.js';
3
+ export type { Compression, Format, Header, OpenOptions, Reader } from './lib/interfaces.js';
4
4
  /**
5
5
  * The `VersaTiles` class is a wrapper around a `.versatiles` container file. It provides methods
6
6
  * to access tile data, metadata, and other properties within the container.
package/dist/index.js CHANGED
@@ -1,12 +1,12 @@
1
- import HttpReader from './reader_http.js';
2
- import FileReader from './reader_file.js';
3
- import { decompress } from './decompress.js';
1
+ import HttpReader from './lib/reader_http.js';
2
+ import FileReader from './lib/reader_file.js';
3
+ import { decompress } from './lib/decompress.js';
4
4
  const FORMATS = {
5
- 'c01': ['png', 'jpeg', 'webp', null, null, null, null, null, null, null, null, null, null, null, null, null, 'pbf'],
6
- 'v01': ['png', 'jpeg', 'webp', 'pbf'],
5
+ 'c01': ['png', 'jpg', 'webp', null, null, null, null, null, null, null, null, null, null, null, null, null, 'pbf'],
6
+ 'v01': ['png', 'jpg', 'webp', 'pbf'],
7
7
  'v02': [
8
8
  'bin', null, null, null, null, null, null, null, null, null, null, null, null, null, null, null,
9
- 'png', 'jpeg', 'webp', 'avif', 'svg', null, null, null, null, null, null, null, null, null, null, null,
9
+ 'png', 'jpg', 'webp', 'avif', 'svg', null, null, null, null, null, null, null, null, null, null, null,
10
10
  'pbf', 'geojson', 'topojson', 'json',
11
11
  ],
12
12
  };
@@ -15,7 +15,7 @@ const MIMETYPES = {
15
15
  'avif': 'image/avif',
16
16
  'bin': 'application/octet-stream',
17
17
  'geojson': 'application/geo+json; charset=utf-8',
18
- 'jpeg': 'image/jpeg',
18
+ 'jpg': 'image/jpeg',
19
19
  'json': 'application/json; charset=utf-8',
20
20
  'pbf': 'application/x-protobuf',
21
21
  'png': 'image/png',
@@ -32,7 +32,6 @@ export class Container {
32
32
  tms: false,
33
33
  };
34
34
  #reader;
35
- #decompress;
36
35
  #header;
37
36
  #metadata;
38
37
  #blockIndex;
@@ -61,7 +60,6 @@ export class Container {
61
60
  else {
62
61
  throw new Error('source must be a string or a Reader');
63
62
  }
64
- this.#decompress = decompress;
65
63
  }
66
64
  /**
67
65
  * Asynchronously retrieves the header information from the `.versatiles` container.
@@ -119,7 +117,7 @@ export class Container {
119
117
  }
120
118
  else {
121
119
  let buffer = await this.read(header.metaOffset, header.metaLength);
122
- buffer = await this.#decompress(buffer, header.tileCompression);
120
+ buffer = await decompress(buffer, header.tileCompression);
123
121
  this.#metadata = buffer.toString();
124
122
  }
125
123
  return this.#metadata;
@@ -183,7 +181,7 @@ export class Container {
183
181
  if (!tile)
184
182
  return null;
185
183
  const header = await this.getHeader();
186
- return this.#decompress(tile, header.tileCompression);
184
+ return decompress(tile, header.tileCompression);
187
185
  }
188
186
  /**
189
187
  * Asynchronously retrieves a mapping of tile block indices. The map's keys are formatted as "{z},{x},{y}".
@@ -198,7 +196,7 @@ export class Container {
198
196
  const header = await this.getHeader();
199
197
  // read block_index buffer
200
198
  let data = await this.read(header.blockIndexOffset, header.blockIndexLength);
201
- data = await this.#decompress(data, 'br');
199
+ data = await decompress(data, 'br');
202
200
  // read index from buffer
203
201
  const blocks = [];
204
202
  switch (header.version) {
@@ -257,7 +255,7 @@ export class Container {
257
255
  if (block.tileIndex)
258
256
  return block.tileIndex;
259
257
  let buffer = await this.read(block.tileIndexOffset, block.tileIndexLength);
260
- buffer = await this.#decompress(buffer, 'br');
258
+ buffer = await decompress(buffer, 'br');
261
259
  const offsets = new Float64Array(block.tileCount);
262
260
  const lengths = new Float64Array(block.tileCount);
263
261
  for (let i = 0; i < block.tileCount; i++) {
@@ -7,7 +7,7 @@ export type Compression = 'br' | 'gzip' | 'raw';
7
7
  /**
8
8
  * Supported tile formats.
9
9
  */
10
- export type Format = 'avif' | 'bin' | 'geojson' | 'jpeg' | 'json' | 'pbf' | 'png' | 'svg' | 'topojson' | 'webp';
10
+ export type Format = 'avif' | 'bin' | 'geojson' | 'jpg' | 'json' | 'pbf' | 'png' | 'svg' | 'topojson' | 'webp';
11
11
  /**
12
12
  * Type definition for a function that decompresses data.
13
13
  *
package/package.json CHANGED
@@ -1,14 +1,17 @@
1
1
  {
2
2
  "name": "@versatiles/container",
3
- "version": "1.1.0",
3
+ "version": "1.2.1",
4
4
  "description": "A client library for reading VersaTiles containers",
5
5
  "scripts": {
6
6
  "build": "rm -rf dist && tsc -p tsconfig.build.json",
7
- "check": "npm run lint && npm run test && npm run build",
7
+ "check": "npm run lint && npm run build && npm run test",
8
8
  "doc": "npx vrt ts2md src/index.ts tsconfig.build.json | npx vrt insertmd README.md '# API' true",
9
9
  "lint": "eslint . --color",
10
- "prepublish": "npm run build && npm run doc",
11
- "test": "cd ..; NODE_OPTIONS=--experimental-vm-modules jest --testPathPattern versatiles-container"
10
+ "prepack": "npm run build && npm run doc",
11
+ "release": "npx vrt release-npm",
12
+ "test-coverage": "NODE_OPTIONS=--experimental-vm-modules jest --coverage",
13
+ "test": "NODE_OPTIONS=--experimental-vm-modules jest",
14
+ "upgrade": "npm-check-updates -u && rm -f package-lock.json; rm -rf node_modules; npm i && npm update"
12
15
  },
13
16
  "files": [
14
17
  "dist/**/*.js",
@@ -16,9 +19,9 @@
16
19
  ],
17
20
  "repository": {
18
21
  "type": "git",
19
- "url": "git+https://github.com/versatiles-org/node-versatiles.git"
22
+ "url": "git+https://github.com/versatiles-org/node-versatiles-container.git"
20
23
  },
21
- "homepage": "https://github.com/versatiles-org/node-versatiles/blob/main/versatiles-container/README.md",
24
+ "homepage": "https://github.com/versatiles-org/node-versatiles-container/blob/main/versatiles-container/README.md",
22
25
  "main": "dist/index.js",
23
26
  "types": "dist/index.d.ts",
24
27
  "type": "module",
@@ -46,9 +49,17 @@
46
49
  "versatiles"
47
50
  ],
48
51
  "devDependencies": {
49
- "@types/node": "^20.9.1",
50
- "tsx": "^4.1.3",
51
- "typescript": "^5.2.2",
52
- "@versatiles/release-tool": "^1.0.0"
52
+ "@types/jest": "^29.5.12",
53
+ "@types/node": "^20.11.20",
54
+ "@typescript-eslint/eslint-plugin": "^7.0.2",
55
+ "@typescript-eslint/parser": "^7.0.2",
56
+ "@versatiles/release-tool": "^1.2.2",
57
+ "eslint": "^8.57.0",
58
+ "jest": "^29.7.0",
59
+ "npm-check-updates": "^16.14.15",
60
+ "ts-jest": "^29.1.2",
61
+ "ts-node": "^10.9.2",
62
+ "tsx": "^4.7.1",
63
+ "typescript": "^5.3.3"
53
64
  }
54
- }
65
+ }
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes