zod-geojson 0.0.1

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 (60) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +107 -0
  3. package/lib/base.d.ts +9 -0
  4. package/lib/base.d.ts.map +1 -0
  5. package/lib/base.js +8 -0
  6. package/lib/bbox.d.ts +4 -0
  7. package/lib/bbox.d.ts.map +1 -0
  8. package/lib/bbox.js +9 -0
  9. package/lib/feature.d.ts +634 -0
  10. package/lib/feature.d.ts.map +1 -0
  11. package/lib/feature.js +37 -0
  12. package/lib/feature_collection.d.ts +3174 -0
  13. package/lib/feature_collection.d.ts.map +1 -0
  14. package/lib/feature_collection.js +61 -0
  15. package/lib/geometry/_simple.d.ts +122 -0
  16. package/lib/geometry/_simple.d.ts.map +1 -0
  17. package/lib/geometry/_simple.js +14 -0
  18. package/lib/geometry/geometry_collection.d.ts +18 -0
  19. package/lib/geometry/geometry_collection.d.ts.map +1 -0
  20. package/lib/geometry/geometry_collection.js +60 -0
  21. package/lib/geometry/index.d.ts +131 -0
  22. package/lib/geometry/index.d.ts.map +1 -0
  23. package/lib/geometry/index.js +27 -0
  24. package/lib/geometry/line_string.d.ts +25 -0
  25. package/lib/geometry/line_string.d.ts.map +1 -0
  26. package/lib/geometry/line_string.js +33 -0
  27. package/lib/geometry/multi_line_string.d.ts +24 -0
  28. package/lib/geometry/multi_line_string.d.ts.map +1 -0
  29. package/lib/geometry/multi_line_string.js +32 -0
  30. package/lib/geometry/multi_point.d.ts +24 -0
  31. package/lib/geometry/multi_point.d.ts.map +1 -0
  32. package/lib/geometry/multi_point.js +32 -0
  33. package/lib/geometry/multi_polygon.d.ts +24 -0
  34. package/lib/geometry/multi_polygon.d.ts.map +1 -0
  35. package/lib/geometry/multi_polygon.js +44 -0
  36. package/lib/geometry/point.d.ts +24 -0
  37. package/lib/geometry/point.d.ts.map +1 -0
  38. package/lib/geometry/point.js +25 -0
  39. package/lib/geometry/polygon.d.ts +28 -0
  40. package/lib/geometry/polygon.d.ts.map +1 -0
  41. package/lib/geometry/polygon.js +51 -0
  42. package/lib/geometry/validation/bbox.d.ts +50 -0
  43. package/lib/geometry/validation/bbox.d.ts.map +1 -0
  44. package/lib/geometry/validation/bbox.js +184 -0
  45. package/lib/geometry/validation/dimension.d.ts +16 -0
  46. package/lib/geometry/validation/dimension.d.ts.map +1 -0
  47. package/lib/geometry/validation/dimension.js +54 -0
  48. package/lib/geometry/validation/keys.d.ts +6 -0
  49. package/lib/geometry/validation/keys.d.ts.map +1 -0
  50. package/lib/geometry/validation/keys.js +14 -0
  51. package/lib/index.d.ts +3930 -0
  52. package/lib/index.d.ts.map +1 -0
  53. package/lib/index.js +29 -0
  54. package/lib/position.d.ts +5 -0
  55. package/lib/position.d.ts.map +1 -0
  56. package/lib/position.js +8 -0
  57. package/lib/type.d.ts +6 -0
  58. package/lib/type.d.ts.map +1 -0
  59. package/lib/type.js +15 -0
  60. package/package.json +41 -0
