-
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.
Merge branch 'new-fpl' into new-fpl-db-tests
- Loading branch information
Showing
10 changed files
with
1,252 additions
and
52 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
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
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,39 @@ | ||
import { loggerSpy } from '../testhelpers'; | ||
import { DefaultRegistryClient } from '../../src/registry/DefaultRegistryClient'; | ||
import { NPMRegistryClient } from '../../src/registry/NPMRegistryClient'; | ||
import { FHIRRegistryClient } from '../../src/registry/FHIRRegistryClient'; | ||
|
||
describe('DefaultRegistryClient', () => { | ||
describe('#constructor', () => { | ||
beforeEach(() => { | ||
loggerSpy.reset(); | ||
delete process.env.FPL_REGISTRY; | ||
}); | ||
|
||
it('should make a client with custom registry when it has been specified', () => { | ||
process.env.FPL_REGISTRY = 'https://custom-registry.example.org'; | ||
const defaultClient = new DefaultRegistryClient({ log: loggerSpy.log }); | ||
expect(defaultClient.clients).toHaveLength(1); | ||
expect(defaultClient.clients[0]).toHaveProperty( | ||
'endpoint', | ||
'https://custom-registry.example.org' | ||
); | ||
expect(defaultClient.clients[0]).toBeInstanceOf(NPMRegistryClient); | ||
expect(loggerSpy.getLastMessage('info')).toBe( | ||
'Using custom registry specified by FPL_REGISTRY environment variable: https://custom-registry.example.org' | ||
); | ||
}); | ||
|
||
it('should make a client with fhir registries if no custom registry specified', () => { | ||
const defaultClient = new DefaultRegistryClient({ log: loggerSpy.log }); | ||
expect(defaultClient.clients).toHaveLength(2); | ||
expect(defaultClient.clients[0]).toHaveProperty('endpoint', 'https://packages.fhir.org'); | ||
expect(defaultClient.clients[0]).toBeInstanceOf(FHIRRegistryClient); | ||
expect(defaultClient.clients[1]).toHaveProperty( | ||
'endpoint', | ||
'https://packages2.fhir.org/packages' | ||
); | ||
expect(defaultClient.clients[1]).toBeInstanceOf(FHIRRegistryClient); | ||
}); | ||
}); | ||
}); |
Oops, something went wrong.