@osmix/shared 0.0.11 → 0.0.13

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.
Files changed (43) hide show
  1. package/CHANGELOG.md +82 -0
  2. package/dist/bbox-intersects.d.ts +1 -1
  3. package/dist/bbox-intersects.d.ts.map +1 -1
  4. package/dist/color.d.ts +1 -1
  5. package/dist/color.d.ts.map +1 -1
  6. package/dist/coordinates.d.ts +1 -1
  7. package/dist/coordinates.d.ts.map +1 -1
  8. package/dist/relation-kind.d.ts +1 -1
  9. package/dist/relation-kind.d.ts.map +1 -1
  10. package/dist/relation-multipolygon.d.ts +1 -1
  11. package/dist/relation-multipolygon.d.ts.map +1 -1
  12. package/dist/stream-to-bytes.js +1 -1
  13. package/dist/stream-to-bytes.js.map +1 -1
  14. package/dist/tile.d.ts +13 -1
  15. package/dist/tile.d.ts.map +1 -1
  16. package/dist/tile.js +15 -0
  17. package/dist/tile.js.map +1 -1
  18. package/dist/transform-bytes.js +2 -2
  19. package/dist/transform-bytes.js.map +1 -1
  20. package/dist/utils.d.ts +1 -1
  21. package/dist/utils.d.ts.map +1 -1
  22. package/dist/way-is-area.d.ts +1 -1
  23. package/dist/way-is-area.d.ts.map +1 -1
  24. package/package.json +12 -47
  25. package/src/bbox-intersects.ts +1 -1
  26. package/src/color.ts +1 -1
  27. package/src/coordinates.ts +1 -1
  28. package/src/relation-kind.ts +1 -1
  29. package/src/relation-multipolygon.ts +1 -1
  30. package/src/stream-to-bytes.ts +1 -1
  31. package/src/tile.ts +18 -1
  32. package/src/transform-bytes.ts +2 -2
  33. package/src/utils.ts +1 -1
  34. package/src/way-is-area.ts +1 -1
  35. package/test/csv-parse-stream.test.ts +67 -0
  36. package/test/haversine-distance.test.ts +8 -0
  37. package/test/relation-kind.test.ts +426 -0
  38. package/test/relation-multipolygon.test.ts +265 -0
  39. package/test/utils.test.ts +103 -0
  40. package/test/way-is-area.test.ts +42 -0
  41. package/tsconfig/base.json +2 -0
  42. package/tsconfig.build.json +5 -0
  43. package/tsconfig.json +9 -0
