UNPKG

bknd

Version:

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

106 lines (105 loc) 5.35 kB
import { type DB as DefaultDB } from "../../core"; import { EventManager } from "../../core/events"; import { Connection } from "../connection/Connection"; import type { Field } from "../fields/Field"; import type { EntityIndex } from "../fields/indices/EntityIndex"; import type { EntityRelation } from "../relations"; import { RelationAccessor } from "../relations/RelationAccessor"; import { SchemaManager } from "../schema/SchemaManager"; import { Entity } from "./Entity"; import { type EntityData, Mutator, Repository, type RepositoryOptions } from "./index"; type EntitySchema<TBD extends object = DefaultDB, E extends Entity | keyof TBD | string = string> = E extends Entity<infer Name> ? Name extends keyof TBD ? Name : never : E extends keyof TBD ? E : never; export declare class EntityManager<TBD extends object = DefaultDB> { connection: Connection; private _entities; private _relations; private _indices; private _schema?; readonly emgr: EventManager<typeof EntityManager.Events>; static readonly Events: { RepositoryFindOneBefore: typeof import("../events").RepositoryFindOneBefore; RepositoryFindOneAfter: typeof import("../events").RepositoryFindOneAfter; RepositoryFindManyBefore: typeof import("../events").RepositoryFindManyBefore; RepositoryFindManyAfter: typeof import("../events").RepositoryFindManyAfter; MutatorInsertBefore: typeof import("../events").MutatorInsertBefore; MutatorInsertAfter: typeof import("../events").MutatorInsertAfter; MutatorUpdateBefore: typeof import("../events").MutatorUpdateBefore; MutatorUpdateAfter: typeof import("../events").MutatorUpdateAfter; MutatorDeleteBefore: typeof import("../events").MutatorDeleteBefore; MutatorDeleteAfter: typeof import("../events").MutatorDeleteAfter; }; constructor(entities: Entity[], connection: Connection, relations?: EntityRelation[], indices?: EntityIndex[], emgr?: EventManager<any>); /** * Forks the EntityManager without the EventManager. * This is useful when used inside an event handler. */ fork(): EntityManager; get entities(): Entity[]; get relations(): RelationAccessor; get indices(): EntityIndex[]; ping(): Promise<boolean>; addEntity(entity: Entity): void; __replaceEntity(entity: Entity, name?: string | undefined): void; entity<Silent extends true | false = false>(e: Entity | keyof TBD | string, silent?: Silent): Silent extends true ? Entity | undefined : Entity; hasEntity(entity: string): boolean; hasEntity(entity: Entity): boolean; hasIndex(index: string): boolean; hasIndex(index: EntityIndex): boolean; getIndexedFields(_entity: Entity | string): Field[]; addRelation(relation: EntityRelation): void; relationsOf(entity_name: string): EntityRelation[]; relationOf(entity_name: string, reference: string): EntityRelation | undefined; hasRelations(entity_name: string): boolean; relatedEntitiesOf(entity_name: string): Entity[]; relationReferencesOf(entity_name: string): string[]; repository<E extends Entity | keyof TBD | string>(entity: E): Repository<TBD, EntitySchema<TBD, E>>; repo<E extends Entity | keyof TBD | string>(entity: E, opts?: Omit<RepositoryOptions, "emgr">): Repository<TBD, EntitySchema<TBD, E>>; mutator<E extends Entity | keyof TBD | string>(entity: E): Mutator<TBD, EntitySchema<TBD, E>>; addIndex(index: EntityIndex, force?: boolean): void; getIndicesOf(_entity: Entity | string): EntityIndex[]; schema(): SchemaManager; hydrate(entity_name: string, _data: EntityData[]): EntityData[]; toJSON(): { entities: { [k: string]: { type: "regular" | "system" | "generated"; fields: { [k: string]: { type: any; config: { required?: boolean | undefined; description?: string | undefined; default_value?: any; label?: string | undefined; fillable?: boolean | ("create" | "read" | "update" | "delete")[] | undefined; hidden?: boolean | ("form" | "table" | "create" | "read" | "update" | "delete" | "submit")[] | undefined; virtual?: boolean | undefined; }; }; }; config: { description?: string | undefined; name?: string | undefined; name_singular?: string | undefined; sort_field?: string | undefined; sort_dir?: "asc" | "desc" | undefined; primary_format?: "uuid" | "integer" | undefined; }; }; }; relations: { [k: string]: { type: import("..").RelationType; source: string; target: string; config: { required?: boolean | undefined; mappedBy?: string | undefined; inversedBy?: string | undefined; }; }; }; indices: any; }; } export {};