operation.js
2.84 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
var Shape = require('./shape');
var util = require('../util');
var property = util.property;
var memoizedProperty = util.memoizedProperty;
function Operation(name, operation, options) {
var self = this;
options = options || {};
property(this, 'name', operation.name || name);
property(this, 'api', options.api, false);
operation.http = operation.http || {};
property(this, 'endpoint', operation.endpoint);
property(this, 'httpMethod', operation.http.method || 'POST');
property(this, 'httpPath', operation.http.requestUri || '/');
property(this, 'authtype', operation.authtype || '');
property(
this,
'endpointDiscoveryRequired',
operation.endpointdiscovery ?
(operation.endpointdiscovery.required ? 'REQUIRED' : 'OPTIONAL') :
'NULL'
);
memoizedProperty(this, 'input', function() {
if (!operation.input) {
return new Shape.create({type: 'structure'}, options);
}
return Shape.create(operation.input, options);
});
memoizedProperty(this, 'output', function() {
if (!operation.output) {
return new Shape.create({type: 'structure'}, options);
}
return Shape.create(operation.output, options);
});
memoizedProperty(this, 'errors', function() {
var list = [];
if (!operation.errors) return null;
for (var i = 0; i < operation.errors.length; i++) {
list.push(Shape.create(operation.errors[i], options));
}
return list;
});
memoizedProperty(this, 'paginator', function() {
return options.api.paginators[name];
});
if (options.documentation) {
property(this, 'documentation', operation.documentation);
property(this, 'documentationUrl', operation.documentationUrl);
}
// idempotentMembers only tracks top-level input shapes
memoizedProperty(this, 'idempotentMembers', function() {
var idempotentMembers = [];
var input = self.input;
var members = input.members;
if (!input.members) {
return idempotentMembers;
}
for (var name in members) {
if (!members.hasOwnProperty(name)) {
continue;
}
if (members[name].isIdempotent === true) {
idempotentMembers.push(name);
}
}
return idempotentMembers;
});
memoizedProperty(this, 'hasEventOutput', function() {
var output = self.output;
return hasEventStream(output);
});
}
function hasEventStream(topLevelShape) {
var members = topLevelShape.members;
var payload = topLevelShape.payload;
if (!topLevelShape.members) {
return false;
}
if (payload) {
var payloadMember = members[payload];
return payloadMember.isEventStream;
}
// check if any member is an event stream
for (var name in members) {
if (!members.hasOwnProperty(name)) {
if (members[name].isEventStream === true) {
return true;
}
}
}
return false;
}
/**
* @api private
*/
module.exports = Operation;