@digitraffic/common 2022.12.2-1 → 2022.12.22-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.
- package/dist/aws/infra/api/handler-factory.d.ts +9 -7
- package/dist/aws/infra/api/handler-factory.js +19 -16
- package/dist/aws/infra/api/integration.d.ts +2 -2
- package/dist/aws/infra/api/responses.js +4 -4
- package/dist/aws/infra/canaries/canary-parameters.d.ts +2 -2
- package/dist/aws/infra/canaries/canary-role.d.ts +1 -1
- package/dist/aws/infra/canaries/canary-role.js +3 -5
- package/dist/aws/infra/documentation.d.ts +1 -1
- package/dist/aws/infra/documentation.js +3 -3
- package/dist/aws/infra/stack/monitoredfunction.d.ts +4 -4
- package/dist/aws/infra/stack/monitoredfunction.js +2 -2
- package/dist/aws/infra/stack/stack-checking-aspect.js +6 -8
- package/dist/aws/infra/stacks/db-stack.js +2 -1
- package/dist/aws/runtime/dt-logger.d.ts +28 -0
- package/dist/aws/runtime/dt-logger.js +41 -0
- package/dist/aws/runtime/secrets/dbsecret.d.ts +4 -4
- package/dist/aws/runtime/secrets/dbsecret.js +1 -1
- package/dist/aws/types/proxytypes.d.ts +4 -4
- package/dist/database/last-updated.js +9 -7
- package/dist/marine/rtz.d.ts +20 -20
- package/dist/test/asserter.d.ts +6 -4
- package/dist/test/asserter.js +1 -1
- package/dist/test/httpserver.d.ts +1 -3
- package/dist/test/httpserver.js +10 -4
- package/dist/types/either.d.ts +4 -4
- package/package.json +1 -1
- package/src/aws/infra/api/handler-factory.ts +36 -26
- package/src/aws/infra/api/integration.ts +2 -2
- package/src/aws/infra/api/responses.ts +6 -4
- package/src/aws/infra/canaries/canary-parameters.ts +3 -3
- package/src/aws/infra/canaries/canary-role.ts +20 -10
- package/src/aws/infra/documentation.ts +42 -24
- package/src/aws/infra/stack/monitoredfunction.ts +6 -6
- package/src/aws/infra/stack/stack-checking-aspect.ts +15 -15
- package/src/aws/infra/stacks/db-stack.ts +2 -1
- package/src/aws/runtime/dt-logger.ts +61 -0
- package/src/aws/runtime/secrets/dbsecret.ts +5 -5
- package/src/aws/types/proxytypes.ts +14 -14
- package/src/database/last-updated.ts +75 -31
- package/src/marine/rtz.ts +29 -29
- package/src/test/asserter.ts +21 -11
- package/src/test/httpserver.ts +17 -8
- package/src/types/either.ts +8 -2
@@ -1,59 +1,103 @@
|
|
1
|
-
import {DTDatabase, DTTransaction} from "./database";
|
1
|
+
import { DTDatabase, DTTransaction } from "./database";
|
2
2
|
|
3
3
|
export enum DataType {
|
4
|
-
VS_DATEX2="VS_DATEX2",
|
5
|
-
COUNTING_SITES_DATA="COUNTING_SITES_DATA",
|
6
|
-
COUNTING_SITES_METADATA="COUNTING_SITES_METADATA",
|
7
|
-
COUNTING_SITES_METADATA_CHECK="COUNTING_SITES_METADATA_CHECK",
|
8
|
-
MAINTENANCE_TRACKING_DATA_CHECKED="MAINTENANCE_TRACKING_DATA_CHECKED",
|
9
|
-
PERMIT_DATA="PERMIT_DATA",
|
10
|
-
PERMIT_DATA_CHECK="PERMIT_DATA_CHECK",
|
4
|
+
VS_DATEX2 = "VS_DATEX2",
|
5
|
+
COUNTING_SITES_DATA = "COUNTING_SITES_DATA",
|
6
|
+
COUNTING_SITES_METADATA = "COUNTING_SITES_METADATA",
|
7
|
+
COUNTING_SITES_METADATA_CHECK = "COUNTING_SITES_METADATA_CHECK",
|
8
|
+
MAINTENANCE_TRACKING_DATA_CHECKED = "MAINTENANCE_TRACKING_DATA_CHECKED",
|
9
|
+
PERMIT_DATA = "PERMIT_DATA",
|
10
|
+
PERMIT_DATA_CHECK = "PERMIT_DATA_CHECK",
|
11
11
|
}
|
12
12
|
|
13
|
-
const UNSET_SUBTYPE =
|
13
|
+
const UNSET_SUBTYPE = "-";
|
14
14
|
|
15
15
|
type UpdatedTimestamp = {
|
16
|
-
updated: Date
|
16
|
+
updated: Date;
|
17
17
|
} | null;
|
18
18
|
|
19
|
-
export function getLastUpdated(
|
20
|
-
|
21
|
-
|
22
|
-
|
19
|
+
export function getLastUpdated(
|
20
|
+
db: DTDatabase,
|
21
|
+
datatype: DataType
|
22
|
+
): Promise<Date | null> {
|
23
|
+
return db.oneOrNone(
|
24
|
+
"select updated from data_updated where data_type=$(datatype) and subtype=$(subtype)",
|
25
|
+
{
|
26
|
+
datatype: datatype,
|
27
|
+
subtype: UNSET_SUBTYPE,
|
28
|
+
},
|
29
|
+
(x: UpdatedTimestamp) => x?.updated ?? null
|
30
|
+
);
|
23
31
|
}
|
24
32
|
|
25
|
-
export function getLastUpdatedWithSubtype(
|
26
|
-
|
27
|
-
|
28
|
-
|
33
|
+
export function getLastUpdatedWithSubtype(
|
34
|
+
db: DTDatabase,
|
35
|
+
datatype: DataType,
|
36
|
+
subtype: string
|
37
|
+
): Promise<Date | null> {
|
38
|
+
return db.oneOrNone(
|
39
|
+
"SELECT updated FROM data_updated WHERE data_type=$(datatype) AND subtype=$(subtype)",
|
40
|
+
{
|
41
|
+
datatype: datatype,
|
42
|
+
subtype: subtype,
|
43
|
+
},
|
44
|
+
(x: UpdatedTimestamp) => x?.updated ?? null
|
45
|
+
);
|
29
46
|
}
|
30
47
|
|
31
|
-
export function updateLastUpdated(
|
32
|
-
|
48
|
+
export function updateLastUpdated(
|
49
|
+
db: DTDatabase | DTTransaction,
|
50
|
+
datatype: DataType,
|
51
|
+
updated: Date
|
52
|
+
): Promise<null> {
|
53
|
+
return db.none(
|
54
|
+
`insert into data_updated(id, data_type, updated)
|
33
55
|
values(nextval('seq_data_updated'), $(datatype), $(updated))
|
34
56
|
on conflict (data_type, subtype)
|
35
57
|
do update set updated = $(updated)`,
|
36
|
-
|
58
|
+
{ updated, datatype }
|
59
|
+
);
|
37
60
|
}
|
38
61
|
|
39
|
-
export function updateLastUpdatedWithSubtype(
|
40
|
-
|
62
|
+
export function updateLastUpdatedWithSubtype(
|
63
|
+
db: DTDatabase | DTTransaction,
|
64
|
+
datatype: DataType,
|
65
|
+
subtype: string,
|
66
|
+
updated: Date
|
67
|
+
): Promise<null> {
|
68
|
+
return db.none(
|
69
|
+
`insert into data_updated(id, data_type, subtype, updated)
|
41
70
|
values(nextval('seq_data_updated'), $(datatype), $(subtype), $(updated))
|
42
71
|
on conflict (data_type, subtype)
|
43
72
|
do update set updated = $(updated)`,
|
44
|
-
|
73
|
+
{ updated, subtype, datatype }
|
74
|
+
);
|
45
75
|
}
|
46
76
|
|
47
|
-
export function getUpdatedTimestamp(
|
48
|
-
|
49
|
-
|
50
|
-
|
77
|
+
export function getUpdatedTimestamp(
|
78
|
+
db: DTDatabase,
|
79
|
+
datatype: string
|
80
|
+
): Promise<Date | null> {
|
81
|
+
return db.oneOrNone(
|
82
|
+
"select updated_time as updated from updated_timestamp where updated_name=$(datatype)",
|
83
|
+
{
|
84
|
+
datatype: datatype,
|
85
|
+
},
|
86
|
+
(x: UpdatedTimestamp) => x?.updated ?? null
|
87
|
+
);
|
51
88
|
}
|
52
89
|
|
53
|
-
export function updateUpdatedTimestamp(
|
54
|
-
|
90
|
+
export function updateUpdatedTimestamp(
|
91
|
+
db: DTDatabase | DTTransaction,
|
92
|
+
datatype: string,
|
93
|
+
date: Date,
|
94
|
+
by = ""
|
95
|
+
): Promise<null> {
|
96
|
+
return db.none(
|
97
|
+
`insert into updated_timestamp(updated_name, updated_time, updated_by)
|
55
98
|
values($(datatype), $(date), $(by))
|
56
99
|
on conflict (updated_name)
|
57
100
|
do update set updated_time = $(date), updated_by = $(by)`,
|
58
|
-
|
101
|
+
{ date, datatype, by }
|
102
|
+
);
|
59
103
|
}
|
package/src/marine/rtz.ts
CHANGED
@@ -1,57 +1,57 @@
|
|
1
|
-
export
|
1
|
+
export interface RtzPositionCoordinate {
|
2
2
|
readonly $: {
|
3
|
-
readonly lat: number
|
4
|
-
readonly lon: number
|
5
|
-
}
|
3
|
+
readonly lat: number;
|
4
|
+
readonly lon: number;
|
5
|
+
};
|
6
6
|
}
|
7
7
|
|
8
|
-
export
|
9
|
-
readonly position: RtzPositionCoordinate[]
|
8
|
+
export interface RtzWaypointPosition {
|
9
|
+
readonly position: RtzPositionCoordinate[];
|
10
10
|
}
|
11
11
|
|
12
|
-
export
|
13
|
-
readonly waypoint: RtzWaypointPosition[]
|
12
|
+
export interface RtzWaypoint {
|
13
|
+
readonly waypoint: RtzWaypointPosition[];
|
14
14
|
}
|
15
15
|
|
16
|
-
export
|
16
|
+
export interface RtzScheduleElement {
|
17
17
|
readonly $: {
|
18
18
|
/**
|
19
19
|
* Date
|
20
20
|
*/
|
21
|
-
readonly etd?: string
|
21
|
+
readonly etd?: string;
|
22
22
|
/**
|
23
23
|
* Date
|
24
24
|
*/
|
25
|
-
readonly eta?: string
|
26
|
-
}
|
25
|
+
readonly eta?: string;
|
26
|
+
};
|
27
27
|
}
|
28
28
|
|
29
|
-
export
|
30
|
-
readonly scheduleElement: RtzScheduleElement[]
|
29
|
+
export interface RtzSchedule {
|
30
|
+
readonly scheduleElement: RtzScheduleElement[];
|
31
31
|
}
|
32
32
|
|
33
|
-
export
|
34
|
-
readonly manual?: RtzSchedule[]
|
35
|
-
readonly calculated?: RtzSchedule[]
|
33
|
+
export interface RtzScheduleWrapper {
|
34
|
+
readonly manual?: RtzSchedule[];
|
35
|
+
readonly calculated?: RtzSchedule[];
|
36
36
|
}
|
37
37
|
|
38
|
-
export
|
39
|
-
readonly schedule: RtzScheduleWrapper[]
|
38
|
+
export interface RtzSchedules {
|
39
|
+
readonly schedule: RtzScheduleWrapper[];
|
40
40
|
}
|
41
41
|
|
42
|
-
export
|
42
|
+
export interface RtzRouteInfo {
|
43
43
|
readonly $: {
|
44
|
-
readonly vesselMMSI: string
|
45
|
-
readonly vesselIMO: string
|
46
|
-
}
|
44
|
+
readonly vesselMMSI: string;
|
45
|
+
readonly vesselIMO: string;
|
46
|
+
};
|
47
47
|
}
|
48
48
|
|
49
|
-
export
|
50
|
-
readonly routeInfo: RtzRouteInfo[]
|
51
|
-
readonly waypoints: RtzWaypoint[]
|
52
|
-
readonly schedules: RtzSchedules[]
|
49
|
+
export interface RtzRoute {
|
50
|
+
readonly routeInfo: RtzRouteInfo[];
|
51
|
+
readonly waypoints: RtzWaypoint[];
|
52
|
+
readonly schedules: RtzSchedules[];
|
53
53
|
}
|
54
54
|
|
55
|
-
export
|
56
|
-
readonly route: RtzRoute
|
55
|
+
export interface RtzVoyagePlan {
|
56
|
+
readonly route: RtzRoute;
|
57
57
|
}
|
package/src/test/asserter.ts
CHANGED
@@ -2,47 +2,57 @@
|
|
2
2
|
* A simple asserter-class for writing canaries without dependency to testing-libraries.
|
3
3
|
*/
|
4
4
|
|
5
|
+
type AssertedValue = string | number;
|
6
|
+
|
5
7
|
export abstract class Asserter {
|
6
|
-
static assertEquals
|
8
|
+
static assertEquals(value: AssertedValue, expected: AssertedValue) {
|
7
9
|
if (value != expected) {
|
8
|
-
throw new Error(
|
10
|
+
throw new Error(
|
11
|
+
`Given value ${value} was not expected ${expected}`
|
12
|
+
);
|
9
13
|
}
|
10
14
|
}
|
11
15
|
|
12
|
-
static assertTrue
|
16
|
+
static assertTrue(value: boolean) {
|
13
17
|
if (!value) {
|
14
|
-
throw new Error(`Given value
|
18
|
+
throw new Error(`Given value was not true`);
|
15
19
|
}
|
16
20
|
}
|
17
21
|
|
18
|
-
static assertLength<T>(data: T[], expected: number) {
|
22
|
+
static assertLength<T>(data: T[] | undefined, expected: number) {
|
19
23
|
if (!data) {
|
20
24
|
throw new Error("Given array was not defined");
|
21
25
|
}
|
22
26
|
|
23
27
|
if (data.length != expected) {
|
24
|
-
throw new Error(
|
28
|
+
throw new Error(
|
29
|
+
`Given array length ${data.length} was not expected ${expected}`
|
30
|
+
);
|
25
31
|
}
|
26
32
|
}
|
27
33
|
|
28
|
-
static assertLengthGreaterThan<T>(data: T[], expected: number) {
|
34
|
+
static assertLengthGreaterThan<T>(data: T[] | undefined, expected: number) {
|
29
35
|
if (!data) {
|
30
36
|
throw new Error("Given array was not defined");
|
31
37
|
}
|
32
38
|
|
33
39
|
if (data.length <= expected) {
|
34
|
-
throw new Error(
|
40
|
+
throw new Error(
|
41
|
+
`Given array length ${data.length} was not greater than ${expected}`
|
42
|
+
);
|
35
43
|
}
|
36
44
|
}
|
37
45
|
|
38
46
|
static assertGreaterThan(value: number, expected: number) {
|
39
47
|
if (value <= expected) {
|
40
|
-
throw new Error(
|
48
|
+
throw new Error(
|
49
|
+
`Value ${value} was expected to be greater than ${expected}`
|
50
|
+
);
|
41
51
|
}
|
42
52
|
}
|
43
53
|
|
44
54
|
static assertToBeCloseTo(value: number, expected: number, delta: number) {
|
45
|
-
expect(expected-value).toBeGreaterThanOrEqual(-1 * delta);
|
46
|
-
expect(expected-value).toBeLessThanOrEqual(delta);
|
55
|
+
expect(expected - value).toBeGreaterThanOrEqual(-1 * delta);
|
56
|
+
expect(expected - value).toBeLessThanOrEqual(delta);
|
47
57
|
}
|
48
58
|
}
|
package/src/test/httpserver.ts
CHANGED
@@ -1,4 +1,5 @@
|
|
1
1
|
import { Server, createServer } from "http";
|
2
|
+
import { parse } from "url";
|
2
3
|
|
3
4
|
export const ERROR_NO_MATCH = "NO MATCH";
|
4
5
|
export const ERRORCODE_NOT_FOUND = 404;
|
@@ -36,11 +37,18 @@ export class TestHttpServer {
|
|
36
37
|
this.debuglog(`Starting test server on port ${port}`);
|
37
38
|
this.server = createServer((req, res) => {
|
38
39
|
this.debuglog("Mapped urls: ");
|
39
|
-
|
40
40
|
Object.keys(props).forEach((k) => this.debuglog(k));
|
41
|
-
|
42
|
-
|
43
|
-
|
41
|
+
|
42
|
+
if (!req.url) {
|
43
|
+
throw new Error("Missing request url!");
|
44
|
+
}
|
45
|
+
|
46
|
+
this.debuglog(`Received request to url ${req.url} ..`);
|
47
|
+
const path = parse(req.url).pathname;
|
48
|
+
|
49
|
+
if (!path) {
|
50
|
+
throw new Error("Missing path from request!");
|
51
|
+
}
|
44
52
|
|
45
53
|
let dataStr = "";
|
46
54
|
req.on("data", (chunk) => {
|
@@ -64,7 +72,7 @@ export class TestHttpServer {
|
|
64
72
|
res.end(props[path](req.url, dataStr));
|
65
73
|
});
|
66
74
|
} else {
|
67
|
-
this.debuglog(
|
75
|
+
this.debuglog(`..no match for ${path}`);
|
68
76
|
req.on("end", () => {
|
69
77
|
// assume sent data is in JSON format
|
70
78
|
this.messageStack[this.messageStack.length] =
|
@@ -91,6 +99,7 @@ export class TestHttpServer {
|
|
91
99
|
}
|
92
100
|
}
|
93
101
|
|
94
|
-
export
|
95
|
-
|
96
|
-
|
102
|
+
export type ListenProperties = Record<
|
103
|
+
string,
|
104
|
+
(url?: string, data?: string) => string
|
105
|
+
>;
|
package/src/types/either.ts
CHANGED
@@ -1,3 +1,9 @@
|
|
1
|
-
export
|
2
|
-
|
1
|
+
export interface EitherOk<T> {
|
2
|
+
result: "ok";
|
3
|
+
value: T;
|
4
|
+
}
|
5
|
+
export interface EitherError {
|
6
|
+
result: "error";
|
7
|
+
message: string;
|
8
|
+
}
|
3
9
|
export type Either<T> = EitherOk<T> | EitherError;
|