library: possiblyUndefinedStringToMaybe()

in src/object-generation-parsing-utils.ts [123:198]


        library: possiblyUndefinedStringToMaybe(typeDefinition['library']),
        file: possiblyUndefinedStringToMaybe(typeDefinition['file']),
        canForwardDeclare: booleanFromString(
          typeDefinition['canForwardDeclare'],
          true,
        ),
      });
    }, soFar);
  } else {
    return Either.match(
      function (errors: Error.Error[]) {
        return Either.Left<Error.Error[], ObjectGeneration.TypeLookup[]>(
          errors.concat(Error.Error('Invalid type annotation')),
        );
      },
      function (typeLookups: ObjectGeneration.TypeLookup[]) {
        return Either.Left<Error.Error[], ObjectGeneration.TypeLookup[]>([
          Error.Error('Invalid type annotation'),
        ]);
      },
      soFar,
    );
  }
}

export function typeLookupsFromRawAnnotations(annotations: {
  [name: string]: {[key: string]: string}[];
}): Either.Either<Error.Error[], ObjectGeneration.TypeLookup[]> {
  const typeDefinitions = annotationValuesFromAnnotations(annotations, 'type');
  return Maybe.match(
    function (annotationValues: {[key: string]: string}[]) {
      return annotationValues.reduce(
        collectTypeLookups,
        Either.Right<Error.Error[], ObjectGeneration.TypeLookup[]>([]),
      );
    },
    function () {
      return Either.Right<Error.Error[], ObjectGeneration.TypeLookup[]>([]);
    },
    typeDefinitions,
  );
}

export function typeLookupsFromAnnotations(
  annotations: ObjectGeneration.Annotation[] | null,
): Either.Either<Error.Error[], ObjectGeneration.TypeLookup[]> {
  return Maybe.match(
    function (annotations: ObjectGeneration.Annotation[]) {
      const annotationProperties = annotations.map(function (
        annotation: ObjectGeneration.Annotation,
      ): {[key: string]: string} {
        return annotation.properties;
      });
      return annotationProperties.reduce(
        collectTypeLookups,
        Either.Right<Error.Error[], ObjectGeneration.TypeLookup[]>([]),
      );
    },
    function () {
      return Either.Right<Error.Error[], ObjectGeneration.TypeLookup[]>([]);
    },
    annotations,
  );
}

export function foundAnnotationFromParsedAnnotations(parsedAnnotations: {
  [name: string]: {[key: string]: string}[];
}): {[key: string]: ObjectGeneration.Annotation[]} {
  const foundAnnotations: {[key: string]: ObjectGeneration.Annotation[]} = {};
  for (const parsedAnnotationName in parsedAnnotations) {
    foundAnnotations[parsedAnnotationName] = parsedAnnotations[
      parsedAnnotationName
    ].map(function (parsedInstance: {
      [key: string]: string;
    }): ObjectGeneration.Annotation {
      return {