@puls-atlas/cli
Version:
The Puls Atlas CLI tool for managing Atlas projects
28 lines • 1.34 kB
JavaScript
import addFirestore from './addFirestore.js';
import addHttp from './addHttp.js';
import { normalizeOptionalString } from '../../../utils/index.js';
const DEFAULT_SEARCH_SOURCE_ADD_TYPE = 'firestore';
const SUPPORTED_SEARCH_SOURCE_ADD_TYPES = [DEFAULT_SEARCH_SOURCE_ADD_TYPE, 'http'];
export const resolveSearchSourceAddType = (options = {}) => {
const sourceType = normalizeOptionalString(options.type)?.toLowerCase() ?? DEFAULT_SEARCH_SOURCE_ADD_TYPE;
if (!SUPPORTED_SEARCH_SOURCE_ADD_TYPES.includes(sourceType)) {
throw new Error(`Atlas search source add supports only --type ${SUPPORTED_SEARCH_SOURCE_ADD_TYPES.join(' or ')} right now.`);
}
return sourceType;
};
export const runSearchSourceAdd = async (options = {}, dependencies = {}, cwd = process.cwd()) => {
const sourceType = resolveSearchSourceAddType(options);
const runSearchFirestoreSourceAddImpl = dependencies.runSearchFirestoreSourceAddImpl ?? addFirestore;
const runSearchHttpSourceAddImpl = dependencies.runSearchHttpSourceAddImpl ?? addHttp;
if (sourceType === 'http') {
return runSearchHttpSourceAddImpl({
...options,
type: 'http'
}, dependencies, cwd);
}
return runSearchFirestoreSourceAddImpl({
...options,
type: 'firestore'
}, dependencies, cwd);
};
export default async options => runSearchSourceAdd(options);