From 7f5050c8341fcec72361223bf0e7496d84e1cf1e Mon Sep 17 00:00:00 2001 From: Florian CHAZAL Date: Fri, 25 Feb 2022 09:26:18 +0100 Subject: [PATCH] Fix test groups and readme --- .projen/tasks.json | 5 +- .projenrc.js | 10 ++-- README.md | 38 +++++++++++- package.json | 143 ++++++++++++++++++++++++++++++++++++++++++++- 4 files changed, 186 insertions(+), 10 deletions(-) diff --git a/.projen/tasks.json b/.projen/tasks.json index 8f8496f..e596b27 100644 --- a/.projen/tasks.json +++ b/.projen/tasks.json @@ -237,16 +237,13 @@ "description": "Run tests", "steps": [ { - "exec": "echo $(cat package.json | jq '.jest.runner = \"groups\"') > package.json && jest --group=unit" + "exec": "jest --group=unit" } ] }, "test:e2e": { "name": "test:e2e", "steps": [ - { - "exec": "echo $(cat package.json | jq '.jest.runner = \"groups\"') > package.json" - }, { "exec": "jest --group=e2e" } diff --git a/.projenrc.js b/.projenrc.js index 67a3863..103c14b 100644 --- a/.projenrc.js +++ b/.projenrc.js @@ -6,7 +6,11 @@ const project = new awscdk.AwsCdkConstructLibrary({ defaultReleaseBranch: 'main', name: 'aws-dynamodb-table-multi-gsis', repositoryUrl: 'https://github.com/flochaz/aws-dynamodb-table-multi-gsis.git', - + jestOptions: { + jestConfig: { + runner: 'groups', + }, + }, cdkDependenciesAsDeps: false, cdkDependencies: ['@aws-cdk/aws-dynamodb', '@aws-cdk/custom-resources', '@aws-cdk/aws-iam'], cdkTestDependencies: ['@aws-cdk/aws-applicationautoscaling', '@aws-cdk/aws-kinesis', '@aws-cdk/aws-kms'], @@ -29,9 +33,7 @@ const project = new awscdk.AwsCdkConstructLibrary({ const e2e = project.addTask('test:e2e', { exec: 'jest --group=e2e', }); -const addJestGroupSupport = 'echo $(cat package.json | jq \'.jest.runner = "groups"\') > package.json'; -e2e.prependExec(addJestGroupSupport); -project.testTask.reset(`${addJestGroupSupport} && jest --group=unit`); +project.testTask.reset('jest --group=unit'); project.synth(); diff --git a/README.md b/README.md index 6a7f7dd..adc4797 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,40 @@ # @aws-cdk/aws-dynamodb + multi GSIs update capability -This construct is fixing https://github.com/aws/aws-cdk/issues/12246 by simply overriding [@aws-cdk/aws-dynamodb Table addGlobalSecondaryIndex](https://github.com/aws/aws-cdk/blob/master/packages/%40aws-cdk/aws-dynamodb/lib/table.ts#L1231) which will leverage the [@aws-cdk/custom-resource Provider](https://docs.aws.amazon.com/cdk/api/v1/docs/custom-resources-readme.html) to sequentially create Global GSIs. \ No newline at end of file +This construct is fixing https://github.com/aws/aws-cdk/issues/12246 by simply overriding [@aws-cdk/aws-dynamodb Table addGlobalSecondaryIndex](https://github.com/aws/aws-cdk/blob/master/packages/%40aws-cdk/aws-dynamodb/lib/table.ts#L1231) which will leverage the [@aws-cdk/custom-resource Provider](https://docs.aws.amazon.com/cdk/api/v1/docs/custom-resources-readme.html) to sequentially create Global GSIs. + +## Usage + +Use `@aws-cdk/aws-dynamodb` as usual except for `Table` that needs to come from `aws-dynamodb-table-multi-gsis` : + + +```typescript +import { AttributeType, BillingMode } from '@aws-cdk/aws-dynamodb'; +import * as cdk from '@aws-cdk/core'; + +// Import the new version of Table +import { Table } from 'aws-dynamodb-table-multi-gsis'; + +const app = new cdk.App(); + +const stack = new cdk.Stack(app, 'integ-dynamodb-table'); + +const testTable = new Table(stack, 'TestTable', { + partitionKey: { name: 'id', type: AttributeType.STRING }, + billingMode: BillingMode.PAY_PER_REQUEST, +}); + +testTable.addGlobalSecondaryIndex({ + indexName: 'global1', + partitionKey: { name: 'global1', type: AttributeType.STRING }, +}); + +testTable.addGlobalSecondaryIndex({ + indexName: 'global2', + partitionKey: { name: 'global2', type: AttributeType.STRING }, +}); +``` + +## Potential caveat + +If the existing table already has GSIs, it will delete and recreates the GSIs ... \ No newline at end of file diff --git a/package.json b/package.json index de44bb4..56aef5f 100644 --- a/package.json +++ b/package.json @@ -1 +1,142 @@ -{ "name": "aws-dynamodb-table-multi-gsis", "repository": { "type": "git", "url": "https://github.com/flochaz/aws-dynamodb-table-multi-gsis.git" }, "scripts": { "build": "npx projen build", "bump": "npx projen bump", "bundle": "npx projen bundle", "bundle:dynamoDBUpdateTable.lambda": "npx projen bundle:dynamoDBUpdateTable.lambda", "bundle:dynamoDBUpdateTable.lambda:watch": "npx projen bundle:dynamoDBUpdateTable.lambda:watch", "clobber": "npx projen clobber", "compat": "npx projen compat", "compile": "npx projen compile", "default": "npx projen default", "docgen": "npx projen docgen", "eject": "npx projen eject", "eslint": "npx projen eslint", "package": "npx projen package", "package-all": "npx projen package-all", "package:js": "npx projen package:js", "post-compile": "npx projen post-compile", "post-upgrade": "npx projen post-upgrade", "pre-compile": "npx projen pre-compile", "release": "npx projen release", "test": "npx projen test", "test:e2e": "npx projen test:e2e", "test:update": "npx projen test:update", "test:watch": "npx projen test:watch", "unbump": "npx projen unbump", "upgrade": "npx projen upgrade", "upgrade-projen": "npx projen upgrade-projen", "watch": "npx projen watch", "projen": "npx projen" }, "author": { "name": "Florian CHAZAL", "email": "florianchazal@gmail.com", "organization": false }, "devDependencies": { "@aws-cdk/assert": "^1.122.0", "@aws-cdk/assertions": "^1.122.0", "@aws-cdk/aws-applicationautoscaling": "^1.122.0", "@aws-cdk/aws-dynamodb": "^1.122.0", "@aws-cdk/aws-iam": "^1.122.0", "@aws-cdk/aws-kinesis": "^1.122.0", "@aws-cdk/aws-kms": "^1.122.0", "@aws-cdk/custom-resources": "^1.122.0", "@types/aws-lambda": "^8.10.92", "@types/jest": "^27.4.0", "@types/node": "^12", "@typescript-eslint/eslint-plugin": "^5", "@typescript-eslint/parser": "^5", "aws-cdk": "^1.122.0", "aws-sdk": "^2.1078.0", "esbuild": "^0.14.23", "eslint": "^8", "eslint-import-resolver-node": "^0.3.6", "eslint-import-resolver-typescript": "^2.5.0", "eslint-plugin-import": "^2.25.4", "jest": "^27.5.1", "jest-junit": "^13", "jest-runner-groups": "^2.1.0", "jsii": "^1.54.0", "jsii-diff": "^1.54.0", "jsii-docgen": "^6.1.11", "json-schema": "^0.4.0", "npm-check-updates": "^12", "projen": "^0.52.43", "standard-version": "^9", "ts-jest": "^27.1.3", "typescript": "^4.5.5" }, "peerDependencies": { "@aws-cdk/aws-dynamodb": "^1.122.0", "@aws-cdk/aws-iam": "^1.122.0", "@aws-cdk/aws-lambda": "^1.122.0", "@aws-cdk/core": "^1.122.0", "@aws-cdk/custom-resources": "^1.122.0", "constructs": "^3.2.27" }, "keywords": [ "cdk" ], "main": "lib/index.js", "license": "Apache-2.0", "version": "0.0.0", "jest": { "testMatch": [ "/src/**/__tests__/**/*.ts?(x)", "/(test|src)/**/?(*.)+(spec|test).ts?(x)" ], "clearMocks": true, "collectCoverage": true, "coverageReporters": [ "json", "lcov", "clover", "cobertura", "text" ], "coverageDirectory": "coverage", "coveragePathIgnorePatterns": [ "/node_modules/" ], "testPathIgnorePatterns": [ "/node_modules/" ], "watchPathIgnorePatterns": [ "/node_modules/" ], "reporters": [ "default", [ "jest-junit", { "outputDirectory": "test-reports" } ] ], "preset": "ts-jest", "globals": { "ts-jest": { "tsconfig": "tsconfig.dev.json" } }, "runner": "groups" }, "types": "lib/index.d.ts", "stability": "stable", "jsii": { "outdir": "dist", "targets": {}, "tsc": { "outDir": "lib", "rootDir": "src" } }, "//": "~~ Generated by projen. To modify, edit .projenrc.js and run \"npx projen\"." } +{ + "name": "aws-dynamodb-table-multi-gsis", + "repository": { + "type": "git", + "url": "https://github.com/flochaz/aws-dynamodb-table-multi-gsis.git" + }, + "scripts": { + "build": "npx projen build", + "bump": "npx projen bump", + "bundle": "npx projen bundle", + "bundle:dynamoDBUpdateTable.lambda": "npx projen bundle:dynamoDBUpdateTable.lambda", + "bundle:dynamoDBUpdateTable.lambda:watch": "npx projen bundle:dynamoDBUpdateTable.lambda:watch", + "clobber": "npx projen clobber", + "compat": "npx projen compat", + "compile": "npx projen compile", + "default": "npx projen default", + "docgen": "npx projen docgen", + "eject": "npx projen eject", + "eslint": "npx projen eslint", + "package": "npx projen package", + "package-all": "npx projen package-all", + "package:js": "npx projen package:js", + "post-compile": "npx projen post-compile", + "post-upgrade": "npx projen post-upgrade", + "pre-compile": "npx projen pre-compile", + "release": "npx projen release", + "test": "npx projen test", + "test:e2e": "npx projen test:e2e", + "test:update": "npx projen test:update", + "test:watch": "npx projen test:watch", + "unbump": "npx projen unbump", + "upgrade": "npx projen upgrade", + "upgrade-projen": "npx projen upgrade-projen", + "watch": "npx projen watch", + "projen": "npx projen" + }, + "author": { + "name": "Florian CHAZAL", + "email": "florianchazal@gmail.com", + "organization": false + }, + "devDependencies": { + "@aws-cdk/assert": "^1.122.0", + "@aws-cdk/assertions": "^1.122.0", + "@aws-cdk/aws-applicationautoscaling": "^1.122.0", + "@aws-cdk/aws-dynamodb": "^1.122.0", + "@aws-cdk/aws-iam": "^1.122.0", + "@aws-cdk/aws-kinesis": "^1.122.0", + "@aws-cdk/aws-kms": "^1.122.0", + "@aws-cdk/custom-resources": "^1.122.0", + "@types/aws-lambda": "^8.10.92", + "@types/jest": "^27.4.0", + "@types/node": "^12", + "@typescript-eslint/eslint-plugin": "^5", + "@typescript-eslint/parser": "^5", + "aws-cdk": "^1.122.0", + "aws-sdk": "^2.1078.0", + "esbuild": "^0.14.23", + "eslint": "^8", + "eslint-import-resolver-node": "^0.3.6", + "eslint-import-resolver-typescript": "^2.5.0", + "eslint-plugin-import": "^2.25.4", + "jest": "^27.5.1", + "jest-junit": "^13", + "jest-runner-groups": "^2.1.0", + "jsii": "^1.54.0", + "jsii-diff": "^1.54.0", + "jsii-docgen": "^6.1.11", + "json-schema": "^0.4.0", + "npm-check-updates": "^12", + "projen": "^0.52.43", + "standard-version": "^9", + "ts-jest": "^27.1.3", + "typescript": "^4.5.5" + }, + "peerDependencies": { + "@aws-cdk/aws-dynamodb": "^1.122.0", + "@aws-cdk/aws-iam": "^1.122.0", + "@aws-cdk/aws-lambda": "^1.122.0", + "@aws-cdk/core": "^1.122.0", + "@aws-cdk/custom-resources": "^1.122.0", + "constructs": "^3.2.27" + }, + "keywords": [ + "cdk" + ], + "main": "lib/index.js", + "license": "Apache-2.0", + "version": "0.0.0", + "jest": { + "runner": "groups", + "testMatch": [ + "/src/**/__tests__/**/*.ts?(x)", + "/(test|src)/**/?(*.)+(spec|test).ts?(x)" + ], + "clearMocks": true, + "collectCoverage": true, + "coverageReporters": [ + "json", + "lcov", + "clover", + "cobertura", + "text" + ], + "coverageDirectory": "coverage", + "coveragePathIgnorePatterns": [ + "/node_modules/" + ], + "testPathIgnorePatterns": [ + "/node_modules/" + ], + "watchPathIgnorePatterns": [ + "/node_modules/" + ], + "reporters": [ + "default", + [ + "jest-junit", + { + "outputDirectory": "test-reports" + } + ] + ], + "preset": "ts-jest", + "globals": { + "ts-jest": { + "tsconfig": "tsconfig.dev.json" + } + } + }, + "types": "lib/index.d.ts", + "stability": "stable", + "jsii": { + "outdir": "dist", + "targets": {}, + "tsc": { + "outDir": "lib", + "rootDir": "src" + } + }, + "//": "~~ Generated by projen. To modify, edit .projenrc.js and run \"npx projen\"." +} \ No newline at end of file