import { Either, type IEither } from "@emprespresso/pengueno"; export const validateIdentifier = (token: string) => { return /^[a-zA-Z0-9_\-:. \/]+$/.test(token) && !token.includes(".."); }; // ensure {@param obj} is a Record with stuff that won't // have the potential for shell injection, just to be super safe. type InvalidEntry = [K, T]; export const validateExecutionEntries = < T, K extends symbol | number | string = symbol | number | string, >( obj: Record, ): IEither>, Record> => { const invalidEntries = >>( Object.entries(obj).filter( (e) => !e.every((x) => typeof x === "string" && validateIdentifier(x)), ) ); if (invalidEntries.length > 0) return Either.left(invalidEntries); return Either.right(>obj); };