fast-osmpbf-js 0.1.2 → 0.1.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
@@ -55,7 +55,7 @@ import { JsElementBlock, OsmReader, getTags } from "fast-osmpbf-js"
55
55
 
56
56
  const reader = new OsmReader("./scripts/osm-data/germany-latest.osm.pbf")
57
57
  const relevantTags = ["addr:city", "addr:postcode", "addr:street", "addr:housenumber"]
58
- const stream = reader.streamBlocks(relevantTags)
58
+ const stream = reader.streamBlocks(null, relevantTags)
59
59
 
60
60
  async function main() {
61
61
  let totalItems = 0
package/index.d.ts ADDED
@@ -0,0 +1,28 @@
1
+ /* auto-generated by NAPI-RS */
2
+ /* eslint-disable */
3
+ export declare class AsyncBlockIterator {
4
+ next(): Promise<JsElementBlock | null>
5
+ }
6
+
7
+ export declare class OsmReader {
8
+ constructor(path: string)
9
+ streamBlocks(elementFilter?: JsElementFilter | undefined | null, tagFilter?: Array<string> | undefined | null): AsyncBlockIterator
10
+ }
11
+
12
+ export interface JsElementBlock {
13
+ ids: BigInt64Array
14
+ elementType: string
15
+ nodeIds?: [BigInt64Array, Uint32Array]
16
+ latitudes?: Float64Array
17
+ longitudes?: Float64Array
18
+ relationMembers?: [BigInt64Array, Uint8Array, Int32Array, Uint32Array]
19
+ denseTags?: [Uint32Array, Uint32Array, Uint32Array]
20
+ tags?: [Uint32Array, Uint32Array, Uint32Array]
21
+ stringTable: Array<string>
22
+ }
23
+
24
+ export interface JsElementFilter {
25
+ nodes: boolean
26
+ ways: boolean
27
+ relations: boolean
28
+ }
package/index.js CHANGED
@@ -1,18 +1,45 @@
1
1
  import { createRequire } from "module"
2
+ import { platform, arch } from "process"
3
+ import { join, dirname } from "path"
4
+ import { fileURLToPath } from "url"
5
+
2
6
  const require = createRequire(import.meta.url)
3
- const native = require("./index.node")
7
+ const __dirname = dirname(fileURLToPath(import.meta.url))
8
+
9
+ // Map Node.js platform/arch to your binding folder names
10
+ function getBindingPath() {
11
+ const platformMap = {
12
+ darwin: "apple-darwin",
13
+ win32: "pc-windows-msvc",
14
+ linux: "unknown-linux-gnu",
15
+ }
16
+
17
+ const archMap = {
18
+ x64: "x86_64",
19
+ arm64: "aarch64",
20
+ }
21
+
22
+ const mappedPlatform = platformMap[platform]
23
+ const mappedArch = archMap[arch]
24
+
25
+ if (!mappedPlatform || !mappedArch) {
26
+ throw new Error(`Unsupported platform: ${platform}-${arch}`)
27
+ }
28
+
29
+ const bindingFolder = `bindings-${mappedArch}-${mappedPlatform}`
30
+ return join(__dirname, bindingFolder, "index.node")
31
+ }
32
+
33
+ const native = require(getBindingPath())
4
34
 
5
35
  export function getTags(block, index) {
6
36
  let tags = block.denseTags || block.tags
7
-
8
37
  const start = tags[2][index]
9
38
  const end = tags[2][index + 1]
10
39
  const result = []
11
-
12
40
  for (let i = start; i < end; i++) {
13
41
  result.push([block.stringTable[tags[0][i]], block.stringTable[tags[1][i]]])
14
42
  }
15
-
16
43
  return result
17
44
  }
18
45
 
@@ -20,15 +47,12 @@ export function getNodeIds(block, index) {
20
47
  if (!block.nodeIds) {
21
48
  return []
22
49
  }
23
-
24
50
  const result = []
25
51
  const start = block.nodeIds[1][index]
26
52
  const end = block.nodeIds[1][index + 1]
27
-
28
53
  for (let i = start; i < end; i++) {
29
54
  result.push(block.nodeIds[0][i])
30
55
  }
31
-
32
56
  return result
33
57
  }
34
58
 
@@ -36,11 +60,9 @@ export function getRelationMembers(block, index) {
36
60
  if (!block.relationMembers) {
37
61
  return []
38
62
  }
39
-
40
63
  const result = []
41
64
  const start = block.relationMembers[3][index]
42
65
  const end = block.relationMembers[3][index + 1]
43
-
44
66
  for (let i = start; i < end; i++) {
45
67
  result.push({
46
68
  id: block.relationMembers[0][i],
@@ -48,7 +70,6 @@ export function getRelationMembers(block, index) {
48
70
  role: block.stringTable[block.relationMembers[2][i]],
49
71
  })
50
72
  }
51
-
52
73
  return result
53
74
  }
54
75
 
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "fast-osmpbf-js",
3
3
  "type": "module",
4
- "version": "0.1.2",
4
+ "version": "0.1.3",
5
5
  "description": "Node.js bindings for the fast-osmpbf Rust library",
6
6
  "author": {
7
7
  "name": "Daniel Steblin",
@@ -12,8 +12,8 @@
12
12
  "files": [
13
13
  "index.js",
14
14
  "wrapper.d.ts",
15
- "index.node",
16
- "index.d.ts"
15
+ "index.d.ts",
16
+ "bindings-*/*.node"
17
17
  ],
18
18
  "scripts": {
19
19
  "artifacts": "napi artifacts",