-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: consider replacing any usage of any with unknown #59
- Loading branch information
Showing
10 changed files
with
151 additions
and
28 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
import { injectable } from 'inversify'; | ||
import { IPackageInfo, IPackageInfoOptions } from '../../utils/packageInfo'; | ||
import { ILoggerFactory } from '../../utils/logger'; | ||
import { ILogger } from '../../utils/logger/interfaces/ILogger'; | ||
import { DependencyVersion, IDependencyVersionRepositoryProvider } from '../../db'; | ||
import { IPackageInfoCache, IPackageInfoCacheOptions, IUpdateCommitShaOptions } from '../interfaces/IPackageInfoCache'; | ||
import { memoize } from '../../utils/memoize/memoize'; | ||
|
||
const keyBuilder = ({ name, semver }: IPackageInfoOptions): string => { | ||
return `${name}@${semver}`; | ||
}; | ||
|
||
@injectable() | ||
export class PackageInfoCache extends IPackageInfoCache { | ||
private readonly logger: ILogger; | ||
|
||
constructor( | ||
private readonly packageInfo: IPackageInfo, | ||
private readonly dependencyVersionRepositoryProvider: IDependencyVersionRepositoryProvider, | ||
loggerFactory: ILoggerFactory | ||
) { | ||
super(); | ||
this.logger = loggerFactory.getLogger(`Package Info Cache`); | ||
} | ||
|
||
@memoize(keyBuilder) | ||
public async getPackageInfo({ name, semver }: IPackageInfoCacheOptions): Promise<DependencyVersion> { | ||
this.logger.info(`Checking if package info is cached ${name}@$${semver}`); | ||
const dependencyVersionRepository = await this.dependencyVersionRepositoryProvider.getRepository(); | ||
try { | ||
const cachedDependencyVersion = await dependencyVersionRepository.findOne({ | ||
name, | ||
semver, | ||
}); | ||
if (cachedDependencyVersion) { | ||
this.logger.info(`Located cached package info for ${name}@$${semver}`); | ||
return cachedDependencyVersion; | ||
} else { | ||
this.logger.info(`No cached package info for ${name}@$${semver}`); | ||
} | ||
} catch (err) { | ||
this.logger.error(`Failed to locate cached package info for ${name}@$${semver}`, err); | ||
} | ||
this.logger.debug(`Locating package info for ${name}@$${semver}`); | ||
const packageInfo = await this.packageInfo.getPackageInfo({ | ||
semver, | ||
name, | ||
}); | ||
const dependencyVersion = new DependencyVersion({ | ||
...packageInfo, | ||
engines: packageInfo.engines || null, | ||
commitSha: packageInfo.commitSha || null, | ||
releaseDate: packageInfo.releaseDate || null, | ||
repoUrl: packageInfo.repoUrl || null, | ||
}); | ||
this.logger.debug(`Saving package info for ${name}@$${semver} in cache`); | ||
await dependencyVersionRepository.save(dependencyVersion); | ||
return dependencyVersion; | ||
} | ||
|
||
public async updateCommitSha({ commitSha, dependencyVersion }: IUpdateCommitShaOptions): Promise<void> { | ||
this.logger.debug( | ||
`Updating commit sha of package info ${dependencyVersion.name}@$${dependencyVersion.semver} to ${commitSha}` | ||
); | ||
const dependencyVersionRepository = await this.dependencyVersionRepositoryProvider.getRepository(); | ||
dependencyVersion.commitSha = commitSha; | ||
await dependencyVersionRepository.update( | ||
{ | ||
name: dependencyVersion.name, | ||
semver: dependencyVersion.semver, | ||
}, | ||
{ | ||
commitSha, | ||
} | ||
); | ||
this.logger.debug( | ||
`Done updating commit sha of package info ${dependencyVersion.name}@$${dependencyVersion.semver}` | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
import { DependencyVersion } from '../../db'; | ||
|
||
export interface IPackageInfoCacheOptions { | ||
name: string; | ||
semver: string; | ||
} | ||
|
||
export interface IUpdateCommitShaOptions { | ||
dependencyVersion: DependencyVersion; | ||
commitSha: string; | ||
} | ||
|
||
export abstract class IPackageInfoCache { | ||
public abstract async getPackageInfo(options: IPackageInfoCacheOptions): Promise<DependencyVersion>; | ||
public abstract async updateCommitSha(options: IUpdateCommitShaOptions): Promise<void>; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters