@digitraffic/common 2026.3.17-1 → 2026.3.26-1-beta
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/README.md +18 -1
- package/dist/__test__/asserter.d.ts +13 -0
- package/dist/__test__/asserter.js +39 -0
- package/dist/__test__/db-testutils.d.ts +3 -0
- package/dist/__test__/db-testutils.js +38 -0
- package/dist/__test__/dependencies.test.d.ts +1 -0
- package/dist/__test__/dependencies.test.js +21 -0
- package/dist/__test__/imports.test.d.ts +1 -0
- package/dist/__test__/imports.test.js +318 -0
- package/dist/__test__/infra/acl-builder.test.d.ts +1 -0
- package/dist/__test__/infra/acl-builder.test.js +72 -0
- package/dist/__test__/infra/api/handler-factory.test.d.ts +1 -0
- package/dist/__test__/infra/api/handler-factory.test.js +42 -0
- package/dist/__test__/infra/api/integration.test.d.ts +1 -0
- package/dist/__test__/infra/api/integration.test.js +162 -0
- package/dist/__test__/infra/api/response.test.d.ts +1 -0
- package/dist/__test__/infra/api/response.test.js +77 -0
- package/dist/__test__/infra/api/static-integration.test.d.ts +1 -0
- package/dist/__test__/infra/api/static-integration.test.js +35 -0
- package/dist/__test__/infra/documentation.test.d.ts +1 -0
- package/dist/__test__/infra/documentation.test.js +38 -0
- package/dist/__test__/infra/scheduler.test.d.ts +1 -0
- package/dist/__test__/infra/scheduler.test.js +23 -0
- package/dist/__test__/infra/security-rule.test.d.ts +1 -0
- package/dist/__test__/infra/security-rule.test.js +21 -0
- package/dist/__test__/infra/stack/rest-apis.test.d.ts +1 -0
- package/dist/__test__/infra/stack/rest-apis.test.js +47 -0
- package/dist/__test__/marine/id_utils.test.d.ts +1 -0
- package/dist/__test__/marine/id_utils.test.js +45 -0
- package/dist/__test__/mock-ky.d.ts +2 -0
- package/dist/__test__/mock-ky.js +15 -0
- package/dist/__test__/promise/promise.test.d.ts +1 -0
- package/dist/__test__/promise/promise.test.js +126 -0
- package/dist/__test__/runtime/dt-logger.test.d.ts +1 -0
- package/dist/__test__/runtime/dt-logger.test.js +193 -0
- package/dist/__test__/secrets/secret-holder.test.d.ts +1 -0
- package/dist/__test__/secrets/secret-holder.test.js +96 -0
- package/dist/__test__/secrets/secret.test.d.ts +1 -0
- package/dist/__test__/secrets/secret.test.js +57 -0
- package/dist/__test__/stack/dt-function.test.d.ts +1 -0
- package/dist/__test__/stack/dt-function.test.js +340 -0
- package/dist/__test__/stack/rest-apis.test.d.ts +1 -0
- package/dist/__test__/stack/rest-apis.test.js +45 -0
- package/dist/__test__/test/mock-ky.test.d.ts +1 -0
- package/dist/__test__/test/mock-ky.test.js +46 -0
- package/dist/__test__/testutils.d.ts +12 -0
- package/dist/__test__/testutils.js +32 -0
- package/dist/__test__/types/lambda-proxy-types.test.d.ts +8 -0
- package/dist/__test__/types/lambda-proxy-types.test.js +155 -0
- package/dist/__test__/types/lambda-response-builder.test.d.ts +1 -0
- package/dist/__test__/types/lambda-response-builder.test.js +81 -0
- package/dist/__test__/types/lambda-response.test.d.ts +9 -0
- package/dist/__test__/types/lambda-response.test.js +73 -0
- package/dist/__test__/utils/base64.test.d.ts +1 -0
- package/dist/__test__/utils/base64.test.js +38 -0
- package/dist/__test__/utils/date-utils.test.d.ts +1 -0
- package/dist/__test__/utils/date-utils.test.js +32 -0
- package/dist/__test__/utils/geometry.test.d.ts +1 -0
- package/dist/__test__/utils/geometry.test.js +25 -0
- package/dist/__test__/utils/lambda-proxy-event.test.d.ts +1 -0
- package/dist/__test__/utils/lambda-proxy-event.test.js +45 -0
- package/dist/__test__/utils/logging.test.d.ts +1 -0
- package/dist/__test__/utils/logging.test.js +75 -0
- package/dist/__test__/utils/stop-watch.test.d.ts +1 -0
- package/dist/__test__/utils/stop-watch.test.js +118 -0
- package/dist/__test__/utils/utils.test.d.ts +1 -0
- package/dist/__test__/utils/utils.test.js +48 -0
- package/dist/aws/infra/acl-builder.d.ts +53 -0
- package/dist/aws/infra/acl-builder.js +407 -0
- package/dist/aws/infra/api/handler-factory.d.ts +22 -0
- package/dist/aws/infra/api/handler-factory.js +68 -0
- package/dist/aws/infra/api/integration.d.ts +49 -0
- package/dist/aws/infra/api/integration.js +162 -0
- package/dist/aws/infra/api/response.d.ts +62 -0
- package/dist/aws/infra/api/response.js +132 -0
- package/dist/aws/infra/api/responses.d.ts +60 -0
- package/dist/aws/infra/api/responses.js +90 -0
- package/dist/aws/infra/api/static-integration.d.ts +16 -0
- package/dist/aws/infra/api/static-integration.js +76 -0
- package/dist/aws/infra/bucket-policy.d.ts +38 -0
- package/dist/aws/infra/bucket-policy.js +30 -0
- package/dist/aws/infra/canaries/canary-alarm.d.ts +6 -0
- package/dist/aws/infra/canaries/canary-alarm.js +20 -0
- package/dist/aws/infra/canaries/canary-keys.d.ts +3 -0
- package/dist/aws/infra/canaries/canary-keys.js +4 -0
- package/dist/aws/infra/canaries/canary-parameters.d.ts +19 -0
- package/dist/aws/infra/canaries/canary-parameters.js +2 -0
- package/dist/aws/infra/canaries/canary-role.d.ts +14 -0
- package/dist/aws/infra/canaries/canary-role.js +51 -0
- package/dist/aws/infra/canaries/canary.d.ts +8 -0
- package/dist/aws/infra/canaries/canary.js +26 -0
- package/dist/aws/infra/canaries/database-canary.d.ts +17 -0
- package/dist/aws/infra/canaries/database-canary.js +65 -0
- package/dist/aws/infra/canaries/database-checker.d.ts +33 -0
- package/dist/aws/infra/canaries/database-checker.js +119 -0
- package/dist/aws/infra/canaries/url-canary.d.ts +16 -0
- package/dist/aws/infra/canaries/url-canary.js +55 -0
- package/dist/aws/infra/canaries/url-checker.d.ts +45 -0
- package/dist/aws/infra/canaries/url-checker.js +256 -0
- package/dist/aws/infra/documentation.d.ts +56 -0
- package/dist/aws/infra/documentation.js +90 -0
- package/dist/aws/infra/import-util.d.ts +17 -0
- package/dist/aws/infra/import-util.js +41 -0
- package/dist/aws/infra/scheduler.d.ts +12 -0
- package/dist/aws/infra/scheduler.js +27 -0
- package/dist/aws/infra/security-rule.d.ts +12 -0
- package/dist/aws/infra/security-rule.js +35 -0
- package/dist/aws/infra/sqs-integration.d.ts +4 -0
- package/dist/aws/infra/sqs-integration.js +85 -0
- package/dist/aws/infra/sqs-queue.d.ts +19 -0
- package/dist/aws/infra/sqs-queue.js +145 -0
- package/dist/aws/infra/stack/dt-function-alarms.d.ts +29 -0
- package/dist/aws/infra/stack/dt-function-alarms.js +54 -0
- package/dist/aws/infra/stack/dt-function.d.ts +124 -0
- package/dist/aws/infra/stack/dt-function.js +315 -0
- package/dist/aws/infra/stack/lambda-configs.d.ts +44 -0
- package/dist/aws/infra/stack/lambda-configs.js +71 -0
- package/dist/aws/infra/stack/lambda-log-group.d.ts +15 -0
- package/dist/aws/infra/stack/lambda-log-group.js +24 -0
- package/dist/aws/infra/stack/monitoredfunction.d.ts +85 -0
- package/dist/aws/infra/stack/monitoredfunction.js +147 -0
- package/dist/aws/infra/stack/parameters.d.ts +40 -0
- package/dist/aws/infra/stack/parameters.js +50 -0
- package/dist/aws/infra/stack/rest-api.d.ts +74 -0
- package/dist/aws/infra/stack/rest-api.js +235 -0
- package/dist/aws/infra/stack/stack-checking-aspect.d.ts +20 -0
- package/dist/aws/infra/stack/stack-checking-aspect.js +183 -0
- package/dist/aws/infra/stack/stack.d.ts +56 -0
- package/dist/aws/infra/stack/stack.js +71 -0
- package/dist/aws/infra/stack/subscription.d.ts +17 -0
- package/dist/aws/infra/stack/subscription.js +37 -0
- package/dist/aws/infra/stacks/db-dns-stack.d.ts +13 -0
- package/dist/aws/infra/stacks/db-dns-stack.js +60 -0
- package/dist/aws/infra/stacks/db-proxy-stack.d.ts +24 -0
- package/dist/aws/infra/stacks/db-proxy-stack.js +74 -0
- package/dist/aws/infra/stacks/db-stack.d.ts +65 -0
- package/dist/aws/infra/stacks/db-stack.js +189 -0
- package/dist/aws/infra/stacks/intra-stack-configuration.d.ts +5 -0
- package/dist/aws/infra/stacks/intra-stack-configuration.js +2 -0
- package/dist/aws/infra/stacks/network-stack.d.ts +14 -0
- package/dist/aws/infra/stacks/network-stack.js +45 -0
- package/dist/aws/infra/usage-plans.d.ts +16 -0
- package/dist/aws/infra/usage-plans.js +38 -0
- package/dist/aws/runtime/apikey.d.ts +2 -0
- package/dist/aws/runtime/apikey.js +13 -0
- package/dist/aws/runtime/digitraffic-integration-response.d.ts +8 -0
- package/dist/aws/runtime/digitraffic-integration-response.js +25 -0
- package/dist/aws/runtime/dt-logger-default.d.ts +9 -0
- package/dist/aws/runtime/dt-logger-default.js +6 -0
- package/dist/aws/runtime/dt-logger.d.ts +117 -0
- package/dist/aws/runtime/dt-logger.js +159 -0
- package/dist/aws/runtime/environment.d.ts +5 -0
- package/dist/aws/runtime/environment.js +7 -0
- package/dist/aws/runtime/s3.d.ts +3 -0
- package/dist/aws/runtime/s3.js +21 -0
- package/dist/aws/runtime/secrets/dbsecret.d.ts +16 -0
- package/dist/aws/runtime/secrets/dbsecret.js +26 -0
- package/dist/aws/runtime/secrets/proxy-holder.d.ts +9 -0
- package/dist/aws/runtime/secrets/proxy-holder.js +25 -0
- package/dist/aws/runtime/secrets/rds-holder.d.ts +9 -0
- package/dist/aws/runtime/secrets/rds-holder.js +25 -0
- package/dist/aws/runtime/secrets/secret-holder.d.ts +30 -0
- package/dist/aws/runtime/secrets/secret-holder.js +81 -0
- package/dist/aws/runtime/secrets/secret.d.ts +8 -0
- package/dist/aws/runtime/secrets/secret.js +61 -0
- package/dist/aws/types/errors.d.ts +8 -0
- package/dist/aws/types/errors.js +13 -0
- package/dist/aws/types/lambda-proxy-types.d.ts +59 -0
- package/dist/aws/types/lambda-proxy-types.js +210 -0
- package/dist/aws/types/lambda-response.d.ts +89 -0
- package/dist/aws/types/lambda-response.js +204 -0
- package/dist/aws/types/mediatypes.d.ts +11 -0
- package/dist/aws/types/mediatypes.js +14 -0
- package/dist/aws/types/model-with-reference.d.ts +7 -0
- package/dist/aws/types/model-with-reference.js +2 -0
- package/dist/aws/types/tags.d.ts +2 -0
- package/dist/aws/types/tags.js +4 -0
- package/dist/database/database.d.ts +27 -0
- package/dist/database/database.js +95 -0
- package/dist/database/last-updated.d.ts +15 -0
- package/dist/database/last-updated.js +46 -0
- package/dist/database/models.d.ts +6 -0
- package/dist/database/models.js +2 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.js +2 -0
- package/dist/marine/id_utils.d.ts +3 -0
- package/dist/marine/id_utils.js +36 -0
- package/dist/marine/rtz.d.ts +48 -0
- package/dist/marine/rtz.js +2 -0
- package/dist/types/async-timeout-error.d.ts +3 -0
- package/dist/types/async-timeout-error.js +6 -0
- package/dist/types/either.d.ts +9 -0
- package/dist/types/either.js +2 -0
- package/dist/types/geojson.d.ts +47 -0
- package/dist/types/geojson.js +51 -0
- package/dist/types/http-error.d.ts +4 -0
- package/dist/types/http-error.js +8 -0
- package/dist/types/input-error.d.ts +2 -0
- package/dist/types/input-error.js +3 -0
- package/dist/types/language.d.ts +5 -0
- package/dist/types/language.js +7 -0
- package/dist/types/nullable.d.ts +24 -0
- package/dist/types/nullable.js +2 -0
- package/dist/types/openapi-schema.d.ts +932 -0
- package/dist/types/openapi-schema.js +151 -0
- package/dist/types/traffictype.d.ts +11 -0
- package/dist/types/traffictype.js +13 -0
- package/dist/types/urn.d.ts +1 -0
- package/dist/types/urn.js +2 -0
- package/dist/types/util-types.d.ts +11 -0
- package/dist/types/util-types.js +2 -0
- package/dist/types/validator.d.ts +4 -0
- package/dist/types/validator.js +9 -0
- package/dist/utils/api-model.d.ts +51 -0
- package/dist/utils/api-model.js +118 -0
- package/dist/utils/base64.d.ts +34 -0
- package/dist/utils/base64.js +53 -0
- package/dist/utils/date-utils.d.ts +27 -0
- package/dist/utils/date-utils.js +45 -0
- package/dist/utils/geojson-types.d.ts +14 -0
- package/dist/utils/geojson-types.js +15 -0
- package/dist/utils/geometry.d.ts +44 -0
- package/dist/utils/geometry.js +154 -0
- package/dist/utils/lambda-proxy-event.d.ts +9 -0
- package/dist/utils/lambda-proxy-event.js +31 -0
- package/dist/utils/logging.d.ts +40 -0
- package/dist/utils/logging.js +88 -0
- package/dist/utils/retry.d.ts +33 -0
- package/dist/utils/retry.js +135 -0
- package/dist/utils/slack.d.ts +5 -0
- package/dist/utils/slack.js +24 -0
- package/dist/utils/stop-watch.d.ts +46 -0
- package/dist/utils/stop-watch.js +114 -0
- package/dist/utils/utils.d.ts +95 -0
- package/dist/utils/utils.js +178 -0
- package/dist/utils/zod-utils.d.ts +27 -0
- package/dist/utils/zod-utils.js +57 -0
- package/package.json +30 -28
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
import pgpImport, {} from "pg-promise";
|
|
2
|
+
import { logger } from "../aws/runtime/dt-logger-default.js";
|
|
3
|
+
import { logException } from "../utils/logging.js";
|
|
4
|
+
import { getEnvVariable, getEnvVariableOrElse } from "../utils/utils.js";
|
|
5
|
+
export var DatabaseEnvironmentKeys;
|
|
6
|
+
(function (DatabaseEnvironmentKeys) {
|
|
7
|
+
DatabaseEnvironmentKeys["DB_USER"] = "DB_USER";
|
|
8
|
+
DatabaseEnvironmentKeys["DB_PASS"] = "DB_PASS";
|
|
9
|
+
DatabaseEnvironmentKeys["DB_URI"] = "DB_URI";
|
|
10
|
+
DatabaseEnvironmentKeys["DB_RO_URI"] = "DB_RO_URI";
|
|
11
|
+
DatabaseEnvironmentKeys["DB_APPLICATION"] = "DB_APPLICATION";
|
|
12
|
+
})(DatabaseEnvironmentKeys || (DatabaseEnvironmentKeys = {}));
|
|
13
|
+
// pg-promise initialization options
|
|
14
|
+
// https://vitaly-t.github.io/pg-promise/global.html#event:receive
|
|
15
|
+
const pgpPromiseInitOptions = {
|
|
16
|
+
receive(e) {
|
|
17
|
+
if (e.data) {
|
|
18
|
+
convertNullColumnsToUndefined(e.data);
|
|
19
|
+
}
|
|
20
|
+
},
|
|
21
|
+
};
|
|
22
|
+
function initPgp(pgpPromiseInitOptions) {
|
|
23
|
+
const pgp = pgpPromiseInitOptions
|
|
24
|
+
? pgpImport(pgpPromiseInitOptions)
|
|
25
|
+
: pgpImport();
|
|
26
|
+
// convert numeric types to number instead of string
|
|
27
|
+
pgp.pg.types.setTypeParser(pgp.pg.types.builtins.INT8, (value) => {
|
|
28
|
+
return parseInt(value, 10);
|
|
29
|
+
});
|
|
30
|
+
pgp.pg.types.setTypeParser(pgp.pg.types.builtins.FLOAT8, (value) => {
|
|
31
|
+
return parseFloat(value);
|
|
32
|
+
});
|
|
33
|
+
pgp.pg.types.setTypeParser(pgp.pg.types.builtins.NUMERIC, (value) => {
|
|
34
|
+
return parseFloat(value);
|
|
35
|
+
});
|
|
36
|
+
return pgp;
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* Creates a non-pooling database connection primarily used by Lambdas.
|
|
40
|
+
*
|
|
41
|
+
* Note! Using this method opens a new RDS connection on every invocation. It is advised to
|
|
42
|
+
* use RDS proxy to pool connections transparently.
|
|
43
|
+
* https://docs.amazonaws.cn/en_us/AmazonRDS/latest/AuroraUserGuide/rds-proxy.html
|
|
44
|
+
* @param username Username
|
|
45
|
+
* @param password Password
|
|
46
|
+
* @param applicationName name of application
|
|
47
|
+
* @param url Connection URL
|
|
48
|
+
* @param convertNullsToUndefined if true null values in query results will be converted to undefined, Default false.
|
|
49
|
+
* @param options pg-promise options
|
|
50
|
+
*/
|
|
51
|
+
export function initDbConnection(username, password, applicationName, url, convertNullsToUndefined, options) {
|
|
52
|
+
const finalUrl = `postgresql://${username}:${password}@${url}?application_name=${applicationName}`;
|
|
53
|
+
return initPgp(convertNullsToUndefined ? pgpPromiseInitOptions : undefined)(finalUrl, options);
|
|
54
|
+
}
|
|
55
|
+
// noinspection JSUnusedGlobalSymbols
|
|
56
|
+
export function inTransaction(fn, convertNullsToUndefined = false) {
|
|
57
|
+
return inDatabase((db) => db.tx((t) => fn(t)), convertNullsToUndefined);
|
|
58
|
+
}
|
|
59
|
+
export function inDatabase(fn, convertNullsToUndefined = false) {
|
|
60
|
+
return doInDatabase(false, fn, convertNullsToUndefined);
|
|
61
|
+
}
|
|
62
|
+
export function inDatabaseReadonly(fn, convertNullsToUndefined = false) {
|
|
63
|
+
return doInDatabase(true, fn, convertNullsToUndefined);
|
|
64
|
+
}
|
|
65
|
+
async function doInDatabase(readonly, fn, convertNullsToUndefined) {
|
|
66
|
+
const db_application = getEnvVariableOrElse(DatabaseEnvironmentKeys.DB_APPLICATION, "unknown-cdk-application");
|
|
67
|
+
const db_uri = readonly
|
|
68
|
+
? getEnvVariable(DatabaseEnvironmentKeys.DB_RO_URI)
|
|
69
|
+
: getEnvVariable(DatabaseEnvironmentKeys.DB_URI);
|
|
70
|
+
const db = initDbConnection(getEnvVariable(DatabaseEnvironmentKeys.DB_USER), getEnvVariable(DatabaseEnvironmentKeys.DB_PASS), db_application, db_uri, convertNullsToUndefined);
|
|
71
|
+
try {
|
|
72
|
+
// deallocate all prepared statements to allow for connection pooling
|
|
73
|
+
// DISCARD instead of DEALLOCATE as it didn't always clean all prepared statements
|
|
74
|
+
await db.none("DISCARD ALL");
|
|
75
|
+
return await fn(db);
|
|
76
|
+
}
|
|
77
|
+
catch (e) {
|
|
78
|
+
logException(logger, e);
|
|
79
|
+
throw e;
|
|
80
|
+
}
|
|
81
|
+
finally {
|
|
82
|
+
await db.$pool.end();
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
function convertNullColumnsToUndefined(rows) {
|
|
86
|
+
rows.forEach((row) => {
|
|
87
|
+
for (const column in row) {
|
|
88
|
+
const columnValue = row[column];
|
|
89
|
+
if (columnValue === null) {
|
|
90
|
+
row[column] = undefined;
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
});
|
|
94
|
+
}
|
|
95
|
+
//# sourceMappingURL=database.js.map
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import type { DTDatabase, DTTransaction } from "./database.js";
|
|
2
|
+
export declare enum DataType {
|
|
3
|
+
VS_DATEX2 = "VS_DATEX2",
|
|
4
|
+
COUNTING_SITES_DATA = "COUNTING_SITES_DATA",
|
|
5
|
+
COUNTING_SITES_METADATA_CHECK = "COUNTING_SITES_METADATA_CHECK",
|
|
6
|
+
MAINTENANCE_TRACKING_DATA_CHECKED = "MAINTENANCE_TRACKING_DATA_CHECKED",
|
|
7
|
+
PERMIT_DATA = "PERMIT_DATA",
|
|
8
|
+
PERMIT_DATA_CHECK = "PERMIT_DATA_CHECK"
|
|
9
|
+
}
|
|
10
|
+
export declare function getLastUpdated(db: DTDatabase, datatype: DataType): Promise<Date | null>;
|
|
11
|
+
export declare function getLastUpdatedWithSubtype(db: DTDatabase, datatype: DataType, subtype: string): Promise<Date | null>;
|
|
12
|
+
export declare function updateLastUpdated(db: DTDatabase | DTTransaction, datatype: DataType, updated: Date): Promise<null>;
|
|
13
|
+
export declare function updateLastUpdatedWithSubtype(db: DTDatabase | DTTransaction, datatype: DataType, subtype: string, updated: Date): Promise<null>;
|
|
14
|
+
export declare function getUpdatedTimestamp(db: DTDatabase, datatype: string): Promise<Date | null>;
|
|
15
|
+
export declare function updateUpdatedTimestamp(db: DTDatabase | DTTransaction, datatype: string, date: Date, by?: string): Promise<null>;
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
export var DataType;
|
|
2
|
+
(function (DataType) {
|
|
3
|
+
DataType["VS_DATEX2"] = "VS_DATEX2";
|
|
4
|
+
DataType["COUNTING_SITES_DATA"] = "COUNTING_SITES_DATA";
|
|
5
|
+
DataType["COUNTING_SITES_METADATA_CHECK"] = "COUNTING_SITES_METADATA_CHECK";
|
|
6
|
+
DataType["MAINTENANCE_TRACKING_DATA_CHECKED"] = "MAINTENANCE_TRACKING_DATA_CHECKED";
|
|
7
|
+
DataType["PERMIT_DATA"] = "PERMIT_DATA";
|
|
8
|
+
DataType["PERMIT_DATA_CHECK"] = "PERMIT_DATA_CHECK";
|
|
9
|
+
})(DataType || (DataType = {}));
|
|
10
|
+
const UNSET_SUBTYPE = "-";
|
|
11
|
+
export function getLastUpdated(db, datatype) {
|
|
12
|
+
return db.oneOrNone("select updated from data_updated where data_type=$(datatype) and subtype=$(subtype)", {
|
|
13
|
+
datatype: datatype,
|
|
14
|
+
subtype: UNSET_SUBTYPE,
|
|
15
|
+
}, (x) => x?.updated ?? null);
|
|
16
|
+
}
|
|
17
|
+
export function getLastUpdatedWithSubtype(db, datatype, subtype) {
|
|
18
|
+
return db.oneOrNone("SELECT updated FROM data_updated WHERE data_type=$(datatype) AND subtype=$(subtype)", {
|
|
19
|
+
datatype: datatype,
|
|
20
|
+
subtype: subtype,
|
|
21
|
+
}, (x) => x?.updated ?? null);
|
|
22
|
+
}
|
|
23
|
+
export function updateLastUpdated(db, datatype, updated) {
|
|
24
|
+
return db.none(`insert into data_updated(id, data_type, updated)
|
|
25
|
+
values(nextval('seq_data_updated'), $(datatype), $(updated))
|
|
26
|
+
on conflict (data_type, subtype)
|
|
27
|
+
do update set updated = $(updated)`, { updated, datatype });
|
|
28
|
+
}
|
|
29
|
+
export function updateLastUpdatedWithSubtype(db, datatype, subtype, updated) {
|
|
30
|
+
return db.none(`insert into data_updated(id, data_type, subtype, updated)
|
|
31
|
+
values(nextval('seq_data_updated'), $(datatype), $(subtype), $(updated))
|
|
32
|
+
on conflict (data_type, subtype)
|
|
33
|
+
do update set updated = $(updated)`, { updated, subtype, datatype });
|
|
34
|
+
}
|
|
35
|
+
export function getUpdatedTimestamp(db, datatype) {
|
|
36
|
+
return db.oneOrNone("select updated_time as updated from updated_timestamp where updated_name=$(datatype)", {
|
|
37
|
+
datatype: datatype,
|
|
38
|
+
}, (x) => x?.updated ?? null);
|
|
39
|
+
}
|
|
40
|
+
export function updateUpdatedTimestamp(db, datatype, date, by = "") {
|
|
41
|
+
return db.none(`insert into updated_timestamp(updated_name, updated_time, updated_by)
|
|
42
|
+
values($(datatype), $(date), $(by))
|
|
43
|
+
on conflict (updated_name)
|
|
44
|
+
do update set updated_time = $(date), updated_by = $(by)`, { date, datatype, by });
|
|
45
|
+
}
|
|
46
|
+
//# sourceMappingURL=last-updated.js.map
|
package/dist/index.d.ts
ADDED
package/dist/index.js
ADDED
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { logger } from "../aws/runtime/dt-logger-default.js";
|
|
2
|
+
export function isValidIMO(imo) {
|
|
3
|
+
return imo >= 1000000 && imo <= 9999999 && imoChecksumIsValid(imo);
|
|
4
|
+
}
|
|
5
|
+
function imoChecksumIsValid(imo) {
|
|
6
|
+
const imoStr = imo.toString();
|
|
7
|
+
const imoDigit1 = Number(imoStr[0]);
|
|
8
|
+
const imoDigit2 = Number(imoStr[1]);
|
|
9
|
+
const imoDigit3 = Number(imoStr[2]);
|
|
10
|
+
const imoDigit4 = Number(imoStr[3]);
|
|
11
|
+
const imoDigit5 = Number(imoStr[4]);
|
|
12
|
+
const imoDigit6 = Number(imoStr[5]);
|
|
13
|
+
const checkDigit = Number(imoStr[6]);
|
|
14
|
+
const checkCalculation = Number(imoDigit1 * 7 +
|
|
15
|
+
imoDigit2 * 6 +
|
|
16
|
+
imoDigit3 * 5 +
|
|
17
|
+
imoDigit4 * 4 +
|
|
18
|
+
imoDigit5 * 3 +
|
|
19
|
+
imoDigit6 * 2);
|
|
20
|
+
const checkResult = checkCalculation % 10 === checkDigit;
|
|
21
|
+
if (!checkResult) {
|
|
22
|
+
logger.warn({
|
|
23
|
+
method: "idUtils.imoChecksumIsValid",
|
|
24
|
+
message: `IMO checksum failed ${imo}`,
|
|
25
|
+
});
|
|
26
|
+
}
|
|
27
|
+
return checkResult;
|
|
28
|
+
}
|
|
29
|
+
export function isValidMMSI(mmsi) {
|
|
30
|
+
return mmsi >= 100000000 && mmsi <= 999999999;
|
|
31
|
+
}
|
|
32
|
+
const LocodePattern = /^FI[A-Z]{3}$/i;
|
|
33
|
+
export function isValidLOCODE(locode) {
|
|
34
|
+
return LocodePattern.test(locode);
|
|
35
|
+
}
|
|
36
|
+
//# sourceMappingURL=id_utils.js.map
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
export interface RtzPositionCoordinate {
|
|
2
|
+
readonly $: {
|
|
3
|
+
readonly lat: number;
|
|
4
|
+
readonly lon: number;
|
|
5
|
+
};
|
|
6
|
+
}
|
|
7
|
+
export interface RtzWaypointPosition {
|
|
8
|
+
readonly position: RtzPositionCoordinate[];
|
|
9
|
+
}
|
|
10
|
+
export interface RtzWaypoint {
|
|
11
|
+
readonly waypoint: RtzWaypointPosition[];
|
|
12
|
+
}
|
|
13
|
+
export interface RtzScheduleElement {
|
|
14
|
+
readonly $: {
|
|
15
|
+
/**
|
|
16
|
+
* Date
|
|
17
|
+
*/
|
|
18
|
+
readonly etd?: string;
|
|
19
|
+
/**
|
|
20
|
+
* Date
|
|
21
|
+
*/
|
|
22
|
+
readonly eta?: string;
|
|
23
|
+
};
|
|
24
|
+
}
|
|
25
|
+
export interface RtzSchedule {
|
|
26
|
+
readonly scheduleElement: RtzScheduleElement[];
|
|
27
|
+
}
|
|
28
|
+
export interface RtzScheduleWrapper {
|
|
29
|
+
readonly manual?: RtzSchedule[];
|
|
30
|
+
readonly calculated?: RtzSchedule[];
|
|
31
|
+
}
|
|
32
|
+
export interface RtzSchedules {
|
|
33
|
+
readonly schedule: RtzScheduleWrapper[];
|
|
34
|
+
}
|
|
35
|
+
export interface RtzRouteInfo {
|
|
36
|
+
readonly $: {
|
|
37
|
+
readonly vesselMMSI: string;
|
|
38
|
+
readonly vesselIMO: string;
|
|
39
|
+
};
|
|
40
|
+
}
|
|
41
|
+
export interface RtzRoute {
|
|
42
|
+
readonly routeInfo: RtzRouteInfo[];
|
|
43
|
+
readonly waypoints: RtzWaypoint[];
|
|
44
|
+
readonly schedules: RtzSchedules[];
|
|
45
|
+
}
|
|
46
|
+
export interface RtzVoyagePlan {
|
|
47
|
+
readonly route: RtzRoute;
|
|
48
|
+
}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
export declare const CoordinatesSchema: z.ZodArray<z.ZodNumber>;
|
|
3
|
+
export declare const PointSchema: z.ZodObject<{
|
|
4
|
+
type: z.ZodLiteral<"Point">;
|
|
5
|
+
coordinates: z.ZodArray<z.ZodNumber>;
|
|
6
|
+
}, z.core.$strip>;
|
|
7
|
+
export declare const MultiPointSchema: z.ZodObject<{
|
|
8
|
+
type: z.ZodLiteral<"MultiPoint">;
|
|
9
|
+
coordinates: z.ZodArray<z.ZodArray<z.ZodNumber>>;
|
|
10
|
+
}, z.core.$strip>;
|
|
11
|
+
export declare const LineStringSchema: z.ZodObject<{
|
|
12
|
+
type: z.ZodLiteral<"LineString">;
|
|
13
|
+
coordinates: z.ZodArray<z.ZodArray<z.ZodNumber>>;
|
|
14
|
+
}, z.core.$strip>;
|
|
15
|
+
export declare const MultiLineStringSchema: z.ZodObject<{
|
|
16
|
+
type: z.ZodLiteral<"MultiLineString">;
|
|
17
|
+
coordinates: z.ZodArray<z.ZodArray<z.ZodArray<z.ZodNumber>>>;
|
|
18
|
+
}, z.core.$strip>;
|
|
19
|
+
export declare const PolygonSchema: z.ZodObject<{
|
|
20
|
+
type: z.ZodLiteral<"Polygon">;
|
|
21
|
+
coordinates: z.ZodArray<z.ZodArray<z.ZodArray<z.ZodNumber>>>;
|
|
22
|
+
}, z.core.$strip>;
|
|
23
|
+
export declare const MultiPolygonSchema: z.ZodObject<{
|
|
24
|
+
type: z.ZodLiteral<"MultiPolygon">;
|
|
25
|
+
coordinates: z.ZodArray<z.ZodArray<z.ZodArray<z.ZodArray<z.ZodNumber>>>>;
|
|
26
|
+
}, z.core.$strip>;
|
|
27
|
+
export type Point = z.infer<typeof PointSchema>;
|
|
28
|
+
export type Geometry = z.infer<typeof PointSchema> | z.infer<typeof MultiPointSchema> | z.infer<typeof LineStringSchema> | z.infer<typeof MultiLineStringSchema> | z.infer<typeof PolygonSchema> | z.infer<typeof MultiPolygonSchema> | {
|
|
29
|
+
type: "GeometryCollection";
|
|
30
|
+
geometries: Geometry[];
|
|
31
|
+
};
|
|
32
|
+
export declare const GeometrySchema: z.ZodType<Geometry>;
|
|
33
|
+
export declare const FeatureSchema: z.ZodObject<{
|
|
34
|
+
type: z.ZodLiteral<"Feature">;
|
|
35
|
+
geometry: z.ZodType<Geometry, unknown, z.core.$ZodTypeInternals<Geometry, unknown>>;
|
|
36
|
+
properties: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodAny>>;
|
|
37
|
+
id: z.ZodOptional<z.ZodUnion<readonly [z.ZodString, z.ZodNumber]>>;
|
|
38
|
+
}, z.core.$strip>;
|
|
39
|
+
export declare const FeatureCollectionSchema: z.ZodObject<{
|
|
40
|
+
type: z.ZodLiteral<"FeatureCollection">;
|
|
41
|
+
features: z.ZodArray<z.ZodObject<{
|
|
42
|
+
type: z.ZodLiteral<"Feature">;
|
|
43
|
+
geometry: z.ZodType<Geometry, unknown, z.core.$ZodTypeInternals<Geometry, unknown>>;
|
|
44
|
+
properties: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodAny>>;
|
|
45
|
+
id: z.ZodOptional<z.ZodUnion<readonly [z.ZodString, z.ZodNumber]>>;
|
|
46
|
+
}, z.core.$strip>>;
|
|
47
|
+
}, z.core.$strip>;
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
export const CoordinatesSchema = z.array(z.number()).min(2).max(3);
|
|
3
|
+
export const PointSchema = z.object({
|
|
4
|
+
type: z.literal("Point"),
|
|
5
|
+
coordinates: CoordinatesSchema,
|
|
6
|
+
});
|
|
7
|
+
export const MultiPointSchema = z.object({
|
|
8
|
+
type: z.literal("MultiPoint"),
|
|
9
|
+
coordinates: z.array(CoordinatesSchema),
|
|
10
|
+
});
|
|
11
|
+
export const LineStringSchema = z.object({
|
|
12
|
+
type: z.literal("LineString"),
|
|
13
|
+
coordinates: z.array(CoordinatesSchema).min(2),
|
|
14
|
+
});
|
|
15
|
+
export const MultiLineStringSchema = z.object({
|
|
16
|
+
type: z.literal("MultiLineString"),
|
|
17
|
+
coordinates: z.array(z.array(CoordinatesSchema).min(2)),
|
|
18
|
+
});
|
|
19
|
+
export const PolygonSchema = z.object({
|
|
20
|
+
type: z.literal("Polygon"),
|
|
21
|
+
coordinates: z.array(z.array(CoordinatesSchema).min(4)),
|
|
22
|
+
});
|
|
23
|
+
export const MultiPolygonSchema = z.object({
|
|
24
|
+
type: z.literal("MultiPolygon"),
|
|
25
|
+
coordinates: z.array(z.array(z.array(CoordinatesSchema).min(4))),
|
|
26
|
+
});
|
|
27
|
+
// --- Recursive GeometrySchema ---
|
|
28
|
+
export const GeometrySchema = z.lazy(() => z.union([
|
|
29
|
+
PointSchema,
|
|
30
|
+
MultiPointSchema,
|
|
31
|
+
LineStringSchema,
|
|
32
|
+
MultiLineStringSchema,
|
|
33
|
+
PolygonSchema,
|
|
34
|
+
MultiPolygonSchema,
|
|
35
|
+
// GeometryCollection is recursive, so we need to use z.lazy
|
|
36
|
+
z.object({
|
|
37
|
+
type: z.literal("GeometryCollection"),
|
|
38
|
+
geometries: z.array(GeometrySchema),
|
|
39
|
+
}),
|
|
40
|
+
]));
|
|
41
|
+
export const FeatureSchema = z.object({
|
|
42
|
+
type: z.literal("Feature"),
|
|
43
|
+
geometry: GeometrySchema,
|
|
44
|
+
properties: z.record(z.string(), z.any()).optional(),
|
|
45
|
+
id: z.union([z.string(), z.number()]).optional(),
|
|
46
|
+
});
|
|
47
|
+
export const FeatureCollectionSchema = z.object({
|
|
48
|
+
type: z.literal("FeatureCollection"),
|
|
49
|
+
features: z.array(FeatureSchema),
|
|
50
|
+
});
|
|
51
|
+
//# sourceMappingURL=geojson.js.map
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import type { ValueOf } from "./util-types.js";
|
|
2
|
+
/**
|
|
3
|
+
* Adds `null` as an accepted type to all properties in given type.
|
|
4
|
+
*/
|
|
5
|
+
export type Nullable<Obj> = {
|
|
6
|
+
[Key in keyof Obj]: Obj[Key] | null;
|
|
7
|
+
};
|
|
8
|
+
type RequiredKeys<Obj> = ValueOf<{
|
|
9
|
+
[Key in keyof Obj]-?: object extends {
|
|
10
|
+
[K in Key]: Obj[Key];
|
|
11
|
+
} ? never : Key;
|
|
12
|
+
}>;
|
|
13
|
+
type OptionalKeys<Obj> = ValueOf<{
|
|
14
|
+
[Key in keyof Obj]-?: object extends {
|
|
15
|
+
[K in Key]: Obj[Key];
|
|
16
|
+
} ? Key : never;
|
|
17
|
+
}>;
|
|
18
|
+
type RequiredProperties<Obj> = Pick<Obj, RequiredKeys<Obj>>;
|
|
19
|
+
type OptionalProperties<Obj> = Pick<Obj, OptionalKeys<Obj>>;
|
|
20
|
+
/**
|
|
21
|
+
* Adds `null` as an accepted type to all optional properties in given type. Required properties remain unchanged.
|
|
22
|
+
*/
|
|
23
|
+
export type NullableOptional<Obj> = RequiredProperties<Obj> & Nullable<OptionalProperties<Obj>>;
|
|
24
|
+
export {};
|