@osmix/shared 0.0.1 → 0.0.2

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 (52) hide show
  1. package/CHANGELOG.md +6 -0
  2. package/dist/src/assert.d.ts +5 -0
  3. package/dist/src/assert.d.ts.map +1 -0
  4. package/dist/src/assert.js +9 -0
  5. package/dist/src/assert.js.map +1 -0
  6. package/dist/src/bytes-to-stream.d.ts +2 -0
  7. package/dist/src/bytes-to-stream.d.ts.map +1 -0
  8. package/dist/src/bytes-to-stream.js +9 -0
  9. package/dist/src/bytes-to-stream.js.map +1 -0
  10. package/dist/src/concat-bytes.d.ts +5 -0
  11. package/dist/src/concat-bytes.d.ts.map +1 -0
  12. package/dist/src/concat-bytes.js +14 -0
  13. package/dist/src/concat-bytes.js.map +1 -0
  14. package/dist/src/haversine-distance.d.ts +8 -0
  15. package/dist/src/haversine-distance.d.ts.map +1 -0
  16. package/dist/src/haversine-distance.js +18 -0
  17. package/dist/src/haversine-distance.js.map +1 -0
  18. package/dist/src/lineclip.d.ts +2 -0
  19. package/dist/src/lineclip.d.ts.map +1 -0
  20. package/dist/src/lineclip.js +3 -0
  21. package/dist/src/lineclip.js.map +1 -0
  22. package/dist/src/spherical-mercator.d.ts +15 -0
  23. package/dist/src/spherical-mercator.d.ts.map +1 -0
  24. package/dist/src/spherical-mercator.js +35 -0
  25. package/dist/src/spherical-mercator.js.map +1 -0
  26. package/dist/src/spherical-mercator.test.d.ts +2 -0
  27. package/dist/src/spherical-mercator.test.d.ts.map +1 -0
  28. package/dist/src/spherical-mercator.test.js +25 -0
  29. package/dist/src/spherical-mercator.test.js.map +1 -0
  30. package/dist/src/stream-to-bytes.d.ts +2 -0
  31. package/dist/src/stream-to-bytes.d.ts.map +1 -0
  32. package/dist/src/stream-to-bytes.js +14 -0
  33. package/dist/src/stream-to-bytes.js.map +1 -0
  34. package/dist/src/test/fixtures.d.ts +36 -0
  35. package/dist/src/test/fixtures.d.ts.map +1 -0
  36. package/dist/src/test/fixtures.js +167 -0
  37. package/dist/src/test/fixtures.js.map +1 -0
  38. package/dist/src/transform-bytes.d.ts +2 -0
  39. package/dist/src/transform-bytes.d.ts.map +1 -0
  40. package/dist/src/transform-bytes.js +6 -0
  41. package/dist/src/transform-bytes.js.map +1 -0
  42. package/dist/src/types.d.ts +24 -0
  43. package/dist/src/types.d.ts.map +1 -0
  44. package/dist/src/types.js +1 -0
  45. package/dist/src/types.js.map +1 -0
  46. package/dist/test/haversine-distance.test.d.ts +2 -0
  47. package/dist/test/haversine-distance.test.d.ts.map +1 -0
  48. package/dist/test/haversine-distance.test.js +8 -0
  49. package/dist/test/haversine-distance.test.js.map +1 -0
  50. package/package.json +3 -1
  51. package/src/test/fixtures.ts +9 -6
  52. package/tsconfig/base.json +2 -0
package/CHANGELOG.md CHANGED
@@ -1,5 +1,11 @@
1
1
  # @osmix/shared
2
2
 
3
+ ## 0.0.2
4
+
5
+ ### Patch Changes
6
+
7
+ - 33d9c12: Modify types to take Uint8Array<ArrayBufferLike> for compatiblity
8
+
3
9
  ## 0.0.1
4
10
 
5
11
  ### Patch Changes
