bknd
Version:
Lightweight Firebase/Supabase alternative built to run anywhere — incl. Next.js, React Router, Astro, Cloudflare, Bun, Node, AWS Lambda & more.
78 lines (77 loc) • 4 kB
TypeScript
import type { EntityManager } from "../../data/entities";
import { Field, type TActionContext, type TRenderContext } from "./Field";
import type { TFieldTSType } from "../../data/entities/EntityTypescript";
import { s } from "bknd/utils";
export declare const enumFieldConfigSchema: s.ObjectSchema<{
readonly description: s.Schema<s.ISchemaOptions, string | undefined, string | undefined>;
readonly required: s.Schema<s.ISchemaOptions, boolean | undefined, boolean | undefined>;
readonly label: s.Schema<s.ISchemaOptions, string | undefined, string | undefined>;
readonly fillable: s.Schema<s.ISchemaOptions, boolean | ("create" | "read" | "update" | "delete")[] | undefined, boolean | ("create" | "read" | "update" | "delete")[] | undefined>;
readonly hidden: s.Schema<s.ISchemaOptions, boolean | ("table" | "create" | "read" | "update" | "delete" | "form" | "submit")[] | undefined, boolean | ("table" | "create" | "read" | "update" | "delete" | "form" | "submit")[] | undefined>;
readonly virtual: s.Schema<s.ISchemaOptions, boolean | undefined, boolean | undefined>;
readonly default_value: s.Schema<s.ISchemaOptions, string | undefined, string | undefined>;
readonly options: s.Schema<s.ISchemaOptions, {
[x: string]: unknown;
values: string[];
type: "strings";
} | {
[x: string]: unknown;
values: {
[x: string]: unknown;
value: string;
label: string;
}[];
type: "objects";
} | undefined, any>;
}, s.Merge<s.IObjectOptions & {
additionalProperties: false;
}>>;
export type EnumFieldConfig = s.Static<typeof enumFieldConfigSchema>;
export declare class EnumField<Required extends true | false = false, TypeOverride = string> extends Field<EnumFieldConfig, TypeOverride, Required> {
readonly type = "enum";
constructor(name: string, config: Partial<EnumFieldConfig>);
protected getSchema(): s.ObjectSchema<{
readonly description: s.Schema<s.ISchemaOptions, string | undefined, string | undefined>;
readonly required: s.Schema<s.ISchemaOptions, boolean | undefined, boolean | undefined>;
readonly label: s.Schema<s.ISchemaOptions, string | undefined, string | undefined>;
readonly fillable: s.Schema<s.ISchemaOptions, boolean | ("create" | "read" | "update" | "delete")[] | undefined, boolean | ("create" | "read" | "update" | "delete")[] | undefined>;
readonly hidden: s.Schema<s.ISchemaOptions, boolean | ("table" | "create" | "read" | "update" | "delete" | "form" | "submit")[] | undefined, boolean | ("table" | "create" | "read" | "update" | "delete" | "form" | "submit")[] | undefined>;
readonly virtual: s.Schema<s.ISchemaOptions, boolean | undefined, boolean | undefined>;
readonly default_value: s.Schema<s.ISchemaOptions, string | undefined, string | undefined>;
readonly options: s.Schema<s.ISchemaOptions, {
[x: string]: unknown;
values: string[];
type: "strings";
} | {
[x: string]: unknown;
values: {
[x: string]: unknown;
value: string;
label: string;
}[];
type: "objects";
} | undefined, any>;
}, s.Merge<s.IObjectOptions & {
additionalProperties: false;
}>>;
getOptions(): {
label: string;
value: string;
}[];
isValidValue(value: string): boolean;
getValue(value: any, context: TRenderContext): any;
/**
* Transform value after retrieving from database
* @param value
*/
transformRetrieve(value: string | null): string | null;
transformPersist(_value: any, em: EntityManager<any>, context: TActionContext): Promise<string | undefined>;
toJsonSchema(): s.StringSchema<{
readonly enum: any[];
readonly default: any;
}> & {
readonly enum: any[];
readonly default: any;
};
toType(): TFieldTSType;
}