forked from aaronshaf/dynamodb-admin
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathutil.js
More file actions
32 lines (29 loc) · 858 Bytes
/
util.js
File metadata and controls
32 lines (29 loc) · 858 Bytes
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
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
}