UNPKG

@christiangalsterer/node-postgres-prometheus-exporter

Version:
64 lines 2.6 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.mergeLabelNamesWithStandardLabels = mergeLabelNamesWithStandardLabels; exports.mergeLabelsWithStandardLabels = mergeLabelsWithStandardLabels; exports.getMaxPoolSize = getMaxPoolSize; exports.getHost = getHost; exports.getPort = getPort; exports.getDatabase = getDatabase; /** * Merges an array of label names with the label names of the default labels into a new array. * @param labelNames array of label names to merge with the default labels * @param defaultLabels default labels to merge with * @returns array of merged label names */ function mergeLabelNamesWithStandardLabels(labelNames, defaultLabels = {}) { return labelNames.concat(Object.keys(defaultLabels)); } /** * Merges Labels with default labels * @param labels labels to merge with the default labels * @param defaultLabels default labels to merge with * @returns merged labels */ function mergeLabelsWithStandardLabels(labels, defaultLabels = {}) { const filtered = Object.fromEntries(Object.entries(labels) .filter(([key, value]) => value !== undefined) .map(([key, value]) => [key, value])); return { ...filtered, ...defaultLabels }; } /** * Tries to determine the max pool size from the pool via direct property access as the configuration is not exported * @param pool the pool from which to get the property * @returns the configured max pool size or undefined */ function getMaxPoolSize(pool) { return pool.options.max; } /** * Tries to determine the host configuration from the pool via direct property access as the configuration is not exported * @param pool the pool from which to get the property * @returns the configured host or undefined */ function getHost(pool) { return pool.options.host ?? undefined; } /** * Tries to determine the port configuration from the pool via direct property access as the configuration is not exported * @param pool the pool from which to get the property * @returns the configured port or 5432 if not set * @see https://node-postgres.com/api/pool#pool-connection-parameters */ function getPort(pool) { // eslint-disable-next-line @typescript-eslint/no-magic-numbers return pool.options.port ?? 5432; } /** * Tries to determine the database configuration from the pool via direct property access as the configuration is not exported * @param pool the pool from which to get the property * @returns the configured database or undefined */ function getDatabase(pool) { return pool.options.database; } //# sourceMappingURL=utils.js.map