Skip to content

Commit fac4f11

Browse files
feat(reflect-metadata): remove import
- reflect-metadata should only exist once in the whole code base of a project so the consumer of our library must import the reflect-metadata project, even if he might not use it in his code base. But if he uses the reflect-metadata in his code or uses another library like InversifyJS we must ensure the Reflect global variable only exists once, to prevent from possible hard to debug issues
1 parent e094a12 commit fac4f11

File tree

9 files changed

+53
-30
lines changed

9 files changed

+53
-30
lines changed

.lintstagedrc.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,9 @@ 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+
- tslint --project ./tsconfig.jest.json -t codeFrame --fix
69
"**/package.json":
710
- sort-package-json
811
- git add

README.md

Lines changed: 31 additions & 8 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,37 @@ 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+
## Metadata Reflection API
21+
22+
> ⚠ The reflect-metadata polyfill should be imported only once in your entire application because the Reflect object is
23+
mean to be a global singleton.
24+
25+
Required always. Use reflect-metadata as polyfill.
26+
27+
```
28+
npm install reflect-metadata --save
29+
```
30+
31+
The type definitions for reflect-metadata are included in the npm package.
32+
You need to add the following reference to the types field in your tsconfig.json:
33+
34+
```
35+
"types": ["reflect-metadata"]
36+
```
37+
38+
Finally, import reflect-metadata in some entry file in your application.
39+
40+
```
41+
import "reflect-metadata"
42+
```
43+
44+
Also make sure to install the other peer dependencies of @shiftcoders/dynamo-easy.
45+
46+
## First Sample
47+
48+
When all the setup work is done, define your first model and create a dynamo store to execute actions on the dynamoDB.
49+
2550
```typescript
2651
@Model()
2752
class Person{
@@ -57,8 +82,6 @@ dynamoStore.scan()
5782

5883
```
5984

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

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": "^15.12.0",

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
//

src/mapper/for-type/object.mapper.spec.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { ObjectMapper } from './object.mapper'
22

3+
// TODO remove test comment
34
describe('object mapper', () => {
45
describe('to db', () => {
56
it('should work', () => {

test/models/complex.model.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ import {
1010
} from '../../src/dynamo-easy'
1111
import { NestedObject } from './nested-object.model'
1212

13+
// TODO remove test comment
14+
1315
@Model({ tableName: 'complex_model' })
1416
export class ComplexModel {
1517
@PartitionKey()

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)