@@ -0,0 +1,103 @@
1
+ import { describe, expect, it } from "bun:test"
2
+ import type {
3
+ OsmNode,
4
+ OsmRelation,
5
+ OsmRelationMember,
6
+ OsmWay,
7
+ } from "../src/types"
8
+ import {
9
+ entityPropertiesEqual,
10
+ getEntityType,
11
+ isMultipolygonRelation,
12
+ isNode,
13
+ isNodeEqual,
14
+ isRelation,
15
+ isRelationEqual,
16
+ isWay,
17
+ isWayEqual,
18
+ } from "../src/utils"
19
+
20
+ describe("utils", () => {
21
+ const node: OsmNode = {
22
+ id: 1,
23
+ lat: 10,
24
+ lon: 20,
25
+ tags: { name: "node" },
26
+ }
27
+ const way: OsmWay = {
28
+ id: 2,
29
+ refs: [1, 2, 3],
30
+ tags: { highway: "residential" },
31
+ }
32
+ const members: OsmRelationMember[] = [
33
+ {
34
+ type: "node",
35
+ ref: 1,
36
+ },
37
+ ]
38
+ const relation: OsmRelation = {
39
+ id: 3,
40
+ members,
41
+ tags: { type: "multipolygon" },
42
+ }
43
+
44
+ it("narrows entity types", () => {
45
+ expect(isNode(node)).toBe(true)
46
+ expect(isWay(way)).toBe(true)
47
+ expect(isRelation(relation)).toBe(true)
48
+ })
49
+
50
+ it("compares entity equality", () => {
51
+ expect(isNodeEqual(node, { ...node })).toBe(true)
52
+ expect(isWayEqual(way, { ...way })).toBe(true)
53
+ expect(isRelationEqual(relation, { ...relation })).toBe(true)
54
+ })
55
+
56
+ it("detects property differences", () => {
57
+ expect(
58
+ entityPropertiesEqual(node, { ...node, tags: { name: "changed" } }),
59
+ ).toBe(false)
60
+ expect(entityPropertiesEqual(way, { ...way, refs: [1, 2, 4] })).toBe(false)
61
+ expect(
62
+ entityPropertiesEqual(relation, {
63
+ ...relation,
64
+ members: [{ type: "node", ref: 2 }],
65
+ }),
66
+ ).toBe(false)
67
+ })
68
+
69
+ it("provides entity type", () => {
70
+ expect(getEntityType(node)).toBe("node")
71
+ expect(getEntityType(way)).toBe("way")
72
+ expect(getEntityType(relation)).toBe("relation")
73
+ })
74
+
75
+ describe("isMultipolygonRelation", () => {
76
+ it("identifies multipolygon relations", () => {
77
+ const relation: OsmRelation = {
78
+ id: 1,
79
+ tags: { type: "multipolygon" },
80
+ members: [],
81
+ }
82
+ expect(isMultipolygonRelation(relation)).toBe(true)
83
+ })
84
+
85
+ it("rejects non-multipolygon relations", () => {
86
+ const relation: OsmRelation = {
87
+ id: 1,
88
+ tags: { type: "route" },
89
+ members: [],
90
+ }
91
+ expect(isMultipolygonRelation(relation)).toBe(false)
92
+ })
93
+
94
+ it("rejects relations without type tag", () => {
95
+ const relation: OsmRelation = {
96
+ id: 1,
97
+ tags: { name: "test" },
98
+ members: [],
99
+ }
100
+ expect(isMultipolygonRelation(relation)).toBe(false)
101
+ })
102
+ })
103
+ })
@@ -0,0 +1,42 @@
1
+ import { describe, expect, it } from "bun:test"
2
+ import { wayIsArea } from "../src/way-is-area"
3
+
4
+ describe("wayIsArea", () => {
5
+ it("returns false for open ways", () => {
6
+ const refs = [1, 2, 3]
7
+ expect(wayIsArea({ id: 0, refs, tags: { building: "yes" } })).toBe(false)
8
+ })
9
+
10
+ it("returns true for closed way without tags", () => {
11
+ const refs = [1, 2, 3, 1]
12
+ expect(wayIsArea({ id: 0, refs })).toBe(true)
13
+ })
14
+
15
+ it("honors explicit area override", () => {
16
+ const refs = [1, 2, 3, 1]
17
+ expect(
18
+ wayIsArea({ id: 0, refs, tags: { area: "no", building: "yes" } }),
19
+ ).toBe(false)
20
+ expect(wayIsArea({ id: 0, refs, tags: { area: "yes" } })).toBe(true)
21
+ })
22
+
23
+ it("treats implied tags as areas", () => {
24
+ const refs = [1, 2, 3, 1]
25
+ expect(wayIsArea({ id: 0, refs, tags: { building: "yes" } })).toBe(true)
26
+ })
27
+
28
+ it("considers included values", () => {
29
+ const refs = [1, 2, 3, 1]
30
+ expect(wayIsArea({ id: 0, refs, tags: { highway: "rest_area" } })).toBe(
31
+ true,
32
+ )
33
+ expect(wayIsArea({ id: 0, refs, tags: { highway: "primary" } })).toBe(false)
34
+ })
35
+
36
+ it("rejects excluded values", () => {
37
+ const refs = [1, 2, 3, 1]
38
+ expect(wayIsArea({ id: 0, refs, tags: { natural: "coastline" } })).toBe(
39
+ false,
40
+ )
41
+ })
42
+ })
@@ -13,6 +13,8 @@
13
13
  "moduleDetection": "force",
14
14
 
15
15
  "moduleResolution": "bundler",
16
+ "allowImportingTsExtensions": true,
17
+ "rewriteRelativeImportExtensions": true,
16
18
  "verbatimModuleSyntax": true,
17
19
  "isolatedModules": true,
18
20
  "erasableSyntaxOnly": true,
@@ -0,0 +1,5 @@
1
+ {
2
+ "$schema": "https://json.schemastore.org/tsconfig",
3
+ "extends": "./tsconfig.json",
4
+ "include": ["src"]
5
+ }
package/tsconfig.json ADDED
@@ -0,0 +1,9 @@
1
+ {
2
+ "$schema": "https://json.schemastore.org/tsconfig",
3
+ "extends": "./tsconfig/base.json",
4
+ "include": ["src", "test"],
5
+ "exclude": ["node_modules", "dist"],
6
+ "compilerOptions": {
7
+ "outDir": "./dist"
8
+ }
9
+ }