@osmix/core 0.1.8 → 0.2.0

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 (71) hide show
  1. package/CHANGELOG.md +37 -0
  2. package/LICENSE +21 -0
  3. package/README.md +86 -69
  4. package/dist/contracts.d.ts +26 -0
  5. package/dist/contracts.d.ts.map +1 -0
  6. package/dist/contracts.js +1 -0
  7. package/dist/contracts.js.map +1 -0
  8. package/dist/entities.d.ts +1 -1
  9. package/dist/entities.d.ts.map +1 -1
  10. package/dist/entities.js +2 -7
  11. package/dist/entities.js.map +1 -1
  12. package/dist/ids.d.ts +2 -0
  13. package/dist/ids.d.ts.map +1 -1
  14. package/dist/ids.js +23 -15
  15. package/dist/ids.js.map +1 -1
  16. package/dist/index.d.ts +1 -1
  17. package/dist/index.d.ts.map +1 -1
  18. package/dist/index.js +0 -1
  19. package/dist/index.js.map +1 -1
  20. package/dist/mocks.d.ts.map +1 -1
  21. package/dist/mocks.js.map +1 -1
  22. package/dist/nodes.d.ts +9 -3
  23. package/dist/nodes.d.ts.map +1 -1
  24. package/dist/nodes.js +6 -13
  25. package/dist/nodes.js.map +1 -1
  26. package/dist/osm.d.ts +1 -1
  27. package/dist/osm.d.ts.map +1 -1
  28. package/dist/osm.js +1 -4
  29. package/dist/osm.js.map +1 -1
  30. package/dist/relations.d.ts +3 -2
  31. package/dist/relations.d.ts.map +1 -1
  32. package/dist/relations.js +15 -9
  33. package/dist/relations.js.map +1 -1
  34. package/dist/stringtable.d.ts.map +1 -1
  35. package/dist/stringtable.js +4 -13
  36. package/dist/stringtable.js.map +1 -1
  37. package/dist/tags.d.ts +1 -1
  38. package/dist/tags.d.ts.map +1 -1
  39. package/dist/tags.js.map +1 -1
  40. package/dist/typed-arrays.d.ts +1 -1
  41. package/dist/typed-arrays.d.ts.map +1 -1
  42. package/dist/typed-arrays.js.map +1 -1
  43. package/dist/ways.d.ts +2 -1
  44. package/dist/ways.d.ts.map +1 -1
  45. package/dist/ways.js +18 -18
  46. package/dist/ways.js.map +1 -1
  47. package/package.json +46 -31
  48. package/src/contracts.ts +28 -0
  49. package/src/entities.ts +179 -194
  50. package/src/ids.ts +228 -235
  51. package/src/index.ts +12 -9
  52. package/src/mocks.ts +114 -113
  53. package/src/nodes.ts +364 -397
  54. package/src/osm.ts +196 -207
  55. package/src/relations.ts +530 -558
  56. package/src/stringtable.ts +174 -183
  57. package/src/tags.ts +263 -271
  58. package/src/typed-arrays.ts +184 -194
  59. package/src/types/geoflatbush.d.ts +28 -33
  60. package/src/types/geokdbush.d.ts +28 -33
  61. package/src/types/kdbush.d.ts +34 -34
  62. package/src/ways.ts +381 -405
  63. package/test/ids.bench.ts +29 -0
  64. package/test/ids.test.ts +84 -0
  65. package/test/memory.test.ts +29 -30
  66. package/test/relations.bench.ts +27 -0
  67. package/test/relations.test.ts +101 -0
  68. package/test/tags-search.test.ts +76 -56
  69. package/test/typed-arrays.test.ts +100 -99
  70. package/tsconfig.build.json +6 -3
  71. package/tsconfig.json +7 -7
@@ -1,134 +1,135 @@
1
- import { describe, expect, it } from "bun:test"
2
- import { BufferConstructor, ResizeableTypedArray } from "../src/typed-arrays"
1
+ import { describe, expect, it } from "vitest";
2
+
3
+ import { BufferConstructor, ResizeableTypedArray } from "../src/typed-arrays";
3
4
 
