UNPKG

3.29 kBJavaScriptView Raw
1var validations = require('./index')
2
3exports.types = {
4 Select: {
5 type: 'String',
6 enum: ['SPECIFIC_ATTRIBUTES', 'COUNT', 'ALL_ATTRIBUTES', 'ALL_PROJECTED_ATTRIBUTES'],
7 },
8 IndexName: {
9 type: 'String',
10 regex: '[a-zA-Z0-9_.-]+',
11 lengthGreaterThanOrEqual: 3,
12 lengthLessThanOrEqual: 255,
13 },
14 TotalSegments: {
15 type: 'Integer',
16 greaterThanOrEqual: 1,
17 },
18 ReturnConsumedCapacity: {
19 type: 'String',
20 enum: ['INDEXES', 'TOTAL', 'NONE'],
21 },
22 TableName: {
23 type: 'String',
24 notNull: true,
25 regex: '[a-zA-Z0-9_.-]+',
26 lengthGreaterThanOrEqual: 3,
27 lengthLessThanOrEqual: 255,
28 },
29 ConditionalOperator: {
30 type: 'String',
31 enum: ['OR', 'AND'],
32 },
33 ScanFilter: {
34 type: 'Map<Condition>',
35 children: {
36 type: 'ValueStruct<Condition>',
37 children: {
38 AttributeValueList: {
39 type: 'List',
40 children: 'AttrStruct<ValueStruct>',
41 },
42 ComparisonOperator: {
43 type: 'String',
44 notNull: true,
45 enum: ['IN', 'NULL', 'BETWEEN', 'LT', 'NOT_CONTAINS', 'EQ', 'GT', 'NOT_NULL', 'NE', 'LE', 'BEGINS_WITH', 'GE', 'CONTAINS'],
46 },
47 },
48 },
49 },
50 Segment: {
51 type: 'Integer',
52 greaterThanOrEqual: 0,
53 },
54 AttributesToGet: {
55 type: 'List',
56 lengthGreaterThanOrEqual: 1,
57 lengthLessThanOrEqual: 255,
58 children: 'String',
59 },
60 Limit: {
61 type: 'Integer',
62 greaterThanOrEqual: 1,
63 },
64 ExclusiveStartKey: {
65 type: 'Map<AttributeValue>',
66 children: 'AttrStruct<ValueStruct>',
67 },
68 FilterExpression: {
69 type: 'String',
70 },
71 ProjectionExpression: {
72 type: 'String',
73 },
74 ExpressionAttributeValues: {
75 type: 'Map<AttributeValue>',
76 children: 'AttrStruct<ValueStruct>',
77 },
78 ExpressionAttributeNames: {
79 type: 'Map<java.lang.String>',
80 children: 'String',
81 },
82}
83
84exports.custom = function(data) {
85
86 var msg = validations.validateExpressionParams(data,
87 ['ProjectionExpression', 'FilterExpression'],
88 ['AttributesToGet', 'ScanFilter', 'ConditionalOperator'])
89 if (msg) return msg
90
91 if (data.AttributesToGet) {
92 msg = validations.findDuplicate(data.AttributesToGet)
93 if (msg) return 'One or more parameter values were invalid: Duplicate value in attribute name: ' + msg
94 }
95
96 msg = validations.validateConditions(data.ScanFilter)
97 if (msg) return msg
98
99 for (var key in data.ExclusiveStartKey) {
100 msg = validations.validateAttributeValue(data.ExclusiveStartKey[key])
101 if (msg) return 'The provided starting key is invalid: ' + msg
102 }
103
104 if (data.Segment && data.TotalSegments == null) {
105 return 'The TotalSegments parameter is required but was not present in the request when Segment parameter is present'
106 }
107
108 if (data.TotalSegments) {
109 if (data.Segment == null) {
110 return 'The Segment parameter is required but was not present in the request when parameter TotalSegments is present'
111 }
112 if (data.Segment >= data.TotalSegments) {
113 return 'The Segment parameter is zero-based and must be less than parameter TotalSegments: ' +
114 'Segment: ' + data.Segment + ' is not less than TotalSegments: ' + data.TotalSegments
115 }
116 }
117
118 msg = validations.validateExpressions(data, ['ProjectionExpression', 'FilterExpression'])
119 if (msg) return msg
120}