import { Attribute, DB, EntryBase, ForeignKeyOptions, Transaction, Type } from "./db"; export { Attribute, base, DB, deepCopy, deepDiff, EntryBase, ForeignKeyActions, ForeignKeyOptions, Index, loaded, size, Table, Transaction, transaction, TxAction, Type } from "./db"; export interface AttributeOptions { defaultValue?: T; fieldName?: string; notNull?: N; unique?: boolean; } export type AttributeOptionsFKey = ForeignKeyOptions & AttributeOptions; export interface AttributeOptionsSize extends AttributeOptions { size?: number; } type NotNull = O extends { notNull: true; } ? true : false; type AttributesDefinitionBase = { [key: string]: [unknown, boolean, unknown]; }; export type AttributesDefinition = keyof N extends never ? { [s: string]: Type; } : { [key in keyof N]: Type; }; declare const attributes: unique symbol; declare const methods: unique symbol; type ForeignKeysAttributes = T extends Type ? (E extends EntryBase ? k : never) : never; type ForeignKeys = Exclude<{ [a in keyof A]?: ForeignKeysAttributes; }[keyof A], undefined>; type Native = T extends Type ? (NN extends true ? N : N | null) : never; export type IndexAttributes = string[] | string; export interface IndexOptions { attributes: IndexAttributes; type?: "btree" | "hash"; unique?: boolean; } export type IndexDefinition = IndexAttributes | IndexOptions; export type IndexesDefinition = { [key: string]: IndexDefinition; }; interface BaseModelOptions { indexes?: IndexesDefinition; sync?: boolean; tableName?: string; } export interface ModelOptions extends BaseModelOptions { int8id?: boolean; parent?: Attribute; primaryKey?: string; } type ConditionAttribute = T | ["=" | ">" | "<" | ">=" | "<=" | "<>", T] | ["IN", T[]] | ["IS NULL"] | ["LIKE", string] | ["NOT"]; type ConditionBase = string | { [a in keyof A]?: ConditionAttribute>; }; type Condition = ConditionBase | ["NOT", Condition] | ["AND", ...Condition[]] | ["OR", ...Condition[]]; type Order_ = keyof A | `-${string & keyof A}`; type Order = Order_ | Order_[]; type UnionToIntersection = (U extends unknown ? (k: U) => void : never) extends (k: infer I) => void ? I : never; type IsUnion = [T] extends [UnionToIntersection] ? false : true; type BaseKeyType = IsUnion extends true ? number : B extends true ? string : number; type KeyType = P extends new () => EntryBase ? (P extends Attribute ? T : never) : BaseKeyType; type ForeignKey = A extends Type ? () => Promise : never; type EntryBaseAttributes = { [a in keyof A]: Native; }; type EntryMethodsBase

= P extends new () => EntryBase ? P[typeof methods] : EntryBase; type EntryMethodsFK = { [a in ForeignKeys & string as `${a}Load`]: ForeignKey; }; type EntryMethods = keyof EntryMethodsFK extends never ? EntryMethodsBase

: EntryMethodsBase

& EntryMethodsFK; type ModelAttributesIf = keyof A extends never ? T : T & A; type ModelAttributes = K extends keyof A ? A : ModelAttributesIf EntryBase ? P[typeof attributes] : { id: Type, true, unknown>; }>; export interface ModelLoad { load(where: Condition, order?: Order, limit?: number, tx?: Transaction, lock?: boolean): Promise; load(where: Condition, order?: Order, tx?: Transaction, lock?: boolean): Promise; load(where: Condition, limit?: number, tx?: Transaction, lock?: boolean): Promise; load(where: Condition, tx: Transaction, lock?: boolean): Promise; cancel(where: Condition, tx?: Transaction): Promise; } type ModelBase, EM extends EntryBase, E extends EntryBase> = (new (from?: Partial, tx?: Transaction) => E) & Attribute & { [attributes]: A; foreignKeys: Record; [methods]: EM; parent?: ModelStd; tableName: string; } & { [a in keyof A]: Attribute, boolean, E>; } & ModelLoad; type Model = ModelBase, EM, EntryBaseAttributes & EM>; type ModelStd = Attribute & { [attributes]: AttributesDefinition; foreignKeys: Record; [methods]: EntryBase; parent?: ModelStd; }; export type Entry = M extends new () => infer E ? E : never; export type OrderBy = M extends { load(where: unknown, order?: infer T): void; load(where: unknown, limit?: number): void; load(where: unknown, tx?: Transaction): void; } ? Exclude : never; export type Where = M extends { load(where: infer T): void; } ? T : never; export interface SedentaryOptions { autoSync?: boolean; log?: ((message: string) => void) | null; sync?: boolean; } /** * Converts a JavaScript name to the default SQL name (snake_case). * Uppercase letters become lowercase preceded by underscore, except the first character * which is only lowercased without underscore. */ export declare function toSqlName(name: string): string; export declare class Sedentary, T extends Transaction> { protected autoSync: boolean; protected db: D; protected doSync: boolean; protected log: (message: string) => void; private models; constructor(options?: SedentaryOptions); Boolean | undefined = undefined>(options?: O): Type, unknown>; DateTime | undefined = undefined>(options?: O): Type, unknown>; FKey(attribute: Attribute): Type; FKey(attribute: Attribute, options: { notNull: true; } & AttributeOptionsFKey): Type; FKey(attribute: Attribute, options: AttributeOptionsFKey): Type; Float | undefined = undefined>(options?: O): Type, unknown>; Int | undefined = undefined>(options?: O): Type, unknown>; Int8 | undefined = undefined>(options?: O): Type, unknown>; JSON(): Type; JSON(options: { notNull: true; } & AttributeOptions): Type; JSON(options: AttributeOptions): Type; Number | undefined = undefined>(options?: O): Type, unknown>; None(): Type; None(options: { notNull: true; } & AttributeOptions): Type; None(options: AttributeOptions): Type; VarChar(): Type; VarChar(options: { notNull: true; } & AttributeOptionsSize): Type; VarChar(options: AttributeOptionsSize): Type; private checkDB; private checkOptions; private checkOrderBy; private checkSize; private createWhere; connect(sync?: boolean): Promise; sync(): Promise; end(): Promise; begin(): Promise; escape(value: unknown): string; model>(modelName: string, attributes: A, options?: BaseModelOptions & { int8id?: B; parent?: P; primaryKey?: K | keyof A; }): Model : KeyType, ModelAttributes, EM>; model>, EM extends EntryMethods, M extends Record(this: EA & EM & S, ...args: any[]) => void>>(modelName: string, attributes: A, options: BaseModelOptions & { int8id?: B; parent?: P; primaryKey?: K | keyof A; }, methods: M & Record void>): Model : KeyType, ModelAttributes, EM & M>; }