@azure/eventgrid
Version:
An isomorphic client library for the Azure Event Grid service.
126 lines • 5.31 kB
JavaScript
/*
* Copyright (c) Microsoft Corporation.
* Licensed under the MIT License.
*
* Code generated by Microsoft (R) AutoRest Code Generator.
* Changes may cause incorrect behavior and will be lost if the code is regenerated.
*/
import * as coreClient from "@azure/core-client";
import * as Parameters from "./models/parameters.js";
import * as Mappers from "./models/mappers.js";
/** @internal */
export class GeneratedClient extends coreClient.ServiceClient {
/**
* Initializes a new instance of the GeneratedClient class.
* @param options The parameter options
*/
constructor(options) {
var _a, _b;
// Initializing default values for options
if (!options) {
options = {};
}
const defaults = {
requestContentType: "application/json; charset=utf-8",
};
const packageDetails = `azsdk-js-eventgrid/5.12.0`;
const userAgentPrefix = options.userAgentOptions && options.userAgentOptions.userAgentPrefix
? `${options.userAgentOptions.userAgentPrefix} ${packageDetails}`
: `${packageDetails}`;
const optionsWithDefaults = Object.assign(Object.assign(Object.assign({}, defaults), options), { userAgentOptions: {
userAgentPrefix,
}, endpoint: (_b = (_a = options.endpoint) !== null && _a !== void 0 ? _a : options.baseUri) !== null && _b !== void 0 ? _b : "{topicHostname}" });
super(optionsWithDefaults);
// Assigning values to Constant parameters
this.apiVersion = options.apiVersion || "2018-01-01";
this.addCustomApiVersionPolicy(options.apiVersion);
}
/** A function that adds a policy that sets the api-version (or equivalent) to reflect the library version. */
addCustomApiVersionPolicy(apiVersion) {
if (!apiVersion) {
return;
}
const apiVersionPolicy = {
name: "CustomApiVersionPolicy",
async sendRequest(request, next) {
const param = request.url.split("?");
if (param.length > 1) {
const newParams = param[1].split("&").map((item) => {
if (item.indexOf("api-version") > -1) {
return "api-version=" + apiVersion;
}
else {
return item;
}
});
request.url = param[0] + "?" + newParams.join("&");
}
return next(request);
},
};
this.pipeline.addPolicy(apiVersionPolicy);
}
/**
* Publishes a batch of events to an Azure Event Grid topic.
* @param topicHostname The host name of the topic, e.g. topic1.westus2-1.eventgrid.azure.net
* @param events An array of events to be published to Event Grid.
* @param options The options parameters.
*/
publishEventGridEvents(topicHostname, events, options) {
return this.sendOperationRequest({ topicHostname, events, options }, publishEventGridEventsOperationSpec);
}
/**
* Publishes a batch of events to an Azure Event Grid topic.
* @param topicHostname The host name of the topic, e.g. topic1.westus2-1.eventgrid.azure.net
* @param events An array of events to be published to Event Grid.
* @param options The options parameters.
*/
publishCloudEventEvents(topicHostname, events, options) {
return this.sendOperationRequest({ topicHostname, events, options }, publishCloudEventEventsOperationSpec);
}
/**
* Publishes a batch of events to an Azure Event Grid topic.
* @param topicHostname The host name of the topic, e.g. topic1.westus2-1.eventgrid.azure.net
* @param events An array of events to be published to Event Grid.
* @param options The options parameters.
*/
publishCustomEventEvents(topicHostname, events, options) {
return this.sendOperationRequest({ topicHostname, events, options }, publishCustomEventEventsOperationSpec);
}
}
// Operation Specifications
const serializer = coreClient.createSerializer(Mappers, /* isXml */ false);
const publishEventGridEventsOperationSpec = {
path: "",
httpMethod: "POST",
responses: { 200: {}, default: {} },
requestBody: Parameters.events,
queryParameters: [Parameters.apiVersion],
urlParameters: [Parameters.topicHostname],
headerParameters: [Parameters.contentType],
mediaType: "json",
serializer,
};
const publishCloudEventEventsOperationSpec = {
path: "",
httpMethod: "POST",
responses: { 200: {}, default: {} },
requestBody: Parameters.events1,
queryParameters: [Parameters.apiVersion],
urlParameters: [Parameters.topicHostname],
headerParameters: [Parameters.contentType1, Parameters.aegChannelName],
mediaType: "json",
serializer,
};
const publishCustomEventEventsOperationSpec = {
path: "",
httpMethod: "POST",
responses: { 200: {}, default: {} },
requestBody: Parameters.events2,
queryParameters: [Parameters.apiVersion],
urlParameters: [Parameters.topicHostname],
headerParameters: [Parameters.contentType],
mediaType: "json",
serializer,
};
//# sourceMappingURL=generatedClient.js.map