@tak-ps/node-cot 13.6.0 → 14.0.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.
- package/CHANGELOG.md +5 -0
- package/dist/index.js +1 -0
- package/dist/index.js.map +1 -1
- package/dist/lib/parser/from_geojson.js +344 -0
- package/dist/lib/parser/from_geojson.js.map +1 -0
- package/dist/lib/parser/normalize_geojson.js +85 -0
- package/dist/lib/parser/normalize_geojson.js.map +1 -0
- package/dist/lib/parser/to_geojson.js +325 -0
- package/dist/lib/parser/to_geojson.js.map +1 -0
- package/dist/lib/parser.js +17 -652
- package/dist/lib/parser.js.map +1 -1
- package/dist/lib/type.js +36 -0
- package/dist/lib/type.js.map +1 -0
- package/dist/lib/types/geojson.js +50 -0
- package/dist/lib/types/geojson.js.map +1 -0
- package/dist/package.json +5 -2
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/index.ts +4 -0
- package/lib/parser/from_geojson.ts +401 -0
- package/lib/parser/normalize_geojson.ts +104 -0
- package/lib/parser/to_geojson.ts +395 -0
- package/lib/parser.ts +25 -765
- package/lib/type.ts +49 -0
- package/lib/types/geojson.ts +59 -0
- package/package.json +5 -2
package/lib/type.ts
ADDED
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import type { Static, TSchema, TUnknown } from '@sinclair/typebox'
|
|
2
|
+
import { Value } from '@sinclair/typebox/value'
|
|
3
|
+
|
|
4
|
+
export type TypeOpts = {
|
|
5
|
+
verbose?: boolean;
|
|
6
|
+
default?: boolean;
|
|
7
|
+
convert?: boolean;
|
|
8
|
+
clean?: boolean;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
export default class TypeValidator {
|
|
12
|
+
static type<T extends TSchema = TUnknown>(
|
|
13
|
+
type: T,
|
|
14
|
+
body: unknown,
|
|
15
|
+
opts?: TypeOpts
|
|
16
|
+
): Static<T> {
|
|
17
|
+
if (!opts) opts = {};
|
|
18
|
+
if (opts.verbose === undefined) opts.verbose = false;
|
|
19
|
+
if (opts.default === undefined) opts.default = true;
|
|
20
|
+
if (opts.convert === undefined) opts.convert = true;
|
|
21
|
+
if (opts.clean === undefined) opts.clean = true;
|
|
22
|
+
|
|
23
|
+
if (opts.default) {
|
|
24
|
+
Value.Default(type, body)
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
if (opts.clean) {
|
|
28
|
+
Value.Clean(type, body)
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
if (opts.convert) {
|
|
32
|
+
Value.Convert(type, body)
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
const result = Value.Check(type, body)
|
|
36
|
+
|
|
37
|
+
if (result) return body;
|
|
38
|
+
|
|
39
|
+
const errors = Value.Errors(type, body);
|
|
40
|
+
|
|
41
|
+
const firstError = errors.First();
|
|
42
|
+
|
|
43
|
+
if (opts.verbose) {
|
|
44
|
+
throw new Error(`Internal Validation Error: ${JSON.stringify(firstError)} -- Body: ${JSON.stringify(body)}`);
|
|
45
|
+
} else {
|
|
46
|
+
throw new Error(`Internal Validation Error`);
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
}
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import { Type } from '@sinclair/typebox';
|
|
2
|
+
|
|
3
|
+
// Intentially no max for increated input flexibility
|
|
4
|
+
// coordinates are clipped in normalize_geojson
|
|
5
|
+
const Position = Type.Array(Type.Number(), { minItems: 2 });
|
|
6
|
+
|
|
7
|
+
const Point = Type.Object({
|
|
8
|
+
type: Type.Literal('Point'),
|
|
9
|
+
coordinates: Position
|
|
10
|
+
})
|
|
11
|
+
|
|
12
|
+
/*
|
|
13
|
+
const MultiPoint = Type.Object({
|
|
14
|
+
type: Type.Literal('MultiPoint'),
|
|
15
|
+
coordinates: Type.Array(Position)
|
|
16
|
+
})
|
|
17
|
+
*/
|
|
18
|
+
|
|
19
|
+
const LineString = Type.Object({
|
|
20
|
+
type: Type.Literal('LineString'),
|
|
21
|
+
coordinates: Type.Array(Position)
|
|
22
|
+
})
|
|
23
|
+
|
|
24
|
+
/*
|
|
25
|
+
const MultiLineString = Type.Object({
|
|
26
|
+
type: Type.Literal('MultiLineString'),
|
|
27
|
+
coordinates: Type.Array(Type.Array(Position))
|
|
28
|
+
})
|
|
29
|
+
*/
|
|
30
|
+
|
|
31
|
+
const Polygon = Type.Object({
|
|
32
|
+
type: Type.Literal('Polygon'),
|
|
33
|
+
coordinates: Type.Array(Type.Array(Position))
|
|
34
|
+
})
|
|
35
|
+
|
|
36
|
+
/*
|
|
37
|
+
const MultiPolygon = Type.Object({
|
|
38
|
+
type: Type.Literal('MultiPolygon'),
|
|
39
|
+
coordinates: Type.Array(Type.Array(Type.Array(Position)))
|
|
40
|
+
})
|
|
41
|
+
*/
|
|
42
|
+
|
|
43
|
+
const Geometry = Type.Union([
|
|
44
|
+
Point,
|
|
45
|
+
LineString,
|
|
46
|
+
Polygon
|
|
47
|
+
]);
|
|
48
|
+
|
|
49
|
+
export const GeoJSONFeature = Type.Object({
|
|
50
|
+
id: Type.Optional(Type.String()),
|
|
51
|
+
type: Type.Literal('Feature'),
|
|
52
|
+
properties: Type.Record(Type.String(), Type.Unknown()),
|
|
53
|
+
geometry: Geometry
|
|
54
|
+
})
|
|
55
|
+
|
|
56
|
+
export const GeoJSONFeatureCollection = Type.Object({
|
|
57
|
+
type: Type.Literal('FeatureCollection'),
|
|
58
|
+
features: Type.Array(GeoJSONFeature)
|
|
59
|
+
});
|
package/package.json
CHANGED
|
@@ -1,14 +1,17 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tak-ps/node-cot",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "
|
|
4
|
+
"version": "14.0.0",
|
|
5
5
|
"description": "Lightweight JavaScript library for parsing and manipulating TAK messages",
|
|
6
6
|
"author": "Nick Ingalls <nick@ingalls.ca>",
|
|
7
7
|
"types": "index.ts",
|
|
8
8
|
"exports": {
|
|
9
9
|
".": "./dist/index.js",
|
|
10
10
|
"./cot": "./dist/lib/cot.js",
|
|
11
|
-
"./2525": "./dist/lib/utils/2525.js"
|
|
11
|
+
"./2525": "./dist/lib/utils/2525.js",
|
|
12
|
+
"./normalize_geojson": "./dist/lib/parser/normalize_geojson.js",
|
|
13
|
+
"./from_geojson": "./dist/lib/parser/from_geojson.js",
|
|
14
|
+
"./to_geojson": "./dist/lib/parser/to_geojson.js"
|
|
12
15
|
},
|
|
13
16
|
"scripts": {
|
|
14
17
|
"test": "c8 --reporter=lcov --reporter html tsx --test test/*.ts",
|