From d897e4c3b5496d666bb770e93dd87f85e8e007c4 Mon Sep 17 00:00:00 2001 From: Thodoris Greasidis Date: Tue, 2 Apr 2024 15:53:22 +0300 Subject: [PATCH 1/2] Use a type guard for `"migration"."migration status"` Change-type: patch --- src/migrator/utils.ts | 29 ++++++++++++++++++++--------- 1 file changed, 20 insertions(+), 9 deletions(-) diff --git a/src/migrator/utils.ts b/src/migrator/utils.ts index c5e767a32..061fcf530 100644 --- a/src/migrator/utils.ts +++ b/src/migrator/utils.ts @@ -326,16 +326,27 @@ WHERE "migration"."model name" = ${1}`, return []; } - /** - * Should be - * if ( Array.isArray(executedMigrations) && executedMigrations.every((migration) => typeof migration === 'string') ) { - * return executedMigrations; - * } - * but typescript does not infer that every element of the array is a string - */ - return sbvrUtils.sbvrTypes.JSON.fetchProcessing( + const executedMigrations = sbvrUtils.sbvrTypes.JSON.fetchProcessing( data.executed_migrations, - ) as string[]; + ); + if (!Array.isArray(executedMigrations)) { + throw new Error( + `"migration"."executed migrations" is expected to be an Array, but the retrieved value was ${typeof executedMigrations}`, + ); + } + if ( + !executedMigrations.every( + (migration): migration is string => typeof migration === 'string', + ) + ) { + const nonStringMigrationValue = executedMigrations.find( + (migration) => typeof migration !== 'string', + ); + throw new Error( + `"migration"."executed migrations" is expected to be an Array, but the retrieved array included ${typeof nonStringMigrationValue}`, + ); + } + return executedMigrations; }; export const migrationTablesExist = async (tx: Tx) => { From cee8cd7c503f656125d8d8603c0ad28dc1a848f9 Mon Sep 17 00:00:00 2001 From: Thodoris Greasidis Date: Tue, 2 Apr 2024 16:18:55 +0300 Subject: [PATCH 2/2] Replace `docker-compose` commands with `docker compose` Change-type: patch --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 5e0854a32..ecfc0e01a 100644 --- a/package.json +++ b/package.json @@ -20,7 +20,7 @@ "webpack-build": "npm run webpack-browser && npm run webpack-module && npm run webpack-server", "lint": "balena-lint -t tsconfig.dev.json -e js -e ts src build typings Gruntfile.ts && npx tsc --project tsconfig.dev.json --noEmit", "test": "npm run lint && npm run build && npm run webpack-build && npm run test:compose", - "test:compose": "trap 'docker-compose -f docker-compose.npm-test.yml down ; echo Stopped ; exit 0' SIGINT; docker-compose -f docker-compose.npm-test.yml up -d && sleep 2 && DATABASE_URL=postgres://docker:docker@localhost:5431/postgres PINEJS_WEBRESOURCE_MAXFILESIZE=1000000000 S3_ENDPOINT=http://localhost:43680 S3_ACCESS_KEY=USERNAME S3_SECRET_KEY=PASSWORD S3_STORAGE_ADAPTER_BUCKET=balena-pine-web-resources S3_REGION=us-east-1 npm run mocha", + "test:compose": "trap 'docker compose -f docker-compose.npm-test.yml down ; echo Stopped ; exit 0' SIGINT; docker compose -f docker-compose.npm-test.yml up -d && sleep 2 && DATABASE_URL=postgres://docker:docker@localhost:5431/postgres PINEJS_WEBRESOURCE_MAXFILESIZE=1000000000 S3_ENDPOINT=http://localhost:43680 S3_ACCESS_KEY=USERNAME S3_SECRET_KEY=PASSWORD S3_STORAGE_ADAPTER_BUCKET=balena-pine-web-resources S3_REGION=us-east-1 npm run mocha", "mocha": "TS_NODE_FILES=true mocha", "prettify": "balena-lint -t tsconfig.dev.json -e js -e ts --fix src test build typings Gruntfile.ts" },