api.js
3.12 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
var Collection = require('./collection');
var Operation = require('./operation');
var Shape = require('./shape');
var Paginator = require('./paginator');
var ResourceWaiter = require('./resource_waiter');
var metadata = require('../../apis/metadata.json');
var util = require('../util');
var property = util.property;
var memoizedProperty = util.memoizedProperty;
function Api(api, options) {
var self = this;
api = api || {};
options = options || {};
options.api = this;
api.metadata = api.metadata || {};
var serviceIdentifier = options.serviceIdentifier;
delete options.serviceIdentifier;
property(this, 'isApi', true, false);
property(this, 'apiVersion', api.metadata.apiVersion);
property(this, 'endpointPrefix', api.metadata.endpointPrefix);
property(this, 'signingName', api.metadata.signingName);
property(this, 'globalEndpoint', api.metadata.globalEndpoint);
property(this, 'signatureVersion', api.metadata.signatureVersion);
property(this, 'jsonVersion', api.metadata.jsonVersion);
property(this, 'targetPrefix', api.metadata.targetPrefix);
property(this, 'protocol', api.metadata.protocol);
property(this, 'timestampFormat', api.metadata.timestampFormat);
property(this, 'xmlNamespaceUri', api.metadata.xmlNamespace);
property(this, 'abbreviation', api.metadata.serviceAbbreviation);
property(this, 'fullName', api.metadata.serviceFullName);
property(this, 'serviceId', api.metadata.serviceId);
if (serviceIdentifier && metadata[serviceIdentifier]) {
property(this, 'xmlNoDefaultLists', metadata[serviceIdentifier].xmlNoDefaultLists, false);
}
memoizedProperty(this, 'className', function() {
var name = api.metadata.serviceAbbreviation || api.metadata.serviceFullName;
if (!name) return null;
name = name.replace(/^Amazon|AWS\s*|\(.*|\s+|\W+/g, '');
if (name === 'ElasticLoadBalancing') name = 'ELB';
return name;
});
function addEndpointOperation(name, operation) {
if (operation.endpointoperation === true) {
property(self, 'endpointOperation', util.string.lowerFirst(name));
}
if (operation.endpointdiscovery && !self.hasRequiredEndpointDiscovery) {
property(
self,
'hasRequiredEndpointDiscovery',
operation.endpointdiscovery.required === true
);
}
}
property(this, 'operations', new Collection(api.operations, options, function(name, operation) {
return new Operation(name, operation, options);
}, util.string.lowerFirst, addEndpointOperation));
property(this, 'shapes', new Collection(api.shapes, options, function(name, shape) {
return Shape.create(shape, options);
}));
property(this, 'paginators', new Collection(api.paginators, options, function(name, paginator) {
return new Paginator(name, paginator, options);
}));
property(this, 'waiters', new Collection(api.waiters, options, function(name, waiter) {
return new ResourceWaiter(name, waiter, options);
}, util.string.lowerFirst));
if (options.documentation) {
property(this, 'documentation', api.documentation);
property(this, 'documentationUrl', api.documentationUrl);
}
}
/**
* @api private
*/
module.exports = Api;