Skip to content

Commit 85f098d

Browse files
author
Simon Mumenthaler
authored
Merge pull request #84 from shiftcode/#72-remove-reflect-metadata-import
#72 remove reflect metadata import
2 parents bb9ab50 + 44c34c1 commit 85f098d

File tree

7 files changed

+70
-35
lines changed

7 files changed

+70
-35
lines changed

.lintstagedrc.yml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,13 @@ linters:
33
- prettier --write --config ./.prettierrc.yml
44
- tslint --project ./tsconfig.json -t codeFrame --fix
55
- git add
6+
"(src/**/*.spec.ts|test/**/*.ts)":
7+
- prettier --write --config ./.prettierrc.yml
8+
# FIXME tslint will not work because of the following error
9+
# ✖ tslint --project ./tsconfig.jest.json -t codeFrame --fix found some errors. Please fix them and try committing again.
10+
#'/Users/michaelwittwer/dev/shiftcode/dynamo-easy/test/models/complex.model.ts' is not included in project.
11+
# - tslint --project ./tsconfig.jest.json -t codeFrame --fix
12+
- git add
613
"**/package.json":
714
- sort-package-json
815
- git add

README.md

Lines changed: 47 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,6 @@
88
[![styled with prettier](https://img.shields.io/badge/styled_with-prettier-ff69b4.svg)](https://github.com/prettier/prettier)
99
[![All Contributors](https://img.shields.io/badge/all_contributors-3-orange.svg)](#contributors)
1010

11-
This is the documentation for the new version of dynamo-easy released as a scoped package using the namespace
12-
@shiftcoders (@shiftcoders/dynamo-easy). If you still want to use the 0.0.x version you can
13-
by installing the old version `npm install dynamo-easy` (https://github
14-
.com/shiftcode/dynamo-easy/releases/tag/v0.10
15-
.1)
16-
1711
Abstracts away the complexity of the low level aws dynamosdk. Provides an easy to use fluent api to for requests and supports typescript decorators,
1812
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.
1913

@@ -22,6 +16,53 @@ Checkout the full technical api documentation [here](https://shiftcode.github.io
2216
Built with :heart: by [shiftcode](https://www.shiftcode.ch).
2317

2418
# Get Started
19+
20+
## Prerequisite
21+
22+
### Typescript Metadata
23+
24+
#### Reflection API
25+
26+
> ⚠ The reflect-metadata polyfill should be imported only once in your entire application because the Reflect object is
27+
mean to be a global singleton.
28+
29+
Install the reflect-metadata polyfill.
30+
31+
```
32+
npm install reflect-metadata --save
33+
```
34+
35+
The type definitions for reflect-metadata are included in the npm package.
36+
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):
37+
38+
```
39+
"types": ["reflect-metadata"]
40+
```
41+
42+
Finally, import reflect-metadata in some entry file in your application.
43+
44+
```
45+
import "reflect-metadata"
46+
```
47+
48+
#### Decorators
49+
50+
51+
We need to enable the two experimental features to work with decorators, add this to your tsconfig.json:
52+
53+
```
54+
"experimentalDecorators": true
55+
"emitDecoratorMetadata": true
56+
```
57+
58+
#### Other
59+
Also make sure to install the other peer dependencies of @shiftcoders/dynamo-easy.
60+
61+
62+
## First Sample
63+
64+
When all the setup work is done, define your first model and create a dynamo store to execute actions on the dynamoDB.
65+
2566
```typescript
2667
@Model()
2768
class Person{
@@ -57,16 +98,9 @@ dynamoStore.scan()
5798

5899
```
59100

60-
Want to use this library with Angular (>4) [checkout our angular-service](TODO).
61-
62101
# Decorators
63102
Decorators are used to add some metadata to our model classes, relevant to our javascript-to-dynamo mapper.
64103

65-
This is an experimental feature and requires to set the following typescript compiler options:
66-
67-
- "experimentalDecorators": true
68-
- "emitDecoratorMetadata": true
69-
70104
Additionally we rely on the reflect-metadata (https://www.npmjs.com/package/reflect-metadata) library for reflection api.
71105

72106
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.

package-lock.json

Lines changed: 0 additions & 9 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,6 @@
4747
"@types/jest": "^23.3.1",
4848
"@types/lodash": "^4.14.116",
4949
"@types/node": "^8.0.26",
50-
"@types/reflect-metadata": "^0.1.0",
5150
"@types/uuid": "^3.4.1",
5251
"aws-sdk": "^2.286.1",
5352
"colors": "^1.1.2",
@@ -60,6 +59,7 @@
6059
"lodash": "^4.17.11",
6160
"lodash.camelcase": "^4.3.0",
6261
"prettier": "^1.15.2",
62+
"reflect-metadata": "^0.1.12",
6363
"rimraf": "^2.6.2",
6464
"rxjs": "^6.3.3",
6565
"semantic-release": "^16.0.0-beta.2",

src/dynamo-easy.ts

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,3 @@
1-
//
2-
// Reflect Metadata
3-
// FIXME: Remove reflect-metadata as hard dep (lib using project needs to import it)
4-
// - possible singleton override issues and it's a shim eg. runtime dependent in future --> es7
5-
//
6-
import 'reflect-metadata'
7-
81
//
92
// Export public api of the library
103
//

tsconfig.jest.json

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,15 @@
11
{
22
"extends": "./tsconfig.json",
33
"compilerOptions": {
4-
"module": "commonjs",
5-
"declaration": false,
6-
"allowJs": true // allow js to be compiled with ts for jest es2015 module import (lodash-es)
7-
}
4+
"declaration": false, /* Generates corresponding '.d.ts' file. */
5+
"types": [ /* Type declaration files to be included in compilation. */
6+
"node",
7+
"reflect-metadata",
8+
"jest"
9+
]
10+
},
11+
"include": [
12+
"src/**/*.spec.ts",
13+
"test/**/*"
14+
]
815
}

tsconfig.json

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,10 @@
4747
// "paths": {}, /* A series of entries which re-map imports to lookup locations relative to the 'baseUrl'. */
4848
// "rootDirs": [], /* List of root folders whose combined content represents the structure of the project at runtime. */
4949
// "typeRoots": [], /* List of folders to include type definitions from. */
50-
// "types": [], /* Type declaration files to be included in compilation. */
50+
"types": [ /* Type declaration files to be included in compilation. */
51+
"node",
52+
"reflect-metadata"
53+
],
5154
// "allowSyntheticDefaultImports": true, /* Allow default imports from modules with no default export. This does not affect code emit, just typechecking. */
5255
// "esModuleInterop": true /* Enables emit interoperability between CommonJS and ES Modules via creation of namespace objects for all imports. Implies 'allowSyntheticDefaultImports'. */
5356
// "preserveSymlinks": true, /* Do not resolve the real path of symlinks. */

0 commit comments

Comments
 (0)