Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions .lintstagedrc.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
60 changes: 47 additions & 13 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.

Expand All @@ -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{
Expand Down Expand Up @@ -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.
Expand Down
9 changes: 0 additions & 9 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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",
Expand Down
7 changes: 0 additions & 7 deletions src/dynamo-easy.ts
Original file line number Diff line number Diff line change
@@ -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
//
Expand Down
15 changes: 11 additions & 4 deletions tsconfig.jest.json
Original file line number Diff line number Diff line change
@@ -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/**/*"
]
}
5 changes: 4 additions & 1 deletion tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -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. */
Expand Down