-
Notifications
You must be signed in to change notification settings - Fork 108
/
Copy pathputItem.js
85 lines (77 loc) · 2.17 KB
/
putItem.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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
var validations = require('./index'),
db = require('../db')
exports.types = {
ReturnConsumedCapacity: {
type: 'String',
enum: [ 'INDEXES', 'TOTAL', 'NONE' ],
},
TableName: {
type: 'String',
notNull: true,
regex: '[a-zA-Z0-9_.-]+',
lengthGreaterThanOrEqual: 3,
lengthLessThanOrEqual: 255,
},
Item: {
type: 'Map<AttributeValue>',
notNull: true,
children: 'AttrStruct<ValueStruct>',
},
ConditionalOperator: {
type: 'String',
enum: [ 'OR', 'AND' ],
},
Expected: {
type: 'Map<ExpectedAttributeValue>',
children: {
type: 'ValueStruct<ExpectedAttributeValue>',
children: {
AttributeValueList: {
type: 'List',
children: 'AttrStruct<ValueStruct>',
},
ComparisonOperator: {
type: 'String',
enum: [ 'IN', 'NULL', 'BETWEEN', 'LT', 'NOT_CONTAINS', 'EQ', 'GT', 'NOT_NULL', 'NE', 'LE', 'BEGINS_WITH', 'GE', 'CONTAINS' ],
},
Exists: 'Boolean',
Value: 'AttrStruct<FieldStruct>',
},
},
},
ReturnValues: {
type: 'String',
enum: [ 'ALL_NEW', 'UPDATED_OLD', 'ALL_OLD', 'NONE', 'UPDATED_NEW' ],
},
ReturnItemCollectionMetrics: {
type: 'String',
enum: [ 'SIZE', 'NONE' ],
},
ConditionExpression: {
type: 'String',
},
ExpressionAttributeValues: {
type: 'Map<AttributeValue>',
children: 'AttrStruct<ValueStruct>',
},
ExpressionAttributeNames: {
type: 'Map<java.lang.String>',
children: 'String',
},
}
exports.custom = function (data, store) {
var msg = validations.validateExpressionParams(data, [ 'ConditionExpression' ], [ 'Expected' ])
if (msg) return msg
for (var key in data.Item) {
msg = validations.validateAttributeValue(data.Item[key])
if (msg) return msg
}
if (data.ReturnValues && data.ReturnValues != 'ALL_OLD' && data.ReturnValues != 'NONE')
return 'ReturnValues can only be ALL_OLD or NONE'
if (db.itemSize(data.Item) > store.options.maxItemSize)
return 'Item size has exceeded the maximum allowed size'
msg = validations.validateAttributeConditions(data)
if (msg) return msg
msg = validations.validateExpressions(data)
if (msg) return msg
}