@@ -0,0 +1,5 @@
1
+ /**
2
+ * Short utility for checking index access.
3
+ */
4
+ export declare function assertValue<T>(value?: T, message?: string): asserts value is NonNullable<T>;
5
+ //# sourceMappingURL=assert.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"assert.d.ts","sourceRoot":"","sources":["../../src/assert.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,wBAAgB,WAAW,CAAC,CAAC,EAC5B,KAAK,CAAC,EAAE,CAAC,EACT,OAAO,CAAC,EAAE,MAAM,GACd,OAAO,CAAC,KAAK,IAAI,WAAW,CAAC,CAAC,CAAC,CAIjC"}
@@ -0,0 +1,9 @@
1
+ /**
2
+ * Short utility for checking index access.
3
+ */
4
+ export function assertValue(value, message) {
5
+ if (value === undefined || value === null) {
6
+ throw Error(message ?? "Value is undefined or null");
7
+ }
8
+ }
9
+ //# sourceMappingURL=assert.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"assert.js","sourceRoot":"","sources":["../../src/assert.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,MAAM,UAAU,WAAW,CAC1B,KAAS,EACT,OAAgB;IAEhB,IAAI,KAAK,KAAK,SAAS,IAAI,KAAK,KAAK,IAAI,EAAE,CAAC;QAC3C,MAAM,KAAK,CAAC,OAAO,IAAI,4BAA4B,CAAC,CAAA;IACrD,CAAC;AACF,CAAC"}
@@ -0,0 +1,2 @@
1
+ export declare function bytesToStream(bytes: Uint8Array<ArrayBuffer>): import("stream/web").ReadableStream<Uint8Array<ArrayBuffer>>;
2
+ //# sourceMappingURL=bytes-to-stream.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"bytes-to-stream.d.ts","sourceRoot":"","sources":["../../src/bytes-to-stream.ts"],"names":[],"mappings":"AAAA,wBAAgB,aAAa,CAAC,KAAK,EAAE,UAAU,CAAC,WAAW,CAAC,gEAO3D"}
@@ -0,0 +1,9 @@
1
+ export function bytesToStream(bytes) {
2
+ return new ReadableStream({
3
+ start(controller) {
4
+ controller.enqueue(bytes);
5
+ controller.close();
6
+ },
7
+ });
8
+ }
9
+ //# sourceMappingURL=bytes-to-stream.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"bytes-to-stream.js","sourceRoot":"","sources":["../../src/bytes-to-stream.ts"],"names":[],"mappings":"AAAA,MAAM,UAAU,aAAa,CAAC,KAA8B;IAC3D,OAAO,IAAI,cAAc,CAA0B;QAClD,KAAK,CAAC,UAAU;YACf,UAAU,CAAC,OAAO,CAAC,KAAK,CAAC,CAAA;YACzB,UAAU,CAAC,KAAK,EAAE,CAAA;QACnB,CAAC;KACD,CAAC,CAAA;AACH,CAAC"}
@@ -0,0 +1,5 @@
1
+ /**
2
+ * Concatenates multiple `Uint8Array` segments into a contiguous array.
3
+ */
4
+ export declare function concatBytes(parts: Uint8Array<ArrayBuffer>[]): Uint8Array<ArrayBuffer>;
5
+ //# sourceMappingURL=concat-bytes.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"concat-bytes.d.ts","sourceRoot":"","sources":["../../src/concat-bytes.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,wBAAgB,WAAW,CAC1B,KAAK,EAAE,UAAU,CAAC,WAAW,CAAC,EAAE,GAC9B,UAAU,CAAC,WAAW,CAAC,CASzB"}
@@ -0,0 +1,14 @@
1
+ /**
2
+ * Concatenates multiple `Uint8Array` segments into a contiguous array.
3
+ */
4
+ export function concatBytes(parts) {
5
+ const total = parts.reduce((n, p) => n + p.length, 0);
6
+ const out = new Uint8Array(new ArrayBuffer(total));
7
+ let offset = 0;
8
+ for (const p of parts) {
9
+ out.set(p, offset);
10
+ offset += p.length;
11
+ }
12
+ return out;
13
+ }
14
+ //# sourceMappingURL=concat-bytes.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"concat-bytes.js","sourceRoot":"","sources":["../../src/concat-bytes.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,MAAM,UAAU,WAAW,CAC1B,KAAgC;IAEhC,MAAM,KAAK,GAAG,KAAK,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC,CAAC,GAAG,CAAC,CAAC,MAAM,EAAE,CAAC,CAAC,CAAA;IACrD,MAAM,GAAG,GAAG,IAAI,UAAU,CAAc,IAAI,WAAW,CAAC,KAAK,CAAC,CAAC,CAAA;IAC/D,IAAI,MAAM,GAAG,CAAC,CAAA;IACd,KAAK,MAAM,CAAC,IAAI,KAAK,EAAE,CAAC;QACvB,GAAG,CAAC,GAAG,CAAC,CAAC,EAAE,MAAM,CAAC,CAAA;QAClB,MAAM,IAAI,CAAC,CAAC,MAAM,CAAA;IACnB,CAAC;IACD,OAAO,GAAG,CAAA;AACX,CAAC"}
@@ -0,0 +1,8 @@
1
+ /**
2
+ * Calculate the haversine distance between two LonLat points.
3
+ * @param p1 - The first point
4
+ * @param p2 - The second point
5
+ * @returns The haversine distance in meters
6
+ */
7
+ export declare function haversineDistance(p1: [number, number], p2: [number, number]): number;
8
+ //# sourceMappingURL=haversine-distance.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"haversine-distance.d.ts","sourceRoot":"","sources":["../../src/haversine-distance.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AACH,wBAAgB,iBAAiB,CAChC,EAAE,EAAE,CAAC,MAAM,EAAE,MAAM,CAAC,EACpB,EAAE,EAAE,CAAC,MAAM,EAAE,MAAM,CAAC,GAClB,MAAM,CAWR"}
@@ -0,0 +1,18 @@
1
+ /**
2
+ * Calculate the haversine distance between two LonLat points.
3
+ * @param p1 - The first point
4
+ * @param p2 - The second point
5
+ * @returns The haversine distance in meters
6
+ */
7
+ export function haversineDistance(p1, p2) {
8
+ const R = 6371008.8; // Earth's radius in meters
9
+ const dLat = (p2[1] - p1[1]) * (Math.PI / 180);
10
+ const dLon = (p2[0] - p1[0]) * (Math.PI / 180);
11
+ const lat1 = p1[1] * (Math.PI / 180);
12
+ const lat2 = p2[1] * (Math.PI / 180);
13
+ const a = Math.sin(dLat / 2) ** 2 +
14
+ Math.sin(dLon / 2) ** 2 * Math.cos(lat1) * Math.cos(lat2);
15
+ const c = 2 * Math.atan2(Math.sqrt(a), Math.sqrt(1 - a));
16
+ return R * c;
17
+ }
18
+ //# sourceMappingURL=haversine-distance.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"haversine-distance.js","sourceRoot":"","sources":["../../src/haversine-distance.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AACH,MAAM,UAAU,iBAAiB,CAChC,EAAoB,EACpB,EAAoB;IAEpB,MAAM,CAAC,GAAG,SAAS,CAAA,CAAC,2BAA2B;IAC/C,MAAM,IAAI,GAAG,CAAC,EAAE,CAAC,CAAC,CAAC,GAAG,EAAE,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,IAAI,CAAC,EAAE,GAAG,GAAG,CAAC,CAAA;IAC9C,MAAM,IAAI,GAAG,CAAC,EAAE,CAAC,CAAC,CAAC,GAAG,EAAE,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,IAAI,CAAC,EAAE,GAAG,GAAG,CAAC,CAAA;IAC9C,MAAM,IAAI,GAAG,EAAE,CAAC,CAAC,CAAC,GAAG,CAAC,IAAI,CAAC,EAAE,GAAG,GAAG,CAAC,CAAA;IACpC,MAAM,IAAI,GAAG,EAAE,CAAC,CAAC,CAAC,GAAG,CAAC,IAAI,CAAC,EAAE,GAAG,GAAG,CAAC,CAAA;IACpC,MAAM,CAAC,GACN,IAAI,CAAC,GAAG,CAAC,IAAI,GAAG,CAAC,CAAC,IAAI,CAAC;QACvB,IAAI,CAAC,GAAG,CAAC,IAAI,GAAG,CAAC,CAAC,IAAI,CAAC,GAAG,IAAI,CAAC,GAAG,CAAC,IAAI,CAAC,GAAG,IAAI,CAAC,GAAG,CAAC,IAAI,CAAC,CAAA;IAC1D,MAAM,CAAC,GAAG,CAAC,GAAG,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,IAAI,CAAC,IAAI,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,CAAA;IACxD,OAAO,CAAC,GAAG,CAAC,CAAA;AACb,CAAC"}
@@ -0,0 +1,2 @@
1
+ export { clipPolygon, clipPolyline } from "lineclip";
2
+ //# sourceMappingURL=lineclip.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"lineclip.d.ts","sourceRoot":"","sources":["../../src/lineclip.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,WAAW,EAAE,YAAY,EAAE,MAAM,UAAU,CAAA"}
@@ -0,0 +1,3 @@
1
+ /// <reference path="./lineclip.d.ts" />
2
+ export { clipPolygon, clipPolyline } from "lineclip";
3
+ //# sourceMappingURL=lineclip.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"lineclip.js","sourceRoot":"","sources":["../../src/lineclip.ts"],"names":[],"mappings":"AAAA,wCAAwC;AACxC,OAAO,EAAE,WAAW,EAAE,YAAY,EAAE,MAAM,UAAU,CAAA"}
@@ -0,0 +1,15 @@
1
+ import { SphericalMercator } from "@mapbox/sphericalmercator";
2
+ import type { GeoBbox2D, LonLat, Tile, XY } from "./types";
3
+ /**
4
+ * Extends the SphericalMercator class to provide tile-local pixel coordinate calculations and clamping.
5
+ */
6
+ export default class SphericalMercatorTile extends SphericalMercator {
7
+ tileSize: number;
8
+ tile?: Tile;
9
+ constructor(options: ConstructorParameters<typeof SphericalMercator>[0] & {
10
+ tile?: Tile;
11
+ });
12
+ llToTilePx(ll: LonLat, tile?: Tile): XY;
13
+ clampAndRoundPx(px: XY, bbox?: GeoBbox2D): XY;
14
+ }
15
+ //# sourceMappingURL=spherical-mercator.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"spherical-mercator.d.ts","sourceRoot":"","sources":["../../src/spherical-mercator.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,MAAM,2BAA2B,CAAA;AAC7D,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,EAAE,IAAI,EAAE,EAAE,EAAE,MAAM,SAAS,CAAA;AAE1D;;GAEG;AACH,MAAM,CAAC,OAAO,OAAO,qBAAsB,SAAQ,iBAAiB;IACnE,QAAQ,EAAE,MAAM,CAAA;IAChB,IAAI,CAAC,EAAE,IAAI,CAAA;gBAEV,OAAO,EAAE,qBAAqB,CAAC,OAAO,iBAAiB,CAAC,CAAC,CAAC,CAAC,GAAG;QAC7D,IAAI,CAAC,EAAE,IAAI,CAAA;KACX;IAOF,UAAU,CAAC,EAAE,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,IAAI,GAAG,EAAE;IAUvC,eAAe,CAAC,EAAE,EAAE,EAAE,EAAE,IAAI,CAAC,EAAE,SAAS,GAAG,EAAE;CAY7C"}
@@ -0,0 +1,35 @@
1
+ import { SphericalMercator } from "@mapbox/sphericalmercator";
2
+ /**
3
+ * Extends the SphericalMercator class to provide tile-local pixel coordinate calculations and clamping.
4
+ */
5
+ export default class SphericalMercatorTile extends SphericalMercator {
6
+ tileSize;
7
+ tile;
8
+ constructor(options) {
9
+ super(options);
10
+ this.tile = options?.tile;
11
+ this.tileSize = options?.size ?? 256;
12
+ }
13
+ llToTilePx(ll, tile) {
14
+ if (tile == null && this.tile == null)
15
+ throw Error("Tile must be set on construction or passed as an argument.");
16
+ const [tx, ty, tz] = (tile ?? this.tile);
17
+ const merc = this.px(ll, tz);
18
+ const x = merc[0] - tx * this.tileSize;
19
+ const y = merc[1] - ty * this.tileSize;
20
+ return [x, y];
21
+ }
22
+ clampAndRoundPx(px, bbox) {
23
+ const [minX, minY, maxX, maxY] = bbox ?? [
24
+ 0,
25
+ 0,
26
+ this.tileSize,
27
+ this.tileSize,
28
+ ];
29
+ return [
30
+ Math.max(minX, Math.min(maxX, Math.round(px[0]))),
31
+ Math.max(minY, Math.min(maxY, Math.round(px[1]))),
32
+ ];
33
+ }
34
+ }
35
+ //# sourceMappingURL=spherical-mercator.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"spherical-mercator.js","sourceRoot":"","sources":["../../src/spherical-mercator.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,MAAM,2BAA2B,CAAA;AAG7D;;GAEG;AACH,MAAM,CAAC,OAAO,OAAO,qBAAsB,SAAQ,iBAAiB;IACnE,QAAQ,CAAQ;IAChB,IAAI,CAAO;IACX,YACC,OAEC;QAED,KAAK,CAAC,OAAO,CAAC,CAAA;QACd,IAAI,CAAC,IAAI,GAAG,OAAO,EAAE,IAAI,CAAA;QACzB,IAAI,CAAC,QAAQ,GAAG,OAAO,EAAE,IAAI,IAAI,GAAG,CAAA;IACrC,CAAC;IAED,UAAU,CAAC,EAAU,EAAE,IAAW;QACjC,IAAI,IAAI,IAAI,IAAI,IAAI,IAAI,CAAC,IAAI,IAAI,IAAI;YACpC,MAAM,KAAK,CAAC,4DAA4D,CAAC,CAAA;QAC1E,MAAM,CAAC,EAAE,EAAE,EAAE,EAAE,EAAE,CAAC,GAAG,CAAC,IAAI,IAAI,IAAI,CAAC,IAAI,CAAE,CAAA;QACzC,MAAM,IAAI,GAAG,IAAI,CAAC,EAAE,CAAC,EAAE,EAAE,EAAE,CAAC,CAAA;QAC5B,MAAM,CAAC,GAAG,IAAI,CAAC,CAAC,CAAC,GAAG,EAAE,GAAG,IAAI,CAAC,QAAQ,CAAA;QACtC,MAAM,CAAC,GAAG,IAAI,CAAC,CAAC,CAAC,GAAG,EAAE,GAAG,IAAI,CAAC,QAAQ,CAAA;QACtC,OAAO,CAAC,CAAC,EAAE,CAAC,CAAC,CAAA;IACd,CAAC;IAED,eAAe,CAAC,EAAM,EAAE,IAAgB;QACvC,MAAM,CAAC,IAAI,EAAE,IAAI,EAAE,IAAI,EAAE,IAAI,CAAC,GAAG,IAAI,IAAI;YACxC,CAAC;YACD,CAAC;YACD,IAAI,CAAC,QAAQ;YACb,IAAI,CAAC,QAAQ;SACb,CAAA;QACD,OAAO;YACN,IAAI,CAAC,GAAG,CAAC,IAAI,EAAE,IAAI,CAAC,GAAG,CAAC,IAAI,EAAE,IAAI,CAAC,KAAK,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;YACjD,IAAI,CAAC,GAAG,CAAC,IAAI,EAAE,IAAI,CAAC,GAAG,CAAC,IAAI,EAAE,IAAI,CAAC,KAAK,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;SACjD,CAAA;IACF,CAAC;CACD"}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=spherical-mercator.test.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"spherical-mercator.test.d.ts","sourceRoot":"","sources":["../../src/spherical-mercator.test.ts"],"names":[],"mappings":""}
@@ -0,0 +1,25 @@
1
+ import { describe, expect, it } from "vitest";
2
+ import SphericalMercatorTile from "./spherical-mercator";
3
+ function lonLatForPixel(merc, tileIndex, tileSize, px, py) {
4
+ const [x, y, z] = tileIndex;
5
+ return merc.ll([x * tileSize + px, y * tileSize + py], z);
6
+ }
7
+ describe("SphericalMercatorTile", () => {
8
+ it("projects lon/lat to tile-local pixels", () => {
9
+ const tile = [300, 300, 10];
10
+ const [tx, ty, tz] = tile;
11
+ const tileSize = 256;
12
+ const merc = new SphericalMercatorTile({ size: tileSize, tile });
13
+ const insideLonLat = lonLatForPixel(merc, tile, tileSize, 32, 16);
14
+ expect(merc.llToTilePx(insideLonLat)).toEqual([32, 16]);
15
+ const outsideTopLeft = merc.ll([tx * tileSize - 10, ty * tileSize - 10], tz);
16
+ expect(outsideTopLeft).toEqual([-74.54498291015625, 59.54128017205441]);
17
+ expect(merc.llToTilePx(outsideTopLeft)).toEqual([-10, -10]);
18
+ const outsideBottomRight = merc.ll([(tx + 1) * tileSize + 10, (ty + 1) * tileSize + 10], tz);
19
+ expect(merc.llToTilePx(outsideBottomRight, tile)).toEqual([
20
+ tileSize + 10,
21
+ tileSize + 10,
22
+ ]);
23
+ });
24
+ });
25
+ //# sourceMappingURL=spherical-mercator.test.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"spherical-mercator.test.js","sourceRoot":"","sources":["../../src/spherical-mercator.test.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,EAAE,EAAE,EAAE,MAAM,QAAQ,CAAA;AAC7C,OAAO,qBAAqB,MAAM,sBAAsB,CAAA;AAGxD,SAAS,cAAc,CACtB,IAA2B,EAC3B,SAAe,EACf,QAAgB,EAChB,EAAU,EACV,EAAU;IAEV,MAAM,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC,GAAG,SAAS,CAAA;IAC3B,OAAO,IAAI,CAAC,EAAE,CAAC,CAAC,CAAC,GAAG,QAAQ,GAAG,EAAE,EAAE,CAAC,GAAG,QAAQ,GAAG,EAAE,CAAC,EAAE,CAAC,CAAqB,CAAA;AAC9E,CA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C,kBAAkB,EAAE,IAAI,CAAC,CAAC,CAAC,OAAO,CAAC;YACzD,QAAQ,GAAG,EAAE;YACb,QAAQ,GAAG,EAAE;SACb,CAAC,CAAA;IACH,CAAC,CAAC,CAAA;AACH,CAAC,CAAC,CAAA"}
@@ -0,0 +1,2 @@
1
+ export declare function streamToBytes(stream: ReadableStream<Uint8Array<ArrayBuffer>>): Promise<Uint8Array<ArrayBuffer>>;
2
+ //# sourceMappingURL=stream-to-bytes.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"stream-to-bytes.d.ts","sourceRoot":"","sources":["../../src/stream-to-bytes.ts"],"names":[],"mappings":"AAEA,wBAAsB,aAAa,CAClC,MAAM,EAAE,cAAc,CAAC,UAAU,CAAC,WAAW,CAAC,CAAC,GAC7C,OAAO,CAAC,UAAU,CAAC,WAAW,CAAC,CAAC,CAelC"}
@@ -0,0 +1,14 @@
1
+ import { concatBytes } from "./concat-bytes";
2
+ export async function streamToBytes(stream) {
3
+ const reader = stream.getReader();
4
+ const chunks = [];
5
+ while (true) {
6
+ const { done, value } = await reader.read();
7
+ if (done) {
8
+ break;
9
+ }
10
+ chunks.push(value);
11
+ }
12
+ return concatBytes(chunks);
13
+ }
14
+ //# sourceMappingURL=stream-to-bytes.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"stream-to-bytes.js","sourceRoot":"","sources":["../../src/stream-to-bytes.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAA;AAE5C,MAAM,CAAC,KAAK,UAAU,aAAa,CAClC,MAA+C;IAE/C,MAAM,MAAM,GAAG,MAAM,CAAC,SAAS,EAAE,CAAA;IACjC,MAAM,MAAM,GAA8B,EAAE,CAAA;IAE5C,OAAO,IAAI,EAAE,CAAC;QACb,MAAM,EAAE,IAAI,EAAE,KAAK,EAAE,GAAG,MAAM,MAAM,CAAC,IAAI,EAAE,CAAA;QAE3C,IAAI,IAAI,EAAE,CAAC;YACV,MAAK;QACN,CAAC;QAED,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC,CAAA;IACnB,CAAC;IAED,OAAO,WAAW,CAAC,MAAM,CAAC,CAAA;AAC3B,CAAC"}
@@ -0,0 +1,36 @@
1
+ export declare function getFixturePath(url: string): string;
2
+ /**
3
+ * Get file from the cache folder or download it from the URL
4
+ */
5
+ export declare function getFixtureFile(url: string): Promise<Uint8Array<ArrayBufferLike>>;
6
+ export declare function getFixtureFileReadStream(url: string): ReadableStream<Uint8Array<ArrayBufferLike>>;
7
+ export declare function getFixtureFileWriteStream(url: string): WritableStream<Uint8Array<ArrayBufferLike>>;
8
+ export type PbfFixture = {
9
+ url: string;
10
+ bbox: {
11
+ bottom: number;
12
+ top: number;
13
+ left: number;
14
+ right: number;
15
+ };
16
+ nodesWithTags: number;
17
+ nodes: number;
18
+ ways: number;
19
+ relations: number;
20
+ node0: {
21
+ lat: number;
22
+ lon: number;
23
+ id: number;
24
+ };
25
+ way0: number;
26
+ relation0: number;
27
+ uniqueStrings: number;
28
+ primitiveGroups: number;
29
+ };
30
+ export declare const AllPBFs: Record<string, PbfFixture>;
31
+ /**
32
+ * A subset of the PBFs that we want to use for current tests. Do not check in changes to this list as it will cause CI to
33
+ * attempt to download PBFs that are not checked into the repository.
34
+ */
35
+ export declare const PBFs: Record<string, PbfFixture>;
36
+ //# sourceMappingURL=fixtures.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"fixtures.d.ts","sourceRoot":"","sources":["../../../src/test/fixtures.ts"],"names":[],"mappings":"AAUA,wBAAgB,cAAc,CAAC,GAAG,EAAE,MAAM,UAOzC;AAED;;GAEG;AACH,wBAAsB,cAAc,CACnC,GAAG,EAAE,MAAM,GACT,OAAO,CAAC,UAAU,CAAC,eAAe,CAAC,CAAC,CAYtC;AAED,wBAAgB,wBAAwB,CAAC,GAAG,EAAE,MAAM,GAGnC,cAAc,CAAC,UAAU,CAAC,eAAe,CAAC,CAAC,CAC3D;AAED,wBAAgB,yBAAyB,CAAC,GAAG,EAAE,MAAM,GAGpC,cAAc,CAAC,UAAU,CAAC,eAAe,CAAC,CAAC,CAC3D;AAED,MAAM,MAAM,UAAU,GAAG;IACxB,GAAG,EAAE,MAAM,CAAA;IACX,IAAI,EAAE;QACL,MAAM,EAAE,MAAM,CAAA;QACd,GAAG,EAAE,MAAM,CAAA;QACX,IAAI,EAAE,MAAM,CAAA;QACZ,KAAK,EAAE,MAAM,CAAA;KACb,CAAA;IACD,aAAa,EAAE,MAAM,CAAA;IACrB,KAAK,EAAE,MAAM,CAAA;IACb,IAAI,EAAE,MAAM,CAAA;IACZ,SAAS,EAAE,MAAM,CAAA;IACjB,KAAK,EAAE;QACN,GAAG,EAAE,MAAM,CAAA;QACX,GAAG,EAAE,MAAM,CAAA;QACX,EAAE,EAAE,MAAM,CAAA;KACV,CAAA;IACD,IAAI,EAAE,MAAM,CAAA;IACZ,SAAS,EAAE,MAAM,CAAA;IACjB,aAAa,EAAE,MAAM,CAAA;IACrB,eAAe,EAAE,MAAM,CAAA;CACvB,CAAA;AAiCD,eAAO,MAAM,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,UAAU,CA0FrC,CAAA;AAEV;;;GAGG;AACH,eAAO,MAAM,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,UAAU,CAAgC,CAAA"}
@@ -0,0 +1,167 @@
1
+ import { createReadStream, createWriteStream } from "node:fs";
2
+ import { readFile, writeFile } from "node:fs/promises";
3
+ import { dirname, join, resolve } from "node:path";
4
+ import { Readable, Writable } from "node:stream";
5
+ import { fileURLToPath } from "node:url";
6
+ const __dirname = dirname(fileURLToPath(import.meta.url));
7
+ const ROOT_DIR = resolve(__dirname, "../../../../");
8
+ const FIXTURES_DIR = resolve(ROOT_DIR, "fixtures");
9
+ export function getFixturePath(url) {
10
+ if (url.startsWith("http")) {
11
+ const fileName = url.split("/").pop();
12
+ if (!fileName)
13
+ throw new Error("Invalid URL");
14
+ return join(FIXTURES_DIR, fileName);
15
+ }
16
+ return join(FIXTURES_DIR, url);
17
+ }
18
+ /**
19
+ * Get file from the cache folder or download it from the URL
20
+ */
21
+ export async function getFixtureFile(url) {
22
+ const filePath = getFixturePath(url);
23
+ try {
24
+ const file = await readFile(filePath);
25
+ return new Uint8Array(file.buffer);
26
+ }
27
+ catch (_error) {
28
+ const response = await fetch(url);
29
+ const buffer = await response.arrayBuffer();
30
+ const data = new Uint8Array(buffer);
31
+ await writeFile(filePath, data);
32
+ return data;
33
+ }
34
+ }
35
+ export function getFixtureFileReadStream(url) {
36
+ return Readable.toWeb(createReadStream(getFixturePath(url)));
37
+ }
38
+ export function getFixtureFileWriteStream(url) {
39
+ return Writable.toWeb(createWriteStream(getFixturePath(url)));
40
+ }
41
+ /**
42
+ * List of PBFs and their metadata used for testing. Cached locally in the top level fixtures directory so they can
43
+ * be used across packages and apps.
44
+ *
45
+ * `monaco.pbf` is checked into the repository so it can be used in CI without causing repeated downloads.
46
+ *
47
+ * Below, we export a subset of the PBFs that we want to use for current tests.
48
+ */
49
+ const monacoPbfFixture = {
50
+ url: "monaco.pbf",
51
+ bbox: {
52
+ bottom: 43.7232244,
53
+ top: 43.7543687,
54
+ left: 7.4053929,
55
+ right: 7.4447259,
56
+ },
57
+ nodesWithTags: 1_254,
58
+ nodes: 14_286,
59
+ ways: 3_346,
60
+ relations: 46,
61
+ node0: {
62
+ lat: 43.7371175,
63
+ lon: 7.4229093,
64
+ id: 21911883,
65
+ },
66
+ way0: 4097656,
67
+ relation0: 3410831,
68
+ uniqueStrings: 1_060,
69
+ primitiveGroups: 7,
70
+ };
71
+ export const AllPBFs = {
72
+ monaco: monacoPbfFixture,
73
+ montenegro: {
74
+ url: "https://download.geofabrik.de/europe/montenegro-250101.osm.pbf",
75
+ bbox: {
76
+ bottom: 41.61621,
77
+ top: 43.562169,
78
+ left: 18.17282,
79
+ right: 20.358827,
80
+ },
81
+ nodesWithTags: 63_321,
82
+ nodes: 3_915_383,
83
+ ways: 321_330,
84
+ relations: 5_501,
85
+ node0: {
86
+ lat: 42.1982436,
87
+ lon: 18.9656482,
88
+ id: 26860768,
89
+ },
90
+ way0: 123,
91
+ relation0: 123,
92
+ uniqueStrings: 55_071,
93
+ primitiveGroups: 532,
94
+ },
95
+ croatia: {
96
+ url: "https://download.geofabrik.de/europe/croatia-250101.osm.pbf",
97
+ bbox: {
98
+ bottom: 42.16483,
99
+ top: 46.557562,
100
+ left: 13.08916,
101
+ right: 19.459968,
102
+ },
103
+ nodesWithTags: 481_613,
104
+ nodes: 23_063_621,
105
+ ways: 2_315_247,
106
+ relations: 39_098,
107
+ primitiveGroups: 3_178,
108
+ node0: {
109
+ lat: 42.9738772,
110
+ lon: 17.021989,
111
+ id: 4_511_653,
112
+ },
113
+ way0: 123,
114
+ relation0: 123,
115
+ uniqueStrings: 269_315,
116
+ },
117
+ italy: {
118
+ url: "https://download.geofabrik.de/europe/italy-250101.osm.pbf",
119
+ bbox: {
120
+ bottom: 35.07638,
121
+ left: 6.602696,
122
+ right: 19.12499,
123
+ top: 47.100045,
124
+ },
125
+ nodesWithTags: 1_513_303,
126
+ nodes: 250_818_620,
127
+ ways: 27_837_987,
128
+ relations: 100_000,
129
+ primitiveGroups: 34_901,
130
+ node0: {
131
+ lat: 41.9033,
132
+ lon: 12.4534,
133
+ id: 1,
134
+ },
135
+ way0: 123,
136
+ relation0: 123,
137
+ uniqueStrings: 3190,
138
+ },
139
+ washington: {
140
+ url: "https://download.geofabrik.de/north-america/us/washington-250101.osm.pbf",
141
+ bbox: {
142
+ bottom: 45.53882,
143
+ top: 49.00708,
144
+ left: -126.7423,
145
+ right: -116.911526,
146
+ },
147
+ nodesWithTags: 1_513_303,
148
+ nodes: 43_032_447,
149
+ ways: 4_541_651,
150
+ relations: 44_373,
151
+ node0: {
152
+ lat: 47.64248,
153
+ lon: -122.3196898,
154
+ id: 29445653,
155
+ },
156
+ way0: 123,
157
+ relation0: 123,
158
+ uniqueStrings: 598_993,
159
+ primitiveGroups: 34_901,
160
+ },
161
+ };
162
+ /**
163
+ * A subset of the PBFs that we want to use for current tests. Do not check in changes to this list as it will cause CI to
164
+ * attempt to download PBFs that are not checked into the repository.
165
+ */
166
+ export const PBFs = { monaco: monacoPbfFixture };
167
+ //# sourceMappingURL=fixtures.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"fixtures.js","sourceRoot":"","sources":["../../../src/test/fixtures.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAE,iBAAiB,EAAE,MAAM,SAAS,CAAA;AAC7D,OAAO,EAAE,QAAQ,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAA;AACtD,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,OAAO,EAAE,MAAM,WAAW,CAAA;AAClD,OAAO,EAAE,QAAQ,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAA;AAChD,OAAO,EAAE,aAAa,EAAE,MAAM,UAAU,CAAA;AAExC,MAAM,SAAS,GAAG,OAAO,CAAC,aAAa,CAAC,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,CAAA;AACzD,MAAM,QAAQ,GAAG,OAAO,CAAC,SAAS,EAAE,cAAc,CAAC,CAAA;AACnD,MAAM,YAAY,GAAG,OAAO,CAAC,QAAQ,EAAE,UAAU,CAAC,CAAA;AAElD,MAAM,UAAU,cAAc,CAAC,GAAW;IACzC,IAAI,GAAG,CAAC,UAAU,CAAC,MAAM,CAAC,EAAE,CAAC;QAC5B,MAAM,QAAQ,GAAG,GAAG,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,GAAG,EAAE,CAAA;QACrC,IAAI,CAAC,QAAQ;YAAE,MAAM,IAAI,KAAK,CAAC,aAAa,CAAC,CAAA;QAC7C,OAAO,IAAI,CAAC,YAAY,EAAE,QAAQ,CAAC,CAAA;IACpC,CAAC;IACD,OAAO,IAAI,CAAC,YAAY,EAAE,GAAG,CAAC,CAAA;AAC/B,CAAC;AAED;;GAEG;AACH,MAAM,CAAC,KAAK,UAAU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K,EAAE,WAAW;QAClB,IAAI,EAAE,UAAU;QAChB,SAAS,EAAE,OAAO;QAClB,eAAe,EAAE,MAAM;QACvB,KAAK,EAAE;YACN,GAAG,EAAE,OAAO;YACZ,GAAG,EAAE,OAAO;YACZ,EAAE,EAAE,CAAC;SACL;QACD,IAAI,EAAE,GAAG;QACT,SAAS,EAAE,GAAG;QACd,aAAa,EAAE,IAAI;KACnB;IACD,UAAU,EAAE;QACX,GAAG,EAAE,0EAA0E;QAC/E,IAAI,EAAE;YACL,MAAM,EAAE,QAAQ;YAChB,GAAG,EAAE,QAAQ;YACb,IAAI,EAAE,CAAC,QAAQ;YACf,KAAK,EAAE,CAAC,UAAU;SAClB;QACD,aAAa,EAAE,SAAS;QACxB,KAAK,EAAE,UAAU;QACjB,IAAI,EAAE,SAAS;QACf,SAAS,EAAE,MAAM;QACjB,KAAK,EAAE;YACN,GAAG,EAAE,QAAQ;YACb,GAAG,EAAE,CAAC,WAAW;YACjB,EAAE,EAAE,QAAQ;SACZ;QACD,IAAI,EAAE,GAAG;QACT,SAAS,EAAE,GAAG;QACd,aAAa,EAAE,OAAO;QACtB,eAAe,EAAE,MAAM;KACvB;CACQ,CAAA;AAEV;;;GAGG;AACH,MAAM,CAAC,MAAM,IAAI,GAA+B,EAAE,MAAM,EAAE,gBAAgB,EAAE,CAAA"}
@@ -0,0 +1,2 @@
1
+ export declare function transformBytes(bytes: Uint8Array<ArrayBuffer>, transformStream: TransformStream<Uint8Array<ArrayBuffer>, Uint8Array<ArrayBuffer>>): Promise<Uint8Array<ArrayBuffer>>;
2
+ //# sourceMappingURL=transform-bytes.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"transform-bytes.d.ts","sourceRoot":"","sources":["../../src/transform-bytes.ts"],"names":[],"mappings":"AAGA,wBAAsB,cAAc,CACnC,KAAK,EAAE,UAAU,CAAC,WAAW,CAAC,EAC9B,eAAe,EAAE,eAAe,CAC/B,UAAU,CAAC,WAAW,CAAC,EACvB,UAAU,CAAC,WAAW,CAAC,CACvB,GACC,OAAO,CAAC,UAAU,CAAC,WAAW,CAAC,CAAC,CAElC"}
@@ -0,0 +1,6 @@
1
+ import { bytesToStream } from "./bytes-to-stream";
2
+ import { streamToBytes } from "./stream-to-bytes";
3
+ export async function transformBytes(bytes, transformStream) {
4
+ return streamToBytes(bytesToStream(bytes).pipeThrough(transformStream));
5
+ }
6
+ //# sourceMappingURL=transform-bytes.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"transform-bytes.js","sourceRoot":"","sources":["../../src/transform-bytes.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,mBAAmB,CAAA;AACjD,OAAO,EAAE,aAAa,EAAE,MAAM,mBAAmB,CAAA;AAEjD,MAAM,CAAC,KAAK,UAAU,cAAc,CACnC,KAA8B,EAC9B,eAGC;IAED,OAAO,aAAa,CAAC,aAAa,CAAC,KAAK,CAAC,CAAC,WAAW,CAAC,eAAe,CAAC,CAAC,CAAA;AACxE,CAAC"}
@@ -0,0 +1,24 @@
1
+ export type LonLat = [lon: number, lat: number];
2
+ export type XY = [x: number, y: number];
3
+ export interface ILonLat {
4
+ lon: number;
5
+ lat: number;
6
+ }
7
+ export type Tile = [x: number, y: number, z: number];
8
+ /**
9
+ * Project LonLat to pixels
10
+ */
11
+ export type LonLatToPixel = (ll: LonLat, zoom: number) => XY;
12
+ export type LonLatToTilePixel = (ll: LonLat, z: number, extent: number) => XY;
13
+ export type Rgba = [number, number, number, number] | Uint8ClampedArray;
14
+ /**
15
+ * A bounding box in the format [minLon, minLat, maxLon, maxLat].
16
+ * GeoJSON.BBox allows for 3D bounding boxes, but we use tools that expect 2D bounding boxes.
17
+ */
18
+ export type GeoBbox2D = [
19
+ minLon: number,
20
+ minLat: number,
21
+ maxLon: number,
22
+ maxLat: number
23
+ ];
24
+ //# sourceMappingURL=types.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/types.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,MAAM,GAAG,CAAC,GAAG,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,CAAC,CAAA;AAC/C,MAAM,MAAM,EAAE,GAAG,CAAC,CAAC,EAAE,MAAM,EAAE,CAAC,EAAE,MAAM,CAAC,CAAA;AACvC,MAAM,WAAW,OAAO;IACvB,GAAG,EAAE,MAAM,CAAA;IACX,GAAG,EAAE,MAAM,CAAA;CACX;AACD,MAAM,MAAM,IAAI,GAAG,CAAC,CAAC,EAAE,MAAM,EAAE,CAAC,EAAE,MAAM,EAAE,CAAC,EAAE,MAAM,CAAC,CAAA;AAEpD;;GAEG;AACH,MAAM,MAAM,aAAa,GAAG,CAAC,EAAE,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,KAAK,EAAE,CAAA;AAE5D,MAAM,MAAM,iBAAiB,GAAG,CAAC,EAAE,EAAE,MAAM,EAAE,CAAC,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,KAAK,EAAE,CAAA;AAE7E,MAAM,MAAM,IAAI,GAAG,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,CAAC,GAAG,iBAAiB,CAAA;AAEvE;;;GAGG;AACH,MAAM,MAAM,SAAS,GAAG;IACvB,MAAM,EAAE,MAAM;IACd,MAAM,EAAE,MAAM;IACd,MAAM,EAAE,MAAM;IACd,MAAM,EAAE,MAAM;CACd,CAAA"}
@@ -0,0 +1 @@
1
+ //# sourceMappingURL=types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/types.ts"],"names":[],"mappings":""}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=haversine-distance.test.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"haversine-distance.test.d.ts","sourceRoot":"","sources":["../../test/haversine-distance.test.ts"],"names":[],"mappings":""}
@@ -0,0 +1,8 @@
1
+ import { assert, test } from "vitest";
2
+ import { haversineDistance } from "../src/haversine-distance";
3
+ test("haversineDistance", () => {
4
+ const p1 = [-75.343, 39.984];
5
+ const p2 = [-75.534, 39.123];
6
+ assert.closeTo(haversineDistance(p1, p2), 97129.2211, 0.0001);
7
+ });
8
+ //# sourceMappingURL=haversine-distance.test.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"haversine-distance.test.js","sourceRoot":"","sources":["../../test/haversine-distance.test.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,QAAQ,CAAA;AACrC,OAAO,EAAE,iBAAiB,EAAE,MAAM,2BAA2B,CAAA;AAE7D,IAAI,CAAC,mBAAmB,EAAE,GAAG,EAAE;IAC9B,MAAM,EAAE,GAAqB,CAAC,CAAC,MAAM,EAAE,MAAM,CAAC,CAAA;IAC9C,MAAM,EAAE,GAAqB,CAAC,CAAC,MAAM,EAAE,MAAM,CAAC,CAAA;IAC9C,MAAM,CAAC,OAAO,CAAC,iBAAiB,CAAC,EAAE,EAAE,EAAE,CAAC,EAAE,UAAU,EAAE,MAAM,CAAC,CAAA;AAC9D,CAAC,CAAC,CAAA"}
package/package.json CHANGED
@@ -2,7 +2,7 @@
2
2
  "$schema": "https://json.schemastore.org/package",
