You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+44-14Lines changed: 44 additions & 14 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -22,7 +22,7 @@ Checkout the full technical api documentation [here](https://shiftcode.github.io
22
22
Built with :heart: by [shiftcode](https://www.shiftcode.ch).
23
23
24
24
# Get Started
25
-
```
25
+
```typescript
26
26
@Model()
27
27
classPerson{
28
28
@PartitionKeyUUID()
@@ -109,7 +109,7 @@ Simple Type (no decorators required to work)
109
109
- Boolean
110
110
- Null
111
111
- Array
112
-
-Date (we only support MomentJS)
112
+
-String/Number Enum
113
113
114
114
Complex Types (properties with these types need some decorators to work properly)
115
115
- Set<simpleType | complexType>
@@ -121,7 +121,6 @@ Complex Types (properties with these types need some decorators to work properly
121
121
| String | S |
122
122
| Number | N |
123
123
| Boolean | BOOL |
124
-
| moment.Moment | S (ISO-8601 formatted) |
125
124
| null | NULL |
126
125
| Array | L, (S,N,B)S |
127
126
| ES6 Set | L, (S,N,B)S |
@@ -132,7 +131,8 @@ Complex Types (properties with these types need some decorators to work properly
132
131
| Date | Not Supported |
133
132
134
133
## Custom Attribute Mapping
135
-
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.
136
136
137
137
## Collection Mapping (Array & Set)
138
138
@@ -150,13 +150,42 @@ When one of the following decorators is present, the value is always mapped to a
150
150
-@TypedArray()
151
151
152
152
## Date
153
-
Right now we only support [MomentJS](http://momentjs.com/) Dates.
153
+
We only support the native Date type and you need to explicitly mark a property to be a Date by using the @Date() decorator\
154
+
(which is basically just syntactic sugar for @CustomMapper(TheDateMapper)).\
155
+
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:\
thrownewError(`the value ${value} cannot be parsed into a valid moment date`)
170
+
}
171
+
returnparsed
172
+
},
173
+
174
+
toDb: (value:moment.Moment) => {
175
+
if (!moment.isMoment(value)) {
176
+
thrownewError(`the value ${value} is not of type moment`)
177
+
}
178
+
if (!value.isValid()) {
179
+
thrownewError(`cannot map property value ${value}, because it is not a valid moment date`)
180
+
}
181
+
return { S: value.clone().utc().format() }
182
+
},
183
+
}
184
+
```
154
185
155
-
If you want to explicitly mark a property to be a Date use the @Date() decorator. If we find a moment value we automatically map it to a String (using ISO-8601 format).
156
-
When coming from db we do a regex test for ISO-8601 format and map it back to a moment object.
157
186
158
187
## Enum
159
-
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.
160
189
161
190
# Request API
162
191
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.
@@ -168,7 +197,8 @@ We support the following dynamodb operations with a fluent api:
168
197
- Delete
169
198
- Scan
170
199
- Query
171
-
- BatchGet
200
+
- BatchGet (from a single table)
201
+
- BatchWrite (to a single table)
172
202
- MakeRequest (generic low level method for special scenarios)
173
203
174
204
There is always the possibility to access the Params object directly to add values which are not covered with our api.
@@ -189,7 +219,7 @@ function sessionValidityEnsurer(): Observable<boolean> {
189
219
this.logger.debug('withValidSession :: cognitoService.isLoggedIn() -> we have a valid session -> proceed')
190
220
returnObservable.of(true)
191
221
} else {
192
-
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)
193
223
returnthis.getUser()
194
224
.catch((err, caught): Observable<boolean>=> {
195
225
this.logger.error('withValidSession :: there was an error when refreshing the session', err)
@@ -209,7 +239,7 @@ By default we create a substitution placeholder for all the attributes, just to
this works seemlesly for top level attribtues, but if we wanna build an expression for where the attribute needs to be accessed with a document path, we need some special logic
0 commit comments