import { TypeLevelError, output } from "../types/helpers.mjs"; import { IsAutoFilledDBField, IsReadOnlyDBField, TailorAnyDBField, TailorAnyDBType } from "../configure/services/tailordb/types.mjs"; import { ColumnType, ColumnType as ColumnType$1, Insertable, Insertable as Insertable$1, Kysely, Kysely as Kysely$1, KyselyConfig, KyselyConfig as KyselyConfig$1, Selectable, Selectable as Selectable$1, Transaction, Transaction as Transaction$1, Updateable, Updateable as Updateable$1, sql } from "kysely"; import { TailordbDialect } from "@tailor-platform/function-kysely-tailordb"; //#region src/kysely/index.d.ts export type Timestamp = ColumnType$1; type ResolveSelect = T extends ColumnType$1 ? S : T; type ResolveInsert = T extends ColumnType$1 ? I : T; type ResolveUpdate = T extends ColumnType$1 ? U : T; export type ObjectColumnType = ColumnType$1<{ [K in keyof T]-?: Exclude, undefined>; }, { [K in keyof T]: ResolveInsert; }, { [K in keyof T]: ResolveUpdate; }>; export type ArrayColumnType = ColumnType$1[], ResolveInsert[], ResolveUpdate[]>; export type Generated = T extends ColumnType$1 ? ColumnType$1 : ColumnType$1; type SerialColumnMustBeOmitted = TypeLevelError<"assigned by .serial(); remove it from the input">; export type Serial = ColumnType$1; type FlattenColumns = { [K in keyof T]: T[K]; } & {}; export type TailordbKysely = Kysely$1; export type NamespaceDB = TailordbKysely; /** * Create a namespace-aware getDB function for generated code. * @returns A getDB function that creates Kysely instances for specific namespaces */ export declare function createGetDB(): (namespace: N, config?: Omit) => TailordbKysely; export type NamespaceTransaction = keyof NS> = K extends TailordbKysely ? Transaction$1 : K extends keyof NS ? Transaction$1 : never; export type NamespaceTableName = { [N in keyof NS]: keyof NS[N]; }[keyof NS]; export type NamespaceTable> = { [N in keyof NS]: T extends keyof NS[N] ? NS[N][T] : never; }[keyof NS]; export type NamespaceInsertable> = FlattenColumns>>; export type NamespaceSelectable> = FlattenColumns>>; export type NamespaceUpdateable> = FlattenColumns>>; /** What the derived input types accept: a table (`typeof myTable`) or a field collection. */ type TailorDBColumnsSource = TailorAnyDBType | Record; type DBFieldsOf = T extends TailorAnyDBType ? T["fields"] : T; type DBFieldType = F extends TailorAnyDBField ? F["_defined"]["type"] : never; type IsArrayDBField = F extends TailorAnyDBField ? F["_defined"]["array"] extends true ? true : false : false; type Unwrapped = Exclude, null>; type ElementOutput = IsArrayDBField extends true ? Unwrapped extends readonly (infer E)[] ? E : Unwrapped : Unwrapped; type NestedFieldsOf = F extends TailorAnyDBField ? F["fields"] : never; type NestedProps = { -readonly [K in keyof Fields as null extends output ? never : K]: DBColumn; } & { -readonly [K in keyof Fields as null extends output ? K : never]?: DBColumn; }; type NestedNeedsColumnType = true extends { [K in keyof Fields]: DBFieldType extends "date" | "datetime" ? true : null extends output ? true : DBFieldType extends "nested" ? NestedNeedsColumnType> : Fields[K] extends TailorAnyDBField ? IsAutoFilledDBField : false; }[keyof Fields] ? true : false; type NestedColumn = NestedNeedsColumnType> extends true ? ObjectColumnType>>> : FlattenColumns>>; type ElementColumn = DBFieldType extends "date" | "datetime" ? Timestamp : DBFieldType extends "nested" ? NestedColumn : ElementOutput; type ArrayedColumn = IsArrayDBField extends true ? ElementColumn extends ColumnType$1 ? ArrayColumnType> : ElementColumn[] : ElementColumn; type NullableColumn = null extends output ? ArrayedColumn | null : ArrayedColumn; type DBColumn = F extends TailorAnyDBField ? IsReadOnlyDBField extends true ? Serial> : IsAutoFilledDBField extends true ? Generated> : NullableColumn : never; type TailorDBColumns = { [K in keyof DBFieldsOf]: K extends "id" ? Generated[K]>> : DBColumn[K]>; }; /** * Create input derived from a TailorDB table (`typeof myTable`) or a field collection. * * Each field resolves to the column type `kyselyTypePlugin` writes for it, so this and * the generated table types agree: `.serial()` fields are never caller-supplied, * `.default()` / `.hooks({ create })` fields may be omitted, optional fields stay * optional, `id` is platform-generated, and a date or datetime reads back as `Date`. * * Pass a field collection when the fields are a type parameter — a shared module that * lets each project extend a table with its own fields cannot name a generated table * type. Declare it as `>` so the field * types are inferred; a bare `Record` erases them and nothing * is checked. * * Hand the result to callers rather than consuming it inside the generic that declares * it: while `F` is still an unresolved type parameter the mapping stays deferred, so * assigning to it inside the function body reports the unevaluated conditional rather * than a readable shape. * @example * function createInput>(fields: F) { * return (input: TailorDBInsertable) => { ... }; * } */ export type TailorDBInsertable = FlattenColumns>>; /** Read shape of a TailorDB table or field collection. See {@link TailorDBInsertable}. */ export type TailorDBSelectable = FlattenColumns>>; /** Update input for a TailorDB table or field collection. See {@link TailorDBInsertable}. */ export type TailorDBUpdateable = FlattenColumns>>; //#endregion export { type ColumnType, type Insertable, Kysely, type KyselyConfig, type Selectable, TailordbDialect, type Transaction, type Updateable, sql };