UNPKG

bknd

Version:

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

119 lines (118 loc) 5.18 kB
import { s } from "bknd/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"; /** * 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 = s.Static<typeof ManyToOneRelation.schema>; export declare class ManyToOneRelation extends EntityRelation<typeof ManyToOneRelation.schema> { private fieldConfig?; static DEFAULTS: { with_limit: number; }; static schema: s.ObjectSchema<{ readonly mappedBy: { default?: any; maxLength?: number | undefined; minLength?: number | undefined; pattern?: (string | RegExp) | undefined; format?: string | undefined; enum?: (readonly any[] | any[]) | undefined; const?: any; } & s.Schema<s.ISchemaOptions, string | undefined, string | undefined>; readonly inversedBy: { default?: any; maxLength?: number | undefined; minLength?: number | undefined; pattern?: (string | RegExp) | undefined; format?: string | undefined; enum?: (readonly any[] | any[]) | undefined; const?: any; } & s.Schema<s.ISchemaOptions, string | undefined, string | undefined>; readonly required: { default?: any; enum?: (readonly any[] | any[]) | undefined; const?: any; } & s.Schema<s.ISchemaOptions, boolean | undefined, boolean | undefined>; readonly sourceCardinality: { default?: any; enum?: (readonly any[] | any[]) | undefined; const?: any; multipleOf?: number | undefined; maximum?: number | undefined; exclusiveMaximum?: number | undefined; minimum?: number | undefined; exclusiveMinimum?: number | undefined; } & s.Schema<s.ISchemaOptions, number | undefined, number | undefined>; readonly with_limit: { readonly default: number; } & s.Schema<s.ISchemaOptions, number | undefined, number | undefined>; readonly fieldConfig: { default?: any; enum?: (readonly any[] | any[]) | undefined; const?: any; $defs?: Record<string, s.Schema> | undefined; patternProperties?: Record<string, s.Schema> | undefined; additionalProperties?: (s.Schema | false) | undefined; minProperties?: number | undefined; maxProperties?: number | undefined; propertyNames?: s.Schema | undefined; properties: { readonly label: s.StringSchema<s.IStringOptions> & s.IStringOptions; }; required: string[] | undefined; strict: () => s.ObjectSchema<{ readonly label: s.StringSchema<s.IStringOptions> & s.IStringOptions; }, s.Merge<s.IObjectOptions & { additionalProperties: false; }>>; partial: () => s.ObjectSchema<{ readonly label: s.Schema<s.ISchemaOptions, string | undefined, string | undefined>; }, s.IObjectOptions>; } & s.Schema<s.ISchemaOptions, { [x: string]: unknown; label: string; } | undefined, { [x: string]: unknown; label: string; } | undefined>; }, s.Merge<s.IObjectOptions & { additionalProperties: false; }>>; constructor(source: Entity, target: Entity, config?: Partial<s.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>; }