|
9 | 9 |
|
10 | 10 | A starter project that makes creating a TypeScript library extremely easy. |
11 | 11 |
|
| 12 | +## Object Mapper |
| 13 | + |
| 14 | +#### Decorators |
| 15 | +Decorators are used to add some metadata to our model classes required by the mapper for some special cases. |
| 16 | + |
| 17 | +This is an experimental feature and requires to set the |
| 18 | + |
| 19 | +- "experimentalDecorators": true |
| 20 | +- "emitDecoratorMetadata": true |
| 21 | + |
| 22 | +compiler options. |
| 23 | +Additionally we rely on the reflect-metadata (https://www.npmjs.com/package/reflect-metadata) package for reflection api. |
| 24 | + |
| 25 | +To get started with decorators just add a @Model() Decorator to any ts class. By default this enables the custom mapping functionality |
| 26 | +and will get you started to work with Dynamo DB. |
| 27 | + |
| 28 | +We make heavy usage of compile time informations about our models and the property types. |
| 29 | +ES6 types like Set, Map will be mapped to Object when calling for the type via Reflect.get, so we need some extra info. |
| 30 | + |
| 31 | +Along the way we will probably need some extra features. Here is a list of these: |
| 32 | + |
| 33 | +**Custom TableName** |
| 34 | +@Model({tableName: tableName}) |
| 35 | + |
| 36 | + |
| 37 | +#### Types |
| 38 | +The type defines how a value will be mapped. Types can be defined using decorators (for complex types) or we use one of the following methods: |
| 39 | +fromDB -> use default for DynamoDB type (see type table) |
| 40 | +toDB -> use property value to resolve the type |
| 41 | + |
| 42 | +design:type |
| 43 | +String, Number, Boolean, Undefined, Object |
| 44 | + |
| 45 | +unsupported |
| 46 | +Set, Map, Date, moment.Moment |
| 47 | + |
| 48 | + |
| 49 | +#### Dynamo DB |
| 50 | + |
| 51 | +To map an js object into the attribute map required by dynamodb requests, we implement our very oppinionated custom mapper. |
| 52 | +We use the DynamoDB Document Mapper to map all «default» types to dynamodb attribute values. |
| 53 | + |
| 54 | +There are some custom requirements for these cases: |
| 55 | + |
| 56 | +- MomentJs Dates |
| 57 | +- Use ES6 Map, Set types |
| 58 | + |
| 59 | +Mapper Strategy: |
| 60 | + |
| 61 | +-> To DB |
| 62 | +1) check if we have some property metadata |
| 63 | + |
| 64 | + YES NO |
| 65 | + |
| 66 | + isCustomType document client can map (check with typeof propertyValue for additional security) |
| 67 | + |
| 68 | + YES NO |
| 69 | + |
| 70 | + custom mapping document client can map |
| 71 | +-> From DB |
| 72 | + |
| 73 | + |
| 74 | +## Open Tasks |
| 75 | +Null Values? |
| 76 | +How does DynamoDb treat empty lists, sets or emtpy strings? |
| 77 | + |
| 78 | +## Node Project Template |
| 79 | + |
| 80 | + |
12 | 81 | ### Usage |
13 | 82 |
|
14 | 83 | ```bash |
|
0 commit comments