api.js 3.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. var Collection = require('./collection');
  2. var Operation = require('./operation');
  3. var Shape = require('./shape');
  4. var Paginator = require('./paginator');
  5. var ResourceWaiter = require('./resource_waiter');
  6. var metadata = require('../../apis/metadata.json');
  7. var util = require('../util');
  8. var property = util.property;
  9. var memoizedProperty = util.memoizedProperty;
  10. function Api(api, options) {
  11. var self = this;
  12. api = api || {};
  13. options = options || {};
  14. options.api = this;
  15. api.metadata = api.metadata || {};
  16. var serviceIdentifier = options.serviceIdentifier;
  17. delete options.serviceIdentifier;
  18. property(this, 'isApi', true, false);
  19. property(this, 'apiVersion', api.metadata.apiVersion);
  20. property(this, 'endpointPrefix', api.metadata.endpointPrefix);
  21. property(this, 'signingName', api.metadata.signingName);
  22. property(this, 'globalEndpoint', api.metadata.globalEndpoint);
  23. property(this, 'signatureVersion', api.metadata.signatureVersion);
  24. property(this, 'jsonVersion', api.metadata.jsonVersion);
  25. property(this, 'targetPrefix', api.metadata.targetPrefix);
  26. property(this, 'protocol', api.metadata.protocol);
  27. property(this, 'timestampFormat', api.metadata.timestampFormat);
  28. property(this, 'xmlNamespaceUri', api.metadata.xmlNamespace);
  29. property(this, 'abbreviation', api.metadata.serviceAbbreviation);
  30. property(this, 'fullName', api.metadata.serviceFullName);
  31. property(this, 'serviceId', api.metadata.serviceId);
  32. if (serviceIdentifier && metadata[serviceIdentifier]) {
  33. property(this, 'xmlNoDefaultLists', metadata[serviceIdentifier].xmlNoDefaultLists, false);
  34. }
  35. memoizedProperty(this, 'className', function() {
  36. var name = api.metadata.serviceAbbreviation || api.metadata.serviceFullName;
  37. if (!name) return null;
  38. name = name.replace(/^Amazon|AWS\s*|\(.*|\s+|\W+/g, '');
  39. if (name === 'ElasticLoadBalancing') name = 'ELB';
  40. return name;
  41. });
  42. function addEndpointOperation(name, operation) {
  43. if (operation.endpointoperation === true) {
  44. property(self, 'endpointOperation', util.string.lowerFirst(name));
  45. }
  46. if (operation.endpointdiscovery && !self.hasRequiredEndpointDiscovery) {
  47. property(
  48. self,
  49. 'hasRequiredEndpointDiscovery',
  50. operation.endpointdiscovery.required === true
  51. );
  52. }
  53. }
  54. property(this, 'operations', new Collection(api.operations, options, function(name, operation) {
  55. return new Operation(name, operation, options);
  56. }, util.string.lowerFirst, addEndpointOperation));
  57. property(this, 'shapes', new Collection(api.shapes, options, function(name, shape) {
  58. return Shape.create(shape, options);
  59. }));
  60. property(this, 'paginators', new Collection(api.paginators, options, function(name, paginator) {
  61. return new Paginator(name, paginator, options);
  62. }));
  63. property(this, 'waiters', new Collection(api.waiters, options, function(name, waiter) {
  64. return new ResourceWaiter(name, waiter, options);
  65. }, util.string.lowerFirst));
  66. if (options.documentation) {
  67. property(this, 'documentation', api.documentation);
  68. property(this, 'documentationUrl', api.documentationUrl);
  69. }
  70. property(this, 'awsQueryCompatible', api.metadata.awsQueryCompatible);
  71. }
  72. /**
  73. * @api private
  74. */
  75. module.exports = Api;