@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.
Files changed (238) hide show
  1. package/README.md +18 -1
  2. package/dist/__test__/asserter.d.ts +13 -0
  3. package/dist/__test__/asserter.js +39 -0
  4. package/dist/__test__/db-testutils.d.ts +3 -0
  5. package/dist/__test__/db-testutils.js +38 -0
  6. package/dist/__test__/dependencies.test.d.ts +1 -0
  7. package/dist/__test__/dependencies.test.js +21 -0
  8. package/dist/__test__/imports.test.d.ts +1 -0
  9. package/dist/__test__/imports.test.js +318 -0
  10. package/dist/__test__/infra/acl-builder.test.d.ts +1 -0
  11. package/dist/__test__/infra/acl-builder.test.js +72 -0
  12. package/dist/__test__/infra/api/handler-factory.test.d.ts +1 -0
  13. package/dist/__test__/infra/api/handler-factory.test.js +42 -0
  14. package/dist/__test__/infra/api/integration.test.d.ts +1 -0
  15. package/dist/__test__/infra/api/integration.test.js +162 -0
  16. package/dist/__test__/infra/api/response.test.d.ts +1 -0
  17. package/dist/__test__/infra/api/response.test.js +77 -0
  18. package/dist/__test__/infra/api/static-integration.test.d.ts +1 -0
  19. package/dist/__test__/infra/api/static-integration.test.js +35 -0
  20. package/dist/__test__/infra/documentation.test.d.ts +1 -0
  21. package/dist/__test__/infra/documentation.test.js +38 -0
  22. package/dist/__test__/infra/scheduler.test.d.ts +1 -0
  23. package/dist/__test__/infra/scheduler.test.js +23 -0
  24. package/dist/__test__/infra/security-rule.test.d.ts +1 -0
  25. package/dist/__test__/infra/security-rule.test.js +21 -0
  26. package/dist/__test__/infra/stack/rest-apis.test.d.ts +1 -0
  27. package/dist/__test__/infra/stack/rest-apis.test.js +47 -0
  28. package/dist/__test__/marine/id_utils.test.d.ts +1 -0
  29. package/dist/__test__/marine/id_utils.test.js +45 -0
  30. package/dist/__test__/mock-ky.d.ts +2 -0
  31. package/dist/__test__/mock-ky.js +15 -0
  32. package/dist/__test__/promise/promise.test.d.ts +1 -0
  33. package/dist/__test__/promise/promise.test.js +126 -0
  34. package/dist/__test__/runtime/dt-logger.test.d.ts +1 -0
  35. package/dist/__test__/runtime/dt-logger.test.js +193 -0
  36. package/dist/__test__/secrets/secret-holder.test.d.ts +1 -0
  37. package/dist/__test__/secrets/secret-holder.test.js +96 -0
  38. package/dist/__test__/secrets/secret.test.d.ts +1 -0
  39. package/dist/__test__/secrets/secret.test.js +57 -0
  40. package/dist/__test__/stack/dt-function.test.d.ts +1 -0
  41. package/dist/__test__/stack/dt-function.test.js +340 -0
  42. package/dist/__test__/stack/rest-apis.test.d.ts +1 -0
  43. package/dist/__test__/stack/rest-apis.test.js +45 -0
  44. package/dist/__test__/test/mock-ky.test.d.ts +1 -0
  45. package/dist/__test__/test/mock-ky.test.js +46 -0
  46. package/dist/__test__/testutils.d.ts +12 -0
  47. package/dist/__test__/testutils.js +32 -0
  48. package/dist/__test__/types/lambda-proxy-types.test.d.ts +8 -0
  49. package/dist/__test__/types/lambda-proxy-types.test.js +155 -0
  50. package/dist/__test__/types/lambda-response-builder.test.d.ts +1 -0
  51. package/dist/__test__/types/lambda-response-builder.test.js +81 -0
  52. package/dist/__test__/types/lambda-response.test.d.ts +9 -0
  53. package/dist/__test__/types/lambda-response.test.js +73 -0
  54. package/dist/__test__/utils/base64.test.d.ts +1 -0
  55. package/dist/__test__/utils/base64.test.js +38 -0
  56. package/dist/__test__/utils/date-utils.test.d.ts +1 -0
  57. package/dist/__test__/utils/date-utils.test.js +32 -0
  58. package/dist/__test__/utils/geometry.test.d.ts +1 -0
  59. package/dist/__test__/utils/geometry.test.js +25 -0
  60. package/dist/__test__/utils/lambda-proxy-event.test.d.ts +1 -0
  61. package/dist/__test__/utils/lambda-proxy-event.test.js +45 -0
  62. package/dist/__test__/utils/logging.test.d.ts +1 -0
  63. package/dist/__test__/utils/logging.test.js +75 -0
  64. package/dist/__test__/utils/stop-watch.test.d.ts +1 -0
  65. package/dist/__test__/utils/stop-watch.test.js +118 -0
  66. package/dist/__test__/utils/utils.test.d.ts +1 -0
  67. package/dist/__test__/utils/utils.test.js +48 -0
  68. package/dist/aws/infra/acl-builder.d.ts +53 -0
  69. package/dist/aws/infra/acl-builder.js +407 -0
  70. package/dist/aws/infra/api/handler-factory.d.ts +22 -0
  71. package/dist/aws/infra/api/handler-factory.js +68 -0
  72. package/dist/aws/infra/api/integration.d.ts +49 -0
  73. package/dist/aws/infra/api/integration.js +162 -0
  74. package/dist/aws/infra/api/response.d.ts +62 -0
  75. package/dist/aws/infra/api/response.js +132 -0
  76. package/dist/aws/infra/api/responses.d.ts +60 -0
  77. package/dist/aws/infra/api/responses.js +90 -0
  78. package/dist/aws/infra/api/static-integration.d.ts +16 -0
  79. package/dist/aws/infra/api/static-integration.js +76 -0
  80. package/dist/aws/infra/bucket-policy.d.ts +38 -0
  81. package/dist/aws/infra/bucket-policy.js +30 -0
  82. package/dist/aws/infra/canaries/canary-alarm.d.ts +6 -0
  83. package/dist/aws/infra/canaries/canary-alarm.js +20 -0
  84. package/dist/aws/infra/canaries/canary-keys.d.ts +3 -0
  85. package/dist/aws/infra/canaries/canary-keys.js +4 -0
  86. package/dist/aws/infra/canaries/canary-parameters.d.ts +19 -0
  87. package/dist/aws/infra/canaries/canary-parameters.js +2 -0
  88. package/dist/aws/infra/canaries/canary-role.d.ts +14 -0
  89. package/dist/aws/infra/canaries/canary-role.js +51 -0
  90. package/dist/aws/infra/canaries/canary.d.ts +8 -0
  91. package/dist/aws/infra/canaries/canary.js +26 -0
  92. package/dist/aws/infra/canaries/database-canary.d.ts +17 -0
  93. package/dist/aws/infra/canaries/database-canary.js +65 -0
  94. package/dist/aws/infra/canaries/database-checker.d.ts +33 -0
  95. package/dist/aws/infra/canaries/database-checker.js +119 -0
  96. package/dist/aws/infra/canaries/url-canary.d.ts +16 -0
  97. package/dist/aws/infra/canaries/url-canary.js +55 -0
  98. package/dist/aws/infra/canaries/url-checker.d.ts +45 -0
  99. package/dist/aws/infra/canaries/url-checker.js +256 -0
  100. package/dist/aws/infra/documentation.d.ts +56 -0
  101. package/dist/aws/infra/documentation.js +90 -0
  102. package/dist/aws/infra/import-util.d.ts +17 -0
  103. package/dist/aws/infra/import-util.js +41 -0
  104. package/dist/aws/infra/scheduler.d.ts +12 -0
  105. package/dist/aws/infra/scheduler.js +27 -0
  106. package/dist/aws/infra/security-rule.d.ts +12 -0
  107. package/dist/aws/infra/security-rule.js +35 -0
  108. package/dist/aws/infra/sqs-integration.d.ts +4 -0
  109. package/dist/aws/infra/sqs-integration.js +85 -0
  110. package/dist/aws/infra/sqs-queue.d.ts +19 -0
  111. package/dist/aws/infra/sqs-queue.js +145 -0
  112. package/dist/aws/infra/stack/dt-function-alarms.d.ts +29 -0
  113. package/dist/aws/infra/stack/dt-function-alarms.js +54 -0
  114. package/dist/aws/infra/stack/dt-function.d.ts +124 -0
  115. package/dist/aws/infra/stack/dt-function.js +315 -0
  116. package/dist/aws/infra/stack/lambda-configs.d.ts +44 -0
  117. package/dist/aws/infra/stack/lambda-configs.js +71 -0
  118. package/dist/aws/infra/stack/lambda-log-group.d.ts +15 -0
  119. package/dist/aws/infra/stack/lambda-log-group.js +24 -0
  120. package/dist/aws/infra/stack/monitoredfunction.d.ts +85 -0
  121. package/dist/aws/infra/stack/monitoredfunction.js +147 -0
  122. package/dist/aws/infra/stack/parameters.d.ts +40 -0
  123. package/dist/aws/infra/stack/parameters.js +50 -0
  124. package/dist/aws/infra/stack/rest-api.d.ts +74 -0
  125. package/dist/aws/infra/stack/rest-api.js +235 -0
  126. package/dist/aws/infra/stack/stack-checking-aspect.d.ts +20 -0
  127. package/dist/aws/infra/stack/stack-checking-aspect.js +183 -0
  128. package/dist/aws/infra/stack/stack.d.ts +56 -0
  129. package/dist/aws/infra/stack/stack.js +71 -0
  130. package/dist/aws/infra/stack/subscription.d.ts +17 -0
  131. package/dist/aws/infra/stack/subscription.js +37 -0
  132. package/dist/aws/infra/stacks/db-dns-stack.d.ts +13 -0
  133. package/dist/aws/infra/stacks/db-dns-stack.js +60 -0
  134. package/dist/aws/infra/stacks/db-proxy-stack.d.ts +24 -0
  135. package/dist/aws/infra/stacks/db-proxy-stack.js +74 -0
  136. package/dist/aws/infra/stacks/db-stack.d.ts +65 -0
  137. package/dist/aws/infra/stacks/db-stack.js +189 -0
  138. package/dist/aws/infra/stacks/intra-stack-configuration.d.ts +5 -0
  139. package/dist/aws/infra/stacks/intra-stack-configuration.js +2 -0
  140. package/dist/aws/infra/stacks/network-stack.d.ts +14 -0
  141. package/dist/aws/infra/stacks/network-stack.js +45 -0
  142. package/dist/aws/infra/usage-plans.d.ts +16 -0
  143. package/dist/aws/infra/usage-plans.js +38 -0
  144. package/dist/aws/runtime/apikey.d.ts +2 -0
  145. package/dist/aws/runtime/apikey.js +13 -0
  146. package/dist/aws/runtime/digitraffic-integration-response.d.ts +8 -0
  147. package/dist/aws/runtime/digitraffic-integration-response.js +25 -0
  148. package/dist/aws/runtime/dt-logger-default.d.ts +9 -0
  149. package/dist/aws/runtime/dt-logger-default.js +6 -0
  150. package/dist/aws/runtime/dt-logger.d.ts +117 -0
  151. package/dist/aws/runtime/dt-logger.js +159 -0
  152. package/dist/aws/runtime/environment.d.ts +5 -0
  153. package/dist/aws/runtime/environment.js +7 -0
  154. package/dist/aws/runtime/s3.d.ts +3 -0
  155. package/dist/aws/runtime/s3.js +21 -0
  156. package/dist/aws/runtime/secrets/dbsecret.d.ts +16 -0
  157. package/dist/aws/runtime/secrets/dbsecret.js +26 -0
  158. package/dist/aws/runtime/secrets/proxy-holder.d.ts +9 -0
  159. package/dist/aws/runtime/secrets/proxy-holder.js +25 -0
  160. package/dist/aws/runtime/secrets/rds-holder.d.ts +9 -0
  161. package/dist/aws/runtime/secrets/rds-holder.js +25 -0
  162. package/dist/aws/runtime/secrets/secret-holder.d.ts +30 -0
  163. package/dist/aws/runtime/secrets/secret-holder.js +81 -0
  164. package/dist/aws/runtime/secrets/secret.d.ts +8 -0
  165. package/dist/aws/runtime/secrets/secret.js +61 -0
  166. package/dist/aws/types/errors.d.ts +8 -0
  167. package/dist/aws/types/errors.js +13 -0
  168. package/dist/aws/types/lambda-proxy-types.d.ts +59 -0
  169. package/dist/aws/types/lambda-proxy-types.js +210 -0
  170. package/dist/aws/types/lambda-response.d.ts +89 -0
  171. package/dist/aws/types/lambda-response.js +204 -0
  172. package/dist/aws/types/mediatypes.d.ts +11 -0
  173. package/dist/aws/types/mediatypes.js +14 -0
  174. package/dist/aws/types/model-with-reference.d.ts +7 -0
  175. package/dist/aws/types/model-with-reference.js +2 -0
  176. package/dist/aws/types/tags.d.ts +2 -0
  177. package/dist/aws/types/tags.js +4 -0
  178. package/dist/database/database.d.ts +27 -0
  179. package/dist/database/database.js +95 -0
  180. package/dist/database/last-updated.d.ts +15 -0
  181. package/dist/database/last-updated.js +46 -0
  182. package/dist/database/models.d.ts +6 -0
  183. package/dist/database/models.js +2 -0
  184. package/dist/index.d.ts +2 -0
  185. package/dist/index.js +2 -0
  186. package/dist/marine/id_utils.d.ts +3 -0
  187. package/dist/marine/id_utils.js +36 -0
  188. package/dist/marine/rtz.d.ts +48 -0
  189. package/dist/marine/rtz.js +2 -0
  190. package/dist/types/async-timeout-error.d.ts +3 -0
  191. package/dist/types/async-timeout-error.js +6 -0
  192. package/dist/types/either.d.ts +9 -0
  193. package/dist/types/either.js +2 -0
  194. package/dist/types/geojson.d.ts +47 -0
  195. package/dist/types/geojson.js +51 -0
  196. package/dist/types/http-error.d.ts +4 -0
  197. package/dist/types/http-error.js +8 -0
  198. package/dist/types/input-error.d.ts +2 -0
  199. package/dist/types/input-error.js +3 -0
  200. package/dist/types/language.d.ts +5 -0
  201. package/dist/types/language.js +7 -0
  202. package/dist/types/nullable.d.ts +24 -0
  203. package/dist/types/nullable.js +2 -0
  204. package/dist/types/openapi-schema.d.ts +932 -0
  205. package/dist/types/openapi-schema.js +151 -0
  206. package/dist/types/traffictype.d.ts +11 -0
  207. package/dist/types/traffictype.js +13 -0
  208. package/dist/types/urn.d.ts +1 -0
  209. package/dist/types/urn.js +2 -0
  210. package/dist/types/util-types.d.ts +11 -0
  211. package/dist/types/util-types.js +2 -0
  212. package/dist/types/validator.d.ts +4 -0
  213. package/dist/types/validator.js +9 -0
  214. package/dist/utils/api-model.d.ts +51 -0
  215. package/dist/utils/api-model.js +118 -0
  216. package/dist/utils/base64.d.ts +34 -0
  217. package/dist/utils/base64.js +53 -0
  218. package/dist/utils/date-utils.d.ts +27 -0
  219. package/dist/utils/date-utils.js +45 -0
  220. package/dist/utils/geojson-types.d.ts +14 -0
  221. package/dist/utils/geojson-types.js +15 -0
  222. package/dist/utils/geometry.d.ts +44 -0
  223. package/dist/utils/geometry.js +154 -0
  224. package/dist/utils/lambda-proxy-event.d.ts +9 -0
  225. package/dist/utils/lambda-proxy-event.js +31 -0
  226. package/dist/utils/logging.d.ts +40 -0
  227. package/dist/utils/logging.js +88 -0
  228. package/dist/utils/retry.d.ts +33 -0
  229. package/dist/utils/retry.js +135 -0
  230. package/dist/utils/slack.d.ts +5 -0
  231. package/dist/utils/slack.js +24 -0
  232. package/dist/utils/stop-watch.d.ts +46 -0
  233. package/dist/utils/stop-watch.js +114 -0
  234. package/dist/utils/utils.d.ts +95 -0
  235. package/dist/utils/utils.js +178 -0
  236. package/dist/utils/zod-utils.d.ts +27 -0
  237. package/dist/utils/zod-utils.js +57 -0
  238. 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
