export type InputRecord = Record export function inputRecord(value: unknown): InputRecord { if (value === null || typeof value !== 'object' || Array.isArray(value)) { throw new Error('Input must be an object.') } return value as InputRecord } export function requiredString(input: InputRecord, key: string): string { const value = input[key] if (typeof value !== 'string' || value.trim().length === 0) { throw new Error(key + ' is required.') } return value } export function optionalString(input: InputRecord, key: string): string | undefined { const value = input[key] if (value === undefined || value === null || value === '') return undefined if (typeof value !== 'string') throw new Error(key + ' must be a string.') return value } export function boundedPageSize(value: unknown, fallback = 100): number { if (value === undefined || value === null) return fallback if (!Number.isInteger(value) || Number(value) < 1 || Number(value) > 100) { throw new Error('pageSize must be an integer from 1 through 100.') } return Number(value) } export function optionalRecord(input: InputRecord, key: string): InputRecord | undefined { const value = input[key] if (value === undefined || value === null) return undefined if (typeof value !== 'object' || Array.isArray(value)) { throw new Error(key + ' must be an object.') } return value as InputRecord } export function requiredRecord(input: InputRecord, key: string): InputRecord { const value = optionalRecord(input, key) if (value === undefined) throw new Error(key + ' is required.') return value } export function optionalArray(input: InputRecord, key: string): unknown[] | undefined { const value = input[key] if (value === undefined || value === null) return undefined if (!Array.isArray(value)) throw new Error(key + ' must be an array.') return value }