diff --git a/.lintstagedrc.yml b/.lintstagedrc.yml index ea7ce9550..0d3aec350 100644 --- a/.lintstagedrc.yml +++ b/.lintstagedrc.yml @@ -3,6 +3,13 @@ linters: - prettier --write --config ./.prettierrc.yml - tslint --project ./tsconfig.json -t codeFrame --fix - git add + "(src/**/*.spec.ts|test/**/*.ts)": + - prettier --write --config ./.prettierrc.yml + # FIXME tslint will not work because of the following error + # ✖ tslint --project ./tsconfig.jest.json -t codeFrame --fix found some errors. Please fix them and try committing again. + #'/Users/michaelwittwer/dev/shiftcode/dynamo-easy/test/models/complex.model.ts' is not included in project. + # - tslint --project ./tsconfig.jest.json -t codeFrame --fix + - git add "**/package.json": - sort-package-json - git add diff --git a/README.md b/README.md index ed1a62eb7..c902bb629 100644 --- a/README.md +++ b/README.md @@ -8,12 +8,6 @@ [![styled with prettier](https://img.shields.io/badge/styled_with-prettier-ff69b4.svg)](https://github.com/prettier/prettier) [![All Contributors](https://img.shields.io/badge/all_contributors-3-orange.svg)](#contributors) -This is the documentation for the new version of dynamo-easy released as a scoped package using the namespace -@shiftcoders (@shiftcoders/dynamo-easy). If you still want to use the 0.0.x version you can -by installing the old version `npm install dynamo-easy` (https://github -.com/shiftcode/dynamo-easy/releases/tag/v0.10 -.1) - Abstracts away the complexity of the low level aws dynamosdk. Provides an easy to use fluent api to for requests and supports typescript decorators, to define some metadata for your models. You don't need to care about the mapping of javascript types to their dynamo types any more. We got you covered. @@ -22,6 +16,53 @@ Checkout the full technical api documentation [here](https://shiftcode.github.io Built with :heart: by [shiftcode](https://www.shiftcode.ch). # Get Started + +## Prerequisite + +### Typescript Metadata + +#### Reflection API + +> ⚠ The reflect-metadata polyfill should be imported only once in your entire application because the Reflect object is +mean to be a global singleton. + +Install the reflect-metadata polyfill. + +``` +npm install reflect-metadata --save +``` + +The type definitions for reflect-metadata are included in the npm package. +You need to add the following reference to the types field in your [tsconfig.json](https://www.typescriptlang.org/docs/handbook/tsconfig-json.html#types-typeroots-and-types): + +``` +"types": ["reflect-metadata"] +``` + +Finally, import reflect-metadata in some entry file in your application. + +``` +import "reflect-metadata" +``` + +#### Decorators + + +We need to enable the two experimental features to work with decorators, add this to your tsconfig.json: + +``` +"experimentalDecorators": true +"emitDecoratorMetadata": true +``` + +#### Other +Also make sure to install the other peer dependencies of @shiftcoders/dynamo-easy. + + +## First Sample + +When all the setup work is done, define your first model and create a dynamo store to execute actions on the dynamoDB. + ```typescript @Model() class Person{ @@ -57,16 +98,9 @@ dynamoStore.scan() ``` -Want to use this library with Angular (>4) [checkout our angular-service](TODO). - # Decorators Decorators are used to add some metadata to our model classes, relevant to our javascript-to-dynamo mapper. -This is an experimental feature and requires to set the following typescript compiler options: - -- "experimentalDecorators": true -- "emitDecoratorMetadata": true - Additionally we rely on the reflect-metadata (https://www.npmjs.com/package/reflect-metadata) library for reflection api. To get started with decorators just add a [@Model()](https://shiftcode.github.io/dynamo-easy/modules/_decorator_impl_model_model_decorator_.html) Decorator to any typescript class. diff --git a/package-lock.json b/package-lock.json index 7d029d7f8..1163ec7d9 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1028,15 +1028,6 @@ "integrity": "sha512-Jnmm57+nHqvJUPwUzt1CLoLzFtF2B2vgG7cWFut+a4nqTp9/L6pL0N+o0Jt3V7AQnCKMsPEqQpLFZYleBCdq3w==", "dev": true }, - "@types/reflect-metadata": { - "version": "0.1.0", - "resolved": "https://registry.npmjs.org/@types/reflect-metadata/-/reflect-metadata-0.1.0.tgz", - "integrity": "sha512-bXltFLY3qhzCnVYP5iUpeSICagQ8rc9K2liS+8M0lBcz54BHs3O6W5UvqespVSuebo1BXLi+/y9ioELAW9SC2A==", - "dev": true, - "requires": { - "reflect-metadata": "*" - } - }, "@types/shelljs": { "version": "0.8.0", "resolved": "https://registry.npmjs.org/@types/shelljs/-/shelljs-0.8.0.tgz", diff --git a/package.json b/package.json index cc2445dae..7afcd371d 100644 --- a/package.json +++ b/package.json @@ -47,7 +47,6 @@ "@types/jest": "^23.3.1", "@types/lodash": "^4.14.116", "@types/node": "^8.0.26", - "@types/reflect-metadata": "^0.1.0", "@types/uuid": "^3.4.1", "aws-sdk": "^2.286.1", "colors": "^1.1.2", @@ -60,6 +59,7 @@ "lodash": "^4.17.11", "lodash.camelcase": "^4.3.0", "prettier": "^1.15.2", + "reflect-metadata": "^0.1.12", "rimraf": "^2.6.2", "rxjs": "^6.3.3", "semantic-release": "^15.12.0", diff --git a/src/dynamo-easy.ts b/src/dynamo-easy.ts index c69ec8101..5daf8d7d3 100644 --- a/src/dynamo-easy.ts +++ b/src/dynamo-easy.ts @@ -1,10 +1,3 @@ -// -// Reflect Metadata -// FIXME: Remove reflect-metadata as hard dep (lib using project needs to import it) -// - possible singleton override issues and it's a shim eg. runtime dependent in future --> es7 -// -import 'reflect-metadata' - // // Export public api of the library // diff --git a/tsconfig.jest.json b/tsconfig.jest.json index 24d3817ec..1577af47b 100644 --- a/tsconfig.jest.json +++ b/tsconfig.jest.json @@ -1,8 +1,15 @@ { "extends": "./tsconfig.json", "compilerOptions": { - "module": "commonjs", - "declaration": false, - "allowJs": true // allow js to be compiled with ts for jest es2015 module import (lodash-es) - } + "declaration": false, /* Generates corresponding '.d.ts' file. */ + "types": [ /* Type declaration files to be included in compilation. */ + "node", + "reflect-metadata", + "jest" + ] + }, + "include": [ + "src/**/*.spec.ts", + "test/**/*" + ] } diff --git a/tsconfig.json b/tsconfig.json index 5fc9a4b6f..5bde973b6 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -47,7 +47,10 @@ // "paths": {}, /* A series of entries which re-map imports to lookup locations relative to the 'baseUrl'. */ // "rootDirs": [], /* List of root folders whose combined content represents the structure of the project at runtime. */ // "typeRoots": [], /* List of folders to include type definitions from. */ - // "types": [], /* Type declaration files to be included in compilation. */ + "types": [ /* Type declaration files to be included in compilation. */ + "node", + "reflect-metadata" + ], // "allowSyntheticDefaultImports": true, /* Allow default imports from modules with no default export. This does not affect code emit, just typechecking. */ // "esModuleInterop": true /* Enables emit interoperability between CommonJS and ES Modules via creation of namespace objects for all imports. Implies 'allowSyntheticDefaultImports'. */ // "preserveSymlinks": true, /* Do not resolve the real path of symlinks. */