diff --git a/CHANGELOG.md b/CHANGELOG.md index 661c548..044800e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,12 @@ ### Master * ... +### 2.1.1 +* unit test that all foreign keys are indexed +* switch between continuation-local-storage and cls-hooked via env var CLS_USE_CONTINUATION_LOCAL_STORAGE +* update to typescript 3.7.2 +* fixed deprecated linter settings + ### 2.0.1-2.0.4 * fix cls.test diff --git a/README.md b/README.md index f703efe..603ef8d 100644 --- a/README.md +++ b/README.md @@ -64,6 +64,22 @@ local$ yarn check-package-validity && git status # Is your git still clean? Else go back to step 0. # +# 1.1 Check scaffolded project compiles and lints correctly +# This is necessary due to different (stricter) compiler and linter +# settings in scaffolded projects +local$ yarn create-aaa-backend scaffold -xly --debug + +# Move the scaffolded project outside of aaa-backend-stack +# Otherwise vagrant gets confused +local$ mv aaa-backend .. && cd ../aaa-backend && code . + +# Now check that scaffolded project in aaa-backend still compiles +local$ vagrant up && vagrant ssh +vagrant$ yarn && yarn build + +# Fix compiler and linter erros until all is well. +# Then change back to aaa-backend-stack and copy the fixes to the template. + # 2. clean all node_modules in root and at the packages level local$ yarn clean-modules diff --git a/lerna.json b/lerna.json index 17b834c..09f28f5 100644 --- a/lerna.json +++ b/lerna.json @@ -6,5 +6,5 @@ "hoist": true, "npmClient": "yarn", "useWorkspaces": true, - "version": "2.0.4" + "version": "2.1.1" } diff --git a/package.json b/package.json index 66c565f..9e4b513 100644 --- a/package.json +++ b/package.json @@ -41,7 +41,7 @@ "lodash": "4.17.15", "rimraf": "2.6.1", "tslint": "5.11.0", - "typescript": "3.6.4" + "typescript": "3.7.2" }, "workspaces": [ "packages/*" diff --git a/packages/aaa-build-tools/package.json b/packages/aaa-build-tools/package.json index 0e33293..aa2b24e 100644 --- a/packages/aaa-build-tools/package.json +++ b/packages/aaa-build-tools/package.json @@ -1,6 +1,6 @@ { "name": "@aaa-backend-stack/build-tools", - "version": "2.0.4", + "version": "2.1.1", "description": "base tools for env sourcing and building cli tools", "license": "MIT", "author": "all about apps", @@ -42,9 +42,9 @@ "sort-package-json": "1.7.1" }, "devDependencies": { - "@aaa-backend-stack/tslint-rules": "^1.16.7", + "@aaa-backend-stack/tslint-rules": "^2.1.1", "tslint": "5.11.0", - "typescript": "3.6.4" + "typescript": "3.7.2" }, "publishConfig": { "access": "public" diff --git a/packages/aaa-devtools/package.json b/packages/aaa-devtools/package.json index 0c332b6..33a7c45 100644 --- a/packages/aaa-devtools/package.json +++ b/packages/aaa-devtools/package.json @@ -1,6 +1,6 @@ { "name": "@aaa-backend-stack/devtools", - "version": "2.0.4", + "version": "2.1.1", "description": "Websocket devtools which integrates with aaa logger (pipes logs from stdout)", "license": "MIT", "author": "all about apps", @@ -16,8 +16,8 @@ "test": "exit 0" }, "dependencies": { - "@aaa-backend-stack/build-tools": "^2.0.4", - "@aaa-backend-stack/git-info": "^2.0.4", + "@aaa-backend-stack/build-tools": "^2.1.1", + "@aaa-backend-stack/git-info": "^2.1.1", "@types/lodash": "4.14.144", "@types/ws": "3.0.2", "bufferutil": "4.0.1", @@ -26,10 +26,10 @@ "ws": "3.2.0" }, "devDependencies": { - "@aaa-backend-stack/test-environment": "^2.0.4", - "@aaa-backend-stack/tslint-rules": "^1.16.7", + "@aaa-backend-stack/test-environment": "^2.1.1", + "@aaa-backend-stack/tslint-rules": "^2.1.1", "tslint": "5.11.0", - "typescript": "3.6.4" + "typescript": "3.7.2" }, "publishConfig": { "access": "public" diff --git a/packages/aaa-example-lib/package.json b/packages/aaa-example-lib/package.json index dd767f2..1ecea8e 100644 --- a/packages/aaa-example-lib/package.json +++ b/packages/aaa-example-lib/package.json @@ -1,6 +1,6 @@ { "name": "@aaa-backend-stack/example-lib", - "version": "2.0.4", + "version": "2.1.1", "private": true, "description": "Example Lib", "license": "MIT", @@ -17,14 +17,14 @@ "test": "exit 0" }, "dependencies": { - "@aaa-backend-stack/build-tools": "^2.0.4", - "@aaa-backend-stack/utils": "^2.0.4" + "@aaa-backend-stack/build-tools": "^2.1.1", + "@aaa-backend-stack/utils": "^2.1.1" }, "devDependencies": { - "@aaa-backend-stack/test-environment": "^2.0.4", - "@aaa-backend-stack/tslint-rules": "^1.16.7", + "@aaa-backend-stack/test-environment": "^2.1.1", + "@aaa-backend-stack/tslint-rules": "^2.1.1", "tslint": "5.11.0", - "typescript": "3.6.4" + "typescript": "3.7.2" }, "publishConfig": { "access": "public" diff --git a/packages/aaa-file-storage-local/package.json b/packages/aaa-file-storage-local/package.json index 7433d25..362ee5a 100644 --- a/packages/aaa-file-storage-local/package.json +++ b/packages/aaa-file-storage-local/package.json @@ -1,6 +1,6 @@ { "name": "@aaa-backend-stack/file-storage-local", - "version": "2.0.4", + "version": "2.1.1", "description": "File storage service implementation using local file system", "license": "MIT", "author": "all about apps", @@ -16,20 +16,20 @@ "test": "exit 0" }, "dependencies": { - "@aaa-backend-stack/build-tools": "^2.0.4", - "@aaa-backend-stack/file-storage": "^2.0.4", - "@aaa-backend-stack/logger": "^2.0.4", - "@aaa-backend-stack/utils": "^2.0.4", + "@aaa-backend-stack/build-tools": "^2.1.1", + "@aaa-backend-stack/file-storage": "^2.1.1", + "@aaa-backend-stack/logger": "^2.1.1", + "@aaa-backend-stack/utils": "^2.1.1", "@types/lodash": "4.14.144", "@types/url-join": "0.8.2", "lodash": "4.17.15", "url-join": "4.0.0" }, "devDependencies": { - "@aaa-backend-stack/test-environment": "^2.0.4", - "@aaa-backend-stack/tslint-rules": "^1.16.7", + "@aaa-backend-stack/test-environment": "^2.1.1", + "@aaa-backend-stack/tslint-rules": "^2.1.1", "tslint": "5.11.0", - "typescript": "3.6.4" + "typescript": "3.7.2" }, "publishConfig": { "access": "public" diff --git a/packages/aaa-file-storage-s3/package.json b/packages/aaa-file-storage-s3/package.json index 926d25d..f514502 100644 --- a/packages/aaa-file-storage-s3/package.json +++ b/packages/aaa-file-storage-s3/package.json @@ -1,6 +1,6 @@ { "name": "@aaa-backend-stack/file-storage-s3", - "version": "2.0.4", + "version": "2.1.1", "description": "File storage service implementation using Amazon S3 buckets (or compatible servers)", "license": "MIT", "author": "all about apps", @@ -16,10 +16,10 @@ "test": "exit 0" }, "dependencies": { - "@aaa-backend-stack/build-tools": "^2.0.4", - "@aaa-backend-stack/file-storage": "^2.0.4", - "@aaa-backend-stack/logger": "^2.0.4", - "@aaa-backend-stack/utils": "^2.0.4", + "@aaa-backend-stack/build-tools": "^2.1.1", + "@aaa-backend-stack/file-storage": "^2.1.1", + "@aaa-backend-stack/logger": "^2.1.1", + "@aaa-backend-stack/utils": "^2.1.1", "@types/lodash": "4.14.144", "@types/url-join": "0.8.2", "aws-sdk": "2.311.0", @@ -27,10 +27,10 @@ "url-join": "4.0.0" }, "devDependencies": { - "@aaa-backend-stack/test-environment": "^2.0.4", - "@aaa-backend-stack/tslint-rules": "^1.16.7", + "@aaa-backend-stack/test-environment": "^2.1.1", + "@aaa-backend-stack/tslint-rules": "^2.1.1", "tslint": "5.11.0", - "typescript": "3.6.4" + "typescript": "3.7.2" }, "publishConfig": { "access": "public" diff --git a/packages/aaa-file-storage/package.json b/packages/aaa-file-storage/package.json index 4a035ef..9840a9d 100644 --- a/packages/aaa-file-storage/package.json +++ b/packages/aaa-file-storage/package.json @@ -1,6 +1,6 @@ { "name": "@aaa-backend-stack/file-storage", - "version": "2.0.4", + "version": "2.1.1", "description": "High level API for a file storage service, actual implementation provided in separate packages", "license": "MIT", "author": "all about apps", @@ -16,12 +16,12 @@ "test": "exit 0" }, "dependencies": { - "@aaa-backend-stack/build-tools": "^2.0.4" + "@aaa-backend-stack/build-tools": "^2.1.1" }, "devDependencies": { - "@aaa-backend-stack/tslint-rules": "^1.16.7", + "@aaa-backend-stack/tslint-rules": "^2.1.1", "tslint": "5.11.0", - "typescript": "3.6.4" + "typescript": "3.7.2" }, "publishConfig": { "access": "public" diff --git a/packages/aaa-git-info/package.json b/packages/aaa-git-info/package.json index e6301a8..6c6d934 100644 --- a/packages/aaa-git-info/package.json +++ b/packages/aaa-git-info/package.json @@ -1,6 +1,6 @@ { "name": "@aaa-backend-stack/git-info", - "version": "2.0.4", + "version": "2.1.1", "description": "Reads base directory to get current git commit information", "license": "MIT", "author": "all about apps", @@ -16,14 +16,14 @@ "test": "exit 0" }, "dependencies": { - "@aaa-backend-stack/build-tools": "^2.0.4", + "@aaa-backend-stack/build-tools": "^2.1.1", "git-rev-sync": "1.9.1" }, "devDependencies": { - "@aaa-backend-stack/test-environment": "^2.0.4", - "@aaa-backend-stack/tslint-rules": "^1.16.7", + "@aaa-backend-stack/test-environment": "^2.1.1", + "@aaa-backend-stack/tslint-rules": "^2.1.1", "tslint": "5.11.0", - "typescript": "3.6.4" + "typescript": "3.7.2" }, "publishConfig": { "access": "public" diff --git a/packages/aaa-graphql-rest-bindings/package.json b/packages/aaa-graphql-rest-bindings/package.json index bc5450e..d7187b3 100644 --- a/packages/aaa-graphql-rest-bindings/package.json +++ b/packages/aaa-graphql-rest-bindings/package.json @@ -1,6 +1,6 @@ { "name": "@aaa-backend-stack/graphql-rest-bindings", - "version": "2.0.4", + "version": "2.1.1", "description": "Provides utils for graphql introspection and devtools in combination with rest layer", "license": "MIT", "author": "all about apps", @@ -16,11 +16,11 @@ "test": "exit 0" }, "dependencies": { - "@aaa-backend-stack/build-tools": "^2.0.4", - "@aaa-backend-stack/graphql": "^2.0.4", - "@aaa-backend-stack/logger": "^2.0.4", - "@aaa-backend-stack/rest": "^2.0.4", - "@aaa-backend-stack/utils": "^2.0.4", + "@aaa-backend-stack/build-tools": "^2.1.1", + "@aaa-backend-stack/graphql": "^2.1.1", + "@aaa-backend-stack/logger": "^2.1.1", + "@aaa-backend-stack/rest": "^2.1.1", + "@aaa-backend-stack/utils": "^2.1.1", "@types/bluebird": "3.5.8", "@types/bluebird-global": "3.5.3", "@types/lodash": "4.14.144", @@ -30,10 +30,10 @@ "lodash": "4.17.15" }, "devDependencies": { - "@aaa-backend-stack/test-environment": "^2.0.4", - "@aaa-backend-stack/tslint-rules": "^1.16.7", + "@aaa-backend-stack/test-environment": "^2.1.1", + "@aaa-backend-stack/tslint-rules": "^2.1.1", "tslint": "5.11.0", - "typescript": "3.6.4" + "typescript": "3.7.2" }, "publishConfig": { "access": "public" diff --git a/packages/aaa-graphql/package.json b/packages/aaa-graphql/package.json index e9c3d13..55648fa 100644 --- a/packages/aaa-graphql/package.json +++ b/packages/aaa-graphql/package.json @@ -1,6 +1,6 @@ { "name": "@aaa-backend-stack/graphql", - "version": "2.0.4", + "version": "2.1.1", "description": "GraphQL Layer", "license": "MIT", "author": "all about apps", @@ -19,9 +19,9 @@ "test": "exit 0" }, "dependencies": { - "@aaa-backend-stack/build-tools": "^2.0.4", - "@aaa-backend-stack/logger": "^2.0.4", - "@aaa-backend-stack/utils": "^2.0.4", + "@aaa-backend-stack/build-tools": "^2.1.1", + "@aaa-backend-stack/logger": "^2.1.1", + "@aaa-backend-stack/utils": "^2.1.1", "@types/bluebird": "3.5.8", "@types/bluebird-global": "3.5.3", "@types/graphql": "0.9.4", @@ -41,10 +41,10 @@ "sequelize": "3.31.0" }, "devDependencies": { - "@aaa-backend-stack/test-environment": "^2.0.4", - "@aaa-backend-stack/tslint-rules": "^1.16.7", + "@aaa-backend-stack/test-environment": "^2.1.1", + "@aaa-backend-stack/tslint-rules": "^2.1.1", "tslint": "5.11.0", - "typescript": "3.6.4" + "typescript": "3.7.2" }, "publishConfig": { "access": "public" diff --git a/packages/aaa-image-service/package.json b/packages/aaa-image-service/package.json index cd86d84..0b4b88f 100644 --- a/packages/aaa-image-service/package.json +++ b/packages/aaa-image-service/package.json @@ -1,6 +1,6 @@ { "name": "@aaa-backend-stack/image-service", - "version": "2.0.4", + "version": "2.1.1", "description": "Image service for handling image uploads", "license": "MIT", "author": "all about apps", @@ -16,12 +16,12 @@ "test": "exit 0" }, "dependencies": { - "@aaa-backend-stack/build-tools": "^2.0.4", - "@aaa-backend-stack/file-storage": "^2.0.4", - "@aaa-backend-stack/logger": "^2.0.4", - "@aaa-backend-stack/rest": "^2.0.4", - "@aaa-backend-stack/storage": "^2.0.4", - "@aaa-backend-stack/utils": "^2.0.4", + "@aaa-backend-stack/build-tools": "^2.1.1", + "@aaa-backend-stack/file-storage": "^2.1.1", + "@aaa-backend-stack/logger": "^2.1.1", + "@aaa-backend-stack/rest": "^2.1.1", + "@aaa-backend-stack/storage": "^2.1.1", + "@aaa-backend-stack/utils": "^2.1.1", "@types/gm": "1.18.0", "@types/lodash": "4.14.144", "command-exists": "1.2.7", @@ -29,10 +29,10 @@ "lodash": "4.17.15" }, "devDependencies": { - "@aaa-backend-stack/test-environment": "^2.0.4", - "@aaa-backend-stack/tslint-rules": "^1.16.7", + "@aaa-backend-stack/test-environment": "^2.1.1", + "@aaa-backend-stack/tslint-rules": "^2.1.1", "tslint": "5.11.0", - "typescript": "3.6.4" + "typescript": "3.7.2" }, "publishConfig": { "access": "public" diff --git a/packages/aaa-logger/package.json b/packages/aaa-logger/package.json index bf66c25..c584d33 100644 --- a/packages/aaa-logger/package.json +++ b/packages/aaa-logger/package.json @@ -1,6 +1,6 @@ { "name": "@aaa-backend-stack/logger", - "version": "2.0.4", + "version": "2.1.1", "description": "Bunyan logger interface implementation, hapi plugin, file rotation and email error reporting setup", "license": "MIT", "author": "all about apps", @@ -19,9 +19,9 @@ "test": "exit 0" }, "dependencies": { - "@aaa-backend-stack/build-tools": "^2.0.4", - "@aaa-backend-stack/git-info": "^2.0.4", - "@aaa-backend-stack/serverdate": "^2.0.4", + "@aaa-backend-stack/build-tools": "^2.1.1", + "@aaa-backend-stack/git-info": "^2.1.1", + "@aaa-backend-stack/serverdate": "^2.1.1", "@types/bunyan": "0.0.30", "@types/lodash": "4.14.144", "@types/nodemailer": "6.2.1", @@ -35,10 +35,10 @@ "safe-json-stringify": "1.1.0" }, "devDependencies": { - "@aaa-backend-stack/test-environment": "^2.0.4", - "@aaa-backend-stack/tslint-rules": "^1.16.7", + "@aaa-backend-stack/test-environment": "^2.1.1", + "@aaa-backend-stack/tslint-rules": "^2.1.1", "tslint": "5.11.0", - "typescript": "3.6.4" + "typescript": "3.7.2" }, "publishConfig": { "access": "public" diff --git a/packages/aaa-mailer/package.json b/packages/aaa-mailer/package.json index 95e8286..7673daa 100644 --- a/packages/aaa-mailer/package.json +++ b/packages/aaa-mailer/package.json @@ -1,6 +1,6 @@ { "name": "@aaa-backend-stack/mailer", - "version": "2.0.4", + "version": "2.1.1", "description": "Example Lib", "license": "MIT", "author": "all about apps", @@ -16,9 +16,9 @@ "test": "exit 0" }, "dependencies": { - "@aaa-backend-stack/build-tools": "^2.0.4", - "@aaa-backend-stack/logger": "^2.0.4", - "@aaa-backend-stack/utils": "^2.0.4", + "@aaa-backend-stack/build-tools": "^2.1.1", + "@aaa-backend-stack/logger": "^2.1.1", + "@aaa-backend-stack/utils": "^2.1.1", "@types/lodash": "4.14.144", "@types/nodemailer": "6.2.1", "handlebars": "4.0.6", @@ -29,10 +29,10 @@ "nodemailer-stub-transport": "1.1.0" }, "devDependencies": { - "@aaa-backend-stack/test-environment": "^2.0.4", - "@aaa-backend-stack/tslint-rules": "^1.16.7", + "@aaa-backend-stack/test-environment": "^2.1.1", + "@aaa-backend-stack/tslint-rules": "^2.1.1", "tslint": "5.11.0", - "typescript": "3.6.4" + "typescript": "3.7.2" }, "publishConfig": { "access": "public" diff --git a/packages/aaa-polyfills/package.json b/packages/aaa-polyfills/package.json index 6d9c7fe..f2b81d9 100644 --- a/packages/aaa-polyfills/package.json +++ b/packages/aaa-polyfills/package.json @@ -1,6 +1,6 @@ { "name": "@aaa-backend-stack/polyfills", - "version": "2.0.4", + "version": "2.1.1", "description": "Unified core and polyfills injector for backend projects. This project explicitly maintains the cls patched sequelize, bluebird, fetch", "license": "MIT", "author": "all about apps", @@ -16,7 +16,7 @@ "test": "exit 0" }, "dependencies": { - "@aaa-backend-stack/build-tools": "^2.0.4", + "@aaa-backend-stack/build-tools": "^2.1.1", "@types/bluebird": "3.5.8", "@types/bluebird-global": "3.5.3", "@types/lodash": "4.14.144", @@ -26,6 +26,7 @@ "bluebird": "3.5.0", "cls-bluebird": "2.1.0", "cls-hooked": "4.2.2", + "continuation-local-storage": "3.2.0", "lodash": "4.17.15", "node-fetch": "1.7.2", "sequelize": "3.31.0", @@ -33,10 +34,10 @@ "uuid": "3.1.0" }, "devDependencies": { - "@aaa-backend-stack/test-environment": "^2.0.4", - "@aaa-backend-stack/tslint-rules": "^1.16.7", + "@aaa-backend-stack/test-environment": "^2.1.1", + "@aaa-backend-stack/tslint-rules": "^2.1.1", "tslint": "5.11.0", - "typescript": "3.6.4" + "typescript": "3.7.2" }, "publishConfig": { "access": "public" diff --git a/packages/aaa-polyfills/src/index.ts b/packages/aaa-polyfills/src/index.ts index 9aa38f9..4bcee35 100644 --- a/packages/aaa-polyfills/src/index.ts +++ b/packages/aaa-polyfills/src/index.ts @@ -43,9 +43,15 @@ export interface ICLSNamespace { bindEmitter(emitter: NodeJS.EventEmitter): void; } - // setup our own process specific CLS namespace. -const cls = require("cls-hooked"); +export const usingClsHooked = !process.env.CLS_USE_CONTINUATION_LOCAL_STORAGE; +const cls = usingClsHooked ? require("cls-hooked") : require("continuation-local-storage"); +if (usingClsHooked) { + console.log(`CLS using cls-hooked`); +} else { + console.log(`CLS using continuation-local-storage`); +} + import * as uuid from "uuid"; @@ -97,6 +103,7 @@ export const __OWNS__ = [ "bluebird", // exposed as global.Promise "cls-bluebird", "cls-hooked", + "continuation-local-storage", "node-fetch", // exposed as global.fetch "source-map-support" ]; diff --git a/packages/aaa-pushes/package.json b/packages/aaa-pushes/package.json index 4ac93c2..83a791f 100644 --- a/packages/aaa-pushes/package.json +++ b/packages/aaa-pushes/package.json @@ -1,6 +1,6 @@ { "name": "@aaa-backend-stack/pushes", - "version": "2.0.4", + "version": "2.1.1", "description": "Push notification lib", "license": "MIT", "author": "all about apps", @@ -16,10 +16,10 @@ "test": "exit 0" }, "dependencies": { - "@aaa-backend-stack/build-tools": "^2.0.4", - "@aaa-backend-stack/logger": "^2.0.4", - "@aaa-backend-stack/serverdate": "^2.0.4", - "@aaa-backend-stack/utils": "^2.0.4", + "@aaa-backend-stack/build-tools": "^2.1.1", + "@aaa-backend-stack/logger": "^2.1.1", + "@aaa-backend-stack/serverdate": "^2.1.1", + "@aaa-backend-stack/utils": "^2.1.1", "@types/lodash": "4.14.144", "@types/node-fetch": "1.6.7", "apn": "2.1.2", @@ -29,10 +29,10 @@ "node-fetch": "1.7.2" }, "devDependencies": { - "@aaa-backend-stack/test-environment": "^2.0.4", - "@aaa-backend-stack/tslint-rules": "^1.16.7", + "@aaa-backend-stack/test-environment": "^2.1.1", + "@aaa-backend-stack/tslint-rules": "^2.1.1", "tslint": "5.11.0", - "typescript": "3.6.4" + "typescript": "3.7.2" }, "publishConfig": { "access": "public" diff --git a/packages/aaa-rest/package.json b/packages/aaa-rest/package.json index 8f112ee..ac1e44f 100644 --- a/packages/aaa-rest/package.json +++ b/packages/aaa-rest/package.json @@ -1,6 +1,6 @@ { "name": "@aaa-backend-stack/rest", - "version": "2.0.4", + "version": "2.1.1", "description": "Example Lib", "license": "MIT", "author": "all about apps", @@ -16,9 +16,9 @@ "test": "exit 0" }, "dependencies": { - "@aaa-backend-stack/build-tools": "^2.0.4", - "@aaa-backend-stack/logger": "^2.0.4", - "@aaa-backend-stack/utils": "^2.0.4", + "@aaa-backend-stack/build-tools": "^2.1.1", + "@aaa-backend-stack/logger": "^2.1.1", + "@aaa-backend-stack/utils": "^2.1.1", "@types/boom": "0.0.33", "@types/handlebars": "4.0.36", "@types/hapi": "16.1.6", @@ -40,10 +40,10 @@ "vision": "4.1.1" }, "devDependencies": { - "@aaa-backend-stack/test-environment": "^2.0.4", - "@aaa-backend-stack/tslint-rules": "^1.16.7", + "@aaa-backend-stack/test-environment": "^2.1.1", + "@aaa-backend-stack/tslint-rules": "^2.1.1", "tslint": "5.11.0", - "typescript": "3.6.4" + "typescript": "3.7.2" }, "publishConfig": { "access": "public" diff --git a/packages/aaa-serverdate/package.json b/packages/aaa-serverdate/package.json index 67f73b2..b5292a9 100644 --- a/packages/aaa-serverdate/package.json +++ b/packages/aaa-serverdate/package.json @@ -1,6 +1,6 @@ { "name": "@aaa-backend-stack/serverdate", - "version": "2.0.4", + "version": "2.1.1", "description": "Utility functions to work with date critical server operations", "license": "MIT", "author": "all about apps", @@ -16,7 +16,7 @@ "test": "exit 0" }, "dependencies": { - "@aaa-backend-stack/build-tools": "^2.0.4", + "@aaa-backend-stack/build-tools": "^2.1.1", "@types/lodash": "4.14.144", "@types/moment-timezone": "0.5.12", "lodash": "4.17.15", @@ -25,10 +25,10 @@ "receptacle": "1.3.0" }, "devDependencies": { - "@aaa-backend-stack/test-environment": "^2.0.4", - "@aaa-backend-stack/tslint-rules": "^1.16.7", + "@aaa-backend-stack/test-environment": "^2.1.1", + "@aaa-backend-stack/tslint-rules": "^2.1.1", "tslint": "5.11.0", - "typescript": "3.6.4" + "typescript": "3.7.2" }, "publishConfig": { "access": "public" diff --git a/packages/aaa-storage/package.json b/packages/aaa-storage/package.json index f1d35c6..91de87a 100644 --- a/packages/aaa-storage/package.json +++ b/packages/aaa-storage/package.json @@ -1,6 +1,6 @@ { "name": "@aaa-backend-stack/storage", - "version": "2.0.4", + "version": "2.1.1", "description": "Storage Package Abstraction", "license": "MIT", "author": "all about apps", @@ -16,9 +16,9 @@ "test": "exit 0" }, "dependencies": { - "@aaa-backend-stack/build-tools": "^2.0.4", - "@aaa-backend-stack/logger": "^2.0.4", - "@aaa-backend-stack/utils": "^2.0.4", + "@aaa-backend-stack/build-tools": "^2.1.1", + "@aaa-backend-stack/logger": "^2.1.1", + "@aaa-backend-stack/utils": "^2.1.1", "@types/bluebird": "3.5.8", "@types/bluebird-global": "3.5.3", "@types/bluebird-retry": "0.0.33", @@ -40,10 +40,10 @@ "uuid": "3.1.0" }, "devDependencies": { - "@aaa-backend-stack/test-environment": "^2.0.4", - "@aaa-backend-stack/tslint-rules": "^1.16.7", + "@aaa-backend-stack/test-environment": "^2.1.1", + "@aaa-backend-stack/tslint-rules": "^2.1.1", "tslint": "5.11.0", - "typescript": "3.6.4" + "typescript": "3.7.2" }, "publishConfig": { "access": "public" diff --git a/packages/aaa-storage/src/adapters/ConnectionAdapter.ts b/packages/aaa-storage/src/adapters/ConnectionAdapter.ts index 9238a61..c4517cc 100644 --- a/packages/aaa-storage/src/adapters/ConnectionAdapter.ts +++ b/packages/aaa-storage/src/adapters/ConnectionAdapter.ts @@ -1,5 +1,5 @@ import { getChildLogger } from "@aaa-backend-stack/logger"; -import { CLS_NAMESPACE } from "@aaa-backend-stack/polyfills"; +import { CLS_NAMESPACE, usingClsHooked } from "@aaa-backend-stack/polyfills"; const logger = getChildLogger("@aaa-backend-stack/storage"); import * as _ from "lodash"; @@ -268,6 +268,38 @@ export class ConnectionAdapter<TConfig extends IConnectionAdapterConfig> { return existingTransaction; } + /** + * Sets the provided transaction for the current CLS context. + * Throws an expection if a transaction has already been set unless the `overwriteExisting` parameter has been set (defaults to `false`). + * + * @param {Sequelize.Transaction} transaction Transaction to set for current CLS context + * @param {boolean} [overwriteExisting=false] Optionally allows for an existing transaction to be overwritten, defaults to `false` + * @memberof ConnectionAdapter + */ + public setTransaction(transaction: Sequelize.Transaction, overwriteExisting: boolean = false): void { + if (!usingClsHooked) { + const existingTransaction: Sequelize.Transaction = CLS_NAMESPACE.get(CLS_TRANSACTION_CONTEXT_IDENTIFIER); + if (!_.isNil(existingTransaction) && !overwriteExisting) { + throw new Error(`ConnectionAdapter.setTransaction: transaction ${(<any>existingTransaction).id} already exists, cannot set another transaction`); + } + + CLS_NAMESPACE.set<Sequelize.Transaction>(CLS_TRANSACTION_CONTEXT_IDENTIFIER, transaction); + } + } + + /** + * Removes any set transaction from the current CLS context. + * Has no effect if no transaction has been set before. + * + * @memberof ConnectionAdapter + */ + public clearTransaction(): void { + if (!usingClsHooked) { + CLS_NAMESPACE.set(CLS_TRANSACTION_CONTEXT_IDENTIFIER, null); + } + } + + protected destroyConnectionAdapter(): void { logger.warn("ConnectionAdapter.destroyConnectionAdapter..."); diff --git a/packages/aaa-storage/src/cli.ts b/packages/aaa-storage/src/cli.ts index dee9029..a40c304 100644 --- a/packages/aaa-storage/src/cli.ts +++ b/packages/aaa-storage/src/cli.ts @@ -1,4 +1,4 @@ -import { Storage } from "./index"; +import storage, { sql, Storage } from "./index"; import { CLI, defineCLIEnvironment } from "@aaa-backend-stack/build-tools"; import { fastDropAndCreate } from "./TestStrategyClass"; import * as _ from "lodash"; @@ -9,6 +9,38 @@ import * as SEQUELIZE from "sequelize"; const pkg = require("../package.json"); +export async function findMissingForeignKeyIndices() { + return storage.sequelize.query(sql` + SELECT c.conrelid::regclass AS "table", + /* list of key column names in order */ + string_agg(a.attname, ',' ORDER BY x.n) AS columns, + pg_catalog.pg_size_pretty( + pg_catalog.pg_relation_size(c.conrelid) + ) AS size, + c.conname AS constraint, + c.confrelid::regclass AS referenced_table + FROM pg_catalog.pg_constraint c + /* enumerated key column numbers per foreign key */ + CROSS JOIN LATERAL + unnest(c.conkey) WITH ORDINALITY AS x(attnum, n) + /* name for each key column */ + JOIN pg_catalog.pg_attribute a + ON a.attnum = x.attnum + AND a.attrelid = c.conrelid + WHERE NOT EXISTS + /* is there a matching index for the constraint? */ + (SELECT 1 FROM pg_catalog.pg_index i + WHERE i.indrelid = c.conrelid + /* the first index columns must be the same as the + key columns, but order doesn't matter */ + AND (i.indkey::smallint[])[0:cardinality(c.conkey)-1] + @> c.conkey) + AND c.contype = 'f' + GROUP BY c.conrelid, c.conname, c.confrelid + ORDER BY pg_catalog.pg_relation_size(c.conrelid) DESC; + `, { type: SEQUELIZE.QueryTypes.SELECT }); +} + export interface IInjectCLIOptions { setUserPassword: { fn: (userUid: string, password: string) => Promise<void | any>; @@ -91,35 +123,7 @@ export function injectCLI(storage: Storage, options: Partial<IInjectCLIOptions>) "check-missing-fk-indices": async () => { // via https://www.cybertec-postgresql.com/en/index-your-foreign-key/ - const rows: { table: string; columns: string; referenced_table: string; constraint: string; size: string }[] = await storage.sequelize.query(` - SELECT c.conrelid::regclass AS "table", - /* list of key column names in order */ - string_agg(a.attname, ',' ORDER BY x.n) AS columns, - pg_catalog.pg_size_pretty( - pg_catalog.pg_relation_size(c.conrelid) - ) AS size, - c.conname AS constraint, - c.confrelid::regclass AS referenced_table - FROM pg_catalog.pg_constraint c - /* enumerated key column numbers per foreign key */ - CROSS JOIN LATERAL - unnest(c.conkey) WITH ORDINALITY AS x(attnum, n) - /* name for each key column */ - JOIN pg_catalog.pg_attribute a - ON a.attnum = x.attnum - AND a.attrelid = c.conrelid - WHERE NOT EXISTS - /* is there a matching index for the constraint? */ - (SELECT 1 FROM pg_catalog.pg_index i - WHERE i.indrelid = c.conrelid - /* the first index columns must be the same as the - key columns, but order doesn't matter */ - AND (i.indkey::smallint[])[0:cardinality(c.conkey)-1] - @> c.conkey) - AND c.contype = 'f' - GROUP BY c.conrelid, c.conname, c.confrelid - ORDER BY pg_catalog.pg_relation_size(c.conrelid) DESC; - `, { type: SEQUELIZE.QueryTypes.SELECT }); + const rows: { table: string; columns: string; referenced_table: string; constraint: string; size: string }[] = await findMissingForeignKeyIndices(); // node_v10+ supported. console.table(rows); diff --git a/packages/aaa-storage/src/index.ts b/packages/aaa-storage/src/index.ts index 323cc27..9ba4acd 100644 --- a/packages/aaa-storage/src/index.ts +++ b/packages/aaa-storage/src/index.ts @@ -58,6 +58,32 @@ export { } from "./dbHelpers"; +/** + * Helper function to allow SQL syntax highlighting using the vscode-sql-template-literal extension + * (https://marketplace.visualstudio.com/items?itemName=forbeslindesay.vscode-sql-template-literal) + * + * Usage: const query = sql`SELECT * FROM bla`; + * + * @param query + */ +export function sql(strings, ...values) { + let str = ""; + strings.forEach((string, i) => { + const v = values[i]; + if (typeof v === "function") { + str += string + v(); + } else if (v !== undefined) { + str += string + v; + } else { + str += string; + } + }); + return str; +} + +export { findMissingForeignKeyIndices } from "./cli"; + + import * as transactionContext from "./transactionContext"; export { transactionContext as TRANSACTION_CONTEXT }; diff --git a/packages/aaa-test-environment/package.json b/packages/aaa-test-environment/package.json index c887b2d..0d992d1 100644 --- a/packages/aaa-test-environment/package.json +++ b/packages/aaa-test-environment/package.json @@ -1,6 +1,6 @@ { "name": "@aaa-backend-stack/test-environment", - "version": "2.0.4", + "version": "2.1.1", "description": "Test environment (encapsulates mocha test stack)", "license": "MIT", "author": "all about apps", @@ -19,7 +19,7 @@ "test": "exit 0" }, "dependencies": { - "@aaa-backend-stack/build-tools": "^2.0.4", + "@aaa-backend-stack/build-tools": "^2.1.1", "@types/chai": "3.5.2", "@types/chai-as-promised": "0.0.29", "@types/chai-http": "0.0.29", @@ -36,9 +36,9 @@ "traverse": "0.6.6" }, "devDependencies": { - "@aaa-backend-stack/tslint-rules": "^1.16.7", + "@aaa-backend-stack/tslint-rules": "^2.1.1", "tslint": "5.11.0", - "typescript": "3.6.4" + "typescript": "3.7.2" }, "publishConfig": { "access": "public" diff --git a/packages/aaa-utils/package.json b/packages/aaa-utils/package.json index 5fe19a3..8a2c9ed 100644 --- a/packages/aaa-utils/package.json +++ b/packages/aaa-utils/package.json @@ -1,6 +1,6 @@ { "name": "@aaa-backend-stack/utils", - "version": "2.0.4", + "version": "2.1.1", "description": "Utility belt for aaa backend projects", "license": "MIT", "author": "all about apps", @@ -16,8 +16,8 @@ "test": "exit 0" }, "dependencies": { - "@aaa-backend-stack/build-tools": "^2.0.4", - "@aaa-backend-stack/logger": "^2.0.4", + "@aaa-backend-stack/build-tools": "^2.1.1", + "@aaa-backend-stack/logger": "^2.1.1", "@types/bluebird": "3.5.8", "@types/bluebird-global": "3.5.3", "@types/bluebird-retry": "0.0.33", @@ -35,10 +35,10 @@ "zxcvbn": "4.4.2" }, "devDependencies": { - "@aaa-backend-stack/test-environment": "^2.0.4", - "@aaa-backend-stack/tslint-rules": "^1.16.7", + "@aaa-backend-stack/test-environment": "^2.1.1", + "@aaa-backend-stack/tslint-rules": "^2.1.1", "tslint": "5.11.0", - "typescript": "3.6.4" + "typescript": "3.7.2" }, "publishConfig": { "access": "public" diff --git a/packages/create-aaa-backend/package.json b/packages/create-aaa-backend/package.json index 2fb9b4b..69dd35a 100644 --- a/packages/create-aaa-backend/package.json +++ b/packages/create-aaa-backend/package.json @@ -1,6 +1,6 @@ { "name": "create-aaa-backend", - "version": "2.0.4", + "version": "2.1.1", "description": "create-aaa-backend global cli. Used for scaffolding new aaa backend projects", "license": "MIT", "author": "all about apps", @@ -20,9 +20,9 @@ "test": "exit 0" }, "dependencies": { - "@aaa-backend-stack/build-tools": "^2.0.4", - "@aaa-backend-stack/polyfills": "^2.0.4", - "@aaa-backend-stack/utils": "^2.0.4", + "@aaa-backend-stack/build-tools": "^2.1.1", + "@aaa-backend-stack/polyfills": "^2.1.1", + "@aaa-backend-stack/utils": "^2.1.1", "@types/inquirer": "0.0.35", "@types/lodash": "4.14.144", "generate-password": "1.3.0", @@ -33,10 +33,10 @@ "uuid": "3.1.0" }, "devDependencies": { - "@aaa-backend-stack/tslint-rules": "^1.16.7", + "@aaa-backend-stack/tslint-rules": "^2.1.1", "@types/uuid": "3.4.5", "tslint": "5.11.0", - "typescript": "3.6.4" + "typescript": "3.7.2" }, "publishConfig": { "access": "public" diff --git a/packages/template/.cabgen/tslint.json.cabgen b/packages/template/.cabgen/tslint.json.cabgen index 52b94ca..587ce8e 100644 --- a/packages/template/.cabgen/tslint.json.cabgen +++ b/packages/template/.cabgen/tslint.json.cabgen @@ -77,6 +77,11 @@ "variable-name": false, // Requires variables to either be lower(Camel)Case or UPPER_CASE "no-null-keyword": false, "newline-per-chained-call": false, - "prefer-readonly": false + "prefer-readonly": false, + "no-unnecessary-bind": false, + "no-function-constructor-with-string-args": false, + "no-reserved-keywords": false, + "no-increment-decrement": false, + "no-use-before-declare": false } } diff --git a/packages/template/env/test.env b/packages/template/env/test.env index 09f3ccf..f10c655 100644 --- a/packages/template/env/test.env +++ b/packages/template/env/test.env @@ -23,4 +23,7 @@ AAA_LOGGER_LOG_FILE_ROTATION_COUNT=1 AAA_LOGGER_LOG_FILE_MIN_SEVERITY_LEVEL=fatal LOG_LVL=fatal -LOG_CONSOLE_TARGET=./node_modules/.bin/bunyan \ No newline at end of file +LOG_CONSOLE_TARGET=./node_modules/.bin/bunyan + +# Use this to switch CLS between continuation-local-storage and cls-hooked (= default) +#CLS_USE_CONTINUATION_LOCAL_STORAGE=true diff --git a/packages/template/env/test.env.cabgen b/packages/template/env/test.env.cabgen index d1d913b..f9b2d5a 100644 --- a/packages/template/env/test.env.cabgen +++ b/packages/template/env/test.env.cabgen @@ -23,4 +23,7 @@ AAA_LOGGER_LOG_FILE_ROTATION_COUNT=1 AAA_LOGGER_LOG_FILE_MIN_SEVERITY_LEVEL=fatal LOG_LVL=fatal -LOG_CONSOLE_TARGET=./node_modules/.bin/bunyan \ No newline at end of file +LOG_CONSOLE_TARGET=./node_modules/.bin/bunyan + +# Use this to switch CLS between continuation-local-storage and cls-hooked (= default) +#CLS_USE_CONTINUATION_LOCAL_STORAGE=true diff --git a/packages/template/package.json b/packages/template/package.json index 25207bf..731aadd 100644 --- a/packages/template/package.json +++ b/packages/template/package.json @@ -1,6 +1,6 @@ { "name": "template-aaa-backend", - "version": "2.0.4", + "version": "2.1.1", "private": true, "description": "the all about apps template project for a node.js backend service", "author": "all about apps", @@ -55,19 +55,19 @@ "utils": "LOG_LVL=fatal env-cmd ./env/service.env --no-override node build/scripts/utils.js" }, "dependencies": { - "@aaa-backend-stack/build-tools": "^2.0.4", - "@aaa-backend-stack/devtools": "^2.0.4", - "@aaa-backend-stack/git-info": "^2.0.4", - "@aaa-backend-stack/graphql": "^2.0.4", - "@aaa-backend-stack/graphql-rest-bindings": "^2.0.4", - "@aaa-backend-stack/logger": "^2.0.4", - "@aaa-backend-stack/mailer": "^2.0.4", - "@aaa-backend-stack/polyfills": "^2.0.4", - "@aaa-backend-stack/pushes": "^2.0.4", - "@aaa-backend-stack/rest": "^2.0.4", - "@aaa-backend-stack/serverdate": "^2.0.4", - "@aaa-backend-stack/storage": "^2.0.4", - "@aaa-backend-stack/utils": "^2.0.4", + "@aaa-backend-stack/build-tools": "^2.1.1", + "@aaa-backend-stack/devtools": "^2.1.1", + "@aaa-backend-stack/git-info": "^2.1.1", + "@aaa-backend-stack/graphql": "^2.1.1", + "@aaa-backend-stack/graphql-rest-bindings": "^2.1.1", + "@aaa-backend-stack/logger": "^2.1.1", + "@aaa-backend-stack/mailer": "^2.1.1", + "@aaa-backend-stack/polyfills": "^2.1.1", + "@aaa-backend-stack/pushes": "^2.1.1", + "@aaa-backend-stack/rest": "^2.1.1", + "@aaa-backend-stack/serverdate": "^2.1.1", + "@aaa-backend-stack/storage": "^2.1.1", + "@aaa-backend-stack/utils": "^2.1.1", "accepts": "1.3.5", "fb": "2.0.0", "google-auth-library": "1.6.1", @@ -75,15 +75,15 @@ "url-join": "4.0.0" }, "devDependencies": { - "@aaa-backend-stack/test-environment": "^2.0.4", - "@aaa-backend-stack/tslint-rules": "^1.16.7", + "@aaa-backend-stack/test-environment": "^2.1.1", + "@aaa-backend-stack/tslint-rules": "^2.1.1", "@types/accepts": "1.3.5", "@types/lodash": "4.14.144", "@types/url-join": "0.8.2", "nyc": "13.1.0", "tslint": "5.20.0", "tslint-microsoft-contrib": "6.2.0", - "typescript": "3.6.4" + "typescript": "3.7.2" }, "nyc": { "exclude": [ diff --git a/packages/template/src/migrations/011-add-missing-foreign-key-indices.ts b/packages/template/src/migrations/011-add-missing-foreign-key-indices.ts new file mode 100644 index 0000000..ac37bf8 --- /dev/null +++ b/packages/template/src/migrations/011-add-missing-foreign-key-indices.ts @@ -0,0 +1,18 @@ +import { IMigration, sql } from "@aaa-backend-stack/storage"; + +// tslint:disable-next-line:no-object-literal-type-assertion +module.exports = <IMigration>{ + up: async function (queryInterface, SEQUELIZE) { + await queryInterface.sequelize.query(sql` + CREATE INDEX idx_access_tokens_fk_user_uid ON "AccessTokens"("UserUid"); + CREATE INDEX idx_refresh_tokens_fk_user_uid ON "RefreshTokens"("UserUid"); + CREATE INDEX idx_user_permissions_fk_permission_uid ON "UserPermissions"("PermissionUid"); + CREATE INDEX idx_push_tokens_fk_user_uid ON "PushTokens"("UserUid"); + CREATE INDEX idx_password_reset_tokens_fk_user_uid ON "PasswordResetTokens"("UserUid"); + `); + }, + + down: async function (queryInterface, SEQUELIZE) { + // + } +}; diff --git a/packages/template/src/test/cls.test.ts b/packages/template/src/test/cls.test.ts index de6d18e..03906d5 100644 --- a/packages/template/src/test/cls.test.ts +++ b/packages/template/src/test/cls.test.ts @@ -102,6 +102,8 @@ describe("@aaa-backend-stack/polyfills", function () { // tslint:disable-next-line:no-unused-expression expect(transaction).to.be.ok; + storage.setTransaction(transaction); + const clsTransaction: any = storage.getTransaction(); expect(clsTransaction.id).to.equal(transaction.id); @@ -110,6 +112,8 @@ describe("@aaa-backend-stack/polyfills", function () { await transaction.rollback(); + storage.clearTransaction(); + // rollback should remove transaction from cls expect(storage.getTransaction()).to.equal(null); @@ -129,6 +133,8 @@ describe("@aaa-backend-stack/polyfills", function () { // tslint:disable-next-line:no-unused-expression expect(transaction).to.be.ok; + storage.setTransaction(transaction); + const clsTransaction: any = storage.getTransaction(); expect(clsTransaction.id).to.equal(transaction.id); @@ -137,6 +143,8 @@ describe("@aaa-backend-stack/polyfills", function () { await transaction.commit(); + storage.clearTransaction(); + // rollback should remove transaction from cls expect(storage.getTransaction()).to.equal(null); diff --git a/packages/template/src/test/storage.test.ts b/packages/template/src/test/storage.test.ts index fe127fd..a8359f1 100644 --- a/packages/template/src/test/storage.test.ts +++ b/packages/template/src/test/storage.test.ts @@ -1,5 +1,7 @@ -import storage, { SEQUELIZE } from "@aaa-backend-stack/storage"; +import { usingClsHooked } from "@aaa-backend-stack/polyfills"; +import storage, { findMissingForeignKeyIndices, SEQUELIZE } from "@aaa-backend-stack/storage"; import { expect } from "@aaa-backend-stack/test-environment"; +import * as _ from "lodash"; describe("@aaa-backend-stack/storage", function () { // tslint:disable-next-line:max-func-body-length @@ -82,9 +84,18 @@ describe("@aaa-backend-stack/storage", function () { // tslint:disable-next-line:no-unused-expression expect(transaction).to.be.ok; + const clsTransaction = storage.getTransaction(); + if (!usingClsHooked) { + // tslint:disable-next-line:no-unused-expression + expect(clsTransaction).to.not.be.ok; + } + + storage.setTransaction(transaction); + const user = await storage.models.User.create({ uid: TEST_USER_UID }); await transaction.commit(); + storage.clearTransaction(); await user.reload(); expect(user).to.not.equal(null); @@ -98,9 +109,18 @@ describe("@aaa-backend-stack/storage", function () { // tslint:disable-next-line:no-unused-expression expect(transaction).to.be.ok; + const clsTransaction = storage.getTransaction(); + if (!usingClsHooked) { + // tslint:disable-next-line:no-unused-expression + expect(clsTransaction).to.not.be.ok; + } + + storage.setTransaction(transaction); + const user = await storage.models.User.create({ uid: TEST_USER_UID }); await transaction.rollback(); + storage.clearTransaction(); try { await user.reload(); @@ -124,18 +144,38 @@ describe("@aaa-backend-stack/storage", function () { // tslint:disable-next-line:no-unused-expression expect(transaction).to.be.ok; + // Verify no transaction has been automatically added to the CLS context by sequelize + const clsTransaction = storage.getTransaction(); + let results; + if (!usingClsHooked) { + // tslint:disable-next-line:no-unused-expression + expect(clsTransaction).to.not.be.ok; + + // Transaction not automatically set in CLS context, no local parameter set + results = await storage.sequelize.query("SELECT current_setting('my.test_user_uid', TRUE);", { type: SEQUELIZE.QueryTypes.SELECT }); + expect(results).to.have.length(1); + expect(results[0].current_setting).to.satisfy((val: any) => val === "" || val === null); + } + + // Manually set transaction in CLS context, all queries afterwards use it + storage.setTransaction(transaction); + // Transaction is now applied, local parameter applied - let results = await storage.sequelize.query("SELECT current_setting('my.test_user_uid', TRUE);", { type: SEQUELIZE.QueryTypes.SELECT }); + results = await storage.sequelize.query("SELECT current_setting('my.test_user_uid', TRUE);", { type: SEQUELIZE.QueryTypes.SELECT }); expect(results).to.have.length(1); expect(results[0].current_setting).to.equal(TEST_USER_UID); // Commit transaction, local parameter no longer applied for queries after this await transaction.commit(); - // Transaction is still set in context, but has already been committed. Local parameter does not apply anymore - results = await storage.sequelize.query("SELECT current_setting('my.test_user_uid', TRUE);", { type: SEQUELIZE.QueryTypes.SELECT }); - expect(results).to.have.length(1); - expect(results[0].current_setting).to.satisfy((val: any) => val === "" || val === null); + if (!usingClsHooked) { + // Transaction is still set in context, but has already been committed. Local parameter does not apply anymore + results = await storage.sequelize.query("SELECT current_setting('my.test_user_uid', TRUE);", { type: SEQUELIZE.QueryTypes.SELECT }); + expect(results).to.have.length(1); + expect(results[0].current_setting).to.satisfy((val: any) => val === "" || val === null); + } + + storage.clearTransaction(); // No transaction set anymore, local parameter does not apply results = await storage.sequelize.query("SELECT current_setting('my.test_user_uid', TRUE);", { type: SEQUELIZE.QueryTypes.SELECT }); @@ -143,4 +183,23 @@ describe("@aaa-backend-stack/storage", function () { expect(results[0].current_setting).to.satisfy((val: any) => val === "" || val === null); }); }); + + it("all FK should be indexed", async function () { + const fks = await findMissingForeignKeyIndices(); + + // If not all FKs are indexed -> output query for migration to achieve that + if (fks.length > 0) { + // tslint:disable-next-line:no-console + console.log("Missing foreign key indices -> add them using the query"); + fks.forEach((row: { table: string; columns: string }) => { + const sanitizedTable = row.table.split("\"").join(""); + const sanitizedFK = row.columns.split("\"").join(""); + // tslint:disable-next-line:no-console + console.log(`CREATE INDEX idx_${_.snakeCase(sanitizedTable)}_fk_${_.snakeCase(sanitizedFK)} ON "${sanitizedTable}" ("${sanitizedFK}");`); + }); + } + + expect(fks.length).to.equal(0); + }); + }); diff --git a/packages/tests/package.json b/packages/tests/package.json index 7e98ae4..64cb701 100644 --- a/packages/tests/package.json +++ b/packages/tests/package.json @@ -1,6 +1,6 @@ { "name": "@aaa-backend-stack/tests", - "version": "2.0.4", + "version": "2.1.1", "private": true, "description": "Integration tests", "license": "MIT", @@ -17,28 +17,28 @@ "test": "exit 0" }, "dependencies": { - "@aaa-backend-stack/build-tools": "^2.0.4", - "@aaa-backend-stack/devtools": "^2.0.4", - "@aaa-backend-stack/git-info": "^2.0.4", - "@aaa-backend-stack/graphql": "^2.0.4", - "@aaa-backend-stack/graphql-rest-bindings": "^2.0.4", - "@aaa-backend-stack/logger": "^2.0.4", - "@aaa-backend-stack/mailer": "^2.0.4", - "@aaa-backend-stack/polyfills": "^2.0.4", - "@aaa-backend-stack/pushes": "^2.0.4", - "@aaa-backend-stack/rest": "^2.0.4", - "@aaa-backend-stack/serverdate": "^2.0.4", - "@aaa-backend-stack/storage": "^2.0.4", - "@aaa-backend-stack/utils": "^2.0.4", + "@aaa-backend-stack/build-tools": "^2.1.1", + "@aaa-backend-stack/devtools": "^2.1.1", + "@aaa-backend-stack/git-info": "^2.1.1", + "@aaa-backend-stack/graphql": "^2.1.1", + "@aaa-backend-stack/graphql-rest-bindings": "^2.1.1", + "@aaa-backend-stack/logger": "^2.1.1", + "@aaa-backend-stack/mailer": "^2.1.1", + "@aaa-backend-stack/polyfills": "^2.1.1", + "@aaa-backend-stack/pushes": "^2.1.1", + "@aaa-backend-stack/rest": "^2.1.1", + "@aaa-backend-stack/serverdate": "^2.1.1", + "@aaa-backend-stack/storage": "^2.1.1", + "@aaa-backend-stack/utils": "^2.1.1", "@types/lodash": "4.14.144", "lodash": "4.17.15", - "template-aaa-backend": "^2.0.4" + "template-aaa-backend": "^2.1.1" }, "devDependencies": { - "@aaa-backend-stack/test-environment": "^2.0.4", - "@aaa-backend-stack/tslint-rules": "^1.16.7", + "@aaa-backend-stack/test-environment": "^2.1.1", + "@aaa-backend-stack/tslint-rules": "^2.1.1", "tslint": "5.11.0", - "typescript": "3.6.4" + "typescript": "3.7.2" }, "resolutions": { "@types/lodash": "4.14.144" diff --git a/packages/tslint-rules/package.json b/packages/tslint-rules/package.json index 5ccca38..187c7fc 100644 --- a/packages/tslint-rules/package.json +++ b/packages/tslint-rules/package.json @@ -1,6 +1,6 @@ { "name": "@aaa-backend-stack/tslint-rules", - "version": "1.16.7", + "version": "2.1.1", "description": "aaa internal tslint rules", "license": "MIT", "author": "all about apps", @@ -21,7 +21,7 @@ "devDependencies": { "rimraf": "2.6.1", "tslint": "5.11.0", - "typescript": "3.6.4" + "typescript": "3.7.2" }, "publishConfig": { "access": "public" diff --git a/yarn.lock b/yarn.lock index ebcee68..a74b072 100644 --- a/yarn.lock +++ b/yarn.lock @@ -923,6 +923,14 @@ async-limiter@~1.0.0: resolved "https://registry.yarnpkg.com/async-limiter/-/async-limiter-1.0.0.tgz#78faed8c3d074ab81f22b4e985d79e8738f720f8" integrity sha512-jp/uFnooOiO+L211eZOoSyzpOITMXx1rBITauYykG3BRYPu8h0UcxsPNB04RR5vo4Tyz3+ay17tR6JVf9qzYWg== +async-listener@^0.6.0: + version "0.6.10" + resolved "https://registry.yarnpkg.com/async-listener/-/async-listener-0.6.10.tgz#a7c97abe570ba602d782273c0de60a51e3e17cbc" + integrity sha512-gpuo6xOyF4D5DE5WvyqZdPA3NGhiT6Qf07l7DCB0wwDEsLvDIbCr6j9S5aj5Ch96dLace5tXVzWBZkxU/c5ohw== + dependencies: + semver "^5.3.0" + shimmer "^1.1.0" + async@^1.4.0, async@^1.5.0: version "1.5.2" resolved "https://registry.yarnpkg.com/async/-/async-1.5.2.tgz#ec6a61ae56480c0c3cb241c95618e20892f9672a" @@ -1664,6 +1672,14 @@ content@3.x.x: dependencies: boom "5.x.x" +continuation-local-storage@3.2.0: + version "3.2.0" + resolved "https://registry.yarnpkg.com/continuation-local-storage/-/continuation-local-storage-3.2.0.tgz#e19fc36b597090a5d4e4a3b2ea3ebc5e29694a24" + integrity sha1-4Z/Da1lwkKXU5KOy6j68XilpSiQ= + dependencies: + async-listener "^0.6.0" + emitter-listener "^1.0.1" + conventional-changelog-angular@^1.5.0: version "1.5.0" resolved "https://registry.yarnpkg.com/conventional-changelog-angular/-/conventional-changelog-angular-1.5.0.tgz#50b2d45008448455fdf67e06ea01972fbd08182a" @@ -7464,10 +7480,10 @@ typedarray@^0.0.6: resolved "https://registry.yarnpkg.com/typedarray/-/typedarray-0.0.6.tgz#867ac74e3864187b1d3d47d996a78ec5c8830777" integrity sha1-hnrHTjhkGHsdPUfZlqeOxciDB3c= -typescript@3.6.4: - version "3.6.4" - resolved "https://registry.yarnpkg.com/typescript/-/typescript-3.6.4.tgz#b18752bb3792bc1a0281335f7f6ebf1bbfc5b91d" - integrity sha512-unoCll1+l+YK4i4F8f22TaNVPRHcD9PA3yCuZ8g5e0qGqlVlJ/8FSateOLLSagn+Yg5+ZwuPkL8LFUc0Jcvksg== +typescript@3.7.2: + version "3.7.2" + resolved "https://registry.yarnpkg.com/typescript/-/typescript-3.7.2.tgz#27e489b95fa5909445e9fef5ee48d81697ad18fb" + integrity sha512-ml7V7JfiN2Xwvcer+XAf2csGO1bPBdRbFCkYBczNZggrBZ9c7G3riSUeJmqEU5uOtXNPMhE3n+R4FA/3YOAWOQ== ua-parser-js@^0.7.9: version "0.7.17"