UNPKG

@puls-atlas/cli

Version:

The Puls Atlas CLI tool for managing Atlas projects

19 lines 1 kB
import { normalizeOptionalString } from '../../utils/value.js'; export const parseRequestedSearchIndexes = (indexesArgument, availableIndexNames) => { if (!Array.isArray(availableIndexNames) || availableIndexNames.length === 0) { throw new Error('Atlas search requires at least one configured index.'); } const normalizedArgument = normalizeOptionalString(indexesArgument); if (!normalizedArgument) { return [...availableIndexNames]; } const requestedIndexNames = [...new Set(normalizedArgument.split(',').map(indexName => indexName.trim()).filter(Boolean))]; if (requestedIndexNames.length === 0) { throw new Error('Atlas search index scope must contain at least one valid index name.'); } const invalidIndexNames = requestedIndexNames.filter(indexName => !availableIndexNames.includes(indexName)); if (invalidIndexNames.length > 0) { throw new Error(`Atlas search received unknown index names: ${invalidIndexNames.join(', ')}.`); } return requestedIndexNames; };