Skip to content

Commit bf77678

Browse files
Merge pull request #75 from shiftcode/#67-make-moment-optional
object instead of classes for Mappers
2 parents 65f47fd + 40bbdad commit bf77678

File tree

126 files changed

+4291
-5381
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

126 files changed

+4291
-5381
lines changed

.lintstagedrc.yml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
linters:
2+
"{src,test}/**/*.ts":
3+
- prettier --write --config ./.prettierrc.yml
4+
- tslint --project ./tsconfig.json -t codeFrame --fix
5+
- git add
6+
"**/package.json":
7+
- sort-package-json
8+
- git add

.prettierrc.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,4 @@
22
printWidth: 120
33
singleQuote: true
44
semi: false
5-
trailingComma: es5
5+
trailingComma: all

.releaserc.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
1+
# run semantic-release on master branch
12
branch: master

README.md

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,7 @@ Simple Type (no decorators required to work)
109109
- Boolean
110110
- Null
111111
- Array
112+
- String/Number Enum
112113

113114
Complex Types (properties with these types need some decorators to work properly)
114115
- Set<simpleType | complexType>
@@ -120,7 +121,6 @@ Complex Types (properties with these types need some decorators to work properly
120121
| String | S |
121122
| Number | N |
122123
| Boolean | BOOL |
123-
| moment.Moment | S (ISO-8601 formatted) |
124124
| null | NULL |
125125
| Array | L, (S,N,B)S |
126126
| ES6 Set | L, (S,N,B)S |
@@ -131,7 +131,8 @@ Complex Types (properties with these types need some decorators to work properly
131131
| Date | Not Supported |
132132

133133
## Custom Attribute Mapping
134-
It is always possible to define a custom mapping strategy, just implement the [MapperForType](https://shiftcode.github.io/dynamo-easy/interfaces/_mapper_for_type_base_mapper_.mapperfortype.html) class.
134+
It is always possible to define a custom mapping strategy,
135+
just implement the [MapperForType](https://shiftcode.github.io/dynamo-easy/interfaces/_mapper_for_type_base_mapper_.mapperfortype.html) and provide with the CustomMapper directive.
135136

136137
## Collection Mapping (Array & Set)
137138

@@ -152,40 +153,39 @@ When one of the following decorators is present, the value is always mapped to a
152153
We only support the native Date type and you need to explicitly mark a property to be a Date by using the @Date() decorator\
153154
(which is basically just syntactic sugar for @CustomMapper(TheDateMapper)).\
154155
If you want to use a different type for the @Date decorator (eg. Moment) you need to define a custom mapper and provide it to the dynamo easy config like this:\
155-
`DynamoEasyConfig.updateConfig({ dateMapper: MomentMapper })`\
156-
-> Update the config before importing any models!
156+
`updateDynamoEasyConfig({ dateMapper: MomentMapper })`\
157157

158158

159159
A mapper for moment dates could look like this:
160160
```typescript
161161
import * as moment from 'moment'
162162
import { MapperForType, StringAttribute } from '@shiftcoders/dynamo-easy'
163163

164-
export class MomentMapper implements MapperForType<moment.Moment, StringAttribute> {
164+
export const MomentMapper: MapperForType<moment.Moment, StringAttribute> = {
165165

166-
fromDb(value: StringAttribute): moment.Moment {
167-
const parsed: moment.Moment = moment(value.S, moment.ISO_8601)
166+
fromDb: (value: StringAttribute) => {
167+
const parsed = moment(value.S, moment.ISO_8601)
168168
if (!parsed.isValid()) {
169169
throw new Error(`the value ${value} cannot be parsed into a valid moment date`)
170170
}
171171
return parsed
172-
}
172+
},
173173

174-
toDb(value: moment.Moment): StringAttribute {
174+
toDb: (value: moment.Moment) => {
175175
if (!moment.isMoment(value)) {
176176
throw new Error(`the value ${value} is not of type moment`)
177177
}
178178
if (!value.isValid()) {
179179
throw new Error(`cannot map property value ${value}, because it is not a valid moment date`)
180180
}
181181
return { S: value.clone().utc().format() }
182-
}
182+
},
183183
}
184184
```
185185

186186

187187
## Enum
188-
Enum values are persisted as Numbers (index of enum).
188+
Enum values are persisted as Numbers (index of enum) or string if string value was given.
189189

190190
# Request API
191191
To start making requests create an instance of [DynamoStore](https://shiftcode.github.io/dynamo-easy/classes/_dynamo_dynamo_store_.dynamostore.html) and execute the desired operation using the provided api.
@@ -197,7 +197,8 @@ We support the following dynamodb operations with a fluent api:
197197
- Delete
198198
- Scan
199199
- Query
200-
- BatchGet
200+
- BatchGet (from a single table)
201+
- BatchWrite (to a single table)
201202
- MakeRequest (generic low level method for special scenarios)
202203

203204
There is always the possibility to access the Params object directly to add values which are not covered with our api.
@@ -218,7 +219,7 @@ function sessionValidityEnsurer(): Observable<boolean> {
218219
this.logger.debug('withValidSession :: cognitoService.isLoggedIn() -> we have a valid session -> proceed')
219220
return Observable.of(true)
220221
} else {
221-
this.logger.debug('withValidSession :: cognitoService.isLoggedIn() -> user is not logged in or token expired, try to get a new session')
222+
this.logger.debug(metadata)
222223
return this.getUser()
223224
.catch((err, caught): Observable<boolean> => {
224225
this.logger.error('withValidSession :: there was an error when refreshing the session', err)

jest.config.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ module.exports = {
22
testEnvironment: "node",
33
globals: {
44
"ts-jest": {
5-
tsConfigFile: "./tsconfig.jest.json"
5+
tsConfig: "./tsconfig.jest.json"
66
}
77
},
88
transform: {

0 commit comments

Comments
 (0)