bknd
Version:
Lightweight Firebase/Supabase alternative built to run anywhere — incl. Next.js, React Router, Astro, Cloudflare, Bun, Node, AWS Lambda & more.
85 lines (84 loc) • 5.33 kB
TypeScript
import type { EntityManager } from "../entities";
import { Field } from "../fields";
import type { EntityRelation } from "./EntityRelation";
import type { EntityRelationAnchor } from "./EntityRelationAnchor";
import type { TFieldTSType } from "../../data/entities/EntityTypescript";
import { s } from "bknd/utils";
export declare const relationFieldConfigSchema: s.ObjectSchema<{
readonly label: s.Schema<s.ISchemaOptions, string | undefined, string | undefined>;
readonly description: s.Schema<s.ISchemaOptions, string | undefined, string | undefined>;
readonly required: s.Schema<s.ISchemaOptions, boolean | undefined, boolean | 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, any, any>;
readonly reference: s.StringSchema<s.IStringOptions> & s.IStringOptions;
readonly target: s.StringSchema<s.IStringOptions> & s.IStringOptions;
readonly target_field: {
readonly default: "id";
} & s.Schema<s.ISchemaOptions, string | undefined, string | undefined>;
readonly target_field_type: {
readonly default: "integer";
readonly enum: ["text", "integer"];
} & s.Schema<s.ISchemaOptions, "text" | "integer" | undefined, "text" | "integer" | undefined>;
readonly on_delete: {
readonly default: "set null";
readonly enum: readonly ["cascade", "set null", "set default", "restrict", "no action"];
} & s.Schema<s.ISchemaOptions, "cascade" | "set null" | "set default" | "restrict" | "no action" | undefined, "cascade" | "set null" | "set default" | "restrict" | "no action" | undefined>;
}, s.Merge<s.IObjectOptions & {
additionalProperties: false;
}>>;
export type RelationFieldConfig = s.Static<typeof relationFieldConfigSchema>;
export type RelationFieldBaseConfig = {
label?: string;
};
export declare class RelationField extends Field<RelationFieldConfig> {
readonly type = "relation";
protected getSchema(): s.ObjectSchema<{
readonly label: s.Schema<s.ISchemaOptions, string | undefined, string | undefined>;
readonly description: s.Schema<s.ISchemaOptions, string | undefined, string | undefined>;
readonly required: s.Schema<s.ISchemaOptions, boolean | undefined, boolean | 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, any, any>;
readonly reference: s.StringSchema<s.IStringOptions> & s.IStringOptions;
readonly target: s.StringSchema<s.IStringOptions> & s.IStringOptions;
readonly target_field: {
readonly default: "id";
} & s.Schema<s.ISchemaOptions, string | undefined, string | undefined>;
readonly target_field_type: {
readonly default: "integer";
readonly enum: ["text", "integer"];
} & s.Schema<s.ISchemaOptions, "text" | "integer" | undefined, "text" | "integer" | undefined>;
readonly on_delete: {
readonly default: "set null";
readonly enum: readonly ["cascade", "set null", "set default", "restrict", "no action"];
} & s.Schema<s.ISchemaOptions, "cascade" | "set null" | "set default" | "restrict" | "no action" | undefined, "cascade" | "set null" | "set default" | "restrict" | "no action" | undefined>;
}, s.Merge<s.IObjectOptions & {
additionalProperties: false;
}>>;
static create(relation: EntityRelation, target: EntityRelationAnchor, config?: RelationFieldBaseConfig): RelationField;
reference(): string;
target(): string;
targetField(): string;
schema(): Readonly<{
type: "text" | "integer";
references: `${string}.${string}` | `${string}.undefined`;
onDelete: "cascade" | "set null" | "set default" | "restrict" | "no action";
name: string;
nullable?: boolean;
dflt?: any;
unique?: boolean;
primary?: boolean;
onUpdate?: import("kysely").OnModifyForeignAction;
}>;
transformRetrieve(value: any): any;
transformPersist(value: any, em: EntityManager<any>): Promise<any>;
toJsonSchema(): s.Schema<{
readonly $ref: `${string}#/properties/undefined` | `${string}#/properties/${string}`;
}, number, number> & {
readonly $ref: `${string}#/properties/undefined` | `${string}#/properties/${string}`;
};
toType(): TFieldTSType;
}