ramda#indexBy TypeScript Examples
The following examples show how to use
ramda#indexBy.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: annotations.ts From spotbugs-github-action with MIT License | 5 votes |
export function annotationsForPath(resultFile: string): Annotation[] {
core.info(`Creating annotations for ${resultFile}`)
const root: string = process.env['GITHUB_WORKSPACE'] || ''
const result: FindbugsResult = parser.parse(
fs.readFileSync(resultFile, 'UTF-8' as BufferEncoding),
XML_PARSE_OPTIONS
)
const violations = asArray(result?.BugCollection?.BugInstance)
const bugPatterns: {[type: string]: BugPattern} = indexBy(
a => a.type,
asArray(result?.BugCollection?.BugPattern)
)
core.info(`${resultFile} has ${violations.length} violations`)
const getFilePath: (sourcePath: string) => string | undefined = memoizeWith(
identity,
(sourcePath: string) =>
asArray(result?.BugCollection?.Project?.SrcDir).find(SrcDir => {
const combinedPath = path.join(SrcDir, sourcePath)
const fileExists = fs.existsSync(combinedPath)
core.debug(`${combinedPath} ${fileExists ? 'does' : 'does not'} exists`)
return fileExists
})
)
return chain(BugInstance => {
const annotationsForBug: Annotation[] = []
const sourceLines = asArray(BugInstance.SourceLine)
const primarySourceLine: SourceLine | undefined =
sourceLines.length > 1
? sourceLines.find(sl => sl.primary)
: sourceLines[0]
const SrcDir: string | undefined =
primarySourceLine?.sourcepath &&
getFilePath(primarySourceLine?.sourcepath)
if (primarySourceLine?.start && SrcDir) {
const annotation: Annotation = {
annotation_level: AnnotationLevel.warning,
path: path.relative(
root,
path.join(SrcDir, primarySourceLine?.sourcepath)
),
start_line: Number(primarySourceLine?.start || 1),
end_line: Number(
primarySourceLine?.end || primarySourceLine?.start || 1
),
title: BugInstance.type,
message: BugInstance.LongMessage,
raw_details: htmlToText(
decode(bugPatterns[BugInstance.type].Details),
HTML_TO_TEXT_OPTIONS
)
}
annotationsForBug.push(annotation)
} else {
core.debug(
`Skipping bug instance because source line start or source directory are missing`
)
}
return annotationsForBug
}, violations)
}
Example #2
Source File: processDatabase.ts From kanel with MIT License | 4 votes |
processDatabase = async ({
connection,
preDeleteModelFolder = false,
customTypeMap = {},
modelHooks = [],
modelNominator = nameIdentity,
propertyNominator = (propertyName) =>
propertyName.indexOf(' ') !== -1 ? `'${propertyName}'` : propertyName,
initializerNominator = (modelName) => `${modelName}Initializer`,
idNominator = (modelName) => `${modelName}Id`,
makeIdType = (innerType, modelName) =>
`${innerType} & { " __flavor"?: '${modelName}' };`,
typeHooks = [],
typeNominator = nameIdentity,
fileNominator = identity,
resolveViews = false,
schemas,
...unknownProps
}: Config) => {
if (!isEmpty(unknownProps)) {
logger.warn(
`Unknown configuration properties: ${Object.keys(unknownProps).join(
', '
)}`
);
}
const typeMap = { ...defaultTypeMap, ...customTypeMap };
/** @type {import('./Config').Nominators} */
const nominators = {
modelNominator,
propertyNominator,
initializerNominator,
idNominator,
typeNominator,
fileNominator,
};
const modelProcessChain = [...defaultHooks, ...modelHooks];
const typeProcessChain = [...defaultHooks, ...typeHooks];
if (typeof connection === 'string') {
logger.log(`Connecting to ${chalk.greenBright(connection)}`);
} else {
logger.log(
`Connecting to ${chalk.greenBright(connection.database)} on ${
connection.host
}`
);
}
const schemaFolderMap = map(
(s: SchemaConfig) => path.resolve(s.modelFolder),
indexBy((s) => s.name, schemas)
) as Record<string, string>;
for (const schemaConfig of schemas) {
const schema = await extractSchema(
schemaConfig.name,
connection,
schemaConfig.resolveViews !== undefined
? schemaConfig.resolveViews
: resolveViews
);
if (preDeleteModelFolder) {
logger.log(` - Clearing old files in ${schemaConfig.modelFolder}`);
await rmfr(schemaConfig.modelFolder, { glob: true });
}
if (!fs.existsSync(schemaConfig.modelFolder)) {
fs.mkdirSync(schemaConfig.modelFolder, { recursive: true });
}
await processSchema(
schemaConfig,
schema,
typeMap,
nominators,
modelProcessChain,
typeProcessChain,
schemaFolderMap,
makeIdType
);
}
}