@puls-atlas/cli
Version:
The Puls Atlas CLI tool for managing Atlas projects
63 lines • 2.19 kB
JavaScript
import { isBoolean, isString, isEmpty, isPlainObject } from 'es-toolkit/compat';
const normalizeCapabilityFlags = capabilities => {
if (capabilities === undefined) {
return {};
}
if (!isPlainObject(capabilities)) {
throw new Error('Atlas search provider descriptor capabilities must be an object.');
}
for (const [capabilityName, capabilityValue] of Object.entries(capabilities)) {
if (!isBoolean(capabilityValue)) {
throw new Error(`Atlas search provider capability "${capabilityName}" must be a boolean.`);
}
}
return {
...capabilities
};
};
const normalizeLabels = labels => {
if (labels === undefined) {
return {
access: 'Provider access',
targetGroup: 'Provider targets'
};
}
if (!isPlainObject(labels)) {
throw new Error('Atlas search provider descriptor labels must be an object.');
}
if (!isString(labels.access) || isEmpty(labels.access)) {
throw new Error('Atlas search provider descriptor labels.access must be a string.');
}
if (!isString(labels.targetGroup) || isEmpty(labels.targetGroup)) {
throw new Error('Atlas search provider descriptor labels.targetGroup must be a string.');
}
return {
access: labels.access,
targetGroup: labels.targetGroup
};
};
export class SearchProviderDescriptor {
constructor({
capabilities,
configSectionKey = null,
displayName,
id,
labels
}) {
if (!isString(id) || isEmpty(id.trim())) {
throw new Error('Atlas search provider descriptor id must be a non-empty string.');
}
if (!isString(displayName) || isEmpty(displayName.trim())) {
throw new Error('Atlas search provider descriptor displayName must be a non-empty string.');
}
if (configSectionKey !== null && (!isString(configSectionKey) || isEmpty(configSectionKey.trim()))) {
throw new Error('Atlas search provider descriptor configSectionKey must be a string or null.');
}
this.id = id;
this.displayName = displayName;
this.configSectionKey = configSectionKey;
this.capabilities = normalizeCapabilityFlags(capabilities);
this.labels = normalizeLabels(labels);
}
}
export default SearchProviderDescriptor;