import type { Options } from 'ajv'; import type { ConnectionConfiguration } from 'tedious'; import type { PoolAttributes } from 'oracledb'; import type { AxiosInterceptorManager, InternalAxiosRequestConfig, AxiosResponse } from 'axios'; export type MappedDbDef = { map>( callback: (mapper: DbMapper) => V ): MappedDbDef>; >(concurrency: O): NegotiateDbInstance; } & T & DbConnectable; type MergeProperties = { [K in keyof T | keyof V]: K extends keyof T ? (T[K] extends MappedTableDef ? (K extends keyof V ? (V[K] extends MappedTableDef ? MappedTableDef : V[K]) : T[K]) : T[K]) : (K extends keyof V ? V[K] : never); }; export type DbMapper = { table(tableName: string): MappedTableDefInit<{}>; } & T; type MappedDb = { >(concurrency: O): NegotiateDbInstance; } & DbConnectable; type DbConnectable = { http(url: string): MappedDbInstance; postgres(connectionString: string, options?: PoolOptions): MappedDbInstance; sqlite(connectionString: string, options?: PoolOptions): MappedDbInstance; sap(connectionString: string, options?: PoolOptions): MappedDbInstance; mssql(connectionConfig: ConnectionConfiguration, options?: PoolOptions): MappedDbInstance; mssql(connectionString: string, options?: PoolOptions): MappedDbInstance; mssqlNative(connectionString: string, options?: PoolOptions): MappedDbInstance; mysql(connectionString: string, options?: PoolOptions): MappedDbInstance; oracle(config: PoolAttributes, options?: PoolOptions): MappedDbInstance; }; type NegotiateDbInstance = C extends WithDb ? MappedDbInstance : MappedDb; type WithDb = { db: Pool | ((connectors: Connectors) => Pool | Promise) }; type DbOptions = { [K in keyof T]?: T[K] extends MappedTableDef ? Concurrency : never; } & { concurrency?: ConcurrencyValues; readonly?: boolean; db?: Pool | ((connectors: Connectors) => Pool | Promise); }; interface Connectors { http(url: string): Pool; postgres(connectionString: string, options?: PoolOptions): Pool; sqlite(connectionString: string, options?: PoolOptions): Pool; sap(connectionString: string, options?: PoolOptions): Pool; mssql(connectionConfig: ConnectionConfiguration, options?: PoolOptions): Pool; mssql(connectionString: string, options?: PoolOptions): Pool; oracle(config: PoolAttributes, options?: PoolOptions): Pool; } export interface Pool { end(): Promise; } export interface PoolOptions { size?: number; } type MappedDbInstance = { [K in keyof T]: T[K] extends MappedTableDef ? MappedTable : never; } & { filter: Filter; and(filter: Filter | RawFilter[], ...filters: RawFilter[]): Filter; or(filter: Filter | RawFilter[], ...filters: RawFilter[]): Filter; not(): Filter; query(filter: RawFilter | string): Promise; query(filter: RawFilter | string): Promise; createPatch(original: any[], modified: any[]): JsonPatch; createPatch(original: any, modified: any): JsonPatch; >(concurrency: O): MappedDbInstance; transaction( fn: (db: MappedDbInstance) => Promise ): Promise; saveChanges(arraysOrRow: { saveChanges(): Promise }): Promise; express(): import('express').RequestHandler; express(config: ExpressConfig): import('express').RequestHandler; readonly metaData: DbConcurrency; interceptors: WithInterceptors; } & DbConnectable & WithInterceptors; interface WithInterceptors { request: AxiosInterceptorManager; response: AxiosInterceptorManager; } type ExpressConfig = { [K in keyof T]?: T[K] extends MappedTableDef ? ExpressTableConfig : never; } & { db?: Pool | ((connectors: Connectors) => Pool | Promise); } type ExpressTableConfig = { baseFilter?: RawFilter | ((db: MappedDbInstance, req: import('express').Request, res: import('express').Response) => RawFilter); } type JsonPatch = Array<{ op: 'add' | 'remove' | 'replace' | 'copy' | 'move' | 'test'; path: string; value?: any; from?: string; }>; type ToJsonType = M extends JsonOf ? N : JsonType; type PrimaryRowFilter = StrategyToRowDataPrimary>; type StrategyToRowDataPrimary = { [K in keyof T]: T[K] extends StringColumnSymbol ? string : T[K] extends UuidColumnSymbol ? string : T[K] extends NumericColumnSymbol ? number : T[K] extends DateColumnSymbol ? string | Date : T[K] extends DateWithTimeZoneColumnSymbol ? string | Date : T[K] extends BinaryColumnSymbol ? string : T[K] extends BooleanColumnSymbol ? boolean : T[K] extends JSONColumnType ? ToJsonType : never; }; type ExpandedFetchingStrategy = { [K in keyof T & keyof RemoveNever< AllowedColumnsAndTablesStrategy >]?: T[K] extends ColumnSymbols ? true : ExpandedFetchingStrategy; }; type ExpandedMappedTable> = { getOne( filter?: Filter | PrimaryRowFilter ): Promise, T>>; getOne>( filter?: Filter | PrimaryRowFilter, fetchingStrategy?: FS ): Promise, T>>; update( row: StrategyToInsertRowData ): Promise, T>>; updateChanges( row: StrategyToInsertRowData, originalRow: StrategyToInsertRowData ): Promise, T>>; update( rows: StrategyToInsertRowData[] ): Promise, T>>; updateChanges( rows: StrategyToInsertRowData[], originalRows: StrategyToInsertRowData[] ): Promise, T>>; update>( row: StrategyToInsertRowData, strategy: FS ): Promise, T>>; updateChanges>( row: StrategyToInsertRowData, originalRow: StrategyToInsertRowData, strategy: FS ): Promise, T>>; update>( rows: StrategyToInsertRowData[], strategy: FS ): Promise, T>>; updateChanges>( rows: StrategyToInsertRowData[], originalRows: StrategyToInsertRowData[], strategy: FS ): Promise, T>>; insert( row: StrategyToInsertRowData ): Promise, T>>; insert( rows: StrategyToInsertRowData[] ): Promise, T>>; insert>( row: StrategyToInsertRowData, strategy: FS ): Promise, T>>; insert>( rows: StrategyToInsertRowData[], strategy: FS ): Promise, T>>; insertAndForget( row: StrategyToRowData ): Promise; insertAndForget( row: StrategyToRowData[] ): Promise; getMany( filter?: Filter | PrimaryRowFilter[] ): Promise, T>>; getMany>( filter?: Filter | PrimaryRowFilter[], fetchingStrategy?: FS ): Promise, T>>; getAll(): Promise, T>>; getAll>( fetchingStrategy: FS ): Promise, T>>; aggregate>( fetchingStrategy: FS ): Promise>[]>; count(filter?: Filter | PrimaryRowFilter[]): Promise; delete(filter?: Filter | PrimaryRowFilter[]): Promise; deleteCascade(filter?: Filter | PrimaryRowFilter[]): Promise; proxify( row: StrategyToInsertRowData ): StrategyToRow, T>; proxify( row: StrategyToInsertRowData[] ): StrategyToRowArray, T>; proxify>( row: StrategyToInsertRowData, strategy: FS ): StrategyToRow, T>; proxify>( row: StrategyToInsertRowData[], strategy: FS ): StrategyToRowArray, T>; patch>( patch: JsonPatch, concurrency?: C ): Promise; tsType>( strategy: FS ): StrategyToRowData>; tsType( ): StrategyToRowData>; readonly metaData: Concurrency; } & MappedColumnsAndRelations & GetById>>; type ReturnArrayOrObj = W extends any[] ? V2 : V1; type MappedTable = { expand(): ExpandedMappedTable getOne( filter?: Filter | PrimaryRowFilter ): Promise, T>>; getOne>( filter?: Filter | PrimaryRowFilter, fetchingStrategy?: FS ): Promise, T>>; update( row: StrategyToInsertRowData ): Promise, T>>; updateChanges( modifiedRow: StrategyToInsertRowData, originalRow: StrategyToInsertRowData ): Promise, T>>; update( rows: StrategyToInsertRowData[] ): Promise, T>>; updateChanges( modifiedRows: StrategyToInsertRowData[], originalRows: StrategyToInsertRowData[] ): Promise, T>>; update>( row: StrategyToInsertRowData, strategy: FS ): Promise, T>>; updateChanges>( modifiedRow: StrategyToInsertRowData, originalRow: StrategyToInsertRowData, strategy: FS ): Promise, T>>; update>( rows: StrategyToInsertRowData[], strategy: FS ): Promise, T>>; updateChanges>( modifiedRows: StrategyToInsertRowData[], originalRows: StrategyToInsertRowData[], strategy: FS ): Promise, T>>; insert( row: StrategyToInsertRowData ): Promise, T>>; insert( rows: StrategyToInsertRowData[] ): Promise, T>>; insert>( row: StrategyToInsertRowData, strategy: FS ): Promise, T>>; insert>( rows: StrategyToInsertRowData[], strategy: FS ): Promise, T>>; insertAndForget | StrategyToInsertRowData[]>( row: TRow ): Promise; getMany( filter?: Filter | PrimaryRowFilter[] ): Promise, T>>; getMany>( filter?: Filter | PrimaryRowFilter[], fetchingStrategy?: FS ): Promise, T>>; getAll(): Promise, T>>; getAll>( fetchingStrategy: FS ): Promise, T>>; aggregate>( fetchingStrategy: FS ): Promise>[]>; count(filter?: Filter | PrimaryRowFilter[]): Promise; delete(filter?: Filter | PrimaryRowFilter[]): Promise; deleteCascade(filter?: Filter | PrimaryRowFilter[]): Promise; proxify( row: StrategyToInsertRowData ): StrategyToRow, T>; proxify( row: StrategyToInsertRowData[] ): StrategyToRowArray, T>; proxify>( row: StrategyToInsertRowData, strategy: FS ): StrategyToRow, T>; proxify>( row: StrategyToInsertRowData[], strategy: FS ): StrategyToRowArray, T>; patch>( patch: JsonPatch, concurrency?: C ): Promise; tsType>( strategy: FS ): StrategyToRowData>; tsType( ): StrategyToRowData>; readonly metaData: Concurrency; } & MappedColumnsAndRelations & GetById>>; type GetById = Count extends 1 ? { getById( id: ColumnToType>> ): Promise, T>>; getById>( id: ColumnToType>>, fetchingStrategy: FS ): Promise, T>>; } : Count extends 2 ? { getById( id: ColumnToType>>, id2: ColumnToType>> ): Promise, T>>; getById>( id: ColumnToType>>, id2: ColumnToType>>, fetchingStrategy: FS ): Promise, T>>; } : Count extends 3 ? { getById( id: ColumnToType>>, id2: ColumnToType>>, id3: ColumnToType>> ): Promise, T>>; getById>( id: ColumnToType>>, id2: ColumnToType>>, id3: ColumnToType>>, fetchingStrategy: FS ): Promise, T>>; } : Count extends 4 ? { getById( id: ColumnToType>>, id2: ColumnToType>>, id3: ColumnToType>>, id4: ColumnToType>> ): Promise, T>>; getById>( id: ColumnToType>>, id2: ColumnToType>>, id3: ColumnToType>>, id4: ColumnToType>>, fetchingStrategy: FS ): Promise, T>>; } : Count extends 5 ? { getById( id: ColumnToType>>, id2: ColumnToType>>, id3: ColumnToType>>, id4: ColumnToType>>, id5: ColumnToType>> ): Promise, T>>; getById>( id: ColumnToType>>, id2: ColumnToType>>, id3: ColumnToType>>, id4: ColumnToType>>, id5: ColumnToType>>, fetchingStrategy: FS ): Promise, T>>; } : Count extends 6 ? { getById( id: ColumnToType>>, id2: ColumnToType>>, id3: ColumnToType>>, id4: ColumnToType>>, id5: ColumnToType>>, id6: ColumnToType>> ): Promise, T>>; getById>( id: ColumnToType>>, id2: ColumnToType>>, id3: ColumnToType>>, id4: ColumnToType>>, id5: ColumnToType>>, id6: ColumnToType>>, fetchingStrategy: FS ): Promise, T>>; } : never; type ColumnToType = T extends UuidColumnSymbol ? string : T extends StringColumnSymbol ? string : T extends NumericColumnSymbol ? number : T extends DateColumnSymbol ? string | Date : T extends DateWithTimeZoneColumnSymbol ? string | Date : T extends BinaryColumnSymbol ? string : T extends BooleanColumnSymbol ? boolean : T extends JsonOf ? M : T extends JSONColumnSymbol ? JsonType : never; type MappedColumnsAndRelations = RemoveNeverFlat<{ [K in keyof T]: T[K] extends StringColumnTypeDef ? StringColumnType : T[K] extends UuidColumnTypeDef ? UuidColumnType : T[K] extends NumericColumnTypeDef ? NumericColumnType : T[K] extends DateColumnTypeDef ? DateColumnType : T[K] extends DateWithTimeZoneColumnTypeDef ? DateWithTimeZoneColumnType : T[K] extends BinaryColumnTypeDef ? BinaryColumnType : T[K] extends BooleanColumnTypeDef ? BooleanColumnType : T[K] extends JSONColumnTypeDef ? JSONColumnType : T[K] extends ManyRelation ? MappedColumnsAndRelations & ManyTable & OneOrJoinTable : T[K] extends RelatedTable ? MappedColumnsAndRelations & OneOrJoinTable : never; }>; type OneOrJoinTable = (( fn: (table: MappedColumnsAndRelations) => RawFilter ) => Filter) & { exists: () => Filter; }; type ManyTable = (( ) => Filter) & { all(selector: (table: MappedColumnsAndRelations) => RawFilter): Filter; any(selector: (table: MappedColumnsAndRelations) => RawFilter): Filter; none(selector: (table: MappedColumnsAndRelations) => RawFilter): Filter; }; export type AllowedDbMap = { [P in keyof T]: T[P] extends MappedTableDef ? T[P] : never; }; type AllowedColumnsAndTablesStrategy = { [P in keyof T]: T[P] extends ColumnAndTableTypes ? T[P] : never; }; type AllowedColumnsAndTablesConcurrency = { [P in keyof T]: T[P] extends ColumnAndTableTypes ? T[P] : never; }; type FetchingStrategy = FetchingStrategyBase | AggType type AggregateStrategy = AggregateStrategyBase | AggType type AggType = { [name: string]: AggregationFunction; } & { where?: (agg: MappedColumnsAndRelations) => RawFilter; }; type AggregateStrategyBase = { limit?: number; offset?: number; where?: (agg: MappedColumnsAndRelations) => RawFilter; }; type FetchingStrategyBase = { [K in keyof T & keyof RemoveNever< AllowedColumnsAndTablesStrategy >]?: T[K] extends ColumnSymbols ? boolean : boolean | FetchingStrategyBase | AggType; } & { orderBy?: | OrderBy, string>>[] | OrderBy, string>>; limit?: number; offset?: number; where?: (agg: MappedColumnsAndRelations) => RawFilter; }; type ExtractAggregates = { [K in keyof Agg as Required[K] extends (agg: Aggregate) => ColumnSymbols ? K extends 'where' ? never : K : never ]: Agg[K] extends (agg: Aggregate) => infer R ? R : never; } type AggregationFunction = (agg: Aggregate) => ColumnSymbols; type Aggregate = RelatedColumns & { sum(fn: (x: AggregateColumns) => NumericColumnSymbol): NumericColumnSymbol & NotNull; avg(fn: (x: AggregateColumns) => NumericColumnSymbol): NumericColumnSymbol & NotNull; min(fn: (x: AggregateColumns) => NumericColumnSymbol): NumericColumnSymbol & NotNull; max(fn: (x: AggregateColumns) => NumericColumnSymbol): NumericColumnSymbol & NotNull; count(fn: (x: AggregateColumns) => NumericColumnSymbol): NumericColumnSymbol & NotNull; } type RelatedColumns = RemoveNeverFlat<{ [K in keyof T]: T[K] extends StringColumnTypeDef ? StringColumnSymbol : T[K] extends UuidColumnTypeDef ? UuidColumnSymbol : T[K] extends NumericColumnTypeDef ? NumericColumnSymbol : T[K] extends DateColumnTypeDef ? DateColumnSymbol : T[K] extends DateWithTimeZoneColumnTypeDef ? DateWithTimeZoneColumnSymbol : T[K] extends BinaryColumnTypeDef ? BinaryColumnSymbol : T[K] extends BooleanColumnTypeDef ? BooleanColumnSymbol : T[K] extends JSONColumnTypeDef ? JSONColumnSymbol : T[K] extends ManyRelation ? RelatedColumns : T[K] extends RelatedTable ? RelatedColumns : never; }>; type AggregateColumns = RemoveNeverFlat<{ [K in keyof T]: T[K] extends ManyRelation ? AggregateColumns2 : T[K] extends RelatedTable ? AggregateColumns2 : never; }>; type AggregateColumns2 = RemoveNeverFlat<{ [K in keyof T]: T[K] extends NumericColumnTypeDef ? NumericColumnSymbol : T[K] extends ManyRelation ? AggregateColumns2 : T[K] extends RelatedTable ? AggregateColumns2 : never; }>; type TablesDeep = RemoveNeverFlat<{ [K in keyof T]: T[K] extends ManyRelation ? TablesDeep : T[K] extends RelatedTable ? TablesDeep : never; }>; type ColumnConcurrency = { readonly?: boolean; concurrency?: ConcurrencyValues; }; type ColumnSymbols = | StringColumnSymbol | UuidColumnSymbol | NumericColumnSymbol | DateColumnSymbol | DateWithTimeZoneColumnSymbol | BooleanColumnSymbol | BinaryColumnSymbol | JSONColumnSymbol; type Concurrency = { [K in keyof T & keyof RemoveNever< AllowedColumnsAndTablesConcurrency >]?: T[K] extends ColumnSymbols ? ColumnConcurrency : Concurrency; } & { readonly?: boolean; concurrency?: ConcurrencyValues; }; type DbConcurrency = { [K in keyof T]: T[K] extends MappedTableDef ? Concurrency : never; } & { readonly?: boolean; concurrency?: ConcurrencyValues; }; type ConcurrencyValues = 'optimistic' | 'skipOnConflict' | 'overwrite'; type OrderBy = `${T} ${'asc' | 'desc'}` | T; type RelatedTable = { [' relatedTable']: boolean; }; type PickTypesOf = { [K in keyof T as T[K] extends U ? K : never]: T[K]; }; type ExtractPrimary = PickTypesOf; type ExtractPrimary1 = PickTypesOf< T, PickPropertyValue1> >; type ExtractPrimary2 = PickTypesOf< T, PickPropertyValue2> >; type ExtractPrimary3 = PickTypesOf< T, PickPropertyValue3> >; type ExtractPrimary4 = PickTypesOf< T, PickPropertyValue4> >; type ExtractPrimary5 = PickTypesOf< T, PickPropertyValue5> >; type ExtractPrimary6 = PickTypesOf< T, PickPropertyValue6> >; type ToColumnTypes = { [K in keyof T]: T[K] extends UuidColumnSymbol ? UuidColumnSymbol : T[K] extends StringColumnSymbol ? StringColumnSymbol : T[K] extends NumericColumnSymbol ? NumericColumnSymbol : T[K] extends DateColumnSymbol ? DateColumnSymbol : T[K] extends DateWithTimeZoneColumnSymbol ? DateWithTimeZoneColumnSymbol : T[K] extends BinaryColumnSymbol ? BinaryColumnSymbol : T[K] extends BooleanColumnSymbol ? BooleanColumnSymbol : T[K] extends JSONColumnSymbol ? JSONColumnSymbol : never; }[keyof T]; type KeyCandidates1 = PickTypesOf< TFrom, ToColumnTypes> >; type KeyCandidates2 = PickTypesOf< TFrom, ToColumnTypes> >; type KeyCandidates3 = PickTypesOf< TFrom, ToColumnTypes> >; type KeyCandidates4 = PickTypesOf< TFrom, ToColumnTypes> >; type KeyCandidates5 = PickTypesOf< TFrom, ToColumnTypes> >; type KeyCandidates6 = PickTypesOf< TFrom, ToColumnTypes> >; type ReferenceMapper = ReferenceMapperHelper< TFrom, TTo, CountProperties> >; type OneMapper = HasMapperHelper< TFrom, TTo, CountProperties>, OneRelation >; type ManyMapper = HasMapperHelper< TFrom, TTo, CountProperties>, ManyRelation >; type ReferenceMapperHelper = 6 extends TPrimaryCount ? { by, C2 extends keyof KeyCandidates2, C3 extends keyof KeyCandidates2, C4 extends keyof KeyCandidates2, C5 extends keyof KeyCandidates2, C6 extends keyof KeyCandidates2>( column: C1, column2: C2, column3: C3, column4: C4, column5: C5, column6: C6 ): MappedTableDef & RelatedTable; } : 5 extends TPrimaryCount ? { by, C2 extends keyof KeyCandidates2, C3 extends keyof KeyCandidates2, C4 extends keyof KeyCandidates2, C5 extends keyof KeyCandidates2>( column: C1, column2: C2, column3: C3, column4: C4, column5: C5 ): MappedTableDef & RelatedTable; } : 4 extends TPrimaryCount ? { by, C2 extends keyof KeyCandidates2, C3 extends keyof KeyCandidates2, C4 extends keyof KeyCandidates2>( column: C1, column2: C2, column3: C3, column4: C4 ): MappedTableDef & RelatedTable; } : 3 extends TPrimaryCount ? { by, C2 extends keyof KeyCandidates2, C3 extends keyof KeyCandidates2>( column: C1, column2: C2, column3: C3 ): MappedTableDef & RelatedTable; } : 2 extends TPrimaryCount ? { by, C2 extends keyof KeyCandidates2>( column: C1, column2: C2 ): MappedTableDef & RelatedTable; } : 1 extends TPrimaryCount ? { by>( column: C1 ): MappedTableDef & RelatedTable; } : {}; type HasMapperHelper< TFrom, TTo, TPrimaryCount, TExtra = {} > = 6 extends TPrimaryCount ? { by( column: keyof KeyCandidates1, column2: keyof KeyCandidates2, column3: keyof KeyCandidates3, column4: keyof KeyCandidates4, column5: keyof KeyCandidates5, column6: keyof KeyCandidates6 ): MappedTableDef & RelatedTable & TExtra; } : 5 extends TPrimaryCount ? { by( column: keyof KeyCandidates1, column2: keyof KeyCandidates2, column3: keyof KeyCandidates3, column4: keyof KeyCandidates4, column5: keyof KeyCandidates5 ): MappedTableDef & RelatedTable & TExtra; } : 4 extends TPrimaryCount ? { by( column: keyof KeyCandidates1, column2: keyof KeyCandidates2, column3: keyof KeyCandidates3, column4: keyof KeyCandidates4 ): MappedTableDef & RelatedTable & TExtra; } : 3 extends TPrimaryCount ? { by( column: keyof KeyCandidates1, column2: keyof KeyCandidates2, column3: keyof KeyCandidates3 ): MappedTableDef & RelatedTable & TExtra; } : 2 extends TPrimaryCount ? { by( column: keyof KeyCandidates1, column2: keyof KeyCandidates2 ): MappedTableDef & RelatedTable & TExtra; } : 1 extends TPrimaryCount ? { by( column: keyof KeyCandidates1 ): MappedTableDef & RelatedTable & TExtra; } : {}; type ColumnMapperInit = { column(columnName: string): ColumnType<{}>; primaryColumn(columnName: string): ColumnType; }; type ColumnMapper = { references(mappedTable: MappedTableDef): ReferenceMapper; hasOne(mappedTable: MappedTableDef): OneMapper; hasMany(mappedTable: MappedTableDef): ManyMapper; }; type ManyRelation = { [' isManyRelation']: true; }; type OneRelation = { [' isOneRelation']: true; }; type MappedTableDefInit = { map>( callback: (mapper: ColumnMapperInit) => V ): MappedTableDef; } & T; type MappedTableDef = { map>( callback: (mapper: ColumnMapper) => V ): MappedTableDef; formulaDiscriminators(...discriminators: string[]): MappedTableDef; columnDiscriminators(...discriminators: string[]): MappedTableDef; } & T; type NotNullProperties = Pick< T, { [K in keyof T]: T[K] extends NotNull ? K : T[K] extends ManyRelation ? K : never }[keyof T] >; type NullProperties = Pick< T, { [K in keyof T]: T[K] extends NotNull | ManyRelation ? never : K }[keyof T] >; type NotNullInsertProperties = Pick< T, { [K in keyof T]: T[K] extends NotNullExceptInsert ? never : T[K] extends NotNull ? K : never }[keyof T] >; type NullInsertProperties = Pick< T, { [K in keyof T]: T[K] extends NotNullExceptInsert ? K : T[K] extends NotNull ? never : K }[keyof T] >; type ColumnTypes = ColumnSymbols; type ColumnAndTableTypes = ColumnSymbols | RelatedTable; type StrategyToRow = StrategyToRowData & { saveChanges(): Promise; saveChanges>(concurrency?: C): Promise; acceptChanges(): void; clearChanges(): void; refresh(): Promise; refresh>( fetchingStrategy?: FS ): Promise, U>>; delete(): Promise; delete(concurrency: Concurrency): Promise; }; type StrategyToRowArray = StrategyToRowData[] & { saveChanges(): Promise; saveChanges>(concurrency?: C): Promise; acceptChanges(): void; clearChanges(): void; refresh(): Promise; refresh>( fetchingStrategy?: FS ): Promise, U>>; delete(): Promise; delete(concurrency: Concurrency): Promise; }; type JsonValue = null | boolean | number | string | JsonArray | JsonObject; interface JsonArray extends Array { } interface JsonObject { [key: string]: JsonValue; } type JsonType = JsonArray | JsonObject; type AllowedColumnsAndTablesMap = { [P in keyof T]: T[P] extends ColumnTypeOf | RelatedTable ? T[P] : never; }; type AllowedColumnsAndTablesWithPrimaryMap = 1 extends CountFirstPrimary< ExtractPrimary > ? { [P in keyof T]: T[P] extends ColumnTypeOf | RelatedTable ? T[P] : never; } : NeedsPrimaryKey; type NeedsPrimaryKey = { ['Primary column']: void; }; type CountFirstPrimary = UnionOfTypes>; type AllowedColumns = RemoveNever<{ [P in keyof T]: T[P] extends ColumnTypes ? T[P] : never; }>; type AtLeastOneOf = { [K in keyof T]: T[K] extends U ? true : never; }[keyof T] extends never ? false : true; type AtLeastOneTrue = { [K in keyof T]: T[K] extends true ? true : never; }[keyof T] extends never ? false : true; type ExtractColumnBools = RemoveNever<{ [K in keyof TStrategy]: K extends keyof T ? T[K] extends ColumnSymbols ? TStrategy[K] : never : never; }>; type NegotiateNotNull = T extends NotNull ? NotNull : {}; type FetchedProperties = FetchedColumnProperties & FetchedRelationProperties & ExtractAggregates type FetchedAggregateProperties = FetchedColumnProperties & ExtractAggregates type FetchedRelationProperties = RemoveNeverFlat<{ [K in keyof T]: K extends keyof TStrategy ? TStrategy[K] extends true ? T[K] extends ColumnSymbols ? never : T[K] extends ManyRelation ? FetchedProperties & ManyRelation : FetchedProperties & NegotiateNotNull : TStrategy[K] extends false ? never : T[K] extends ManyRelation ? FetchedProperties & ManyRelation : FetchedProperties & NegotiateNotNull : never; }>; type FetchedColumnProperties = RemoveNeverFlat< AtLeastOneTrue> extends true ? { [K in keyof T]: K extends keyof TStrategy ? TStrategy[K] extends true ? T[K] extends ColumnSymbols ? T[K] : never : never : never; } : { [K in keyof T]: K extends keyof TStrategy ? TStrategy[K] extends true ? T[K] extends ColumnSymbols ? T[K] : never : never : NegotiateDefaultStrategy; } >; type StrategyToRowData = { [K in keyof RemoveNever< NotNullProperties >]: T[K] extends StringColumnSymbol ? string : T[K] extends UuidColumnSymbol ? string : T[K] extends NumericColumnSymbol ? number : T[K] extends DateColumnSymbol ? string | Date : T[K] extends DateWithTimeZoneColumnSymbol ? string | Date : T[K] extends BinaryColumnSymbol ? string : T[K] extends BooleanColumnSymbol ? boolean : T[K] extends JsonOf ? M : T[K] extends JSONColumnSymbol ? JsonType : T[K] extends ManyRelation ? StrategyToRowData[] : StrategyToRowData; } & { [K in keyof RemoveNever< NullProperties >]?: T[K] extends StringColumnSymbol ? string | null : T[K] extends UuidColumnSymbol ? string | null : T[K] extends NumericColumnSymbol ? number | null : T[K] extends DateColumnSymbol ? string | Date | null : T[K] extends DateWithTimeZoneColumnSymbol ? string | Date | null : T[K] extends BinaryColumnSymbol ? string | null : T[K] extends BooleanColumnSymbol ? boolean | null : T[K] extends JsonOf ? M | null : T[K] extends JSONColumnSymbol ? JsonType | null : T[K] extends ManyRelation ? StrategyToRowData[] : StrategyToRowData; }; type StrategyToInsertRowData = Omit<{ [K in keyof RemoveNever< NotNullInsertProperties >]: T[K] extends StringColumnSymbol ? string : T[K] extends UuidColumnSymbol ? string : T[K] extends NumericColumnSymbol ? number : T[K] extends DateColumnSymbol ? string | Date : T[K] extends DateWithTimeZoneColumnSymbol ? string | Date : T[K] extends BinaryColumnSymbol ? string : T[K] extends BooleanColumnSymbol ? boolean : T[K] extends JsonOf ? M : T[K] extends JSONColumnSymbol ? JsonType : T[K] extends ManyRelation ? StrategyToInsertRowData[] : StrategyToInsertRowData; } & { [K in keyof RemoveNever< NullInsertProperties >]?: T[K] extends StringColumnSymbol ? string | null : T[K] extends UuidColumnSymbol ? string | null : T[K] extends NumericColumnSymbol ? number | null : T[K] extends DateColumnSymbol ? string | Date | null : T[K] extends DateWithTimeZoneColumnSymbol ? string | Date | null : T[K] extends BinaryColumnSymbol ? string | null : T[K] extends BooleanColumnSymbol ? boolean | null : T[K] extends JsonOf ? M | null : T[K] extends JSONColumnSymbol ? JsonType | null : T[K] extends ManyRelation ? StrategyToInsertRowData[] : StrategyToInsertRowData; }, 'formulaDiscriminators' | 'columnDiscriminators' | 'map' | ' isManyRelation' | ' relatedTable' | ' isOneRelation'> ; type NegotiateDefaultStrategy = T extends ColumnSymbols ? T : never; type RemoveNever = { [K in keyof T as T[K] extends never ? never : K]: T[K] extends object ? RemoveNever : T[K]; }; type RemoveNeverFlat = { [K in keyof T as T[K] extends never ? never : K]: T[K]; }; type UuidColumnSymbol = { [' isUuid']: true; }; type UuidColumnType = { equal(value: string | null | undefined): Filter; eq(value: string | null | undefined): Filter; notEqual(value: string | null | undefined): Filter; ne(value: string | null | undefined): Filter; lessThan(value: string | null | undefined): Filter; lt(value: string | null | undefined): Filter; lessThanOrEqual(value: string | null | undefined): Filter; le(value: string | null | undefined): Filter; greaterThan(value: string | null | undefined): Filter; gt(value: string | null | undefined): Filter; greaterThanOrEqual(value: string | null | undefined): Filter; ge(value: string | null | undefined): Filter; between(from: string | null | undefined, to: string | null | undefined): Filter; in(values: Array): Filter; } & M & UuidColumnSymbol; type BinaryColumnSymbol = { [' isBinary']: true; }; type BinaryColumnType = { equal(value: string | null | undefined): Filter; eq(value: string | null | undefined): Filter; notEqual(value: string | null | undefined): Filter; ne(value: string | null | undefined): Filter; lessThan(value: string | null | undefined): Filter; lt(value: string | null | undefined): Filter; lessThanOrEqual(value: string | null | undefined): Filter; le(value: string | null | undefined): Filter; greaterThan(value: string | null | undefined): Filter; gt(value: string | null | undefined): Filter; greaterThanOrEqual(value: string | null | undefined): Filter; ge(value: string | null | undefined): Filter; between(from: string | null | undefined, to: string | null | undefined): Filter; in(values: Array): Filter; } & M & BinaryColumnSymbol; type BooleanColumnSymbol = { [' isBoolean']: true; }; type BooleanColumnType = { equal(value: boolean | null | undefined): Filter; eq(value: boolean | null | undefined): Filter; notEqual(value: boolean | null | undefined): Filter; ne(value: boolean | null | undefined): Filter; lessThan(value: boolean | null | undefined): Filter; lt(value: boolean | null | undefined): Filter; lessThanOrEqual(value: boolean | null | undefined): Filter; le(value: boolean | null | undefined): Filter; greaterThan(value: boolean | null | undefined): Filter; gt(value: boolean | null | undefined): Filter; greaterThanOrEqual(value: boolean | null | undefined): Filter; ge(value: boolean | null | undefined): Filter; between(from: boolean | null | undefined, to: boolean | null | undefined): Filter; in(values: Array): Filter; } & M & BooleanColumnSymbol; type DateColumnSymbol = { [' isDate']: true; }; type DateColumnType = { equal(value: string | Date | null | undefined): Filter; eq(value: string | Date | null | undefined): Filter; notEqual(value: string | Date | null | undefined): Filter; ne(value: string | Date | null | undefined): Filter; lessThan(value: string | Date | null | undefined): Filter; lt(value: string | Date | null | undefined): Filter; lessThanOrEqual(value: string | Date | null | undefined): Filter; le(value: string | Date | null | undefined): Filter; greaterThan(value: string | Date | null | undefined): Filter; gt(value: string | Date | null | undefined): Filter; greaterThanOrEqual(value: string | Date | null | undefined): Filter; ge(value: string | Date | null | undefined): Filter; between(from: string | Date, to: string | Date | null | undefined): Filter; in(values: Array): Filter; } & M & DateColumnSymbol; type DateWithTimeZoneColumnSymbol = { [' isDateTimeZone']: true; }; type DateWithTimeZoneColumnType = { equal(value: string | Date | null | undefined): Filter; eq(value: string | Date | null | undefined): Filter; notEqual(value: string | Date | null | undefined): Filter; ne(value: string | Date | null | undefined): Filter; lessThan(value: string | Date | null | undefined): Filter; lt(value: string | Date | null | undefined): Filter; lessThanOrEqual(value: string | Date | null | undefined): Filter; le(value: string | Date | null | undefined): Filter; greaterThan(value: string | Date | null | undefined): Filter; gt(value: string | Date | null | undefined): Filter; greaterThanOrEqual(value: string | Date | null | undefined): Filter; ge(value: string | Date | null | undefined): Filter; between(from: string | Date, to: string | Date | null | undefined): Filter; in(values: Array): Filter; } & M & DateWithTimeZoneColumnSymbol; type StringColumnSymbol = { [' isString']: true; }; type StringColumnType = { equal(value: string | null | undefined): Filter; eq(value: string | null | undefined): Filter; notEqual(value: string | null | undefined): Filter; ne(value: string | null | undefined): Filter; lessThan(value: string | null | undefined): Filter; lt(value: string | null | undefined): Filter; lessThanOrEqual(value: string | null | undefined): Filter; le(value: string | null | undefined): Filter; greaterThan(value: string | null | undefined): Filter; gt(value: string | null | undefined): Filter; greaterThanOrEqual(value: string | null | undefined): Filter; ge(value: string | null | undefined): Filter; between(from: string | null | undefined, to: string | null | undefined): Filter; in(values: Array): Filter; startsWith(value: string | null | undefined): Filter; endsWith(value: string | null | undefined): Filter; contains(value: string | null | undefined): Filter; iStartsWith(value: string | null | undefined): Filter; iEndsWith(value: string | null | undefined): Filter; iContains(value: string | null | undefined): Filter; iEqual(value: string | null | undefined): Filter; ieq(value: string | null | undefined): Filter; } & M & StringColumnSymbol; type NumericColumnSymbol = { [' isNumeric']: true; }; type NumericColumnType = { equal(value: number | null | undefined): Filter; eq(value: number | null | undefined): Filter; notEqual(value: number | null | undefined): Filter; ne(value: number | null | undefined): Filter; lessThan(value: number | null | undefined): Filter; lt(value: number | null | undefined): Filter; lessThanOrEqual(value: number | null | undefined): Filter; le(value: number | null | undefined): Filter; greaterThan(value: number | null | undefined): Filter; gt(value: number | null | undefined): Filter; greaterThanOrEqual(value: number | null | undefined): Filter; ge(value: number | null | undefined): Filter; between(from: number, to: number | null | undefined): Filter; in(values: Array): Filter; } & M & NumericColumnSymbol; type JSONColumnSymbol = { [' isJSON']: true; }; type JSONColumnType = { equal(value: ToJsonType | null | undefined): Filter; eq(value: ToJsonType | null | undefined): Filter; notEqual(value: ToJsonType | null | undefined): Filter; ne(value: ToJsonType | null | undefined): Filter; lessThan(value: ToJsonType | null | undefined): Filter; lt(value: ToJsonType | null | undefined): Filter; lessThanOrEqual(value: ToJsonType | null | undefined): Filter; le(value: ToJsonType | null | undefined): Filter; greaterThan(value: ToJsonType | null | undefined): Filter; gt(value: ToJsonType | null | undefined): Filter; greaterThanOrEqual(value: ToJsonType | null | undefined): Filter; ge(value: ToJsonType | null | undefined): Filter; between(from: ToJsonType, to: ToJsonType | null | undefined): Filter; in(values: Array | null | undefined>): Filter; } & M & JSONColumnSymbol; interface IsPrimary { [' isPrimary']: boolean; } type NotNull = { [' notNull']: boolean; }; type NotNullExceptInsert = { [' notNullExceptInsert']: boolean; }; type JsonOf = { [' isjsonOf']: boolean; type: T; }; interface ColumnType { string(): StringColumnTypeDef; uuid(): UuidColumnTypeDef; numeric(): NumericColumnTypeDef; date(): DateColumnTypeDef; dateWithTimeZone(): DateWithTimeZoneColumnTypeDef; binary(): BinaryColumnTypeDef; boolean(): BooleanColumnTypeDef; json(): JSONColumnTypeDef; jsonOf(): JSONColumnTypeDef>; jsonOf(helper: T): JSONColumnTypeDef>; } type UuidValidator = M extends NotNull ? { validate(validator: (value: string) => void): UuidColumnTypeDef; } : { validate( validator: (value?: string | null) => void ): UuidColumnTypeDef; }; type StringValidator = M extends NotNull ? { validate(validator: (value: string) => void): StringColumnTypeDef; } : { validate( validator: (value?: string | null) => void ): StringColumnTypeDef; }; type NumericValidator = M extends NotNull ? { validate(validator: (value: number) => void): NumericColumnTypeDef; } : { validate( validator: (value?: number | null) => void ): NumericColumnTypeDef; }; type BinaryValidator = M extends NotNull ? { validate(validator: (value: string) => void): BinaryColumnTypeDef; } : { validate( validator: (value?: string | null) => void ): BinaryColumnTypeDef; }; type BooleanValidator = M extends NotNull ? { validate(validator: (value: boolean) => void): BooleanColumnTypeDef; } : { validate( validator: (value?: boolean | null) => void ): BooleanColumnTypeDef; }; type JSONValidator = M extends NotNull ? { validate( validator: (value: ToJsonType) => void ): JSONColumnTypeDef; } : { validate( validator: (value?: ToJsonType | null) => void ): JSONColumnTypeDef; }; type DateValidator = M extends NotNull ? { validate( validator: (value: string | Date) => void ): DateColumnTypeDef; } : { validate( validator: (value?: string | Date | null) => void ): DateColumnTypeDef; }; type DateWithTimeZoneValidator = M extends NotNull ? { validate( validator: (value: string | Date) => void ): DateWithTimeZoneColumnTypeDef; } : { validate( validator: (value?: string | Date | null) => void ): DateWithTimeZoneColumnTypeDef; }; type StringColumnTypeDef = StringValidator & { primary(): StringColumnTypeDef & IsPrimary; notNull(): StringColumnTypeDef & NotNull; notNullExceptInsert(): StringColumnTypeDef & NotNull & NotNullExceptInsert; serializable(value: boolean): StringColumnTypeDef; JSONSchema(schema: object, options?: Options): StringColumnTypeDef; default(value: string | null | undefined | (() => string | null | undefined)): StringColumnTypeDef; dbNull(value: string): StringColumnTypeDef; } & ColumnTypeOf> & M; type NumericColumnTypeDef = NumericValidator & { primary(): NumericColumnTypeDef & IsPrimary; notNull(): NumericColumnTypeDef & NotNull; notNullExceptInsert(): NumericColumnTypeDef & NotNull & NotNullExceptInsert; serializable(value: boolean): NumericColumnTypeDef; JSONSchema(schema: object, options?: Options): NumericColumnTypeDef; default(value: number | null | undefined | (() => string | null | undefined)): NumericColumnTypeDef; dbNull(value: number): NumericColumnTypeDef; } & ColumnTypeOf> & M; type UuidColumnTypeDef = UuidValidator & { primary(): UuidColumnTypeDef & IsPrimary; notNull(): UuidColumnTypeDef & NotNull; notNullExceptInsert(): UuidColumnTypeDef & NotNull & NotNullExceptInsert; serializable(value: boolean): UuidColumnTypeDef; JSONSchema(schema: object, options?: Options): UuidColumnTypeDef; default(value: string | null | undefined | (() => string | null | undefined)): UuidColumnTypeDef; dbNull(value: string): UuidColumnTypeDef; } & ColumnTypeOf> & M; type JSONColumnTypeDef = JSONValidator & { primary(): JSONColumnTypeDef & IsPrimary; notNull(): JSONColumnTypeDef & NotNull; notNullExceptInsert(): JSONColumnTypeDef & NotNull & NotNullExceptInsert; serializable(value: boolean): JSONColumnTypeDef; JSONSchema(schema: object, options?: Options): JSONColumnTypeDef; default(value: ToJsonType | null | undefined | (() => string | null | undefined)): JSONColumnTypeDef; dbNull(value: ToJsonType): JSONColumnTypeDef; } & ColumnTypeOf> & M; type BinaryColumnTypeDef = BinaryValidator & { primary(): BinaryColumnTypeDef & IsPrimary; notNull(): BinaryColumnTypeDef & NotNull; notNullExceptInsert(): BinaryColumnTypeDef & NotNull & NotNullExceptInsert; serializable(value: boolean): BinaryColumnTypeDef; JSONSchema(schema: object, options?: Options): BinaryColumnTypeDef; default(value: string | null | undefined | (() => string | null | undefined)): BinaryColumnTypeDef; dbNull(value: string): BinaryColumnTypeDef; } & ColumnTypeOf> & M; type BooleanColumnTypeDef = BooleanValidator & { primary(): BooleanColumnTypeDef & IsPrimary; notNull(): BooleanColumnTypeDef & NotNull; notNullExceptInsert(): BooleanColumnTypeDef & NotNull & NotNullExceptInsert; serializable(value: boolean): BooleanColumnTypeDef; JSONSchema(schema: object, options?: Options): BooleanColumnTypeDef; default(value: boolean | null | undefined | (() => string | null | undefined)): BooleanColumnTypeDef; dbNull(value: boolean): BooleanColumnTypeDef; } & ColumnTypeOf> & M; type DateColumnTypeDef = DateValidator & { primary(): DateColumnTypeDef & IsPrimary; notNull(): DateColumnTypeDef & NotNull; notNullExceptInsert(): DateColumnTypeDef & NotNull & NotNullExceptInsert; serializable(value: boolean): DateColumnTypeDef; JSONSchema(schema: object, options?: Options): DateColumnTypeDef; default(value: string | Date | null | undefined | (() => string | Date | null | undefined)): DateColumnTypeDef; dbNull(value: String | Date): DateColumnTypeDef; } & ColumnTypeOf> & M; type DateWithTimeZoneColumnTypeDef = DateValidator & { primary(): DateWithTimeZoneColumnTypeDef & IsPrimary; notNull(): DateWithTimeZoneColumnTypeDef & NotNull; notNullExceptInsert(): DateWithTimeZoneColumnTypeDef & NotNull & NotNullExceptInsert; serializable(value: boolean): DateWithTimeZoneColumnTypeDef; JSONSchema(schema: object, options?: Options): DateWithTimeZoneColumnTypeDef; default(value: string | Date | null | undefined | (() => string | Date | null | undefined)): DateWithTimeZoneColumnTypeDef; dbNull(value: String | Date): DateWithTimeZoneColumnTypeDef; } & ColumnTypeOf> & M; interface ColumnTypeOf { [' type']: T; } type MapPropertiesTo1 = { [K in keyof T]: V }; type MapPropertiesTo2 = { [K in keyof T]: UnionOfTypes, V>>; }; type MapPropertiesTo3 = { [K in keyof T]: UnionOfTypes, V>>; }; type MapPropertiesTo4 = { [K in keyof T]: UnionOfTypes, V>>; }; type MapPropertiesTo5 = { [K in keyof T]: UnionOfTypes, V>>; }; type MapPropertiesTo6 = { [K in keyof T]: UnionOfTypes, V>>; }; type UnionOfTypes = T[keyof T]; interface RawFilter { sql: string | (() => string); parameters?: any[]; } interface Filter extends RawFilter { and(filter: RawFilter | RawFilter[], ...filters: RawFilter[]): Filter; or(filter: RawFilter | RawFilter[], ...filters: RawFilter[]): Filter; not(): Filter; } type UnionToIntersection = ( U extends any ? (k: U) => void : never ) extends (k: infer I) => void ? I : never; type PopFront = ((...t: T) => void) extends ( _: any, ...rest: infer R ) => void ? R : never; type TupleToUnion = T extends (infer First)[] ? First : T extends [] ? never : T extends [infer First, ...infer Rest] ? First | TupleToUnion : never; type First = T extends [infer Target, ...any[]] ? Target : never; type UnionToTuple = UnionToIntersection< T extends any ? (t: T) => void : never > extends (t: infer T1) => void ? [...UnionToTuple>, T1] : []; type FirstOfUnion = First>; type ToKeyObjects = { [K in keyof T]: { name: K; value: T[K] }; }[keyof T]; type ToKeys = { [K in keyof T]: K; }[keyof T]; type GetKeys = { [K in keyof T]: T[K]; }[keyof T]; type ToUnionTuple = UnionToTuple>; type PropertyToTuple = FirstOfUnion>; type PickProperty = PropertyToTuple; type PickProperty2 = FirstOfUnion>>>; type PickProperty3 = FirstOfUnion< TupleToUnion>>> >; type PickProperty4 = FirstOfUnion< TupleToUnion>>>> >; type PickProperty5 = FirstOfUnion< TupleToUnion>>>>> >; type PickProperty6 = FirstOfUnion< TupleToUnion< PopFront>>>>> > >; type PickPropertyName1 = GetKeys, 'value'>>; type PickPropertyName2 = GetKeys, 'value'>>; type PickPropertyName3 = GetKeys, 'value'>>; type PickPropertyName4 = GetKeys, 'value'>>; type PickPropertyName5 = GetKeys, 'value'>>; type PickPropertyName6 = GetKeys, 'value'>>; type PickPropertyValue1 = GetKeys, 'name'>>; type PickPropertyValue2 = GetKeys, 'name'>>; type PickPropertyValue3 = GetKeys, 'name'>>; type PickPropertyValue4 = GetKeys, 'name'>>; type PickPropertyValue5 = GetKeys, 'name'>>; type PickPropertyValue6 = GetKeys, 'name'>>; type CountProperties = CountPropertiesHelper>>; type CountPropertiesHelper< T extends any[], C extends number = 0 > = T extends [] ? C : CountPropertiesHelper, Increment>; type Increment = C extends 0 ? 1 : C extends 1 ? 2 : C extends 2 ? 3 : C extends 3 ? 4 : C extends 4 ? 5 : 0;