@digitraffic/common 2022.10.25-1 → 2022.10.31-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.
- package/.editorconfig +9 -0
- package/.eslintignore +4 -0
- package/.eslintrc.json +27 -0
- package/.github/CODEOWNERS +2 -0
- package/.github/workflows/build.yml +36 -0
- package/.github/workflows/eslint.yml +38 -0
- package/.github/workflows/mirror.yml +15 -0
- package/.gitignore +29 -0
- package/.husky/pre-commit +4 -0
- package/.prettierrc.json +10 -0
- package/dist/aws/infra/api/integration.js +52 -0
- package/dist/aws/infra/api/response.js +61 -0
- package/dist/aws/infra/api/responses.js +82 -0
- package/dist/aws/infra/api/static-integration.js +54 -0
- package/dist/aws/infra/canaries/canary-alarm.js +26 -0
- package/dist/aws/infra/canaries/canary-keys.js +7 -0
- package/dist/aws/infra/canaries/canary-parameters.js +3 -0
- package/dist/aws/infra/canaries/canary-role.js +46 -0
- package/dist/aws/infra/canaries/canary.js +32 -0
- package/dist/aws/infra/canaries/database-canary.js +70 -0
- package/dist/aws/infra/canaries/database-checker.js +103 -0
- package/dist/aws/infra/canaries/url-canary.js +47 -0
- package/dist/aws/infra/canaries/url-checker.js +252 -0
- package/dist/aws/infra/documentation.js +95 -0
- package/dist/aws/infra/scheduler.js +31 -0
- package/dist/aws/infra/security-rule.js +39 -0
- package/dist/aws/infra/sqs-integration.js +93 -0
- package/dist/aws/infra/sqs-queue.js +130 -0
- package/dist/aws/infra/stack/lambda-configs.js +105 -0
- package/dist/aws/infra/stack/monitoredfunction.js +143 -0
- package/dist/aws/infra/stack/rest_apis.js +185 -0
- package/dist/aws/infra/stack/stack-checking-aspect.js +174 -0
- package/dist/aws/infra/stack/stack.js +67 -0
- package/dist/aws/infra/stack/subscription.js +42 -0
- package/dist/aws/infra/usage-plans.js +42 -0
- package/dist/aws/runtime/apikey.js +13 -0
- package/dist/aws/runtime/digitraffic-integration-response.js +26 -0
- package/dist/aws/runtime/environment.js +12 -0
- package/dist/aws/runtime/messaging.js +31 -0
- package/dist/aws/runtime/s3.js +30 -0
- package/dist/aws/runtime/secrets/dbsecret.js +96 -0
- package/dist/aws/runtime/secrets/proxy-holder.js +27 -0
- package/dist/aws/runtime/secrets/rds-holder.js +27 -0
- package/dist/aws/runtime/secrets/secret-holder.js +76 -0
- package/dist/aws/runtime/secrets/secret.js +43 -0
- package/dist/aws/types/errors.js +16 -0
- package/dist/aws/types/lambda-response.js +33 -0
- package/dist/aws/types/mediatypes.js +16 -0
- package/dist/aws/types/model-with-reference.js +3 -0
- package/dist/aws/types/proxytypes.js +3 -0
- package/dist/aws/types/tags.js +7 -0
- package/dist/database/cached.js +32 -0
- package/dist/database/database.js +70 -0
- package/dist/database/last-updated.js +54 -0
- package/dist/database/models.js +3 -0
- package/dist/marine/id_utils.js +33 -0
- package/dist/marine/rtz.js +3 -0
- package/dist/test/asserter.js +45 -0
- package/dist/test/db-testutils.js +31 -0
- package/dist/test/httpserver.js +74 -0
- package/dist/test/secret.js +25 -0
- package/dist/test/secrets-manager.js +59 -0
- package/dist/test/testutils.js +44 -0
- package/dist/types/either.js +3 -0
- package/dist/types/input-error.js +7 -0
- package/dist/types/language.js +10 -0
- package/dist/types/traffictype.js +13 -0
- package/dist/types/validator.js +14 -0
- package/dist/utils/api-model.js +129 -0
- package/dist/utils/base64.js +21 -0
- package/dist/utils/date-utils.js +34 -0
- package/dist/utils/geojson-types.js +18 -0
- package/dist/utils/geometry.js +164 -0
- package/dist/utils/retry.js +50 -0
- package/dist/utils/slack.js +25 -0
- package/dist/utils/utils.js +75 -0
- package/jest.config.js +15 -0
- package/package.json +15 -13
- package/src/@types/geojson-validation/index.d.ts +4 -0
- package/src/aws/infra/api/integration.ts +73 -0
- package/src/aws/infra/api/response.ts +67 -0
- package/src/aws/infra/api/responses.ts +124 -0
- package/src/aws/infra/api/static-integration.ts +62 -0
- package/src/aws/infra/canaries/canary-alarm.ts +31 -0
- package/src/aws/infra/canaries/canary-keys.ts +3 -0
- package/{aws/infra/canaries/canary-parameters.d.ts → src/aws/infra/canaries/canary-parameters.ts} +7 -6
- package/src/aws/infra/canaries/canary-role.ts +47 -0
- package/src/aws/infra/canaries/canary.ts +46 -0
- package/src/aws/infra/canaries/database-canary.ts +98 -0
- package/src/aws/infra/canaries/database-checker.ts +155 -0
- package/src/aws/infra/canaries/url-canary.ts +74 -0
- package/src/aws/infra/canaries/url-checker.ts +366 -0
- package/src/aws/infra/documentation.ts +124 -0
- package/src/aws/infra/scheduler.ts +59 -0
- package/src/aws/infra/security-rule.ts +38 -0
- package/src/aws/infra/sqs-integration.ts +102 -0
- package/src/aws/infra/sqs-queue.ts +148 -0
- package/src/aws/infra/stack/lambda-configs.ts +207 -0
- package/src/aws/infra/stack/monitoredfunction.ts +342 -0
- package/src/aws/infra/stack/rest_apis.ts +223 -0
- package/src/aws/infra/stack/stack-checking-aspect.ts +279 -0
- package/src/aws/infra/stack/stack.ts +145 -0
- package/src/aws/infra/stack/subscription.ts +58 -0
- package/src/aws/infra/usage-plans.ts +41 -0
- package/src/aws/runtime/apikey.ts +9 -0
- package/src/aws/runtime/digitraffic-integration-response.ts +28 -0
- package/src/aws/runtime/environment.ts +9 -0
- package/src/aws/runtime/messaging.ts +26 -0
- package/src/aws/runtime/s3.ts +44 -0
- package/src/aws/runtime/secrets/dbsecret.ts +116 -0
- package/src/aws/runtime/secrets/proxy-holder.ts +37 -0
- package/src/aws/runtime/secrets/rds-holder.ts +33 -0
- package/src/aws/runtime/secrets/secret-holder.ts +116 -0
- package/src/aws/runtime/secrets/secret.ts +50 -0
- package/src/aws/types/errors.ts +14 -0
- package/src/aws/types/lambda-response.ts +43 -0
- package/{aws/types/mediatypes.d.ts → src/aws/types/mediatypes.ts} +4 -3
- package/{aws/types/model-with-reference.d.ts → src/aws/types/model-with-reference.ts} +2 -1
- package/src/aws/types/proxytypes.ts +27 -0
- package/src/aws/types/tags.ts +3 -0
- package/src/database/cached.ts +35 -0
- package/src/database/database.ts +96 -0
- package/src/database/last-updated.ts +59 -0
- package/{database/models.d.ts → src/database/models.ts} +1 -0
- package/src/marine/id_utils.ts +30 -0
- package/src/marine/rtz.ts +57 -0
- package/src/test/asserter.ts +48 -0
- package/src/test/db-testutils.ts +44 -0
- package/src/test/httpserver.ts +96 -0
- package/src/test/secret.ts +23 -0
- package/src/test/secrets-manager.ts +34 -0
- package/src/test/testutils.ts +39 -0
- package/src/types/either.ts +3 -0
- package/src/types/input-error.ts +2 -0
- package/src/types/language.ts +3 -0
- package/src/types/traffictype.ts +8 -0
- package/src/types/validator.ts +10 -0
- package/src/utils/api-model.ts +133 -0
- package/src/utils/base64.ts +16 -0
- package/src/utils/date-utils.ts +30 -0
- package/src/utils/geojson-types.ts +22 -0
- package/src/utils/geometry.ts +164 -0
- package/src/utils/retry.ts +49 -0
- package/src/utils/slack.ts +22 -0
- package/src/utils/utils.ts +105 -0
- package/test/marine/id_utils.test.ts +57 -0
- package/test/promise/promise.test.ts +143 -0
- package/test/secrets/dbsecret.test.ts +59 -0
- package/test/secrets/secret-holder.test.ts +143 -0
- package/test/secrets/secret.test.ts +49 -0
- package/test/test/httpserver.test.ts +128 -0
- package/test/utils/date-utils.test.ts +28 -0
- package/test/utils/geometry.test.ts +29 -0
- package/test/utils/utils.test.ts +64 -0
- package/tsconfig.eslint.json +4 -0
- package/tsconfig.json +22 -0
- package/yarn.lock +4060 -0
- package/aws/infra/api/integration.d.ts +0 -21
- package/aws/infra/api/integration.js +0 -52
- package/aws/infra/api/response.d.ts +0 -22
- package/aws/infra/api/response.js +0 -61
- package/aws/infra/api/responses.d.ts +0 -39
- package/aws/infra/api/responses.js +0 -79
- package/aws/infra/api/static-integration.d.ts +0 -15
- package/aws/infra/api/static-integration.js +0 -54
- package/aws/infra/canaries/canary-alarm.d.ts +0 -6
- package/aws/infra/canaries/canary-alarm.js +0 -26
- package/aws/infra/canaries/canary-parameters.js +0 -3
- package/aws/infra/canaries/canary-role.d.ts +0 -6
- package/aws/infra/canaries/canary-role.js +0 -46
- package/aws/infra/canaries/canary.d.ts +0 -8
- package/aws/infra/canaries/canary.js +0 -32
- package/aws/infra/canaries/database-canary.d.ts +0 -18
- package/aws/infra/canaries/database-canary.js +0 -55
- package/aws/infra/canaries/database-checker.d.ts +0 -21
- package/aws/infra/canaries/database-checker.js +0 -109
- package/aws/infra/canaries/url-canary.d.ts +0 -19
- package/aws/infra/canaries/url-canary.js +0 -46
- package/aws/infra/canaries/url-checker.d.ts +0 -46
- package/aws/infra/canaries/url-checker.js +0 -238
- package/aws/infra/documentation.d.ts +0 -56
- package/aws/infra/documentation.js +0 -95
- package/aws/infra/scheduler.d.ts +0 -12
- package/aws/infra/scheduler.js +0 -31
- package/aws/infra/security-rule.d.ts +0 -12
- package/aws/infra/security-rule.js +0 -39
- package/aws/infra/sqs-integration.d.ts +0 -7
- package/aws/infra/sqs-integration.js +0 -93
- package/aws/infra/sqs-queue.d.ts +0 -16
- package/aws/infra/sqs-queue.js +0 -130
- package/aws/infra/stack/lambda-configs.d.ts +0 -72
- package/aws/infra/stack/lambda-configs.js +0 -93
- package/aws/infra/stack/monitoredfunction.d.ts +0 -84
- package/aws/infra/stack/monitoredfunction.js +0 -135
- package/aws/infra/stack/rest_apis.d.ts +0 -41
- package/aws/infra/stack/rest_apis.js +0 -185
- package/aws/infra/stack/stack-checking-aspect.d.ts +0 -21
- package/aws/infra/stack/stack-checking-aspect.js +0 -174
- package/aws/infra/stack/stack.d.ts +0 -44
- package/aws/infra/stack/stack.js +0 -60
- package/aws/infra/stack/subscription.d.ts +0 -17
- package/aws/infra/stack/subscription.js +0 -41
- package/aws/infra/usage-plans.d.ts +0 -15
- package/aws/infra/usage-plans.js +0 -42
- package/aws/runtime/apikey.d.ts +0 -2
- package/aws/runtime/apikey.js +0 -13
- package/aws/runtime/digitraffic-integration-response.d.ts +0 -8
- package/aws/runtime/digitraffic-integration-response.js +0 -26
- package/aws/runtime/environment.d.ts +0 -1
- package/aws/runtime/environment.js +0 -12
- package/aws/runtime/messaging.d.ts +0 -10
- package/aws/runtime/messaging.js +0 -31
- package/aws/runtime/s3.d.ts +0 -2
- package/aws/runtime/s3.js +0 -30
- package/aws/runtime/secrets/dbsecret.d.ts +0 -54
- package/aws/runtime/secrets/dbsecret.js +0 -96
- package/aws/runtime/secrets/proxy-holder.d.ts +0 -9
- package/aws/runtime/secrets/proxy-holder.js +0 -26
- package/aws/runtime/secrets/rds-holder.d.ts +0 -9
- package/aws/runtime/secrets/rds-holder.js +0 -26
- package/aws/runtime/secrets/secret-holder.d.ts +0 -26
- package/aws/runtime/secrets/secret-holder.js +0 -73
- package/aws/runtime/secrets/secret.d.ts +0 -8
- package/aws/runtime/secrets/secret.js +0 -43
- package/aws/types/errors.d.ts +0 -4
- package/aws/types/errors.js +0 -9
- package/aws/types/lambda-response.d.ts +0 -12
- package/aws/types/lambda-response.js +0 -28
- package/aws/types/mediatypes.js +0 -15
- package/aws/types/model-with-reference.js +0 -3
- package/aws/types/proxytypes.d.ts +0 -26
- package/aws/types/proxytypes.js +0 -3
- package/aws/types/tags.d.ts +0 -2
- package/aws/types/tags.js +0 -7
- package/database/cached.d.ts +0 -7
- package/database/cached.js +0 -32
- package/database/database.d.ts +0 -19
- package/database/database.js +0 -62
- package/database/last-updated.d.ts +0 -16
- package/database/last-updated.js +0 -54
- package/database/models.js +0 -3
- package/index.d.ts +0 -1
- package/index.js +0 -18
- package/marine/id_utils.d.ts +0 -3
- package/marine/id_utils.js +0 -33
- package/marine/rtz.d.ts +0 -48
- package/marine/rtz.js +0 -3
- package/test/asserter.d.ts +0 -11
- package/test/asserter.js +0 -45
- package/test/db-testutils.d.ts +0 -2
- package/test/db-testutils.js +0 -31
- package/test/httpserver.d.ts +0 -18
- package/test/httpserver.js +0 -67
- package/test/secret.d.ts +0 -3
- package/test/secret.js +0 -25
- package/test/secrets-manager.d.ts +0 -9
- package/test/secrets-manager.js +0 -59
- package/test/testutils.d.ts +0 -12
- package/test/testutils.js +0 -44
- package/types/input-error.d.ts +0 -2
- package/types/input-error.js +0 -7
- package/types/language.d.ts +0 -5
- package/types/language.js +0 -10
- package/types/traffictype.d.ts +0 -8
- package/types/traffictype.js +0 -13
- package/types/validator.d.ts +0 -4
- package/types/validator.js +0 -14
- package/utils/api-model.d.ts +0 -87
- package/utils/api-model.js +0 -129
- package/utils/base64.d.ts +0 -12
- package/utils/base64.js +0 -21
- package/utils/date-utils.d.ts +0 -17
- package/utils/date-utils.js +0 -34
- package/utils/geojson-types.d.ts +0 -14
- package/utils/geojson-types.js +0 -18
- package/utils/geometry.d.ts +0 -36
- package/utils/geometry.js +0 -140
- package/utils/retry.d.ts +0 -13
- package/utils/retry.js +0 -50
- package/utils/slack.d.ts +0 -5
- package/utils/slack.js +0 -25
- package/utils/utils.d.ts +0 -30
- package/utils/utils.js +0 -64
@@ -0,0 +1,43 @@
|
|
1
|
+
"use strict";
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
+
exports.withSecretAndPrefix = exports.getSecret = exports.withSecret = void 0;
|
4
|
+
const aws_sdk_1 = require("aws-sdk");
|
5
|
+
const smClient = new aws_sdk_1.SecretsManager({
|
6
|
+
region: process.env.AWS_REGION,
|
7
|
+
});
|
8
|
+
/**
|
9
|
+
@deprecated use SecretHolder & ProxyHolder
|
10
|
+
*/
|
11
|
+
async function withSecret(secretId, fn) {
|
12
|
+
return fn(await getSecret(secretId));
|
13
|
+
}
|
14
|
+
exports.withSecret = withSecret;
|
15
|
+
async function getSecret(secretId, prefix = '') {
|
16
|
+
const secretObj = await smClient.getSecretValue({
|
17
|
+
SecretId: secretId,
|
18
|
+
}).promise();
|
19
|
+
if (!secretObj.SecretString) {
|
20
|
+
throw new Error('No secret found!');
|
21
|
+
}
|
22
|
+
const secret = JSON.parse(secretObj.SecretString);
|
23
|
+
if (prefix === '') {
|
24
|
+
return secret;
|
25
|
+
}
|
26
|
+
return parseSecret(secret, `${prefix}.`);
|
27
|
+
}
|
28
|
+
exports.getSecret = getSecret;
|
29
|
+
function parseSecret(secret, prefix) {
|
30
|
+
const parsed = {};
|
31
|
+
const skip = prefix.length;
|
32
|
+
for (const key in secret) {
|
33
|
+
if (key.startsWith(prefix)) {
|
34
|
+
parsed[key.substring(skip)] = secret[key];
|
35
|
+
}
|
36
|
+
}
|
37
|
+
return parsed;
|
38
|
+
}
|
39
|
+
async function withSecretAndPrefix(secretId, prefix, fn) {
|
40
|
+
return fn(await getSecret(secretId, prefix));
|
41
|
+
}
|
42
|
+
exports.withSecretAndPrefix = withSecretAndPrefix;
|
43
|
+
//# sourceMappingURL=secret.js.map
|
@@ -0,0 +1,16 @@
|
|
1
|
+
"use strict";
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
+
exports.ValidationError = exports.BAD_REQUEST_MESSAGE = exports.OK_MESSAGE = exports.ERROR_MESSAGE = exports.NOT_FOUND_MESSAGE = void 0;
|
4
|
+
// DEPRECATED, remove these!
|
5
|
+
exports.NOT_FOUND_MESSAGE = "NOT_FOUND";
|
6
|
+
exports.ERROR_MESSAGE = "ERROR";
|
7
|
+
exports.OK_MESSAGE = "OK";
|
8
|
+
exports.BAD_REQUEST_MESSAGE = "BAD REQUEST";
|
9
|
+
class ValidationError extends Error {
|
10
|
+
constructor(statusCode, body) {
|
11
|
+
super(body);
|
12
|
+
this.statusCode = statusCode;
|
13
|
+
}
|
14
|
+
}
|
15
|
+
exports.ValidationError = ValidationError;
|
16
|
+
//# sourceMappingURL=errors.js.map
|
@@ -0,0 +1,33 @@
|
|
1
|
+
"use strict";
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
+
exports.LambdaResponse = void 0;
|
4
|
+
class LambdaResponse {
|
5
|
+
constructor(status, body, fileName) {
|
6
|
+
this.status = status;
|
7
|
+
this.body = body;
|
8
|
+
this.fileName = fileName;
|
9
|
+
}
|
10
|
+
static ok(body, fileName) {
|
11
|
+
return this.create(200, body, fileName);
|
12
|
+
}
|
13
|
+
static okJson(json, fileName) {
|
14
|
+
return this.create(200, JSON.stringify(json, null, 2), fileName);
|
15
|
+
}
|
16
|
+
static badRequest(body) {
|
17
|
+
return this.create(400, body);
|
18
|
+
}
|
19
|
+
static notFound() {
|
20
|
+
return this.create(404, "Not found");
|
21
|
+
}
|
22
|
+
static internalError() {
|
23
|
+
return this.create(500, "Internal error");
|
24
|
+
}
|
25
|
+
static notImplemented() {
|
26
|
+
return this.create(501, "Not implemented");
|
27
|
+
}
|
28
|
+
static create(status, body, fileName) {
|
29
|
+
return Promise.resolve(new LambdaResponse(status, body, fileName));
|
30
|
+
}
|
31
|
+
}
|
32
|
+
exports.LambdaResponse = LambdaResponse;
|
33
|
+
//# sourceMappingURL=lambda-response.js.map
|
@@ -0,0 +1,16 @@
|
|
1
|
+
"use strict";
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
+
exports.MediaType = void 0;
|
4
|
+
// charset=UTF-8 is deprecated but mobile applications sometimes needs it
|
5
|
+
var MediaType;
|
6
|
+
(function (MediaType) {
|
7
|
+
MediaType["APPLICATION_JSON"] = "application/json;charset=UTF-8";
|
8
|
+
MediaType["APPLICATION_XML"] = "application/xml";
|
9
|
+
MediaType["APPLICATION_GEOJSON"] = "application/geo+json;charset=UTF-8";
|
10
|
+
MediaType["IMAGE_SVG"] = "image/svg+xml";
|
11
|
+
MediaType["IMAGE_JPEG"] = "image/jpeg";
|
12
|
+
MediaType["TEXT_PLAIN"] = "text/plain";
|
13
|
+
MediaType["TEXT_HTML"] = "text/html";
|
14
|
+
MediaType["TEXT_CSV"] = "text/csv";
|
15
|
+
})(MediaType = exports.MediaType || (exports.MediaType = {}));
|
16
|
+
//# sourceMappingURL=mediatypes.js.map
|
@@ -0,0 +1,7 @@
|
|
1
|
+
"use strict";
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
+
exports.DATA_V1_TAGS = exports.BETA_TAGS = void 0;
|
4
|
+
// DEPRECATED! This must be replaced with new application specific tags
|
5
|
+
exports.BETA_TAGS = ['Beta'];
|
6
|
+
exports.DATA_V1_TAGS = ['Data v1'];
|
7
|
+
//# sourceMappingURL=tags.js.map
|
@@ -0,0 +1,32 @@
|
|
1
|
+
"use strict";
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
+
exports.getJsonFromCache = exports.updateCachedJson = exports.JSON_CACHE_KEY = void 0;
|
4
|
+
const pg_promise_1 = require("pg-promise");
|
5
|
+
const SQL_UPDATE_CACHE_VALUE = `insert into cached_json(cache_id, content, last_updated)
|
6
|
+
values ($1, $2, now())
|
7
|
+
on conflict(cache_id) do
|
8
|
+
update set content = $2, last_updated = now()`;
|
9
|
+
const SQL_GET_CACHE_VALUE = `select content, last_updated from cached_json
|
10
|
+
where cache_id = $1`;
|
11
|
+
const PS_UPDATE_CACHE_VALUE = new pg_promise_1.PreparedStatement({
|
12
|
+
name: 'update-cache-value',
|
13
|
+
text: SQL_UPDATE_CACHE_VALUE,
|
14
|
+
});
|
15
|
+
const PS_GET_CACHE_VALUE = new pg_promise_1.PreparedStatement({
|
16
|
+
name: 'get-cache-value',
|
17
|
+
text: SQL_GET_CACHE_VALUE,
|
18
|
+
});
|
19
|
+
var JSON_CACHE_KEY;
|
20
|
+
(function (JSON_CACHE_KEY) {
|
21
|
+
JSON_CACHE_KEY["NAUTICAL_WARNINGS_ACTIVE"] = "nautical-warnings-active";
|
22
|
+
JSON_CACHE_KEY["NAUTICAL_WARNINGS_ARCHIVED"] = "nautical-warnings-archived";
|
23
|
+
})(JSON_CACHE_KEY = exports.JSON_CACHE_KEY || (exports.JSON_CACHE_KEY = {}));
|
24
|
+
function updateCachedJson(db, cacheKey, value) {
|
25
|
+
return db.none(PS_UPDATE_CACHE_VALUE, [cacheKey, value]);
|
26
|
+
}
|
27
|
+
exports.updateCachedJson = updateCachedJson;
|
28
|
+
function getJsonFromCache(db, cacheKey) {
|
29
|
+
return db.oneOrNone(PS_GET_CACHE_VALUE, [cacheKey]).then(value => value?.content ?? null);
|
30
|
+
}
|
31
|
+
exports.getJsonFromCache = getJsonFromCache;
|
32
|
+
//# sourceMappingURL=cached.js.map
|
@@ -0,0 +1,70 @@
|
|
1
|
+
"use strict";
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
+
exports.inDatabaseReadonly = exports.inDatabase = exports.inTransaction = exports.initDbConnection = void 0;
|
4
|
+
const dbsecret_1 = require("../aws/runtime/secrets/dbsecret");
|
5
|
+
const utils_1 = require("../utils/utils");
|
6
|
+
// eslint-disable-next-line @typescript-eslint/no-var-requires
|
7
|
+
const pgp = require("pg-promise")();
|
8
|
+
// convert numeric types to number instead of string
|
9
|
+
pgp.pg.types.setTypeParser(pgp.pg.types.builtins.INT8, (value) => {
|
10
|
+
return parseInt(value);
|
11
|
+
});
|
12
|
+
pgp.pg.types.setTypeParser(pgp.pg.types.builtins.FLOAT8, (value) => {
|
13
|
+
return parseFloat(value);
|
14
|
+
});
|
15
|
+
pgp.pg.types.setTypeParser(pgp.pg.types.builtins.NUMERIC, (value) => {
|
16
|
+
return parseFloat(value);
|
17
|
+
});
|
18
|
+
/**
|
19
|
+
* Creates a non-pooling database connection primarily used by Lambdas.
|
20
|
+
*
|
21
|
+
* Note! Using this method opens a new RDS connection on every invocation. It is advised to
|
22
|
+
* use RDS proxy to pool connections transparently.
|
23
|
+
* https://docs.amazonaws.cn/en_us/AmazonRDS/latest/AuroraUserGuide/rds-proxy.html
|
24
|
+
* @param username Username
|
25
|
+
* @param password Password
|
26
|
+
* @param applicationName name of application
|
27
|
+
* @param url Connection URL
|
28
|
+
* @param options pg-promise options
|
29
|
+
*/
|
30
|
+
function initDbConnection(username, password, applicationName, url, options) {
|
31
|
+
const finalUrl = `postgresql://${username}:${password}@${url}?application_name=${applicationName}`;
|
32
|
+
return pgp(finalUrl, options);
|
33
|
+
}
|
34
|
+
exports.initDbConnection = initDbConnection;
|
35
|
+
function inTransaction(fn) {
|
36
|
+
return inDatabase((db) => db.tx((t) => fn(t)));
|
37
|
+
}
|
38
|
+
exports.inTransaction = inTransaction;
|
39
|
+
function inDatabase(fn) {
|
40
|
+
return doInDatabase(false, fn);
|
41
|
+
}
|
42
|
+
exports.inDatabase = inDatabase;
|
43
|
+
function inDatabaseReadonly(fn) {
|
44
|
+
return doInDatabase(true, fn);
|
45
|
+
}
|
46
|
+
exports.inDatabaseReadonly = inDatabaseReadonly;
|
47
|
+
async function doInDatabase(readonly, fn) {
|
48
|
+
const db_application = (0, utils_1.getEnvVariableSafe)(dbsecret_1.DatabaseEnvironmentKeys.DB_APPLICATION);
|
49
|
+
const db_ro_uri = (0, utils_1.getEnvVariableSafe)(dbsecret_1.DatabaseEnvironmentKeys.DB_RO_URI);
|
50
|
+
const db_uri = db_ro_uri.result === "ok"
|
51
|
+
? db_ro_uri.value
|
52
|
+
: (0, utils_1.getEnvVariable)(dbsecret_1.DatabaseEnvironmentKeys.DB_URI);
|
53
|
+
const db = initDbConnection((0, utils_1.getEnvVariable)(dbsecret_1.DatabaseEnvironmentKeys.DB_USER), (0, utils_1.getEnvVariable)(dbsecret_1.DatabaseEnvironmentKeys.DB_PASS), db_application.result === "ok"
|
54
|
+
? db_application.value
|
55
|
+
: "unknown-cdk-application", db_uri);
|
56
|
+
try {
|
57
|
+
// deallocate all prepared statements to allow for connection pooling
|
58
|
+
// DISCARD instead of DEALLOCATE as it didn't always clean all prepared statements
|
59
|
+
await db.none("DISCARD ALL");
|
60
|
+
return await fn(db);
|
61
|
+
}
|
62
|
+
catch (e) {
|
63
|
+
console.error("Error in db:", e);
|
64
|
+
throw e;
|
65
|
+
}
|
66
|
+
finally {
|
67
|
+
db.$pool.end();
|
68
|
+
}
|
69
|
+
}
|
70
|
+
//# sourceMappingURL=database.js.map
|
@@ -0,0 +1,54 @@
|
|
1
|
+
"use strict";
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
+
exports.updateUpdatedTimestamp = exports.getUpdatedTimestamp = exports.updateLastUpdatedWithSubtype = exports.updateLastUpdated = exports.getLastUpdatedWithSubtype = exports.getLastUpdated = exports.DataType = void 0;
|
4
|
+
var DataType;
|
5
|
+
(function (DataType) {
|
6
|
+
DataType["VS_DATEX2"] = "VS_DATEX2";
|
7
|
+
DataType["COUNTING_SITES_DATA"] = "COUNTING_SITES_DATA";
|
8
|
+
DataType["COUNTING_SITES_METADATA"] = "COUNTING_SITES_METADATA";
|
9
|
+
DataType["COUNTING_SITES_METADATA_CHECK"] = "COUNTING_SITES_METADATA_CHECK";
|
10
|
+
DataType["MAINTENANCE_TRACKING_DATA_CHECKED"] = "MAINTENANCE_TRACKING_DATA_CHECKED";
|
11
|
+
DataType["PERMIT_DATA"] = "PERMIT_DATA";
|
12
|
+
DataType["PERMIT_DATA_CHECK"] = "PERMIT_DATA_CHECK";
|
13
|
+
})(DataType = exports.DataType || (exports.DataType = {}));
|
14
|
+
const UNSET_SUBTYPE = '-';
|
15
|
+
function getLastUpdated(db, datatype) {
|
16
|
+
return db.oneOrNone("select updated from data_updated where data_type=$(datatype) and subtype=$(subtype)", {
|
17
|
+
datatype: datatype, subtype: UNSET_SUBTYPE,
|
18
|
+
}, (x) => x?.updated || null);
|
19
|
+
}
|
20
|
+
exports.getLastUpdated = getLastUpdated;
|
21
|
+
function getLastUpdatedWithSubtype(db, datatype, subtype) {
|
22
|
+
return db.oneOrNone("SELECT updated FROM data_updated WHERE data_type=$(datatype) AND subtype=$(subtype)", {
|
23
|
+
datatype: datatype, subtype: subtype,
|
24
|
+
}, (x) => x?.updated || null);
|
25
|
+
}
|
26
|
+
exports.getLastUpdatedWithSubtype = getLastUpdatedWithSubtype;
|
27
|
+
function updateLastUpdated(db, datatype, updated) {
|
28
|
+
return db.none(`insert into data_updated(id, data_type, updated)
|
29
|
+
values(nextval('seq_data_updated'), $(datatype), $(updated))
|
30
|
+
on conflict (data_type, subtype)
|
31
|
+
do update set updated = $(updated)`, { updated, datatype });
|
32
|
+
}
|
33
|
+
exports.updateLastUpdated = updateLastUpdated;
|
34
|
+
function updateLastUpdatedWithSubtype(db, datatype, subtype, updated) {
|
35
|
+
return db.none(`insert into data_updated(id, data_type, subtype, updated)
|
36
|
+
values(nextval('seq_data_updated'), $(datatype), $(subtype), $(updated))
|
37
|
+
on conflict (data_type, subtype)
|
38
|
+
do update set updated = $(updated)`, { updated, subtype, datatype });
|
39
|
+
}
|
40
|
+
exports.updateLastUpdatedWithSubtype = updateLastUpdatedWithSubtype;
|
41
|
+
function getUpdatedTimestamp(db, datatype) {
|
42
|
+
return db.oneOrNone("select updated_time as updated from updated_timestamp where updated_name=$(datatype)", {
|
43
|
+
datatype: datatype,
|
44
|
+
}, (x) => x?.updated || null);
|
45
|
+
}
|
46
|
+
exports.getUpdatedTimestamp = getUpdatedTimestamp;
|
47
|
+
function updateUpdatedTimestamp(db, datatype, date, by = '') {
|
48
|
+
return db.none(`insert into updated_timestamp(updated_name, updated_time, updated_by)
|
49
|
+
values($(datatype), $(date), $(by))
|
50
|
+
on conflict (updated_name)
|
51
|
+
do update set updated_time = $(date), updated_by = $(by)`, { date, datatype, by });
|
52
|
+
}
|
53
|
+
exports.updateUpdatedTimestamp = updateUpdatedTimestamp;
|
54
|
+
//# sourceMappingURL=last-updated.js.map
|
@@ -0,0 +1,33 @@
|
|
1
|
+
"use strict";
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
+
exports.isValidLOCODE = exports.isValidMMSI = exports.isValidIMO = void 0;
|
4
|
+
function isValidIMO(imo) {
|
5
|
+
return imo >= 1000000 && imo <= 9999999 && imoChecksumIsValid(imo);
|
6
|
+
}
|
7
|
+
exports.isValidIMO = isValidIMO;
|
8
|
+
function imoChecksumIsValid(imo) {
|
9
|
+
const imoStr = imo.toString();
|
10
|
+
const imoDigit1 = Number(imoStr[0]);
|
11
|
+
const imoDigit2 = Number(imoStr[1]);
|
12
|
+
const imoDigit3 = Number(imoStr[2]);
|
13
|
+
const imoDigit4 = Number(imoStr[3]);
|
14
|
+
const imoDigit5 = Number(imoStr[4]);
|
15
|
+
const imoDigit6 = Number(imoStr[5]);
|
16
|
+
const checkDigit = Number(imoStr[6]);
|
17
|
+
const checkCalculation = Number(((imoDigit1 * 7) + (imoDigit2 * 6) + (imoDigit3 * 5) + (imoDigit4 * 4) + (imoDigit5 * 3) + (imoDigit6 * 2)));
|
18
|
+
const checkResult = checkCalculation % 10 === checkDigit;
|
19
|
+
if (!checkResult) {
|
20
|
+
console.warn('method=imoChecksumIsValid IMO checksum failed %d', imo);
|
21
|
+
}
|
22
|
+
return checkResult;
|
23
|
+
}
|
24
|
+
function isValidMMSI(mmsi) {
|
25
|
+
return mmsi >= 100000000 && mmsi <= 999999999;
|
26
|
+
}
|
27
|
+
exports.isValidMMSI = isValidMMSI;
|
28
|
+
const LocodePattern = /^FI[A-Z]{3}$/i;
|
29
|
+
function isValidLOCODE(locode) {
|
30
|
+
return LocodePattern.test(locode);
|
31
|
+
}
|
32
|
+
exports.isValidLOCODE = isValidLOCODE;
|
33
|
+
//# sourceMappingURL=id_utils.js.map
|
@@ -0,0 +1,45 @@
|
|
1
|
+
"use strict";
|
2
|
+
/**
|
3
|
+
* A simple asserter-class for writing canaries without dependency to testing-libraries.
|
4
|
+
*/
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
6
|
+
exports.Asserter = void 0;
|
7
|
+
class Asserter {
|
8
|
+
static assertEquals(value, expected) {
|
9
|
+
if (value != expected) {
|
10
|
+
throw new Error(`Given value ${value} was not expected ${expected}`);
|
11
|
+
}
|
12
|
+
}
|
13
|
+
static assertTrue(value) {
|
14
|
+
if (!value) {
|
15
|
+
throw new Error(`Given value ${value} was not true`);
|
16
|
+
}
|
17
|
+
}
|
18
|
+
static assertLength(data, expected) {
|
19
|
+
if (!data) {
|
20
|
+
throw new Error("Given array was not defined");
|
21
|
+
}
|
22
|
+
if (data.length != expected) {
|
23
|
+
throw new Error(`Given array length ${data.length} was not expected ${expected}`);
|
24
|
+
}
|
25
|
+
}
|
26
|
+
static assertLengthGreaterThan(data, expected) {
|
27
|
+
if (!data) {
|
28
|
+
throw new Error("Given array was not defined");
|
29
|
+
}
|
30
|
+
if (data.length <= expected) {
|
31
|
+
throw new Error(`Given array length ${data.length} was not greater than ${expected}`);
|
32
|
+
}
|
33
|
+
}
|
34
|
+
static assertGreaterThan(value, expected) {
|
35
|
+
if (value <= expected) {
|
36
|
+
throw new Error(`Value ${value} was expected to be greater than ${expected}`);
|
37
|
+
}
|
38
|
+
}
|
39
|
+
static assertToBeCloseTo(value, expected, delta) {
|
40
|
+
expect(expected - value).toBeGreaterThanOrEqual(-1 * delta);
|
41
|
+
expect(expected - value).toBeLessThanOrEqual(delta);
|
42
|
+
}
|
43
|
+
}
|
44
|
+
exports.Asserter = Asserter;
|
45
|
+
//# sourceMappingURL=asserter.js.map
|
@@ -0,0 +1,31 @@
|
|
1
|
+
"use strict";
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
+
exports.dbTestBase = void 0;
|
4
|
+
const database_1 = require("../database/database");
|
5
|
+
const dbsecret_1 = require("../aws/runtime/secrets/dbsecret");
|
6
|
+
function dbTestBase(fn, truncateFn, dbUser, dbPass, dbUri) {
|
7
|
+
const theDbUri = process.env.DB_URI ?? dbUri;
|
8
|
+
console.log(`Test database URI: ${theDbUri}`);
|
9
|
+
return () => {
|
10
|
+
const db = (0, database_1.initDbConnection)(dbUser, dbPass, "test", theDbUri, {
|
11
|
+
noWarnings: true, // ignore duplicate connection warning for tests
|
12
|
+
});
|
13
|
+
beforeAll(async () => {
|
14
|
+
process.env[dbsecret_1.DatabaseEnvironmentKeys.DB_USER] = dbUser;
|
15
|
+
process.env[dbsecret_1.DatabaseEnvironmentKeys.DB_PASS] = dbPass;
|
16
|
+
process.env[dbsecret_1.DatabaseEnvironmentKeys.DB_URI] = theDbUri;
|
17
|
+
process.env[dbsecret_1.DatabaseEnvironmentKeys.DB_RO_URI] = theDbUri;
|
18
|
+
await truncateFn(db);
|
19
|
+
});
|
20
|
+
afterAll(async () => {
|
21
|
+
await truncateFn(db);
|
22
|
+
await db.$pool.end();
|
23
|
+
});
|
24
|
+
beforeEach(async () => {
|
25
|
+
await truncateFn(db);
|
26
|
+
});
|
27
|
+
fn(db);
|
28
|
+
};
|
29
|
+
}
|
30
|
+
exports.dbTestBase = dbTestBase;
|
31
|
+
//# sourceMappingURL=db-testutils.js.map
|
@@ -0,0 +1,74 @@
|
|
1
|
+
"use strict";
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
+
exports.TestHttpServer = exports.ERRORCODE_NOT_FOUND = exports.ERROR_NO_MATCH = void 0;
|
4
|
+
const http_1 = require("http");
|
5
|
+
exports.ERROR_NO_MATCH = "NO MATCH";
|
6
|
+
exports.ERRORCODE_NOT_FOUND = 404;
|
7
|
+
/**
|
8
|
+
* A mock HTTP server created for testing connections from a Lambda to an outside integration
|
9
|
+
*/
|
10
|
+
class TestHttpServer {
|
11
|
+
constructor() {
|
12
|
+
this.debug = false;
|
13
|
+
this.messageStack = [];
|
14
|
+
}
|
15
|
+
getCallCount() {
|
16
|
+
return this.messageStack.length;
|
17
|
+
}
|
18
|
+
getRequestBody(callNumber) {
|
19
|
+
return this.messageStack[callNumber];
|
20
|
+
}
|
21
|
+
listen(port, props, debug = false, statusCode = 200) {
|
22
|
+
this.debug = debug;
|
23
|
+
this.messageStack = [];
|
24
|
+
this.debuglog(`Starting test server on port ${port}`);
|
25
|
+
this.server = (0, http_1.createServer)((req, res) => {
|
26
|
+
this.debuglog("Mapped urls: ");
|
27
|
+
Object.keys(props).forEach((k) => this.debuglog(k));
|
28
|
+
this.debuglog("Received request to url " + req.url + "..");
|
29
|
+
// eslint-disable-next-line @typescript-eslint/no-var-requires
|
30
|
+
const path = require("url").parse(req.url).pathname;
|
31
|
+
let dataStr = "";
|
32
|
+
req.on("data", (chunk) => {
|
33
|
+
if (chunk) {
|
34
|
+
dataStr += chunk;
|
35
|
+
}
|
36
|
+
});
|
37
|
+
if (path in props) {
|
38
|
+
this.debuglog("..url matched");
|
39
|
+
res.setHeader("Access-Control-Allow-Origin", "*");
|
40
|
+
res.setHeader("Access-Control-Allow-Headers", "Authorization,X-User-Id,X-Auth-Token");
|
41
|
+
res.writeHead(statusCode);
|
42
|
+
req.on("end", () => {
|
43
|
+
// assume sent data is in JSON format
|
44
|
+
this.messageStack[this.messageStack.length] = dataStr;
|
45
|
+
res.end(props[path](req.url, dataStr));
|
46
|
+
});
|
47
|
+
}
|
48
|
+
else {
|
49
|
+
this.debuglog("..no match for %" + path);
|
50
|
+
req.on("end", () => {
|
51
|
+
// assume sent data is in JSON format
|
52
|
+
this.messageStack[this.messageStack.length] =
|
53
|
+
exports.ERROR_NO_MATCH;
|
54
|
+
res.writeHead(exports.ERRORCODE_NOT_FOUND);
|
55
|
+
res.end(exports.ERROR_NO_MATCH);
|
56
|
+
});
|
57
|
+
}
|
58
|
+
});
|
59
|
+
this.server.listen(port);
|
60
|
+
}
|
61
|
+
close() {
|
62
|
+
this.debuglog("Closing test server");
|
63
|
+
if (this.server !== undefined) {
|
64
|
+
this.server.close();
|
65
|
+
}
|
66
|
+
}
|
67
|
+
debuglog(str) {
|
68
|
+
if (this.debug) {
|
69
|
+
console.debug(str);
|
70
|
+
}
|
71
|
+
}
|
72
|
+
}
|
73
|
+
exports.TestHttpServer = TestHttpServer;
|
74
|
+
//# sourceMappingURL=httpserver.js.map
|
@@ -0,0 +1,25 @@
|
|
1
|
+
"use strict";
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
+
exports.createEmptySecretFunction = exports.createSecretFunction = void 0;
|
4
|
+
const EMPTY_DB_SECRET = {
|
5
|
+
username: '',
|
6
|
+
password: '',
|
7
|
+
host: '',
|
8
|
+
// eslint-disable-next-line camelcase
|
9
|
+
ro_host: '',
|
10
|
+
};
|
11
|
+
function createSecretFunction(secret) {
|
12
|
+
// eslint-disable-next-line require-await
|
13
|
+
return async (secretId, fn) => {
|
14
|
+
return fn(secret);
|
15
|
+
};
|
16
|
+
}
|
17
|
+
exports.createSecretFunction = createSecretFunction;
|
18
|
+
function createEmptySecretFunction() {
|
19
|
+
// eslint-disable-next-line require-await
|
20
|
+
return async (secretId, fn) => {
|
21
|
+
return fn(EMPTY_DB_SECRET);
|
22
|
+
};
|
23
|
+
}
|
24
|
+
exports.createEmptySecretFunction = createEmptySecretFunction;
|
25
|
+
//# sourceMappingURL=secret.js.map
|
@@ -0,0 +1,59 @@
|
|
1
|
+
"use strict";
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
3
|
+
if (k2 === undefined) k2 = k;
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
7
|
+
}
|
8
|
+
Object.defineProperty(o, k2, desc);
|
9
|
+
}) : (function(o, m, k, k2) {
|
10
|
+
if (k2 === undefined) k2 = k;
|
11
|
+
o[k2] = m[k];
|
12
|
+
}));
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
15
|
+
}) : function(o, v) {
|
16
|
+
o["default"] = v;
|
17
|
+
});
|
18
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
19
|
+
if (mod && mod.__esModule) return mod;
|
20
|
+
var result = {};
|
21
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
22
|
+
__setModuleDefault(result, mod);
|
23
|
+
return result;
|
24
|
+
};
|
25
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
26
|
+
exports.mockSecret = exports.stubSecretsManager = void 0;
|
27
|
+
const AWS = require("aws-sdk");
|
28
|
+
const sinon = __importStar(require("sinon"));
|
29
|
+
const secretValue = sinon.stub();
|
30
|
+
/**
|
31
|
+
* Stub Secrets Manager for tests. You must call this
|
32
|
+
* before you instantiate Secrets Manager(this might happen when you import the function that uses Secrets Manager).
|
33
|
+
*
|
34
|
+
* To mock the actual secret, call mockSecret()
|
35
|
+
*/
|
36
|
+
function stubSecretsManager() {
|
37
|
+
const smStub = {
|
38
|
+
getSecretValue: secretValue,
|
39
|
+
};
|
40
|
+
sinon.stub(AWS, 'SecretsManager').returns(smStub);
|
41
|
+
return smStub.getSecretValue;
|
42
|
+
}
|
43
|
+
exports.stubSecretsManager = stubSecretsManager;
|
44
|
+
function mockSecret(secret) {
|
45
|
+
if (!secret) {
|
46
|
+
secretValue.returns({
|
47
|
+
promise: sinon.stub().returns({}),
|
48
|
+
});
|
49
|
+
}
|
50
|
+
else {
|
51
|
+
secretValue.returns({
|
52
|
+
promise: sinon.stub().returns({
|
53
|
+
SecretString: JSON.stringify(secret),
|
54
|
+
}),
|
55
|
+
});
|
56
|
+
}
|
57
|
+
}
|
58
|
+
exports.mockSecret = mockSecret;
|
59
|
+
//# sourceMappingURL=secrets-manager.js.map
|
@@ -0,0 +1,44 @@
|
|
1
|
+
"use strict";
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
+
exports.shuffle = exports.randomBoolean = exports.getRandomBigInt = exports.getRandomIntegerAsString = exports.getRandomInteger = exports.getRandomNumberAsString = exports.getRandomNumber = exports.randomString = void 0;
|
4
|
+
function randomString() {
|
5
|
+
return Math.random().toString(36).substring(2);
|
6
|
+
}
|
7
|
+
exports.randomString = randomString;
|
8
|
+
function getRandomNumber(min, max) {
|
9
|
+
return Math.random() * (max - min) + min;
|
10
|
+
}
|
11
|
+
exports.getRandomNumber = getRandomNumber;
|
12
|
+
function getRandomNumberAsString(min, max) {
|
13
|
+
return getRandomNumber(min, max).toString();
|
14
|
+
}
|
15
|
+
exports.getRandomNumberAsString = getRandomNumberAsString;
|
16
|
+
function getRandomInteger(min, max) {
|
17
|
+
return Math.round(getRandomNumber(min, max));
|
18
|
+
}
|
19
|
+
exports.getRandomInteger = getRandomInteger;
|
20
|
+
function getRandomIntegerAsString(min, max) {
|
21
|
+
return Math.round(getRandomInteger(min, max)).toString();
|
22
|
+
}
|
23
|
+
exports.getRandomIntegerAsString = getRandomIntegerAsString;
|
24
|
+
function getRandomBigInt(min, max) {
|
25
|
+
return BigInt(getRandomInteger(min, max));
|
26
|
+
}
|
27
|
+
exports.getRandomBigInt = getRandomBigInt;
|
28
|
+
function randomBoolean() {
|
29
|
+
return Math.random() < 0.5;
|
30
|
+
}
|
31
|
+
exports.randomBoolean = randomBoolean;
|
32
|
+
/**
|
33
|
+
* Returns a new copy of an array, shuffled using Math.random()
|
34
|
+
* @param array Array
|
35
|
+
*/
|
36
|
+
function shuffle(array) {
|
37
|
+
// pretty fast way to copy an array, not necessarily the fastest
|
38
|
+
const newArray = array.slice(0);
|
39
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
40
|
+
newArray.sort((x) => 0.5 - Math.random());
|
41
|
+
return newArray;
|
42
|
+
}
|
43
|
+
exports.shuffle = shuffle;
|
44
|
+
//# sourceMappingURL=testutils.js.map
|
@@ -0,0 +1,10 @@
|
|
1
|
+
"use strict";
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
+
exports.Language = void 0;
|
4
|
+
var Language;
|
5
|
+
(function (Language) {
|
6
|
+
Language["FI"] = "fi";
|
7
|
+
Language["EN"] = "en";
|
8
|
+
Language["SV"] = "sv";
|
9
|
+
})(Language = exports.Language || (exports.Language = {}));
|
10
|
+
//# sourceMappingURL=language.js.map
|
@@ -0,0 +1,13 @@
|
|
1
|
+
"use strict";
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
+
exports.TrafficType = void 0;
|
4
|
+
var TrafficType;
|
5
|
+
(function (TrafficType) {
|
6
|
+
TrafficType["ROAD"] = "Road";
|
7
|
+
TrafficType["MARINE"] = "Marine";
|
8
|
+
TrafficType["RAIL"] = "Rail";
|
9
|
+
TrafficType["AVIATION"] = "Aviation";
|
10
|
+
TrafficType["MCP"] = "MCP";
|
11
|
+
TrafficType["OTHER"] = "Other";
|
12
|
+
})(TrafficType = exports.TrafficType || (exports.TrafficType = {}));
|
13
|
+
//# sourceMappingURL=traffictype.js.map
|