UNPKG

5.48 kBJavaScriptView Raw
1exports.types = {
2 TableName: {
3 type: 'String',
4 required: true,
5 tableName: true,
6 regex: '[a-zA-Z0-9_.-]+',
7 },
8 ProvisionedThroughput: {
9 type: 'FieldStruct<ProvisionedThroughput>',
10 children: {
11 WriteCapacityUnits: {
12 type: 'Long',
13 notNull: true,
14 greaterThanOrEqual: 1,
15 },
16 ReadCapacityUnits: {
17 type: 'Long',
18 notNull: true,
19 greaterThanOrEqual: 1,
20 },
21 },
22 },
23 GlobalSecondaryIndexUpdates: {
24 type: 'List',
25 children: {
26 type: 'ValueStruct<GlobalSecondaryIndexUpdate>',
27 children: {
28 Update: {
29 type: 'FieldStruct<UpdateGlobalSecondaryIndexAction>',
30 children: {
31 IndexName: {
32 type: 'String',
33 notNull: true,
34 regex: '[a-zA-Z0-9_.-]+',
35 lengthGreaterThanOrEqual: 3,
36 lengthLessThanOrEqual: 255,
37 },
38 ProvisionedThroughput: {
39 type: 'FieldStruct<ProvisionedThroughput>',
40 notNull: true,
41 children: {
42 WriteCapacityUnits: {
43 type: 'Long',
44 notNull: true,
45 greaterThanOrEqual: 1,
46 },
47 ReadCapacityUnits: {
48 type: 'Long',
49 notNull: true,
50 greaterThanOrEqual: 1,
51 },
52 },
53 },
54 },
55 },
56 Create: {
57 type: 'FieldStruct<CreateGlobalSecondaryIndexAction>',
58 children: {
59 Projection: {
60 type: 'FieldStruct<Projection>',
61 notNull: true,
62 children: {
63 ProjectionType: {
64 type: 'String',
65 enum: ['ALL', 'INCLUDE', 'KEYS_ONLY'],
66 },
67 NonKeyAttributes: {
68 type: 'List',
69 lengthGreaterThanOrEqual: 1,
70 children: 'String',
71 },
72 },
73 },
74 IndexName: {
75 type: 'String',
76 notNull: true,
77 regex: '[a-zA-Z0-9_.-]+',
78 lengthGreaterThanOrEqual: 3,
79 lengthLessThanOrEqual: 255,
80 },
81 ProvisionedThroughput: {
82 type: 'FieldStruct<ProvisionedThroughput>',
83 notNull: true,
84 children: {
85 WriteCapacityUnits: {
86 type: 'Long',
87 notNull: true,
88 greaterThanOrEqual: 1,
89 },
90 ReadCapacityUnits: {
91 type: 'Long',
92 notNull: true,
93 greaterThanOrEqual: 1,
94 },
95 },
96 },
97 KeySchema: {
98 type: 'List',
99 notNull: true,
100 lengthGreaterThanOrEqual: 1,
101 lengthLessThanOrEqual: 2,
102 children: {
103 type: 'ValueStruct<KeySchemaElement>',
104 children: {
105 AttributeName: {
106 type: 'String',
107 notNull: true,
108 },
109 KeyType: {
110 type: 'String',
111 notNull: true,
112 },
113 },
114 },
115 },
116 },
117 },
118 Delete: {
119 type: 'FieldStruct<DeleteGlobalSecondaryIndexAction>',
120 children: {
121 IndexName: {
122 type: 'String',
123 notNull: true,
124 regex: '[a-zA-Z0-9_.-]+',
125 lengthGreaterThanOrEqual: 3,
126 lengthLessThanOrEqual: 255,
127 },
128 },
129 },
130 },
131 },
132 },
133}
134
135exports.custom = function(data) {
136
137 if (!data.ProvisionedThroughput && !data.UpdateStreamEnabled &&
138 (!data.GlobalSecondaryIndexUpdates || !data.GlobalSecondaryIndexUpdates.length) && !data.SSESpecification) {
139 return 'At least one of ProvisionedThroughput, UpdateStreamEnabled, GlobalSecondaryIndexUpdates or SSESpecification is required'
140 }
141
142 if (data.ProvisionedThroughput) {
143 if (data.ProvisionedThroughput.ReadCapacityUnits > 1000000000000)
144 return 'Given value ' + data.ProvisionedThroughput.ReadCapacityUnits + ' for ReadCapacityUnits is out of bounds'
145 if (data.ProvisionedThroughput.WriteCapacityUnits > 1000000000000)
146 return 'Given value ' + data.ProvisionedThroughput.WriteCapacityUnits + ' for WriteCapacityUnits is out of bounds'
147 }
148
149 if (data.GlobalSecondaryIndexUpdates) {
150 var length = data.GlobalSecondaryIndexUpdates.length
151 var indexNames = Object.create(null)
152 for (var i = 0; i < length; i++) {
153 var update = data.GlobalSecondaryIndexUpdates[i]
154 if (!update.Update && !update.Create && !update.Delete) {
155 return 'One or more parameter values were invalid: ' +
156 'One of GlobalSecondaryIndexUpdate.Update, GlobalSecondaryIndexUpdate.Create, ' +
157 'GlobalSecondaryIndexUpdate.Delete must not be null'
158 }
159 var indexName = (update.Update && update.Update.IndexName) ||
160 (update.Create && update.Create.IndexName) ||
161 (update.Delete && update.Delete.IndexName)
162 if (indexNames[indexName]) {
163 return 'One or more parameter values were invalid: ' +
164 'Only one global secondary index update per index is allowed simultaneously. Index: ' + indexName
165 }
166 indexNames[indexName] = true
167 }
168 }
169}
170