Skip to content

Commit

Permalink
More validation here
Browse files Browse the repository at this point in the history
  • Loading branch information
mxcl committed Jul 20, 2022
1 parent 020f846 commit e3d02fc
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
7 changes: 5 additions & 2 deletions src/hooks/usePantry.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Package, PackageRequirement, Path, PlainObject, SemVer } from "types"
import useGitHubAPI from "hooks/useGitHubAPI.ts"
import { run, flatMap, isNumber, isPlainObject, isString, isArray, isPrimitive, undent, isBoolean, validatePlainObject, validateString } from "utils"
import { run, flatMap, isNumber, isPlainObject, isString, isArray, isPrimitive, undent, isBoolean, validatePlainObject, validateString, validateArray } from "utils"
import useCellar from "hooks/useCellar.ts"
import usePlatform from "hooks/usePlatform.ts"
import { validatePackageRequirement } from "utils/lvl2.ts"
Expand Down Expand Up @@ -46,7 +46,10 @@ export default function usePantry(): Response {

async function github(): Promise<boolean> {
const yml = await files.yml()
const ignoredVersions = yml['ignore-versions']?.map((v: string) => new RegExp(v))
const ignoredVersions = flatMap(flatMap(
yml['ignore-versions'],
x => validateArray<string>(x)),
x => x.map(v => new RegExp(v)))
try {
const { user, repo } = get()
rv = await useGitHubAPI().getVersions({ user, repo, ignoredVersions })
Expand Down
6 changes: 6 additions & 0 deletions src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,12 @@ export function validatePlainObject(input: any): PlainObject {
return input
}

// deno-lint-ignore no-explicit-any
export function validateArray<T>(input: any): Array<T> {
if (!isArray(input)) throw new Error(`not-array: ${JSON.stringify(input)}`)
return input
}

///////////////////////////////////////////////////////////////////////// HTTP
import { cache, File, Policy, configure } from "mxcl/deno-cache"

Expand Down

0 comments on commit e3d02fc

Please sign in to comment.