Page MenuHomeSealhub

props-parser.ts
No OneTemporary

props-parser.ts

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<string, unknown>;
// 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<PropsType> {
abstract decode(ctx: Context): Record<string, FormDataValue>;
abstract encode(props: Record<string, FormData>): EncodedProps;
abstract getHTMLInputName(prop_name: string): string;
overwriteProp(ctx: Context, new_props: Partial<PropsType>): EncodedProps {
const result = {};
merge.recursive(result, this.decode(ctx), new_props);
return result;
}
}
export class AllQueryParams<
PropsType extends BasePageProps
> extends PagePropsParser<PropsType> {
decode(ctx: Context): Record<string, FormDataValue> {
return ctx.query;
}
encode(props: PropsType): Record<string, unknown> {
return props;
}
getHTMLInputName(prop_name: string): string {
return prop_name;
}
}

File Metadata

Mime Type
text/x-java
Expires
Thu, Jan 23, 19:19 (14 h, 19 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
600738
Default Alt Text
props-parser.ts (1 KB)

Event Timeline