-
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.
Put interfaces and their implementations into folders based on their purpose: db, registry, current, loader.
- Loading branch information
Showing
24 changed files
with
219 additions
and
174 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
17 changes: 4 additions & 13 deletions
17
src/CurrentBuildClient.ts → src/current/BuildDotFhirDotOrgClient.ts
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,10 @@ | ||
import { LogFunction } from '../utils'; | ||
|
||
export type CurrentBuildClientOptions = { | ||
log?: LogFunction; | ||
}; | ||
|
||
export interface CurrentBuildClient { | ||
downloadCurrentBuild(name: string, branch: string | null, cachePath: string): Promise<string>; | ||
getCurrentBuildDate(name: string, branch?: string): Promise<string>; | ||
} |
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,2 @@ | ||
export * from './CurrentBuildClient'; | ||
export * from './BuildDotFhirDotOrgClient'; |
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,11 @@ | ||
import { PackageInfo, PackageStats, ResourceInfo } from '../package'; | ||
|
||
export interface PackageDB { | ||
clear(): void; | ||
savePackageInfo(info: PackageInfo): void; | ||
saveResourceInfo(info: ResourceInfo): void; | ||
findPackageInfo(name: string, version: string): PackageInfo | undefined; | ||
findResourceInfos(key: string): ResourceInfo[]; | ||
findResourceInfo(key: string): ResourceInfo | undefined; | ||
getPackageStats(name: string, version: string): PackageStats | undefined; | ||
} |
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,2 @@ | ||
export * from './PackageDB'; | ||
export * from './SQLJSPackageDB'; |
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 |
---|---|---|
@@ -1,4 +1,6 @@ | ||
export * from './CurrentPackageLoadError'; | ||
export * from './IncorrectWildcardVersionFormatError'; | ||
export * from './InvalidPackageError'; | ||
export * from './InvalidResourceError'; | ||
export * from './LatestVersionUnavailableError'; | ||
export * from './PackageLoadError'; |
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 @@ | ||
export * from './PackageLoader'; |
File renamed without changes.
File renamed without changes.
File renamed without changes.
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,3 @@ | ||
export * from './PackageInfo'; | ||
export * from './PackageStats'; | ||
export * from './ResourceInfo'; |
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,42 @@ | ||
import { LogFunction } from '../utils'; | ||
import { FHIRRegistryClient } from './FHIRRegistryClient'; | ||
import { NPMRegistryClient } from './NPMRegistryClient'; | ||
import { RedundantRegistryClient } from './RedundantRegistryClient'; | ||
import { RegistryClient, RegistryClientOptions } from './RegistryClient'; | ||
|
||
const FHIR_PACKAGES_ENDPOINT = 'https://packages.fhir.org'; | ||
const FHIR_PACKAGES2_ENDPOINT = 'https://packages2.fhir.org/packages'; | ||
|
||
export class DefaultRegistryClient extends RedundantRegistryClient { | ||
constructor(options?: RegistryClientOptions) { | ||
let clients: RegistryClient[]; | ||
// If a custom registry has been specified, use that | ||
const customRegistry = getCustomRegistry(options.log); | ||
if (customRegistry) { | ||
clients = [new NPMRegistryClient(customRegistry, options)]; | ||
} | ||
// Otherwise use packages.fhir.org w/ packages2.fhir.org fallback | ||
else { | ||
clients = [ | ||
new FHIRRegistryClient(FHIR_PACKAGES_ENDPOINT, options), | ||
new FHIRRegistryClient(FHIR_PACKAGES2_ENDPOINT, options) | ||
]; | ||
} | ||
super(clients, options); | ||
} | ||
} | ||
|
||
let hasLoggedCustomRegistry = false; | ||
|
||
function getCustomRegistry(log: LogFunction = () => {}) { | ||
if (process.env.FPL_REGISTRY) { | ||
if (!hasLoggedCustomRegistry) { | ||
hasLoggedCustomRegistry = true; | ||
log( | ||
'info', | ||
`Using custom registry specified by FPL_REGISTRY environment variable: ${process.env.FPL_REGISTRY}` | ||
); | ||
} | ||
return process.env.FPL_REGISTRY; | ||
} | ||
} |
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,21 @@ | ||
import { downloadPackageTarballToCache } from '../download'; | ||
import { LogFunction } from '../utils'; | ||
import { RegistryClient, RegistryClientOptions } from './RegistryClient'; | ||
|
||
export class FHIRRegistryClient implements RegistryClient { | ||
public endpoint: string; | ||
private log: LogFunction; | ||
|
||
constructor(endpoint: string, options?: RegistryClientOptions) { | ||
// Remove trailing '/' from endpoint if applicable | ||
this.endpoint = endpoint.replace(/\/$/, ''); | ||
this.log = options.log ?? (() => {}); | ||
} | ||
|
||
async download(name: string, version: string, cachePath: string): Promise<string> { | ||
// Construct URL from endpoint, name, and version | ||
// See: https://confluence.hl7.org/pages/viewpage.action?pageId=97454344#FHIRPackageRegistryUserDocumentation-Download | ||
const url = `${this.endpoint}/${name}/${version}`; | ||
return downloadPackageTarballToCache(name, version, url, cachePath, this.log); | ||
} | ||
} |
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,27 @@ | ||
import { downloadPackageTarballToCache } from '../download'; | ||
import { LogFunction, axiosGet } from '../utils'; | ||
import { RegistryClient, RegistryClientOptions } from './RegistryClient'; | ||
|
||
export class NPMRegistryClient implements RegistryClient { | ||
public endpoint: string; | ||
private log: LogFunction; | ||
|
||
constructor(endpoint: string, options?: RegistryClientOptions) { | ||
// Remove trailing '/' from endpoint if applicable | ||
this.endpoint = endpoint.replace(/\/$/, ''); | ||
this.log = options.log ?? (() => {}); | ||
} | ||
|
||
async download(name: string, version: string, cachePath: string): Promise<string> { | ||
// Get the manifest information about the package from the registry | ||
const res = await axiosGet(`${this.endpoint}/${name}`); | ||
// Find the NPM tarball location in the manifest | ||
let url = res.data?.versions?.[version]?.dist?.tarball; | ||
// If tarball URL is not found, fallback to standard NPM approach per | ||
// https://docs.fire.ly/projects/Simplifier/features/api.html#package-server-api | ||
if (!url) { | ||
url = `${this.endpoint}/${name}/-/${name}-${version}.tgz`; | ||
} | ||
return downloadPackageTarballToCache(name, version, url, cachePath, this.log); | ||
} | ||
} |
Oops, something went wrong.