Skip to content

Commit

Permalink
feat: make default latest version supported be the 2nd latest
Browse files Browse the repository at this point in the history
  • Loading branch information
scolladon committed Sep 26, 2023
1 parent 4f087ca commit 12dfef8
Showing 1 changed file with 14 additions and 11 deletions.
25 changes: 14 additions & 11 deletions src/metadata/metadataManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,17 @@ const buildAPIMap = async () => {
.forEach((file: string) => {
const version: number = parseInt(file.match(/\d+/)?.[0] as string)
_apiMap.set(version, file)
_latestVersion = Math.max(_latestVersion, version)
})
setLatestSupportedVersion()
}
}

const setLatestSupportedVersion = () => {
const versions: number[] = Array.from(_apiMap.keys())
versions.sort((a, b) => a - b)
_latestVersion = versions[versions.length - 2]
}

export const getLatestSupportedVersion = async () => {
await buildAPIMap()
return _latestVersion
Expand All @@ -41,23 +47,20 @@ export const isVersionSupported = async (version: number) => {
export const getDefinition = async (
apiVersion: number
): Promise<MetadataRepository> => {
if (!describeMetadata.has(apiVersion)) {
await buildAPIMap()
const apiFile = (
_apiMap.has(apiVersion)
? _apiMap.get(apiVersion)
: _apiMap.get(_latestVersion)
) as string
await buildAPIMap()
const version: number = _apiMap.has(apiVersion) ? apiVersion : _latestVersion
if (!describeMetadata.has(version)) {
const apiFile = _apiMap.get(version)
const fileContent: string = await readFile(
resolve(__dirname, apiFile),
resolve(__dirname, apiFile!),
'utf-8'
)
describeMetadata.set(apiVersion, JSON.parse(fileContent))
describeMetadata.set(version, JSON.parse(fileContent))
}

const metadataRepository: MetadataRepository = new Map<string, Metadata>()
describeMetadata
.get(apiVersion)
.get(version)
?.reduce((metadata: MetadataRepository, describe: Metadata) => {
metadata.set(describe.directoryName, describe)
return metadata
Expand Down

0 comments on commit 12dfef8

Please sign in to comment.