UNPKG

bknd

Version:

Lightweight Firebase/Supabase alternative built to run anywhere — incl. Next.js, React Router, Astro, Cloudflare, Bun, Node, AWS Lambda & more.

61 lines (60 loc) 2.62 kB
import type { Static } from "../../core/utils"; import type { ExpressionBuilder } from "kysely"; import type { Entity, EntityManager } from "../entities"; import type { RepoQuery } from "../server/query"; import { EntityRelation, type KyselyQueryBuilder } from "./EntityRelation"; import { EntityRelationAnchor } from "./EntityRelationAnchor"; import { RelationField } from "./RelationField"; import type { MutationInstructionResponse } from "./RelationMutator"; import { type RelationType } from "./relation-types"; import * as tbbox from "@sinclair/typebox"; /** * Source entity receives the mapping field * * Many-to-one (many) [sources] has (one) [target] * Example: [posts] has (one) [user] * posts gets a users_id field */ export type ManyToOneRelationConfig = Static<typeof ManyToOneRelation.schema>; export declare class ManyToOneRelation extends EntityRelation<typeof ManyToOneRelation.schema> { private fieldConfig?; static DEFAULTS: { with_limit: number; }; static schema: tbbox.TObject<{ required: tbbox.TOptional<tbbox.TBoolean>; mappedBy: tbbox.TOptional<tbbox.TString>; inversedBy: tbbox.TOptional<tbbox.TString>; sourceCardinality: tbbox.TOptional<tbbox.TNumber>; with_limit: tbbox.TOptional<tbbox.TNumber>; fieldConfig: tbbox.TOptional<tbbox.TObject<{ label: tbbox.TString; }>>; }>; constructor(source: Entity, target: Entity, config?: Partial<Static<typeof ManyToOneRelation.schema>>); type(): RelationType; initialize(em: EntityManager<any>): void; /** * Retrieve the RelationField */ getField(): RelationField; protected queryInfo(entity: Entity, reference: string): { other: EntityRelationAnchor; self: EntityRelationAnchor; relationRef: string; entityRef: string; otherRef: string; groupBy: string; }; getReferenceQuery(entity: Entity, id: number, reference: string): Partial<RepoQuery>; buildJoin(entity: Entity, qb: KyselyQueryBuilder, reference: string): import("kysely").SelectQueryBuilder<any, any, any>; buildWith(entity: Entity, reference: string): (eb: ExpressionBuilder<any, any>) => import("kysely").SelectQueryBuilder<any, any, Partial<Omit<unknown, never>>>; /** * $set is performed using the reference: * { [reference]: { $set: { id: 1 } } } * * It must resolve from [reference] ("users") to field ("user_id") * -> returns instructions */ $set(em: EntityManager<any>, key: string, value: object): Promise<void | MutationInstructionResponse>; }