4
5
  describe("typed array helpers", () => {
5
- it("selects the appropriate buffer constructor", () => {
6
- if (typeof SharedArrayBuffer !== "undefined") {
7
- expect(BufferConstructor).toBe(SharedArrayBuffer)
8
- } else {
9
- expect(BufferConstructor).toBe(ArrayBuffer)
10
- }
11
- })
6
+ it("selects the appropriate buffer constructor", () => {
7
+ if (typeof SharedArrayBuffer !== "undefined") {
8
+ expect(BufferConstructor).toBe(SharedArrayBuffer);
9
+ } else {
10
+ expect(BufferConstructor).toBe(ArrayBuffer);
11
+ }
12
+ });
12
13
 
13
- describe("ResizeableTypedArray", () => {
14
- it("push stores values and returns the index", () => {
15
- const arr = new ResizeableTypedArray(Float64Array)
14
+ describe("ResizeableTypedArray", () => {
15
+ it("push stores values and returns the index", () => {
16
+ const arr = new ResizeableTypedArray(Float64Array);
16
17
 
17
- const first = arr.push(1.5)
18
- const second = arr.push(2.5)
18
+ const first = arr.push(1.5);
19
+ const second = arr.push(2.5);
19
20
 
20
- expect(first).toBe(0)
21
- expect(second).toBe(1)
22
- expect(arr.length).toBe(2)
23
- expect(arr.at(0)).toBe(1.5)
24
- expect(arr.at(1)).toBe(2.5)
25
- })
21
+ expect(first).toBe(0);
22
+ expect(second).toBe(1);
23
+ expect(arr.length).toBe(2);
24
+ expect(arr.at(0)).toBe(1.5);
25
+ expect(arr.at(1)).toBe(2.5);
26
+ });
26
27
 
27
- it("should push many values", () => {
28
- const arr = new ResizeableTypedArray(Float64Array)
28
+ it("should push many values", () => {
29
+ const arr = new ResizeableTypedArray(Float64Array);
29
30
 
30
- arr.pushMany([1.5, 2.5])
31
+ arr.pushMany([1.5, 2.5]);
31
32
 
32
- expect(arr.length).toBe(2)
33
- expect(arr.at(0)).toBe(1.5)
34
- expect(arr.at(1)).toBe(2.5)
35
- })
33
+ expect(arr.length).toBe(2);
34
+ expect(arr.at(0)).toBe(1.5);
35
+ expect(arr.at(1)).toBe(2.5);
36
+ });
36
37
 
37
- it("at supports negative indices and guards bounds", () => {
38
- const arr = new ResizeableTypedArray(Int16Array)
38
+ it("at supports negative indices and guards bounds", () => {
39
+ const arr = new ResizeableTypedArray(Int16Array);
39
40
 
40
- arr.pushMany([10, 20, 30])
41
+ arr.pushMany([10, 20, 30]);
41
42
 
42
- expect(arr.length).toBe(3)
43
- expect(Array.from(arr.slice(0, arr.length))).toEqual([10, 20, 30])
44
- expect(arr.at(-1)).toBe(30)
45
- expect(arr.at(-3)).toBe(10)
46
- expect(() => arr.at(-4)).toThrow(/Index out of bounds/)
47
- expect(() => arr.at(3)).toThrow(/Index out of bounds/)
48
- })
43
+ expect(arr.length).toBe(3);
44
+ expect(Array.from(arr.slice(0, arr.length))).toEqual([10, 20, 30]);
45
+ expect(arr.at(-1)).toBe(30);
46
+ expect(arr.at(-3)).toBe(10);
47
+ expect(() => arr.at(-4)).toThrow(/Index out of bounds/);
48
+ expect(() => arr.at(3)).toThrow(/Index out of bounds/);
49
+ });
49
50
 
50
- it("pushMany appends arrays while preserving order", () => {
51
- const arr = new ResizeableTypedArray(Uint32Array)
51
+ it("pushMany appends arrays while preserving order", () => {
52
+ const arr = new ResizeableTypedArray(Uint32Array);
52
53
 
53
- arr.pushMany([1, 2, 3])
54
- arr.pushMany(Uint32Array.from([4, 5]))
54
+ arr.pushMany([1, 2, 3]);
55
+ arr.pushMany(Uint32Array.from([4, 5]));
55
56
 
56
- expect(arr.length).toBe(5)
57
- expect(Array.from(arr.slice(0, arr.length))).toEqual([1, 2, 3, 4, 5])
58
- })
57
+ expect(arr.length).toBe(5);
58
+ expect(Array.from(arr.slice(0, arr.length))).toEqual([1, 2, 3, 4, 5]);
59
+ });
59
60
 
60
- it("slice returns a copy of the requested segment", () => {
61
- const arr = new ResizeableTypedArray(Uint8Array)
61
+ it("slice returns a copy of the requested segment", () => {
62
+ const arr = new ResizeableTypedArray(Uint8Array);
62
63
 
63
- arr.pushMany([1, 2, 3, 4])
64
+ arr.pushMany([1, 2, 3, 4]);
64
65
 
65
- const segment = arr.slice(1, 3)
66
+ const segment = arr.slice(1, 3);
66
67
 
67
- expect(segment).toBeInstanceOf(Uint8Array)
68
- expect(Array.from(segment)).toEqual([2, 3])
68
+ expect(segment).toBeInstanceOf(Uint8Array);
69
+ expect(Array.from(segment)).toEqual([2, 3]);
69
70
 
70
- segment[0] = 99
71
- expect(arr.at(1)).toBe(2)
72
- })
71
+ segment[0] = 99;
72
+ expect(arr.at(1)).toBe(2);
73
+ });
73
74
 
74
- it("compact trims unused capacity", () => {
75
- const arr = new ResizeableTypedArray(Float64Array)
75
+ it("compact trims unused capacity", () => {
76
+ const arr = new ResizeableTypedArray(Float64Array);
76
77
 
77
- arr.pushMany([5, 6, 7])
78
+ arr.pushMany([5, 6, 7]);
78
79
 
79
- const previousCapacity = arr.array.length
80
- const compacted = arr.compact()
81
- const expectedByteLength = arr.length * Float64Array.BYTES_PER_ELEMENT
80
+ const previousCapacity = arr.array.length;
81
+ const compacted = arr.compact();
82
+ const expectedByteLength = arr.length * Float64Array.BYTES_PER_ELEMENT;
82
83
 
83
- expect(compacted).toBe(arr.array)
84
- expect(compacted.length).toBe(arr.length)
85
- expect(compacted.length).toBeLessThan(previousCapacity)
86
- expect(arr.array.buffer.byteLength).toBe(expectedByteLength)
87
- })
84
+ expect(compacted).toBe(arr.array);
85
+ expect(compacted.length).toBe(arr.length);
86
+ expect(compacted.length).toBeLessThan(previousCapacity);
87
+ expect(arr.array.buffer.byteLength).toBe(expectedByteLength);
88
+ });
88
89
 
89
- it("from reuses an existing buffer and grows when needed", () => {
90
- const backing = new ArrayBuffer(16)
91
- new Uint32Array(backing).set([1, 2, 3, 4])
90
+ it("from reuses an existing buffer and grows when needed", () => {
91
+ const backing = new ArrayBuffer(16);
92
+ new Uint32Array(backing).set([1, 2, 3, 4]);
92
93
 
93
- const arr = ResizeableTypedArray.from(Uint32Array, backing)
94
+ const arr = ResizeableTypedArray.from(Uint32Array, backing);
94
95
 
95
- arr.bufferSize = arr.buffer.byteLength
96
- arr.maxByteLength = Math.max(arr.maxByteLength, arr.bufferSize * 2)
97
- arr.items = arr.array.length
96
+ arr.bufferSize = arr.buffer.byteLength;
97
+ arr.maxByteLength = Math.max(arr.maxByteLength, arr.bufferSize * 2);
98
+ arr.items = arr.array.length;
98
99
 
99
- expect(arr.length).toBe(4)
100
- expect(Array.from(arr.slice(0, arr.length))).toEqual([1, 2, 3, 4])
100
+ expect(arr.length).toBe(4);
101
+ expect(Array.from(arr.slice(0, arr.length))).toEqual([1, 2, 3, 4]);
101
102
 
102
- arr.push(5)
103
+ arr.push(5);
103
104
 
104
- expect(arr.length).toBe(5)
105
- expect(arr.array.length).toBe(8)
106
- expect(Array.from(arr.slice(0, arr.length))).toEqual([1, 2, 3, 4, 5])
107
- })
105
+ expect(arr.length).toBe(5);
106
+ expect(arr.array.length).toBe(8);
107
+ expect(Array.from(arr.slice(0, arr.length))).toEqual([1, 2, 3, 4, 5]);
108
+ });
108
109
 
109
- if (typeof SharedArrayBuffer !== "undefined") {
110
- it("grows shared buffers in place", () => {
111
- const backing = new SharedArrayBuffer(8, {
112
- maxByteLength: 32,
113
- })
114
- const seed = new Uint8Array(backing)
115
- seed.set([1, 2, 3, 4, 5, 6, 7, 8])
110
+ if (typeof SharedArrayBuffer !== "undefined") {
111
+ it("grows shared buffers in place", () => {
112
+ const backing = new SharedArrayBuffer(8, {
113
+ maxByteLength: 32,
114
+ });
115
+ const seed = new Uint8Array(backing);
116
+ seed.set([1, 2, 3, 4, 5, 6, 7, 8]);
116
117
 
117
- const arr = ResizeableTypedArray.from(Uint8Array, backing)
118
+ const arr = ResizeableTypedArray.from(Uint8Array, backing);
118
119
 
119
- arr.bufferSize = arr.buffer.byteLength
120
- arr.maxByteLength = backing.maxByteLength
121
- arr.items = arr.array.length
120
+ arr.bufferSize = arr.buffer.byteLength;
121
+ arr.maxByteLength = backing.maxByteLength;
122
+ arr.items = arr.array.length;
122
123
 
123
- const originalBuffer = arr.buffer
124
+ const originalBuffer = arr.buffer;
124
125
 
125
- arr.push(9)
126
+ arr.push(9);
126
127
 
127
- expect(arr.buffer).toBe(originalBuffer)
128
- expect(arr.array.length).toBe(16)
129
- expect(arr.buffer.byteLength).toBe(16)
130
- expect(Array.from(arr.slice(0, 9))).toEqual([1, 2, 3, 4, 5, 6, 7, 8, 9])
131
- })
132
- }
133
- })
134
- })
128
+ expect(arr.buffer).toBe(originalBuffer);
129
+ expect(arr.array.length).toBe(16);
130
+ expect(arr.buffer.byteLength).toBe(16);
131
+ expect(Array.from(arr.slice(0, 9))).toEqual([1, 2, 3, 4, 5, 6, 7, 8, 9]);
132
+ });
133
+ }
134
+ });
135
+ });
@@ -1,5 +1,8 @@
1
1
  {
2
- "$schema": "https://json.schemastore.org/tsconfig",
3
- "extends": "./tsconfig.json",
4
- "include": ["src"]
2
+ "$schema": "https://json.schemastore.org/tsconfig",
3
+ "extends": "./tsconfig.json",
4
+ "include": ["src"],
5
+ "compilerOptions": {
6
+ "rootDir": "./src"
7
+ }
5
8
  }
package/tsconfig.json CHANGED
@@ -1,9 +1,9 @@
1
1
  {
2
- "$schema": "https://json.schemastore.org/tsconfig",
3
- "extends": "@osmix/shared/tsconfig/base.json",
4
- "exclude": ["node_modules", "dist"],
5
- "include": ["src", "test"],
6
- "compilerOptions": {
7
- "outDir": "./dist"
8
- }
2
+ "$schema": "https://json.schemastore.org/tsconfig",
3
+ "extends": "@osmix/shared/tsconfig/base.json",
4
+ "exclude": ["node_modules", "dist"],
5
+ "include": ["src", "test"],
6
+ "compilerOptions": {
7
+ "outDir": "./dist"
8
+ }
9
9
  }