@@ -0,0 +1,6 @@
1
+ export interface Countable {
2
+ count: number;
3
+ }
4
+ export interface Identifiable<T> {
5
+ id: T;
6
+ }
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=models.js.map
@@ -0,0 +1,2 @@
1
+ export type { DigitrafficStackLike } from "./aws/infra/stack/stack.js";
2
+ export { DigitrafficStack } from "./aws/infra/stack/stack.js";
package/dist/index.js ADDED
@@ -0,0 +1,2 @@
1
+ export { DigitrafficStack } from "./aws/infra/stack/stack.js";
2
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1,3 @@
1
+ export declare function isValidIMO(imo: number): boolean;
2
+ export declare function isValidMMSI(mmsi: number): boolean;
3
+ export declare function isValidLOCODE(locode: string): boolean;
@@ -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,2 @@
1
+ export {};
2
+ //# sourceMappingURL=rtz.js.map
@@ -0,0 +1,3 @@
1
+ export declare class AsyncTimeoutError extends Error {
2
+ constructor();
3
+ }
@@ -0,0 +1,6 @@
1
+ export class AsyncTimeoutError extends Error {
2
+ constructor() {
3
+ super("Async operation timed out");
4
+ }
5
+ }
6
+ //# sourceMappingURL=async-timeout-error.js.map
@@ -0,0 +1,9 @@
1
+ export interface EitherOk<T> {
2
+ result: "ok";
3
+ value: T;
4
+ }
5
+ export interface EitherError {
6
+ result: "error";
7
+ message: string;
8
+ }
9
+ export type Either<T> = EitherOk<T> | EitherError;
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=either.js.map
@@ -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,4 @@
1
+ export declare class HttpError extends Error {
2
+ statusCode: number;
3
+ constructor(statusCode: number, message: string);
4
+ }
@@ -0,0 +1,8 @@
1
+ export class HttpError extends Error {
2
+ statusCode;
3
+ constructor(statusCode, message) {
4
+ super(message);
5
+ this.statusCode = statusCode;
6
+ }
7
+ }
8
+ //# sourceMappingURL=http-error.js.map
@@ -0,0 +1,2 @@
1
+ export declare class InputError extends Error {
2
+ }
@@ -0,0 +1,3 @@
1
+ export class InputError extends Error {
2
+ }
3
+ //# sourceMappingURL=input-error.js.map
@@ -0,0 +1,5 @@
1
+ export declare enum Language {
2
+ FI = "fi",
3
+ EN = "en",
4
+ SV = "sv"
5
+ }
@@ -0,0 +1,7 @@
1
+ export var Language;
2
+ (function (Language) {
3
+ Language["FI"] = "fi";
4
+ Language["EN"] = "en";
5
+ Language["SV"] = "sv";
6
+ })(Language || (Language = {}));
7
+ //# sourceMappingURL=language.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 {};
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=nullable.js.map