function parseComponentCFilter()

in packages/@aws-c2a/engine/lib/rules/rule-parser.ts [92:114]


function parseComponentCFilter(selector: ComponentCFilter): SelectorFilter {
  const { name, ...shortform} = selector;
  let { type, subtype } = selector;

  const shortformKeys = Object.keys(shortform);
  if(shortformKeys.length + ((isDefined(type) || isDefined(subtype)) ? 1 : 0) > 1)
    throw Error('Cannot specify type or subtype more than once');

  if(shortformKeys.length){
    type = shortformKeys[0];
    const tmpSubtype = (shortform as {[type: string]: string})[type];
    if(typeof tmpSubtype !== 'string')
      throw Error('Shortform of component selector must have a string subtype');
    subtype = tmpSubtype;
  }

  return {
    entityType: ModelEntityTypes.component,
    type,
    ...subtype ? {subtype} : {},
    ...name ? {name} : {},
  };
}