forked from aaronshaf/dynamodb-admin
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathutil.js
36 lines (33 loc) · 885 Bytes
/
util.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
exports.extractKey = function(item, KeySchema) {
return KeySchema.reduce((prev, current) => {
return Object.assign({}, prev, {
[current.AttributeName]: item[current.AttributeName]
})
}, {})
}
exports.parseKey = function(keys, table) {
const splitKeys = keys.split(',')
return table.KeySchema.reduce((prev, current, index) => {
return Object.assign({}, prev, {
[current.AttributeName]: typecastKey(
current.AttributeName,
splitKeys[index],
table
)
})
}, {})
}
function typecastKey(keyName, keyValue, table) {
const definition = table.AttributeDefinitions.find(attribute => {
return attribute.AttributeName === keyName
})
if (definition) {
switch (definition.AttributeType) {
case 'N':
return Number(keyValue)
case 'S':
return String(keyValue)
}
}
return keyValue
}