UNPKG

2.43 kBJavaScriptView Raw
1var validations = require('./index'),
2 db = require('../db')
3
4exports.types = {
5 ReturnConsumedCapacity: {
6 type: 'String',
7 enum: ['INDEXES', 'TOTAL', 'NONE'],
8 },
9 ReturnItemCollectionMetrics: {
10 type: 'String',
11 enum: ['SIZE', 'NONE'],
12 },
13 RequestItems: {
14 type: 'Map<java.util.List<com.amazonaws.dynamodb.v20120810.WriteRequest>>',
15 notNull: true,
16 lengthGreaterThanOrEqual: 1,
17 keys: {
18 lengthLessThanOrEqual: 255,
19 lengthGreaterThanOrEqual: 3,
20 regex: '[a-zA-Z0-9_.-]+',
21 },
22 values: {
23 lengthLessThanOrEqual: 25,
24 lengthGreaterThanOrEqual: 1,
25 },
26 children: {
27 type: 'ParameterizedList',
28 children: {
29 type: 'ValueStruct<WriteRequest>',
30 children: {
31 DeleteRequest: {
32 type: 'FieldStruct<DeleteRequest>',
33 children: {
34 Key: {
35 type: 'Map<AttributeValue>',
36 notNull: true,
37 children: 'AttrStruct<ValueStruct>',
38 },
39 },
40 },
41 PutRequest: {
42 type: 'FieldStruct<PutRequest>',
43 children: {
44 Item: {
45 type: 'Map<AttributeValue>',
46 notNull: true,
47 children: 'AttrStruct<ValueStruct>',
48 },
49 },
50 },
51 },
52 },
53 },
54 },
55}
56
57exports.custom = function(data, store) {
58 var table, i, request, key, msg
59 for (table in data.RequestItems) {
60 if (data.RequestItems[table].some(function(item) { return !Object.keys(item).length })) // eslint-disable-line no-loop-func
61 return 'Supplied AttributeValue has more than one datatypes set, ' +
62 'must contain exactly one of the supported datatypes'
63 for (i = 0; i < data.RequestItems[table].length; i++) {
64 request = data.RequestItems[table][i]
65 if (request.PutRequest) {
66 for (key in request.PutRequest.Item) {
67 msg = validations.validateAttributeValue(request.PutRequest.Item[key])
68 if (msg) return msg
69 }
70 if (db.itemSize(request.PutRequest.Item) > store.options.maxItemSize)
71 return 'Item size has exceeded the maximum allowed size'
72 } else if (request.DeleteRequest) {
73 for (key in request.DeleteRequest.Key) {
74 msg = validations.validateAttributeValue(request.DeleteRequest.Key[key])
75 if (msg) return msg
76 }
77 }
78 }
79 }
80}