3
3
  "name": "@osmix/shared",
4
4
  "type": "module",
5
- "version": "0.0.1",
5
+ "version": "0.0.2",
6
6
  "description": "Shared utilities for Osmix",
7
7
  "exports": {
8
8
  "./*": "./src/*.ts",
@@ -38,10 +38,12 @@
38
38
  "scripts": {
39
39
  "build": "tsc",
40
40
  "bench": "vitest bench",
41
+ "prepublishOnly": "tsc",
41
42
  "test": "vitest",
42
43
  "typecheck": "tsc --noEmit"
43
44
  },
44
45
  "devDependencies": {
46
+ "@types/node": "catalog:",
45
47
  "typescript": "catalog:",
46
48
  "vitest": "catalog:"
47
49
  },
@@ -20,29 +20,32 @@ export function getFixturePath(url: string) {
20
20
  /**
21
21
  * Get file from the cache folder or download it from the URL
22
22
  */
23
- export async function getFixtureFile(url: string): Promise<ArrayBuffer> {
23
+ export async function getFixtureFile(
24
+ url: string,
25
+ ): Promise<Uint8Array<ArrayBufferLike>> {
24
26
  const filePath = getFixturePath(url)
25
27
  try {
26
28
  const file = await readFile(filePath)
27
- return file.buffer as ArrayBuffer
29
+ return new Uint8Array<ArrayBuffer>(file.buffer as ArrayBuffer)
28
30
  } catch (_error) {
29
31
  const response = await fetch(url)
30
32
  const buffer = await response.arrayBuffer()
31
- await writeFile(filePath, new Uint8Array(buffer))
32
- return buffer
33
+ const data = new Uint8Array<ArrayBuffer>(buffer)
34
+ await writeFile(filePath, data)
35
+ return data
33
36
  }
34
37
  }
35
38
 
36
39
  export function getFixtureFileReadStream(url: string) {
37
40
  return Readable.toWeb(
38
41
  createReadStream(getFixturePath(url)),
39
- ) as unknown as ReadableStream<ArrayBuffer>
42
+ ) as unknown as ReadableStream<Uint8Array<ArrayBufferLike>>
40
43
  }
41
44
 
42
45
  export function getFixtureFileWriteStream(url: string) {
43
46
  return Writable.toWeb(
44
47
  createWriteStream(getFixturePath(url)),
45
- ) as unknown as WritableStream<Uint8Array>
48
+ ) as unknown as WritableStream<Uint8Array<ArrayBufferLike>>
46
49
  }
47
50
 
48
51
  export type PbfFixture = {
@@ -17,9 +17,11 @@
17
17
  "isolatedModules": true,
18
18
  "erasableSyntaxOnly": true,
19
19
  "skipLibCheck": true,
20
+ "forceConsistentCasingInFileNames": true,
20
21
 
21
22
  "strict": true,
22
23
  "noFallthroughCasesInSwitch": true,
24
+ "noImplicitOverride": true,
23
25
  "noUncheckedIndexedAccess": true,
24
26
  "noUnusedLocals": true,
25
27
  "noUnusedParameters": true,