-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
pull common tests into registryClientHelper, sync up fhir and npm reg…
…istry client tests, add in versioning check to npm client, cleanup
- Loading branch information
1 parent
47f0078
commit c5a322e
Showing
5 changed files
with
607 additions
and
294 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
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,45 @@ | ||
import { IncorrectWildcardVersionFormatError, LatestVersionUnavailableError } from '../errors'; | ||
import { axiosGet } from '../utils'; | ||
import { maxSatisfying } from 'semver'; | ||
|
||
export async function lookUpLatestVersion(endpoint: string, name: string): Promise<string> { | ||
try { | ||
const res = await axiosGet(`${endpoint}/${name}`, { | ||
responseType: 'json' | ||
}); | ||
if (res?.data?.['dist-tags']?.latest?.length) { | ||
return res.data['dist-tags'].latest; | ||
} else { | ||
throw new LatestVersionUnavailableError(name); | ||
} | ||
} catch { | ||
throw new LatestVersionUnavailableError(name); | ||
} | ||
} | ||
|
||
export async function lookUpLatestPatchVersion( | ||
endpoint: string, | ||
name: string, | ||
version: string | ||
): Promise<string> { | ||
if (!/^\d+\.\d+\.x$/.test(version)) { | ||
throw new IncorrectWildcardVersionFormatError(name, version); | ||
} | ||
try { | ||
const res = await axiosGet(`${endpoint}/${name}`, { | ||
responseType: 'json' | ||
}); | ||
if (res?.data?.versions) { | ||
const versions = Object.keys(res.data.versions); | ||
const latest = maxSatisfying(versions, version); | ||
if (latest == null) { | ||
throw new LatestVersionUnavailableError(name, null, true); | ||
} | ||
return latest; | ||
} else { | ||
throw new LatestVersionUnavailableError(name, null, true); | ||
} | ||
} catch { | ||
throw new LatestVersionUnavailableError(name, null, true); | ||
} | ||
} |
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
Oops, something went wrong.