UNPKG

3.42 kBJavaScriptView Raw
1var validations = require('./index')
2
3exports.types = {
4 ReturnConsumedCapacity: {
5 type: 'String',
6 enum: ['INDEXES', 'TOTAL', 'NONE'],
7 },
8 TableName: {
9 type: 'String',
10 notNull: true,
11 regex: '[a-zA-Z0-9_.-]+',
12 lengthGreaterThanOrEqual: 3,
13 lengthLessThanOrEqual: 255,
14 },
15 ReturnItemCollectionMetrics: {
16 type: 'String',
17 enum: ['SIZE', 'NONE'],
18 },
19 ReturnValues: {
20 type: 'String',
21 enum: ['ALL_NEW', 'UPDATED_OLD', 'ALL_OLD', 'NONE', 'UPDATED_NEW'],
22 },
23 Key: {
24 type: 'Map<AttributeValue>',
25 notNull: true,
26 children: 'AttrStruct<ValueStruct>',
27 },
28 ConditionalOperator: {
29 type: 'String',
30 enum: ['OR', 'AND'],
31 },
32 Expected: {
33 type: 'Map<ExpectedAttributeValue>',
34 children: {
35 type: 'ValueStruct<ExpectedAttributeValue>',
36 children: {
37 AttributeValueList: {
38 type: 'List',
39 children: 'AttrStruct<ValueStruct>',
40 },
41 ComparisonOperator: {
42 type: 'String',
43 enum: ['IN', 'NULL', 'BETWEEN', 'LT', 'NOT_CONTAINS', 'EQ', 'GT', 'NOT_NULL', 'NE', 'LE', 'BEGINS_WITH', 'GE', 'CONTAINS'],
44 },
45 Exists: 'Boolean',
46 Value: 'AttrStruct<FieldStruct>',
47 },
48 },
49 },
50 AttributeUpdates: {
51 type: 'Map<AttributeValueUpdate>',
52 children: {
53 type: 'ValueStruct<AttributeValueUpdate>',
54 children: {
55 Action: 'String',
56 Value: 'AttrStruct<FieldStruct>',
57 },
58 },
59 },
60 ConditionExpression: {
61 type: 'String',
62 },
63 UpdateExpression: {
64 type: 'String',
65 },
66 ExpressionAttributeValues: {
67 type: 'Map<AttributeValue>',
68 children: 'AttrStruct<ValueStruct>',
69 },
70 ExpressionAttributeNames: {
71 type: 'Map<java.lang.String>',
72 children: 'String',
73 },
74}
75
76exports.custom = function(data) {
77
78 var msg = validations.validateExpressionParams(data,
79 ['UpdateExpression', 'ConditionExpression'],
80 ['AttributeUpdates', 'Expected'])
81 if (msg) return msg
82
83 for (var key in data.Key) {
84 msg = validations.validateAttributeValue(data.Key[key])
85 if (msg) return msg
86 }
87
88 for (key in data.AttributeUpdates) {
89 if (data.AttributeUpdates[key].Value != null) {
90 msg = validations.validateAttributeValue(data.AttributeUpdates[key].Value)
91 if (msg) return msg
92 }
93 if (data.AttributeUpdates[key].Value == null && data.AttributeUpdates[key].Action != 'DELETE')
94 return 'One or more parameter values were invalid: ' +
95 'Only DELETE action is allowed when no attribute value is specified'
96 if (data.AttributeUpdates[key].Value != null && data.AttributeUpdates[key].Action == 'DELETE') {
97 var type = Object.keys(data.AttributeUpdates[key].Value)[0]
98 if (type != 'SS' && type != 'NS' && type != 'BS')
99 return 'One or more parameter values were invalid: ' +
100 'DELETE action with value is not supported for the type ' + type
101 }
102 if (data.AttributeUpdates[key].Value != null && data.AttributeUpdates[key].Action == 'ADD') {
103 type = Object.keys(data.AttributeUpdates[key].Value)[0]
104 if (type != 'L' && type != 'SS' && type != 'NS' && type != 'BS' && type != 'N')
105 return 'One or more parameter values were invalid: ' +
106 'ADD action is not supported for the type ' + type
107 }
108 }
109
110 msg = validations.validateAttributeConditions(data)
111 if (msg) return msg
112
113 msg = validations.validateExpressions(data)
114 if (msg) return msg
115}