@azure/functions-extensions-servicebus
Version:
Node.js Azure ServiceBus extension implementations for Azure Functions
33 lines (27 loc) • 1.28 kB
text/typescript
// Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the MIT License.
import minimist from 'minimist';
/**
* GrpcUriBuilder is a utility class to build a gRPC URI from command line arguments.
* It expects two arguments: 'host' and 'port'.
*/
export class GrpcUriBuilder {
/**
* Builds a gRPC URI from command line arguments.
* The expected arguments are 'host' and 'port'.
* @returns A string representing the gRPC URI in the format "host:port".
* @throws Error if 'host' or 'port' arguments are missing.
*/
static build(): { uri: string; grpcMaxMessageLength: number } {
const parsedArgs = minimist(process.argv.slice(2));
const { host, port, 'functions-grpc-max-message-length': grpcMaxMessageLength } = parsedArgs;
const missing: string[] = [];
if (!host) missing.push("'host'");
if (!port) missing.push("'port'");
if (!grpcMaxMessageLength) missing.push("'functions-grpc-max-message-length'");
if (missing.length) {
throw new Error(`Missing required arguments: ${missing.join(', ')}`);
}
return { uri: `${String(host)}:${String(port)}`, grpcMaxMessageLength: Number(grpcMaxMessageLength) };
}
}