import { getErrorDocumentSchema, getErrorSchema } from './jsonapi.ts'; import { z } from './zod-openapi.ts'; export function mapKeys< T extends object, M extends (k: Extract) => PropertyKey, >(obj: T, fn: M) { return Object.fromEntries( Object.entries(obj).map(([key, value]) => { // @ts-expect-error: we assume T has no extra properties so key is // a valid key of T. return [fn(key), value]; }), ) as { [K in keyof T as ReturnType]: T[K] }; } // Common types export const StringOrArrayOfStrings = z .union([z.string(), z.array(z.string())]) .openapi('StringOrArrayOfStrings'); export const ForbiddenErrorResponse = getErrorDocumentSchema( getErrorSchema({ code: 'FORBIDDEN', statusText: 'Forbidden', statusCode: 403, }), ).openapi('ForbiddenErrorResponse');