@azure/event-hubs
Version:
Azure Event Hubs SDK for JS.
109 lines (108 loc) • 4.44 kB
JavaScript
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __export = (target, all) => {
for (var name in all)
__defProp(target, name, { get: all[name], enumerable: true });
};
var __copyProps = (to, from, except, desc) => {
if (from && typeof from === "object" || typeof from === "function") {
for (let key of __getOwnPropNames(from))
if (!__hasOwnProp.call(to, key) && key !== except)
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
}
return to;
};
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
var eventhubConnectionConfig_exports = {};
__export(eventhubConnectionConfig_exports, {
EventHubConnectionConfig: () => EventHubConnectionConfig
});
module.exports = __toCommonJS(eventhubConnectionConfig_exports);
var import_core_amqp = require("@azure/core-amqp");
var import_parseEndpoint = require("./util/parseEndpoint.js");
const EventHubConnectionConfig = {
/**
* Creates the connection config.
* @param connectionString - The connection string for a given service like
* EventHub/ServiceBus.
* @param path - The name/path of the entity (hub name) to which the
* connection needs to happen. This will override the EntityPath in the connectionString
* if present.
* @returns EventHubConnectionConfig
*/
create(connectionString, path) {
const config = import_core_amqp.ConnectionConfig.create(connectionString, path);
if (!config.entityPath) {
throw new TypeError(
`Either provide "path" or the "connectionString": "${connectionString}", must contain EntityPath="<path-to-the-entity>".`
);
}
return EventHubConnectionConfig.createFromConnectionConfig(config);
},
/**
* Creates an EventHubConnectionConfig from the provided base ConnectionConfig.
* @param config - The base connection config from which the EventHubConnectionConfig needs to be
* created.
* @returns EventHubConnectionConfig
*/
createFromConnectionConfig(config) {
import_core_amqp.ConnectionConfig.validate(config, { isEntityPathRequired: true });
config.getManagementAudience = () => {
return `${config.endpoint}${config.entityPath}/$management`;
};
config.getManagementAddress = () => {
return `${config.entityPath}/$management`;
};
config.getSenderAudience = (partitionId) => {
if (partitionId != void 0) {
return `${config.endpoint}${config.entityPath}/Partitions/${partitionId}`;
} else {
return `${config.endpoint}${config.entityPath}`;
}
};
config.getSenderAddress = (partitionId) => {
if (partitionId != void 0) {
return `${config.entityPath}/Partitions/${partitionId}`;
} else {
return `${config.entityPath}`;
}
};
config.getReceiverAudience = (partitionId, consumergroup) => {
if (!consumergroup) consumergroup = "$default";
return `${config.endpoint}${config.entityPath}/ConsumerGroups/${consumergroup}/Partitions/${partitionId}`;
};
config.getReceiverAddress = (partitionId, consumergroup) => {
if (!consumergroup) consumergroup = "$default";
return `${config.entityPath}/ConsumerGroups/${consumergroup}/Partitions/${partitionId}`;
};
return config;
},
/**
* Updates the provided EventHubConnectionConfig to use the custom endpoint address.
* @param config - An existing connection configuration to be updated.
* @param customEndpointAddress - The custom endpoint address to use.
*/
setCustomEndpointAddress(config, customEndpointAddress) {
config.amqpHostname = config.host;
const { hostname, port } = (0, import_parseEndpoint.parseEndpoint)(customEndpointAddress);
config.host = hostname;
if (port) {
config.port = parseInt(port, 10);
}
},
/**
* Validates the properties of connection config.
* @param config - The connection config to be validated.
* @returns void
*/
validate(config) {
return import_core_amqp.ConnectionConfig.validate(config, { isEntityPathRequired: true });
}
};
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
EventHubConnectionConfig
});
//# sourceMappingURL=eventhubConnectionConfig.js.map