1 | var validations = require('./index'),
|
2 | db = require('../db')
|
3 |
|
4 | exports.types = {
|
5 | ReturnConsumedCapacity: {
|
6 | type: 'String',
|
7 | enum: ['INDEXES', 'TOTAL', 'NONE'],
|
8 | },
|
9 | TableName: {
|
10 | type: 'String',
|
11 | notNull: true,
|
12 | regex: '[a-zA-Z0-9_.-]+',
|
13 | lengthGreaterThanOrEqual: 3,
|
14 | lengthLessThanOrEqual: 255,
|
15 | },
|
16 | Item: {
|
17 | type: 'Map<AttributeValue>',
|
18 | notNull: true,
|
19 | children: 'AttrStruct<ValueStruct>',
|
20 | },
|
21 | ConditionalOperator: {
|
22 | type: 'String',
|
23 | enum: ['OR', 'AND'],
|
24 | },
|
25 | Expected: {
|
26 | type: 'Map<ExpectedAttributeValue>',
|
27 | children: {
|
28 | type: 'ValueStruct<ExpectedAttributeValue>',
|
29 | children: {
|
30 | AttributeValueList: {
|
31 | type: 'List',
|
32 | children: 'AttrStruct<ValueStruct>',
|
33 | },
|
34 | ComparisonOperator: {
|
35 | type: 'String',
|
36 | enum: ['IN', 'NULL', 'BETWEEN', 'LT', 'NOT_CONTAINS', 'EQ', 'GT', 'NOT_NULL', 'NE', 'LE', 'BEGINS_WITH', 'GE', 'CONTAINS'],
|
37 | },
|
38 | Exists: 'Boolean',
|
39 | Value: 'AttrStruct<FieldStruct>',
|
40 | },
|
41 | },
|
42 | },
|
43 | ReturnValues: {
|
44 | type: 'String',
|
45 | enum: ['ALL_NEW', 'UPDATED_OLD', 'ALL_OLD', 'NONE', 'UPDATED_NEW'],
|
46 | },
|
47 | ReturnItemCollectionMetrics: {
|
48 | type: 'String',
|
49 | enum: ['SIZE', 'NONE'],
|
50 | },
|
51 | ConditionExpression: {
|
52 | type: 'String',
|
53 | },
|
54 | ExpressionAttributeValues: {
|
55 | type: 'Map<AttributeValue>',
|
56 | children: 'AttrStruct<ValueStruct>',
|
57 | },
|
58 | ExpressionAttributeNames: {
|
59 | type: 'Map<java.lang.String>',
|
60 | children: 'String',
|
61 | },
|
62 | }
|
63 |
|
64 | exports.custom = function(data, store) {
|
65 |
|
66 | var msg = validations.validateExpressionParams(data, ['ConditionExpression'], ['Expected'])
|
67 | if (msg) return msg
|
68 |
|
69 | for (var key in data.Item) {
|
70 | msg = validations.validateAttributeValue(data.Item[key])
|
71 | if (msg) return msg
|
72 | }
|
73 |
|
74 | if (data.ReturnValues && data.ReturnValues != 'ALL_OLD' && data.ReturnValues != 'NONE')
|
75 | return 'ReturnValues can only be ALL_OLD or NONE'
|
76 |
|
77 | if (db.itemSize(data.Item) > store.options.maxItemSize)
|
78 | return 'Item size has exceeded the maximum allowed size'
|
79 |
|
80 | msg = validations.validateAttributeConditions(data)
|
81 | if (msg) return msg
|
82 |
|
83 | msg = validations.validateExpressions(data)
|
84 | if (msg) return msg
|
85 | }
|