UNPKG

@datastax/astra-db-ts

Version:
20 lines (19 loc) 791 B
// Copyright Datastax, Inc // SPDX-License-Identifier: Apache-2.0 import { oneOrMany } from '../../lib/utils.js'; import { either, nullish, string, tuple } from 'decoders'; import { OptionsHandler } from '../../lib/opts-handlers.js'; import { CLIENT_USER_AGENT } from '../../lib/api/constants.js'; const decoder = nullish(oneOrMany(either(tuple(string), tuple(string, string))), []); const transformer = decoder.transform((config) => { const callers = ((Array.isArray(config[0])) ? config : [config]); const callerString = callers.map((c) => { return (c[1]) ? `${c[0]}/${c[1]}` : c[0]; }).join(' '); return { userAgent: `${CLIENT_USER_AGENT} ${callerString}`.trim(), }; }); export const CallerCfgHandler = new OptionsHandler(transformer);