@osmix/pbf 0.0.6 → 0.0.8
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/CHANGELOG.md +12 -0
- package/dist/utils.d.ts +24 -0
- package/dist/utils.d.ts.map +1 -1
- package/dist/utils.js +46 -0
- package/dist/utils.js.map +1 -1
- package/package.json +8 -31
- package/src/utils.ts +86 -0
- package/test/read.bench.ts +2 -2
- package/test/read.test.ts +2 -2
- package/test/write.test.ts +2 -2
- package/test/utils.ts +0 -65
package/CHANGELOG.md
CHANGED
package/dist/utils.d.ts
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import type { PbfFixture } from "@osmix/shared/fixtures";
|
|
2
|
+
import type { OsmPbfBlock, OsmPbfGroup, OsmPbfHeaderBlock } from "../src/proto/osmformat";
|
|
1
3
|
export type AsyncGeneratorValue<T> = T | ReadableStream<T> | AsyncGenerator<T> | Promise<T> | Promise<ReadableStream<T>> | Promise<AsyncGenerator<T>>;
|
|
2
4
|
/**
|
|
3
5
|
* Normalizes values, streams, and iterables into a unified async generator interface.
|
|
@@ -19,4 +21,26 @@ export declare function concatUint8(...parts: Uint8Array[]): Uint8Array;
|
|
|
19
21
|
* Encodes a 32-bit big-endian unsigned integer as a four-byte buffer.
|
|
20
22
|
*/
|
|
21
23
|
export declare function uint32BE(n: number): Uint8Array;
|
|
24
|
+
export declare function testOsmPbfReader(osm: {
|
|
25
|
+
header: OsmPbfHeaderBlock;
|
|
26
|
+
blocks: AsyncGenerator<OsmPbfBlock>;
|
|
27
|
+
}, pbf: PbfFixture): Promise<{
|
|
28
|
+
nodes: number;
|
|
29
|
+
ways: number;
|
|
30
|
+
relations: number;
|
|
31
|
+
node0: number;
|
|
32
|
+
way0: number;
|
|
33
|
+
relation0: number;
|
|
34
|
+
}>;
|
|
35
|
+
export declare function createOsmEntityCounter(): {
|
|
36
|
+
onGroup: (group: OsmPbfGroup) => void;
|
|
37
|
+
count: {
|
|
38
|
+
nodes: number;
|
|
39
|
+
ways: number;
|
|
40
|
+
relations: number;
|
|
41
|
+
node0: number;
|
|
42
|
+
way0: number;
|
|
43
|
+
relation0: number;
|
|
44
|
+
};
|
|
45
|
+
};
|
|
22
46
|
//# sourceMappingURL=utils.d.ts.map
|
package/dist/utils.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../src/utils.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../src/utils.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,wBAAwB,CAAA;AAExD,OAAO,KAAK,EACX,WAAW,EACX,WAAW,EACX,iBAAiB,EACjB,MAAM,wBAAwB,CAAA;AAE/B,MAAM,MAAM,mBAAmB,CAAC,CAAC,IAC9B,CAAC,GACD,cAAc,CAAC,CAAC,CAAC,GACjB,cAAc,CAAC,CAAC,CAAC,GACjB,OAAO,CAAC,CAAC,CAAC,GACV,OAAO,CAAC,cAAc,CAAC,CAAC,CAAC,CAAC,GAC1B,OAAO,CAAC,cAAc,CAAC,CAAC,CAAC,CAAC,CAAA;AAE7B;;GAEG;AACH,wBAAuB,gBAAgB,CAAC,CAAC,EACxC,CAAC,EAAE,mBAAmB,CAAC,CAAC,CAAC,GACvB,cAAc,CAAC,CAAC,CAAC,CAuBnB;AAED;;GAEG;AACH,wBAAsB,aAAa,CAClC,IAAI,EAAE,UAAU,CAAC,WAAW,CAAC,GAC3B,OAAO,CAAC,UAAU,CAAC,WAAW,CAAC,CAAC,CAElC;AAED;;GAEG;AACH,wBAAsB,WAAW,CAChC,IAAI,EAAE,UAAU,CAAC,WAAW,CAAC,GAC3B,OAAO,CAAC,UAAU,CAAC,WAAW,CAAC,CAAC,CAElC;AAED;;GAEG;AACH,wBAAgB,WAAW,CAAC,GAAG,KAAK,EAAE,UAAU,EAAE,GAAG,UAAU,CAS9D;AAED;;GAEG;AACH,wBAAgB,QAAQ,CAAC,CAAC,EAAE,MAAM,GAAG,UAAU,CAO9C;AAED,wBAAsB,gBAAgB,CACrC,GAAG,EAAE;IACJ,MAAM,EAAE,iBAAiB,CAAA;IACzB,MAAM,EAAE,cAAc,CAAC,WAAW,CAAC,CAAA;CACnC,EACD,GAAG,EAAE,UAAU;;;;;;;GAqCf;AAED,wBAAgB,sBAAsB;qBAUb,WAAW;;;;;;;;;EAuBnC"}
|
package/dist/utils.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { assertValue as assert } from "@osmix/shared/assert";
|
|
1
2
|
import { transformBytes } from "@osmix/shared/transform-bytes";
|
|
2
3
|
/**
|
|
3
4
|
* Normalizes values, streams, and iterables into a unified async generator interface.
|
|
@@ -65,4 +66,49 @@ export function uint32BE(n) {
|
|
|
65
66
|
out[3] = n & 0xff;
|
|
66
67
|
return out;
|
|
67
68
|
}
|
|
69
|
+
export async function testOsmPbfReader(osm, pbf) {
|
|
70
|
+
assert(JSON.stringify(osm.header.bbox) === JSON.stringify(pbf.bbox), `Header bbox ${JSON.stringify(osm.header.bbox)} != ${JSON.stringify(pbf.bbox)}`);
|
|
71
|
+
const { onGroup, count } = createOsmEntityCounter();
|
|
72
|
+
for await (const block of osm.blocks)
|
|
73
|
+
for (const group of block.primitivegroup)
|
|
74
|
+
onGroup(group);
|
|
75
|
+
assert(count.nodes === pbf.nodes, `Expected nodes: ${pbf.nodes}, got: ${count.nodes}`);
|
|
76
|
+
assert(count.ways === pbf.ways, `Expected ways: ${pbf.ways}, got: ${count.ways}`);
|
|
77
|
+
assert(count.relations === pbf.relations, `Expected relations: ${pbf.relations}, got: ${count.relations}`);
|
|
78
|
+
assert(count.node0 === pbf.node0.id, `Expected node0: ${pbf.node0.id}, got: ${count.node0}`);
|
|
79
|
+
assert(count.way0 === pbf.way0, `Expected way0: ${pbf.way0}, got: ${count.way0}`);
|
|
80
|
+
assert(count.relation0 === pbf.relation0, `Expected relation0: ${pbf.relation0}, got: ${count.relation0}`);
|
|
81
|
+
return count;
|
|
82
|
+
}
|
|
83
|
+
export function createOsmEntityCounter() {
|
|
84
|
+
const count = {
|
|
85
|
+
nodes: 0,
|
|
86
|
+
ways: 0,
|
|
87
|
+
relations: 0,
|
|
88
|
+
node0: -1,
|
|
89
|
+
way0: -1,
|
|
90
|
+
relation0: -1,
|
|
91
|
+
};
|
|
92
|
+
const onGroup = (group) => {
|
|
93
|
+
if (count.node0 === -1 && group.dense?.id?.[0] != null) {
|
|
94
|
+
count.node0 = group.dense.id[0];
|
|
95
|
+
}
|
|
96
|
+
if (count.way0 === -1 && group.ways?.[0]?.id != null) {
|
|
97
|
+
count.way0 = group.ways[0].id;
|
|
98
|
+
}
|
|
99
|
+
if (count.relation0 === -1 && group.relations?.[0]?.id != null) {
|
|
100
|
+
count.relation0 = group.relations[0].id;
|
|
101
|
+
}
|
|
102
|
+
count.nodes += group.nodes?.length ?? 0;
|
|
103
|
+
if (group.dense) {
|
|
104
|
+
count.nodes += group.dense.id.length;
|
|
105
|
+
}
|
|
106
|
+
count.ways += group.ways?.length ?? 0;
|
|
107
|
+
count.relations += group.relations?.length ?? 0;
|
|
108
|
+
};
|
|
109
|
+
return {
|
|
110
|
+
onGroup,
|
|
111
|
+
count,
|
|
112
|
+
};
|
|
113
|
+
}
|
|
68
114
|
//# sourceMappingURL=utils.js.map
|
package/dist/utils.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"utils.js","sourceRoot":"","sources":["../src/utils.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,+BAA+B,CAAA;
|
|
1
|
+
{"version":3,"file":"utils.js","sourceRoot":"","sources":["../src/utils.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,IAAI,MAAM,EAAE,MAAM,sBAAsB,CAAA;AAE5D,OAAO,EAAE,cAAc,EAAE,MAAM,+BAA+B,CAAA;AAe9D;;GAEG;AACH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K;KACL,CAAA;AACF,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,51 +1,28 @@
|
|
|
1
1
|
{
|
|
2
|
-
"$schema": "https://json.schemastore.org/package",
|
|
2
|
+
"$schema": "https://json.schemastore.org/package.json",
|
|
3
3
|
"name": "@osmix/pbf",
|
|
4
4
|
"description": "A low level, modern, runtime agnostic OSM PBF parser and writer written in TypeScript.",
|
|
5
|
-
"version": "0.0.
|
|
5
|
+
"version": "0.0.8",
|
|
6
6
|
"type": "module",
|
|
7
|
-
"main": "./src/index.ts",
|
|
8
|
-
"publishConfig": {
|
|
9
|
-
"access": "public",
|
|
10
|
-
"registry": "https://registry.npmjs.org/",
|
|
11
|
-
"main": "./dist/index.js",
|
|
12
|
-
"types": "./dist/index.d.ts",
|
|
13
|
-
"exports": {
|
|
14
|
-
".": {
|
|
15
|
-
"import": "./dist/index.js",
|
|
16
|
-
"types": "./dist/index.d.ts"
|
|
17
|
-
}
|
|
18
|
-
},
|
|
19
|
-
"files": [
|
|
20
|
-
"dist",
|
|
21
|
-
"README.md",
|
|
22
|
-
"LICENSE"
|
|
23
|
-
]
|
|
24
|
-
},
|
|
25
7
|
"license": "MIT",
|
|
26
8
|
"repository": {
|
|
27
9
|
"type": "git",
|
|
28
10
|
"url": "git+https://github.com/conveyal/osmix.git"
|
|
29
11
|
},
|
|
30
|
-
"
|
|
31
|
-
"bugs": {
|
|
32
|
-
"url": "https://github.com/conveyal/osmix/issues"
|
|
33
|
-
},
|
|
34
|
-
"sideEffects": false,
|
|
12
|
+
"main": "./dist/index.js",
|
|
35
13
|
"scripts": {
|
|
36
14
|
"bench": "bun test --bench",
|
|
37
15
|
"build": "tsc -p tsconfig.build.json",
|
|
38
|
-
"prepare": "bun run build",
|
|
39
|
-
"release": "bun publish",
|
|
40
16
|
"test": "bun test",
|
|
41
17
|
"typecheck": "tsgo --noEmit"
|
|
42
18
|
},
|
|
43
19
|
"devDependencies": {
|
|
44
|
-
"@osmix/shared": "0.0.
|
|
45
|
-
"@types/bun": "^1.3.
|
|
20
|
+
"@osmix/shared": "0.0.12",
|
|
21
|
+
"@types/bun": "^1.3.9",
|
|
46
22
|
"typescript": "^5.9.0"
|
|
47
23
|
},
|
|
48
24
|
"dependencies": {
|
|
49
25
|
"pbf": "^4.0.1"
|
|
50
|
-
}
|
|
51
|
-
|
|
26
|
+
},
|
|
27
|
+
"types": "./dist/index.d.ts"
|
|
28
|
+
}
|
package/src/utils.ts
CHANGED
|
@@ -1,4 +1,11 @@
|
|
|
1
|
+
import { assertValue as assert } from "@osmix/shared/assert"
|
|
2
|
+
import type { PbfFixture } from "@osmix/shared/fixtures"
|
|
1
3
|
import { transformBytes } from "@osmix/shared/transform-bytes"
|
|
4
|
+
import type {
|
|
5
|
+
OsmPbfBlock,
|
|
6
|
+
OsmPbfGroup,
|
|
7
|
+
OsmPbfHeaderBlock,
|
|
8
|
+
} from "../src/proto/osmformat"
|
|
2
9
|
|
|
3
10
|
export type AsyncGeneratorValue<T> =
|
|
4
11
|
| T
|
|
@@ -81,3 +88,82 @@ export function uint32BE(n: number): Uint8Array {
|
|
|
81
88
|
out[3] = n & 0xff
|
|
82
89
|
return out
|
|
83
90
|
}
|
|
91
|
+
|
|
92
|
+
export async function testOsmPbfReader(
|
|
93
|
+
osm: {
|
|
94
|
+
header: OsmPbfHeaderBlock
|
|
95
|
+
blocks: AsyncGenerator<OsmPbfBlock>
|
|
96
|
+
},
|
|
97
|
+
pbf: PbfFixture,
|
|
98
|
+
) {
|
|
99
|
+
assert(
|
|
100
|
+
JSON.stringify(osm.header.bbox) === JSON.stringify(pbf.bbox),
|
|
101
|
+
`Header bbox ${JSON.stringify(osm.header.bbox)} != ${JSON.stringify(pbf.bbox)}`,
|
|
102
|
+
)
|
|
103
|
+
|
|
104
|
+
const { onGroup, count } = createOsmEntityCounter()
|
|
105
|
+
for await (const block of osm.blocks)
|
|
106
|
+
for (const group of block.primitivegroup) onGroup(group)
|
|
107
|
+
|
|
108
|
+
assert(
|
|
109
|
+
count.nodes === pbf.nodes,
|
|
110
|
+
`Expected nodes: ${pbf.nodes}, got: ${count.nodes}`,
|
|
111
|
+
)
|
|
112
|
+
assert(
|
|
113
|
+
count.ways === pbf.ways,
|
|
114
|
+
`Expected ways: ${pbf.ways}, got: ${count.ways}`,
|
|
115
|
+
)
|
|
116
|
+
assert(
|
|
117
|
+
count.relations === pbf.relations,
|
|
118
|
+
`Expected relations: ${pbf.relations}, got: ${count.relations}`,
|
|
119
|
+
)
|
|
120
|
+
assert(
|
|
121
|
+
count.node0 === pbf.node0.id,
|
|
122
|
+
`Expected node0: ${pbf.node0.id}, got: ${count.node0}`,
|
|
123
|
+
)
|
|
124
|
+
assert(
|
|
125
|
+
count.way0 === pbf.way0,
|
|
126
|
+
`Expected way0: ${pbf.way0}, got: ${count.way0}`,
|
|
127
|
+
)
|
|
128
|
+
assert(
|
|
129
|
+
count.relation0 === pbf.relation0,
|
|
130
|
+
`Expected relation0: ${pbf.relation0}, got: ${count.relation0}`,
|
|
131
|
+
)
|
|
132
|
+
|
|
133
|
+
return count
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
export function createOsmEntityCounter() {
|
|
137
|
+
const count = {
|
|
138
|
+
nodes: 0,
|
|
139
|
+
ways: 0,
|
|
140
|
+
relations: 0,
|
|
141
|
+
node0: -1,
|
|
142
|
+
way0: -1,
|
|
143
|
+
relation0: -1,
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
const onGroup = (group: OsmPbfGroup) => {
|
|
147
|
+
if (count.node0 === -1 && group.dense?.id?.[0] != null) {
|
|
148
|
+
count.node0 = group.dense.id[0]
|
|
149
|
+
}
|
|
150
|
+
if (count.way0 === -1 && group.ways?.[0]?.id != null) {
|
|
151
|
+
count.way0 = group.ways[0].id
|
|
152
|
+
}
|
|
153
|
+
if (count.relation0 === -1 && group.relations?.[0]?.id != null) {
|
|
154
|
+
count.relation0 = group.relations[0].id
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
count.nodes += group.nodes?.length ?? 0
|
|
158
|
+
if (group.dense) {
|
|
159
|
+
count.nodes += group.dense.id.length
|
|
160
|
+
}
|
|
161
|
+
count.ways += group.ways?.length ?? 0
|
|
162
|
+
count.relations += group.relations?.length ?? 0
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
return {
|
|
166
|
+
onGroup,
|
|
167
|
+
count,
|
|
168
|
+
}
|
|
169
|
+
}
|
package/test/read.bench.ts
CHANGED
|
@@ -3,7 +3,7 @@ import {
|
|
|
3
3
|
getFixtureFile,
|
|
4
4
|
getFixtureFileReadStream,
|
|
5
5
|
PBFs,
|
|
6
|
-
} from "@osmix/shared/
|
|
6
|
+
} from "@osmix/shared/fixtures"
|
|
7
7
|
|
|
8
8
|
// @ts-expect-error - bench is available at runtime but not in types
|
|
9
9
|
const { bench } = globalThis as { bench: typeof import("bun:test").test }
|
|
@@ -12,7 +12,7 @@ import {
|
|
|
12
12
|
OsmPbfBytesToBlocksTransformStream,
|
|
13
13
|
readOsmPbf,
|
|
14
14
|
} from "../src/pbf-to-blocks"
|
|
15
|
-
import { createOsmEntityCounter, testOsmPbfReader } from "
|
|
15
|
+
import { createOsmEntityCounter, testOsmPbfReader } from "../src/utils"
|
|
16
16
|
|
|
17
17
|
describe.each(Object.entries(PBFs))("%s", (_name, pbf) => {
|
|
18
18
|
beforeAll(() => getFixtureFile(pbf.url))
|
package/test/read.test.ts
CHANGED
|
@@ -3,12 +3,12 @@ import {
|
|
|
3
3
|
getFixtureFile,
|
|
4
4
|
getFixtureFileReadStream,
|
|
5
5
|
PBFs,
|
|
6
|
-
} from "@osmix/shared/
|
|
6
|
+
} from "@osmix/shared/fixtures"
|
|
7
7
|
import {
|
|
8
8
|
OsmPbfBytesToBlocksTransformStream,
|
|
9
9
|
readOsmPbf,
|
|
10
10
|
} from "../src/pbf-to-blocks"
|
|
11
|
-
import { createOsmEntityCounter, testOsmPbfReader } from "
|
|
11
|
+
import { createOsmEntityCounter, testOsmPbfReader } from "../src/utils"
|
|
12
12
|
|
|
13
13
|
describe("read", () => {
|
|
14
14
|
describe.each(Object.entries(PBFs))("%s", async (_name, pbf) => {
|
package/test/write.test.ts
CHANGED
|
@@ -6,7 +6,7 @@ import {
|
|
|
6
6
|
getFixtureFileWriteStream,
|
|
7
7
|
getFixturePath,
|
|
8
8
|
PBFs,
|
|
9
|
-
} from "@osmix/shared/
|
|
9
|
+
} from "@osmix/shared/fixtures"
|
|
10
10
|
import {
|
|
11
11
|
OsmBlocksToPbfBytesTransformStream,
|
|
12
12
|
osmBlockToPbfBlobBytes,
|
|
@@ -15,7 +15,7 @@ import {
|
|
|
15
15
|
OsmPbfBytesToBlocksTransformStream,
|
|
16
16
|
readOsmPbf,
|
|
17
17
|
} from "../src/pbf-to-blocks"
|
|
18
|
-
import { testOsmPbfReader } from "
|
|
18
|
+
import { testOsmPbfReader } from "../src/utils"
|
|
19
19
|
|
|
20
20
|
describe("write", () => {
|
|
21
21
|
describe.each(Object.entries(PBFs))("%s", (name, pbf) => {
|
package/test/utils.ts
DELETED
|
@@ -1,65 +0,0 @@
|
|
|
1
|
-
import { expect } from "bun:test"
|
|
2
|
-
import type { PbfFixture } from "@osmix/shared/test/fixtures"
|
|
3
|
-
import type {
|
|
4
|
-
OsmPbfBlock,
|
|
5
|
-
OsmPbfGroup,
|
|
6
|
-
OsmPbfHeaderBlock,
|
|
7
|
-
} from "../src/proto/osmformat"
|
|
8
|
-
|
|
9
|
-
export async function testOsmPbfReader(
|
|
10
|
-
osm: {
|
|
11
|
-
header: OsmPbfHeaderBlock
|
|
12
|
-
blocks: AsyncGenerator<OsmPbfBlock>
|
|
13
|
-
},
|
|
14
|
-
pbf: PbfFixture,
|
|
15
|
-
) {
|
|
16
|
-
expect(osm.header.bbox).toEqual(pbf.bbox)
|
|
17
|
-
|
|
18
|
-
const { onGroup, count } = createOsmEntityCounter()
|
|
19
|
-
for await (const block of osm.blocks)
|
|
20
|
-
for (const group of block.primitivegroup) onGroup(group)
|
|
21
|
-
|
|
22
|
-
expect(count.nodes).toBe(pbf.nodes)
|
|
23
|
-
expect(count.ways).toBe(pbf.ways)
|
|
24
|
-
expect(count.relations).toBe(pbf.relations)
|
|
25
|
-
expect(count.node0).toBe(pbf.node0.id)
|
|
26
|
-
expect(count.way0).toBe(pbf.way0)
|
|
27
|
-
expect(count.relation0).toBe(pbf.relation0)
|
|
28
|
-
|
|
29
|
-
return count
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
export function createOsmEntityCounter() {
|
|
33
|
-
const count = {
|
|
34
|
-
nodes: 0,
|
|
35
|
-
ways: 0,
|
|
36
|
-
relations: 0,
|
|
37
|
-
node0: -1,
|
|
38
|
-
way0: -1,
|
|
39
|
-
relation0: -1,
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
const onGroup = (group: OsmPbfGroup) => {
|
|
43
|
-
if (count.node0 === -1 && group.dense?.id?.[0] != null) {
|
|
44
|
-
count.node0 = group.dense.id[0]
|
|
45
|
-
}
|
|
46
|
-
if (count.way0 === -1 && group.ways?.[0]?.id != null) {
|
|
47
|
-
count.way0 = group.ways[0].id
|
|
48
|
-
}
|
|
49
|
-
if (count.relation0 === -1 && group.relations?.[0]?.id != null) {
|
|
50
|
-
count.relation0 = group.relations[0].id
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
count.nodes += group.nodes?.length ?? 0
|
|
54
|
-
if (group.dense) {
|
|
55
|
-
count.nodes += group.dense.id.length
|
|
56
|
-
}
|
|
57
|
-
count.ways += group.ways?.length ?? 0
|
|
58
|
-
count.relations += group.relations?.length ?? 0
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
return {
|
|
62
|
-
onGroup,
|
|
63
|
-
count,
|
|
64
|
-
}
|
|
65
|
-
}
|