import { Context } from "koa"; import merge from "merge"; import { FormDataValue } from "../forms/form-types.js"; import type { BasePageProps } from "./list.js"; export type EncodedProps = Record; // page props parser is only tasked with getting the raw props from *somewhere* // and being able to put new values back to that somewhere. Parsing to numbers // or any other exotic types is done by fields logic. export abstract class PagePropsParser { abstract decode(ctx: Context): Record; abstract encode(props: Record): EncodedProps; abstract getHTMLInputName(prop_name: string): string; overwriteProp(ctx: Context, new_props: Partial): EncodedProps { const result = {}; merge.recursive(result, this.decode(ctx), new_props); return result; } } export class AllQueryParams< PropsType extends BasePageProps, > extends PagePropsParser { decode(ctx: Context): Record { return ctx.query; } encode(props: PropsType): Record { return props; } getHTMLInputName(prop_name: string): string { return prop_name; } }