@@ -0,0 +1,24 @@
1
+ import { z } from "zod";
2
+ export declare const GeoJSONMultiPointSchema: z.ZodEffects<z.ZodObject<{
3
+ bbox: z.ZodOptional<z.ZodEffects<z.ZodArray<z.ZodNumber, "many">, number[], number[]>>;
4
+ type: z.ZodLiteral<"MultiPoint">;
5
+ coordinates: z.ZodArray<z.ZodArray<z.ZodNumber, "many">, "many">;
6
+ }, "passthrough", z.ZodTypeAny, z.objectOutputType<{
7
+ bbox: z.ZodOptional<z.ZodEffects<z.ZodArray<z.ZodNumber, "many">, number[], number[]>>;
8
+ type: z.ZodLiteral<"MultiPoint">;
9
+ coordinates: z.ZodArray<z.ZodArray<z.ZodNumber, "many">, "many">;
10
+ }, z.ZodTypeAny, "passthrough">, z.objectInputType<{
11
+ bbox: z.ZodOptional<z.ZodEffects<z.ZodArray<z.ZodNumber, "many">, number[], number[]>>;
12
+ type: z.ZodLiteral<"MultiPoint">;
13
+ coordinates: z.ZodArray<z.ZodArray<z.ZodNumber, "many">, "many">;
14
+ }, z.ZodTypeAny, "passthrough">>, z.objectOutputType<{
15
+ bbox: z.ZodOptional<z.ZodEffects<z.ZodArray<z.ZodNumber, "many">, number[], number[]>>;
16
+ type: z.ZodLiteral<"MultiPoint">;
17
+ coordinates: z.ZodArray<z.ZodArray<z.ZodNumber, "many">, "many">;
18
+ }, z.ZodTypeAny, "passthrough">, z.objectInputType<{
19
+ bbox: z.ZodOptional<z.ZodEffects<z.ZodArray<z.ZodNumber, "many">, number[], number[]>>;
20
+ type: z.ZodLiteral<"MultiPoint">;
21
+ coordinates: z.ZodArray<z.ZodArray<z.ZodNumber, "many">, "many">;
22
+ }, z.ZodTypeAny, "passthrough">>;
23
+ export type GeoJSONMultiPoint = z.infer<typeof GeoJSONMultiPointSchema>;
24
+ //# sourceMappingURL=multi_point.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"multi_point.d.ts","sourceRoot":"","sources":["../../src/geometry/multi_point.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAOxB,eAAO,MAAM,uBAAuB;;;;;;;;;;;;;;;;;;;;gCAuB9B,CAAC;AAEP,MAAM,MAAM,iBAAiB,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,uBAAuB,CAAC,CAAC"}
@@ -0,0 +1,32 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.GeoJSONMultiPointSchema = void 0;
4
+ var zod_1 = require("zod");
5
+ var position_1 = require("../position");
6
+ var bbox_1 = require("./validation/bbox");
7
+ var dimension_1 = require("./validation/dimension");
8
+ var keys_1 = require("./validation/keys");
9
+ var base_1 = require("../base");
10
+ exports.GeoJSONMultiPointSchema = base_1.GeoJSONBaseSchema.extend({
11
+ type: zod_1.z.literal("MultiPoint"),
12
+ coordinates: zod_1.z.array(position_1.GeoJSONPositionSchema).min(1),
13
+ })
14
+ .passthrough()
15
+ .superRefine(function (val, ctx) {
16
+ if (!(0, keys_1.validGeometryKeys)(val)) {
17
+ ctx.addIssue(keys_1.INVALID_KEYS_ISSUE);
18
+ return;
19
+ }
20
+ // Skip remaining checks if coordinates empty
21
+ if (!val.coordinates.length) {
22
+ return;
23
+ }
24
+ if (!(0, dimension_1.validDimensionsForPositionList)(val)) {
25
+ ctx.addIssue(dimension_1.INVALID_DIMENSIONS_ISSUE);
26
+ return;
27
+ }
28
+ if (!(0, bbox_1.validBboxForPositionList)(val)) {
29
+ ctx.addIssue(bbox_1.INVALID_BBOX_ISSUE);
30
+ return;
31
+ }
32
+ });
@@ -0,0 +1,24 @@
1
+ import { z } from "zod";
2
+ export declare const GeoJSONMultiPolygonSchema: z.ZodEffects<z.ZodObject<{
3
+ bbox: z.ZodOptional<z.ZodEffects<z.ZodArray<z.ZodNumber, "many">, number[], number[]>>;
4
+ type: z.ZodLiteral<"MultiPolygon">;
5
+ coordinates: z.ZodArray<z.ZodArray<z.ZodArray<z.ZodArray<z.ZodNumber, "many">, "many">, "many">, "many">;
6
+ }, "passthrough", z.ZodTypeAny, z.objectOutputType<{
7
+ bbox: z.ZodOptional<z.ZodEffects<z.ZodArray<z.ZodNumber, "many">, number[], number[]>>;
8
+ type: z.ZodLiteral<"MultiPolygon">;
9
+ coordinates: z.ZodArray<z.ZodArray<z.ZodArray<z.ZodArray<z.ZodNumber, "many">, "many">, "many">, "many">;
10
+ }, z.ZodTypeAny, "passthrough">, z.objectInputType<{
11
+ bbox: z.ZodOptional<z.ZodEffects<z.ZodArray<z.ZodNumber, "many">, number[], number[]>>;
12
+ type: z.ZodLiteral<"MultiPolygon">;
13
+ coordinates: z.ZodArray<z.ZodArray<z.ZodArray<z.ZodArray<z.ZodNumber, "many">, "many">, "many">, "many">;
14
+ }, z.ZodTypeAny, "passthrough">>, z.objectOutputType<{
15
+ bbox: z.ZodOptional<z.ZodEffects<z.ZodArray<z.ZodNumber, "many">, number[], number[]>>;
16
+ type: z.ZodLiteral<"MultiPolygon">;
17
+ coordinates: z.ZodArray<z.ZodArray<z.ZodArray<z.ZodArray<z.ZodNumber, "many">, "many">, "many">, "many">;
18
+ }, z.ZodTypeAny, "passthrough">, z.objectInputType<{
19
+ bbox: z.ZodOptional<z.ZodEffects<z.ZodArray<z.ZodNumber, "many">, number[], number[]>>;
20
+ type: z.ZodLiteral<"MultiPolygon">;
21
+ coordinates: z.ZodArray<z.ZodArray<z.ZodArray<z.ZodArray<z.ZodNumber, "many">, "many">, "many">, "many">;
22
+ }, z.ZodTypeAny, "passthrough">>;
23
+ export type GeoJSONMultiPolygon = z.infer<typeof GeoJSONMultiPolygonSchema>;
24
+ //# sourceMappingURL=multi_polygon.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"multi_polygon.d.ts","sourceRoot":"","sources":["../../src/geometry/multi_polygon.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAgBxB,eAAO,MAAM,yBAAyB;;;;;;;;;;;;;;;;;;;;gCA6BhC,CAAC;AAEP,MAAM,MAAM,mBAAmB,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,yBAAyB,CAAC,CAAC"}
@@ -0,0 +1,44 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.GeoJSONMultiPolygonSchema = void 0;
4
+ var zod_1 = require("zod");
5
+ var bbox_1 = require("./validation/bbox");
6
+ var dimension_1 = require("./validation/dimension");
7
+ var keys_1 = require("./validation/keys");
8
+ var polygon_1 = require("./polygon");
9
+ var base_1 = require("../base");
10
+ var INVALID_LINEAR_RING_MESSAGE = {
11
+ code: "custom",
12
+ message: "Invalid multi polygon. Each polygon inside the multi polygon must be made out of linear rings.",
13
+ };
14
+ function validMultiPolygonLinearRings(_a) {
15
+ var coordinates = _a.coordinates;
16
+ return coordinates.every(function (polygon) { return (0, polygon_1.validPolygonRings)({ coordinates: polygon }); });
17
+ }
18
+ exports.GeoJSONMultiPolygonSchema = base_1.GeoJSONBaseSchema.extend({
19
+ type: zod_1.z.literal("MultiPolygon"),
20
+ coordinates: zod_1.z.array(polygon_1.GeoJSONPolygonCoordinatesSchema).min(1),
21
+ })
22
+ .passthrough()
23
+ .superRefine(function (val, ctx) {
24
+ if (!(0, keys_1.validGeometryKeys)(val)) {
25
+ ctx.addIssue(keys_1.INVALID_KEYS_ISSUE);
26
+ return;
27
+ }
28
+ // Skip remaining checks if coordinates array is empty
29
+ if (!val.coordinates.length) {
30
+ return;
31
+ }
32
+ if (!(0, dimension_1.validDimensionsForPositionGridList)(val)) {
33
+ ctx.addIssue(dimension_1.INVALID_DIMENSIONS_ISSUE);
34
+ return;
35
+ }
36
+ if (!validMultiPolygonLinearRings(val)) {
37
+ ctx.addIssue(INVALID_LINEAR_RING_MESSAGE);
38
+ return;
39
+ }
40
+ if (!(0, bbox_1.validBboxForPositionGridList)(val)) {
41
+ ctx.addIssue(bbox_1.INVALID_BBOX_ISSUE);
42
+ return;
43
+ }
44
+ });
@@ -0,0 +1,24 @@
1
+ import { z } from "zod";
2
+ export declare const GeoJSONPointSchema: z.ZodEffects<z.ZodObject<{
3
+ bbox: z.ZodOptional<z.ZodEffects<z.ZodArray<z.ZodNumber, "many">, number[], number[]>>;
4
+ type: z.ZodLiteral<"Point">;
5
+ coordinates: z.ZodArray<z.ZodNumber, "many">;
6
+ }, "passthrough", z.ZodTypeAny, z.objectOutputType<{
7
+ bbox: z.ZodOptional<z.ZodEffects<z.ZodArray<z.ZodNumber, "many">, number[], number[]>>;
8
+ type: z.ZodLiteral<"Point">;
9
+ coordinates: z.ZodArray<z.ZodNumber, "many">;
10
+ }, z.ZodTypeAny, "passthrough">, z.objectInputType<{
11
+ bbox: z.ZodOptional<z.ZodEffects<z.ZodArray<z.ZodNumber, "many">, number[], number[]>>;
12
+ type: z.ZodLiteral<"Point">;
13
+ coordinates: z.ZodArray<z.ZodNumber, "many">;
14
+ }, z.ZodTypeAny, "passthrough">>, z.objectOutputType<{
15
+ bbox: z.ZodOptional<z.ZodEffects<z.ZodArray<z.ZodNumber, "many">, number[], number[]>>;
16
+ type: z.ZodLiteral<"Point">;
17
+ coordinates: z.ZodArray<z.ZodNumber, "many">;
18
+ }, z.ZodTypeAny, "passthrough">, z.objectInputType<{
19
+ bbox: z.ZodOptional<z.ZodEffects<z.ZodArray<z.ZodNumber, "many">, number[], number[]>>;
20
+ type: z.ZodLiteral<"Point">;
21
+ coordinates: z.ZodArray<z.ZodNumber, "many">;
22
+ }, z.ZodTypeAny, "passthrough">>;
23
+ export type GeoJSONPoint = z.infer<typeof GeoJSONPointSchema>;
24
+ //# sourceMappingURL=point.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"point.d.ts","sourceRoot":"","sources":["../../src/geometry/point.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAMxB,eAAO,MAAM,kBAAkB;;;;;;;;;;;;;;;;;;;;gCAiBzB,CAAC;AAEP,MAAM,MAAM,YAAY,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,kBAAkB,CAAC,CAAC"}
@@ -0,0 +1,25 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.GeoJSONPointSchema = void 0;
4
+ var zod_1 = require("zod");
5
+ var position_1 = require("../position");
6
+ var bbox_1 = require("./validation/bbox");
7
+ var keys_1 = require("./validation/keys");
8
+ var base_1 = require("../base");
9
+ exports.GeoJSONPointSchema = base_1.GeoJSONBaseSchema.extend({
10
+ type: zod_1.z.literal("Point"),
11
+ coordinates: position_1.GeoJSONPositionSchema,
12
+ })
13
+ .passthrough()
14
+ .superRefine(function (val, ctx) {
15
+ if (!(0, keys_1.validGeometryKeys)(val)) {
16
+ ctx.addIssue(keys_1.INVALID_KEYS_ISSUE);
17
+ }
18
+ // Skip remaining checks if coordinates empty
19
+ if (!val.coordinates.length) {
20
+ return;
21
+ }
22
+ if (!(0, bbox_1.validBboxForPosition)(val)) {
23
+ ctx.addIssue(bbox_1.INVALID_BBOX_ISSUE);
24
+ }
25
+ });
@@ -0,0 +1,28 @@
1
+ import { z } from "zod";
2
+ export declare function validPolygonRings({ coordinates: rings }: {
3
+ coordinates: number[][][];
4
+ }): boolean;
5
+ export declare const GeoJSONPolygonSchema: z.ZodEffects<z.ZodObject<{
6
+ bbox: z.ZodOptional<z.ZodEffects<z.ZodArray<z.ZodNumber, "many">, number[], number[]>>;
7
+ type: z.ZodLiteral<"Polygon">;
8
+ coordinates: z.ZodArray<z.ZodArray<z.ZodArray<z.ZodNumber, "many">, "many">, "many">;
9
+ }, "passthrough", z.ZodTypeAny, z.objectOutputType<{
10
+ bbox: z.ZodOptional<z.ZodEffects<z.ZodArray<z.ZodNumber, "many">, number[], number[]>>;
11
+ type: z.ZodLiteral<"Polygon">;
12
+ coordinates: z.ZodArray<z.ZodArray<z.ZodArray<z.ZodNumber, "many">, "many">, "many">;
13
+ }, z.ZodTypeAny, "passthrough">, z.objectInputType<{
14
+ bbox: z.ZodOptional<z.ZodEffects<z.ZodArray<z.ZodNumber, "many">, number[], number[]>>;
15
+ type: z.ZodLiteral<"Polygon">;
16
+ coordinates: z.ZodArray<z.ZodArray<z.ZodArray<z.ZodNumber, "many">, "many">, "many">;
17
+ }, z.ZodTypeAny, "passthrough">>, z.objectOutputType<{
18
+ bbox: z.ZodOptional<z.ZodEffects<z.ZodArray<z.ZodNumber, "many">, number[], number[]>>;
19
+ type: z.ZodLiteral<"Polygon">;
20
+ coordinates: z.ZodArray<z.ZodArray<z.ZodArray<z.ZodNumber, "many">, "many">, "many">;
21
+ }, z.ZodTypeAny, "passthrough">, z.objectInputType<{
22
+ bbox: z.ZodOptional<z.ZodEffects<z.ZodArray<z.ZodNumber, "many">, number[], number[]>>;
23
+ type: z.ZodLiteral<"Polygon">;
24
+ coordinates: z.ZodArray<z.ZodArray<z.ZodArray<z.ZodNumber, "many">, "many">, "many">;
25
+ }, z.ZodTypeAny, "passthrough">>;
26
+ export declare const GeoJSONPolygonCoordinatesSchema: z.ZodArray<z.ZodArray<z.ZodArray<z.ZodNumber, "many">, "many">, "many">;
27
+ export type GeoJSONPolygon = z.infer<typeof GeoJSONPolygonSchema>;
28
+ //# sourceMappingURL=polygon.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"polygon.d.ts","sourceRoot":"","sources":["../../src/geometry/polygon.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAkBxB,wBAAgB,iBAAiB,CAAC,EAAE,WAAW,EAAE,KAAK,EAAE,EAAE;IAAE,WAAW,EAAE,MAAM,EAAE,EAAE,EAAE,CAAA;CAAE,GAAG,OAAO,CAEhG;AAED,eAAO,MAAM,oBAAoB;;;;;;;;;;;;;;;;;;;;gCA2B3B,CAAC;AAEP,eAAO,MAAM,+BAA+B,yEAAqD,CAAC;AAElG,MAAM,MAAM,cAAc,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,oBAAoB,CAAC,CAAC"}
@@ -0,0 +1,51 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.GeoJSONPolygonCoordinatesSchema = exports.GeoJSONPolygonSchema = exports.validPolygonRings = void 0;
4
+ var zod_1 = require("zod");
5
+ var position_1 = require("../position");
6
+ var bbox_1 = require("./validation/bbox");
7
+ var dimension_1 = require("./validation/dimension");
8
+ var keys_1 = require("./validation/keys");
9
+ var base_1 = require("../base");
10
+ var INVALID_LINEAR_RING_MESSAGE = {
11
+ code: "custom",
12
+ message: "Invalid polygon. Each ring inside a polygon must form a linear ring.",
13
+ };
14
+ function validLinearRing(linearRing) {
15
+ var firstPosition = linearRing[0];
16
+ var lastPosition = linearRing[linearRing.length - 1];
17
+ return firstPosition.every(function (value, index) { return value === lastPosition[index]; });
18
+ }
19
+ function validPolygonRings(_a) {
20
+ var rings = _a.coordinates;
21
+ return rings.every(validLinearRing);
22
+ }
23
+ exports.validPolygonRings = validPolygonRings;
24
+ exports.GeoJSONPolygonSchema = base_1.GeoJSONBaseSchema.extend({
25
+ type: zod_1.z.literal("Polygon"),
26
+ coordinates: zod_1.z.array(zod_1.z.array(position_1.GeoJSONPositionSchema).min(4)),
27
+ })
28
+ .passthrough()
29
+ .superRefine(function (val, ctx) {
30
+ if (!(0, keys_1.validGeometryKeys)(val)) {
31
+ ctx.addIssue(keys_1.INVALID_KEYS_ISSUE);
32
+ return;
33
+ }
34
+ // Skip remaining checks if coordinates array is empty
35
+ if (!val.coordinates.length) {
36
+ return;
37
+ }
38
+ if (!(0, dimension_1.validDimensionsForPositionGrid)(val)) {
39
+ ctx.addIssue(dimension_1.INVALID_DIMENSIONS_ISSUE);
40
+ return;
41
+ }
42
+ if (!validPolygonRings(val)) {
43
+ ctx.addIssue(INVALID_LINEAR_RING_MESSAGE);
44
+ return;
45
+ }
46
+ if (!(0, bbox_1.validBboxForPositionGrid)(val)) {
47
+ ctx.addIssue(bbox_1.INVALID_BBOX_ISSUE);
48
+ return;
49
+ }
50
+ });
51
+ exports.GeoJSONPolygonCoordinatesSchema = exports.GeoJSONPolygonSchema.innerType().shape.coordinates;
@@ -0,0 +1,50 @@
1
+ import { GeoJSONGeometry } from "../index";
2
+ type BboxPositionOptions = {
3
+ bbox?: number[];
4
+ coordinates: number[];
5
+ };
6
+ type BboxPositionListOptions = {
7
+ bbox?: number[];
8
+ coordinates: number[][];
9
+ };
10
+ type BboxPositionGridOptions = {
11
+ bbox?: number[];
12
+ coordinates: number[][][];
13
+ };
14
+ type BboxPositionGridListOptions = {
15
+ bbox?: number[];
16
+ coordinates: number[][][][];
17
+ };
18
+ /**
19
+ * Checks if given bbox is valid for the given position.
20
+ * @param bbox The bbox to validate
21
+ * @param coordinates Contains the position
22
+ */
23
+ export declare function validBboxForPosition({ bbox, coordinates }: BboxPositionOptions): boolean;
24
+ /**
25
+ * Checks if given bbox is valid for the given positions.
26
+ * @param bbox The bbox to validate
27
+ * @param coordinates Contains the list of positions
28
+ */
29
+ export declare function validBboxForPositionList({ bbox, coordinates }: BboxPositionListOptions): boolean;
30
+ /**
31
+ * Checks if given bbox is valid for the given positions grid.
32
+ * @param bbox The bbox to validate
33
+ * @param coordinates Contains the grid of positions
34
+ */
35
+ export declare function validBboxForPositionGrid({ bbox, coordinates }: BboxPositionGridOptions): boolean;
36
+ /**
37
+ * Checks if given bbox is valid for the given positions grid.
38
+ * @param bbox The bbox to validate
39
+ * @param coordinates Contains the grid of positions
40
+ */
41
+ export declare function validBboxForPositionGridList({ bbox, coordinates }: BboxPositionGridListOptions): boolean;
42
+ export declare function getBboxForGeometry(geometry: GeoJSONGeometry): number[];
43
+ export declare function getBboxForGeometries(geometries: GeoJSONGeometry[]): number[];
44
+ export declare function bboxEquals(bbox1: number[], bbox2: number[]): boolean;
45
+ export declare const INVALID_BBOX_ISSUE: {
46
+ code: "custom";
47
+ message: string;
48
+ };
49
+ export {};
50
+ //# sourceMappingURL=bbox.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"bbox.d.ts","sourceRoot":"","sources":["../../../src/geometry/validation/bbox.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,UAAU,CAAC;AAE3C,KAAK,mBAAmB,GAAG;IAAE,IAAI,CAAC,EAAE,MAAM,EAAE,CAAC;IAAC,WAAW,EAAE,MAAM,EAAE,CAAA;CAAE,CAAC;AACtE,KAAK,uBAAuB,GAAG;IAAE,IAAI,CAAC,EAAE,MAAM,EAAE,CAAC;IAAC,WAAW,EAAE,MAAM,EAAE,EAAE,CAAA;CAAE,CAAC;AAC5E,KAAK,uBAAuB,GAAG;IAAE,IAAI,CAAC,EAAE,MAAM,EAAE,CAAC;IAAC,WAAW,EAAE,MAAM,EAAE,EAAE,EAAE,CAAA;CAAE,CAAC;AAC9E,KAAK,2BAA2B,GAAG;IAAE,IAAI,CAAC,EAAE,MAAM,EAAE,CAAC;IAAC,WAAW,EAAE,MAAM,EAAE,EAAE,EAAE,EAAE,CAAA;CAAE,CAAC;AAEpF;;;;GAIG;AACH,wBAAgB,oBAAoB,CAAC,EAAE,IAAI,EAAE,WAAW,EAAE,EAAE,mBAAmB,GAAG,OAAO,CASxF;AAED;;;;GAIG;AACH,wBAAgB,wBAAwB,CAAC,EAAE,IAAI,EAAE,WAAW,EAAE,EAAE,uBAAuB,GAAG,OAAO,CAYhG;AAED;;;;GAIG;AACH,wBAAgB,wBAAwB,CAAC,EAAE,IAAI,EAAE,WAAW,EAAE,EAAE,uBAAuB,GAAG,OAAO,CAYhG;AAED;;;;GAIG;AACH,wBAAgB,4BAA4B,CAAC,EAAE,IAAI,EAAE,WAAW,EAAE,EAAE,2BAA2B,GAAG,OAAO,CAYxG;AAED,wBAAgB,kBAAkB,CAAC,QAAQ,EAAE,eAAe,GAAG,MAAM,EAAE,CAetE;AAED,wBAAgB,oBAAoB,CAAC,UAAU,EAAE,eAAe,EAAE,GAAG,MAAM,EAAE,CAE5E;AAED,wBAAgB,UAAU,CAAC,KAAK,EAAE,MAAM,EAAE,EAAE,KAAK,EAAE,MAAM,EAAE,GAAG,OAAO,CAKpE;AAsDD,eAAO,MAAM,kBAAkB;;;CAI9B,CAAC"}
@@ -0,0 +1,184 @@
1
+ "use strict";
2
+ var __read = (this && this.__read) || function (o, n) {
3
+ var m = typeof Symbol === "function" && o[Symbol.iterator];
4
+ if (!m) return o;
5
+ var i = m.call(o), r, ar = [], e;
6
+ try {
7
+ while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
8
+ }
9
+ catch (error) { e = { error: error }; }
10
+ finally {
11
+ try {
12
+ if (r && !r.done && (m = i["return"])) m.call(i);
13
+ }
14
+ finally { if (e) throw e.error; }
15
+ }
16
+ return ar;
17
+ };
18
+ var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
19
+ if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
20
+ if (ar || !(i in from)) {
21
+ if (!ar) ar = Array.prototype.slice.call(from, 0, i);
22
+ ar[i] = from[i];
23
+ }
24
+ }
25
+ return to.concat(ar || Array.prototype.slice.call(from));
26
+ };
27
+ Object.defineProperty(exports, "__esModule", { value: true });
28
+ exports.INVALID_BBOX_ISSUE = exports.bboxEquals = exports.getBboxForGeometries = exports.getBboxForGeometry = exports.validBboxForPositionGridList = exports.validBboxForPositionGrid = exports.validBboxForPositionList = exports.validBboxForPosition = void 0;
29
+ /**
30
+ * Checks if given bbox is valid for the given position.
31
+ * @param bbox The bbox to validate
32
+ * @param coordinates Contains the position
33
+ */
34
+ function validBboxForPosition(_a) {
35
+ var bbox = _a.bbox, coordinates = _a.coordinates;
36
+ if (!bbox) {
37
+ return true;
38
+ }
39
+ var dimension = coordinates.length;
40
+ if (bbox.length !== dimension * 2) {
41
+ return false;
42
+ }
43
+ return bbox.every(function (value, index) { return value === coordinates[index % dimension]; });
44
+ }
45
+ exports.validBboxForPosition = validBboxForPosition;
46
+ /**
47
+ * Checks if given bbox is valid for the given positions.
48
+ * @param bbox The bbox to validate
49
+ * @param coordinates Contains the list of positions
50
+ */
51
+ function validBboxForPositionList(_a) {
52
+ var bbox = _a.bbox, coordinates = _a.coordinates;
53
+ if (!bbox) {
54
+ return true;
55
+ }
56
+ var dimension = coordinates[0].length;
57
+ if (bbox.length !== dimension * 2) {
58
+ return false;
59
+ }
60
+ var expectedBbox = [];
61
+ updateBboxForPositionList(expectedBbox, coordinates);
62
+ return bboxEquals(bbox, expectedBbox);
63
+ }
64
+ exports.validBboxForPositionList = validBboxForPositionList;
65
+ /**
66
+ * Checks if given bbox is valid for the given positions grid.
67
+ * @param bbox The bbox to validate
68
+ * @param coordinates Contains the grid of positions
69
+ */
70
+ function validBboxForPositionGrid(_a) {
71
+ var bbox = _a.bbox, coordinates = _a.coordinates;
72
+ if (bbox == null) {
73
+ return true;
74
+ }
75
+ var dimension = coordinates[0][0].length;
76
+ if (bbox.length !== 2 * dimension) {
77
+ return false;
78
+ }
79
+ var expectedBbox = [];
80
+ updateBboxForPositionGrid(expectedBbox, coordinates);
81
+ return bboxEquals(bbox, expectedBbox);
82
+ }
83
+ exports.validBboxForPositionGrid = validBboxForPositionGrid;
84
+ /**
85
+ * Checks if given bbox is valid for the given positions grid.
86
+ * @param bbox The bbox to validate
87
+ * @param coordinates Contains the grid of positions
88
+ */
89
+ function validBboxForPositionGridList(_a) {
90
+ var bbox = _a.bbox, coordinates = _a.coordinates;
91
+ if (bbox == null) {
92
+ return true;
93
+ }
94
+ var dimension = coordinates[0][0][0].length;
95
+ if (bbox.length !== 2 * dimension) {
96
+ return false;
97
+ }
98
+ var expectedBbox = [];
99
+ updateBboxForPositionGridList(expectedBbox, coordinates);
100
+ return bboxEquals(bbox, expectedBbox);
101
+ }
102
+ exports.validBboxForPositionGridList = validBboxForPositionGridList;
103
+ function getBboxForGeometry(geometry) {
104
+ switch (geometry.type) {
105
+ case "Point":
106
+ return updateBboxForPosition([], geometry.coordinates);
107
+ case "MultiPoint":
108
+ case "LineString":
109
+ return updateBboxForPositionList([], geometry.coordinates);
110
+ case "MultiLineString":
111
+ case "Polygon":
112
+ return updateBboxForPositionGrid([], geometry.coordinates);
113
+ case "MultiPolygon":
114
+ return updateBboxForPositionGridList([], geometry.coordinates);
115
+ case "GeometryCollection":
116
+ return getBboxForGeometries(geometry.geometries);
117
+ }
118
+ }
119
+ exports.getBboxForGeometry = getBboxForGeometry;
120
+ function getBboxForGeometries(geometries) {
121
+ return mergeBboxs(geometries.map(getBboxForGeometry));
122
+ }
123
+ exports.getBboxForGeometries = getBboxForGeometries;
124
+ function bboxEquals(bbox1, bbox2) {
125
+ if (bbox1.length !== bbox2.length) {
126
+ return false;
127
+ }
128
+ return bbox1.every(function (value, index) { return value === bbox2[index]; });
129
+ }
130
+ exports.bboxEquals = bboxEquals;
131
+ /**
132
+ * NOTE: Mutates the given bbox. Performance optimisation to avoid unnecessary copies.
133
+ */
134
+ function updateBboxForPositionGridList(currentBbox, positions) {
135
+ positions.forEach(function (positionGrid) { return updateBboxForPositionGrid(currentBbox, positionGrid); });
136
+ return currentBbox;
137
+ }
138
+ /**
139
+ * NOTE: Mutates the given bbox. Performance optimisation to avoid unnecessary copies.
140
+ */
141
+ function updateBboxForPositionGrid(currentBbox, positions) {
142
+ positions.forEach(function (positionList) { return updateBboxForPositionList(currentBbox, positionList); });
143
+ return currentBbox;
144
+ }
145
+ /**
146
+ * NOTE: Mutates the given bbox. Performance optimisation to avoid unnecessary copies.
147
+ */
148
+ function updateBboxForPositionList(currentBbox, positions) {
149
+ positions.forEach(function (position) { return updateBboxForPosition(currentBbox, position); });
150
+ return currentBbox;
151
+ }
152
+ /**
153
+ * NOTE: Mutates the given bbox. Performance optimisation to avoid unnecessary copies.
154
+ */
155
+ function updateBboxForPosition(currentBbox, position) {
156
+ var dimension = position.length;
157
+ position.forEach(function (value, index) {
158
+ var iMin = currentBbox[index];
159
+ var iMax = currentBbox[index + dimension];
160
+ if (iMin === undefined || value < iMin) {
161
+ currentBbox[index] = value;
162
+ }
163
+ if (iMax === undefined || value > iMax) {
164
+ currentBbox[index + dimension] = value;
165
+ }
166
+ });
167
+ return currentBbox;
168
+ }
169
+ function mergeBboxs(bboxs) {
170
+ var dimension = bboxs[0].length / 2;
171
+ var mergedBbox = [];
172
+ var _loop_1 = function (i) {
173
+ mergedBbox[i] = Math.min.apply(Math, __spreadArray([], __read(bboxs.map(function (bbox) { return bbox[i]; })), false));
174
+ mergedBbox[i + dimension] = Math.max.apply(Math, __spreadArray([], __read(bboxs.map(function (bbox) { return bbox[i + dimension]; })), false));
175
+ };
176
+ for (var i = 0; i < dimension; i++) {
177
+ _loop_1(i);
178
+ }
179
+ return mergedBbox;
180
+ }
181
+ exports.INVALID_BBOX_ISSUE = {
182
+ code: "custom",
183
+ message: "Invalid bbox. Bbox length must be 2 * n, where n is the dimension of the geometry. Bbox must be a valid extent for the geometry.",
184
+ };
@@ -0,0 +1,16 @@
1
+ import { GeoJSONGeometry } from "../index";
2
+ export declare function validDimensionsForPositionList({ coordinates }: {
3
+ coordinates: number[][];
4
+ }): boolean;
5
+ export declare function validDimensionsForPositionGrid({ coordinates }: {
6
+ coordinates: number[][][];
7
+ }): boolean;
8
+ export declare function validDimensionsForPositionGridList({ coordinates }: {
9
+ coordinates: number[][][][];
10
+ }): boolean;
11
+ export declare function getDimensionForGeometry(geometry: GeoJSONGeometry): number;
12
+ export declare const INVALID_DIMENSIONS_ISSUE: {
13
+ code: "custom";
14
+ message: string;
15
+ };
16
+ //# sourceMappingURL=dimension.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"dimension.d.ts","sourceRoot":"","sources":["../../../src/geometry/validation/dimension.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,UAAU,CAAC;AAE3C,wBAAgB,8BAA8B,CAAC,EAAE,WAAW,EAAE,EAAE;IAAE,WAAW,EAAE,MAAM,EAAE,EAAE,CAAA;CAAE,GAAG,OAAO,CAGpG;AAED,wBAAgB,8BAA8B,CAAC,EAAE,WAAW,EAAE,EAAE;IAAE,WAAW,EAAE,MAAM,EAAE,EAAE,EAAE,CAAA;CAAE,GAAG,OAAO,CAGtG;AAED,wBAAgB,kCAAkC,CAAC,EAAE,WAAW,EAAE,EAAE;IAAE,WAAW,EAAE,MAAM,EAAE,EAAE,EAAE,EAAE,CAAA;CAAE,GAAG,OAAO,CAG5G;AAED,wBAAgB,uBAAuB,CAAC,QAAQ,EAAE,eAAe,GAAG,MAAM,CAezE;AAkBD,eAAO,MAAM,wBAAwB;;;CAGpC,CAAC"}
@@ -0,0 +1,54 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.INVALID_DIMENSIONS_ISSUE = exports.getDimensionForGeometry = exports.validDimensionsForPositionGridList = exports.validDimensionsForPositionGrid = exports.validDimensionsForPositionList = void 0;
4
+ function validDimensionsForPositionList(_a) {
5
+ var coordinates = _a.coordinates;
6
+ var dimension = coordinates[0].length;
7
+ return sameDimensionsForPositions(dimension)(coordinates);
8
+ }
9
+ exports.validDimensionsForPositionList = validDimensionsForPositionList;
10
+ function validDimensionsForPositionGrid(_a) {
11
+ var coordinates = _a.coordinates;
12
+ var dimension = coordinates[0][0].length;
13
+ return sameDimensionsForPositionGrid(dimension)(coordinates);
14
+ }
15
+ exports.validDimensionsForPositionGrid = validDimensionsForPositionGrid;
16
+ function validDimensionsForPositionGridList(_a) {
17
+ var coordinates = _a.coordinates;
18
+ var dimension = coordinates[0][0][0].length;
19
+ return sameDimensionsForPositionGrids(dimension)(coordinates);
20
+ }
21
+ exports.validDimensionsForPositionGridList = validDimensionsForPositionGridList;
22
+ function getDimensionForGeometry(geometry) {
23
+ switch (geometry.type) {
24
+ case "Point":
25
+ return geometry.coordinates.length;
26
+ case "MultiPoint":
27
+ case "LineString":
28
+ return geometry.coordinates[0].length;
29
+ case "MultiLineString":
30
+ case "Polygon":
31
+ return geometry.coordinates[0][0].length;
32
+ case "MultiPolygon":
33
+ return geometry.coordinates[0][0][0].length;
34
+ case "GeometryCollection":
35
+ return getDimensionForGeometry(geometry.geometries[0]);
36
+ }
37
+ }
38
+ exports.getDimensionForGeometry = getDimensionForGeometry;
39
+ function sameDimensionsForPosition(dimension) {
40
+ return function (position) { return position.length === dimension; };
41
+ }
42
+ function sameDimensionsForPositions(dimension) {
43
+ return function (positions) { return positions.every(sameDimensionsForPosition(dimension)); };
44
+ }
45
+ function sameDimensionsForPositionGrid(dimension) {
46
+ return function (positionGrid) { return positionGrid.every(sameDimensionsForPositions(dimension)); };
47
+ }
48
+ function sameDimensionsForPositionGrids(dimension) {
49
+ return function (positionGrids) { return positionGrids.every(sameDimensionsForPositionGrid(dimension)); };
50
+ }
51
+ exports.INVALID_DIMENSIONS_ISSUE = {
52
+ code: "custom",
53
+ message: "Invalid dimensions. All positions in the geometry must have the same dimension.",
54
+ };
@@ -0,0 +1,6 @@
1
+ export declare function validGeometryKeys(geometry: Record<string, unknown>): boolean;
2
+ export declare const INVALID_KEYS_ISSUE: {
3
+ code: "custom";
4
+ message: string;
5
+ };
6
+ //# sourceMappingURL=keys.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"keys.d.ts","sourceRoot":"","sources":["../../../src/geometry/validation/keys.ts"],"names":[],"mappings":"AAAA,wBAAgB,iBAAiB,CAAC,QAAQ,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,OAAO,CAO5E;AAED,eAAO,MAAM,kBAAkB;;;CAG9B,CAAC"}
@@ -0,0 +1,14 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.INVALID_KEYS_ISSUE = exports.validGeometryKeys = void 0;
4
+ function validGeometryKeys(geometry) {
5
+ return (!("geometry" in geometry) &&
6
+ !("properties" in geometry) &&
7
+ !("features" in geometry) &&
8
+ !("geometries" in geometry));
9
+ }
10
+ exports.validGeometryKeys = validGeometryKeys;
11
+ exports.INVALID_KEYS_ISSUE = {
12
+ code: "custom",
13
+ message: 'GeoJSON geometry object cannot have "geometry", "properties", "features", or "geometries" keys',
14
+ };