-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor(azure-bicep-resource): Refactor schema usage (#21402)
Co-authored-by: Michael Kriese <michael.kriese@visualon.de>
- Loading branch information
Showing
3 changed files
with
99 additions
and
98 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 |
---|---|---|
@@ -1,25 +1,45 @@ | ||
import { z } from 'zod'; | ||
|
||
export const BicepTypeIndex = z.object({ | ||
Resources: z.record( | ||
z.string(), | ||
z.object({ | ||
RelativePath: z.string(), | ||
Index: z.number(), | ||
}) | ||
), | ||
Functions: z.record( | ||
z.string(), | ||
z.record( | ||
export const BicepResourceVersionIndex = z | ||
.object({ | ||
Resources: z.record( | ||
z.string(), | ||
z.array( | ||
z.object({ | ||
RelativePath: z.string(), | ||
Index: z.number(), | ||
}) | ||
z.object({ | ||
RelativePath: z.string(), | ||
Index: z.number(), | ||
}) | ||
), | ||
Functions: z.record( | ||
z.string(), | ||
z.record( | ||
z.string(), | ||
z.array( | ||
z.object({ | ||
RelativePath: z.string(), | ||
Index: z.number(), | ||
}) | ||
) | ||
) | ||
) | ||
), | ||
}); | ||
), | ||
}) | ||
.transform(({ Resources, Functions }) => { | ||
const releaseMap = new Map<string, string[]>(); | ||
|
||
for (const resourceReference of Object.keys(Resources)) { | ||
const [type, version] = resourceReference.toLowerCase().split('@', 2); | ||
const versions = releaseMap.get(type) ?? []; | ||
versions.push(version); | ||
releaseMap.set(type, versions); | ||
} | ||
|
||
for (const [type, versionMap] of Object.entries(Functions)) { | ||
const versions = Object.keys(versionMap); | ||
releaseMap.set(type, versions); | ||
} | ||
|
||
return Object.fromEntries(releaseMap); | ||
}); | ||
|
||
export type BicepTypeIndex = z.infer<typeof BicepTypeIndex>; | ||
export type BicepResourceVersionIndex = z.infer< | ||
typeof BicepResourceVersionIndex | ||
>; |