hysteria-orm 10.1.9 → 10.2.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/lib/index.d.cts CHANGED
@@ -2,9 +2,9 @@ import * as mongodb from 'mongodb';
2
2
  import { Collection as Collection$1 } from 'mongodb';
3
3
  import * as sqlite3 from 'sqlite3';
4
4
  import * as pg from 'pg';
5
- import { PoolClient } from 'pg';
5
+ import { ClientConfig, PoolClient } from 'pg';
6
6
  import * as mysql2_promise from 'mysql2/promise';
7
- import { PoolConnection } from 'mysql2/promise';
7
+ import { PoolOptions, PoolConnection } from 'mysql2/promise';
8
8
  import { RedisOptions, Redis } from 'ioredis';
9
9
  import { PassThrough } from 'node:stream';
10
10
  import { FormatOptionsWithLanguage } from 'sql-formatter';
@@ -49,7 +49,6 @@ interface PostgresSqlDataSourceInput extends CommonDataSourceInput {
49
49
  readonly username?: string;
50
50
  readonly password?: string;
51
51
  readonly database?: string;
52
- readonly driverOptions?: PgClientOptions;
53
52
  }
54
53
  interface NotNullablePostgresSqlDataSourceInput extends PostgresSqlDataSourceInput {
55
54
  readonly type?: "postgres" | "cockroachdb";
@@ -58,7 +57,6 @@ interface NotNullablePostgresSqlDataSourceInput extends PostgresSqlDataSourceInp
58
57
  readonly password: string;
59
58
  readonly database: string;
60
59
  readonly port?: number;
61
- readonly driverOptions?: PgClientOptions;
62
60
  }
63
61
  interface MysqlSqlDataSourceInput extends CommonDataSourceInput {
64
62
  readonly type?: "mysql" | "mariadb";
@@ -67,7 +65,6 @@ interface MysqlSqlDataSourceInput extends CommonDataSourceInput {
67
65
  readonly username?: string;
68
66
  readonly password?: string;
69
67
  readonly database?: string;
70
- readonly driverOptions?: MysqlCreateConnectionOptions;
71
68
  }
72
69
  interface NotNullableMysqlSqlDataSourceInput extends MysqlSqlDataSourceInput {
73
70
  readonly type?: "mysql" | "mariadb";
@@ -76,7 +73,6 @@ interface NotNullableMysqlSqlDataSourceInput extends MysqlSqlDataSourceInput {
76
73
  readonly password: string;
77
74
  readonly database: string;
78
75
  readonly port?: number;
79
- readonly driverOptions?: MysqlCreateConnectionOptions;
80
76
  }
81
77
  interface SqliteDataSourceInput extends CommonDataSourceInput {
82
78
  readonly type?: "sqlite";
@@ -95,11 +91,10 @@ type Mysql2Import = typeof mysql2_promise;
95
91
  type PgImport = typeof pg;
96
92
  type Sqlite3Import = typeof sqlite3;
97
93
  type MongoClientImport = typeof mongodb;
98
- type ExcludeStringFromOptions<T> = T extends string ? never : T;
99
- type MysqlCreateConnectionOptions = Parameters<Mysql2Import["createPool"]>[0];
100
- type PgClientOptions = ExcludeStringFromOptions<ConstructorParameters<PgImport["Pool"]>[0]>;
94
+ type MysqlCreateConnectionOptions = PoolOptions;
95
+ type PgClientOptions = ClientConfig;
101
96
  type MongoConnectionOptions = NonNullable<ConstructorParameters<MongoClientImport["MongoClient"]>[1]>;
102
- type DriverSpecificOptions<T extends DataSourceType> = T extends "mongo" ? MongoConnectionOptions : T extends "cockroachdb" ? PgClientOptions : T extends "redis" ? RedisOptions : T extends "postgres" ? PgClientOptions : T extends "mongo" ? MongoConnectionOptions : T extends "mariadb" ? MysqlCreateConnectionOptions : T extends "mysql" ? MysqlCreateConnectionOptions : never;
97
+ type DriverSpecificOptions<T extends DataSourceType> = T extends "mongo" ? MongoConnectionOptions : T extends "cockroachdb" | "postgres" ? PgClientOptions : T extends "redis" ? RedisOptions : T extends "mysql" | "mariadb" ? MysqlCreateConnectionOptions : never;
103
98
 
104
99
  type MongoCollectionKey<T> = T extends Collection ? T : never;
105
100
  type BaseModelMethodOptions$1 = {
@@ -1237,11 +1232,11 @@ declare class AlterTableBuilder extends BaseBuilder {
1237
1232
  */
1238
1233
  dropDefault(columnName: string): void;
1239
1234
  /**
1240
- * @description Adds a primary key to a column
1235
+ * @description Adds a primary key constraint to a column
1236
+ * @param columnName is the column name to add the primary key to
1241
1237
  * @sqlite not supported and will throw error
1242
- * @private Used internally by alterColumn
1243
1238
  */
1244
- private addPrimaryKey;
1239
+ addPrimaryKey(columnName: string): void;
1245
1240
  /**
1246
1241
  * @description Raw non type safe way builder to add a constraint
1247
1242
  * @sqlite not supported and will throw error
@@ -1249,23 +1244,21 @@ declare class AlterTableBuilder extends BaseBuilder {
1249
1244
  addConstraint(...options: ConstructorParameters<typeof ConstraintNode>): void;
1250
1245
  /**
1251
1246
  * @description Adds a foreign key constraint to a column
1247
+ * @param columnName is the column name in the current table
1248
+ * @param foreignTable is the referenced table name
1249
+ * @param foreignColumn is the referenced column name
1250
+ * @param options optional foreign key options (constraintName, onDelete, onUpdate)
1252
1251
  * @sqlite not supported and will throw error
1253
- * @private Used internally by alterColumn
1254
1252
  */
1255
- private addForeignKey;
1253
+ foreignKey(columnName: string, foreignTable: string, foreignColumn: string, options?: ForeignKeyOptions): void;
1256
1254
  /**
1257
1255
  * @description Adds a unique constraint to a column
1258
1256
  * @description By default generates a constraint name using standard pattern: uq_${table}_${column}
1257
+ * @param columnName is the column name in the current table
1258
+ * @param options optional constraint options (constraintName)
1259
1259
  * @sqlite not supported and will throw error
1260
- * @private Used internally by alterColumn
1261
1260
  */
1262
- private unique;
1263
- /**
1264
- * @description Sets a default value for a column
1265
- * @sqlite not supported and will throw error
1266
- * @private Used internally by alterColumn
1267
- */
1268
- private setDefault;
1261
+ unique(columnName: string, options?: CommonConstraintOptions): void;
1269
1262
  /**
1270
1263
  * @description Drops a foreign key by column name and referenced column, generates constraint name using standard pattern: fk_${table}_${leftColumn}_${rightColumn}
1271
1264
  * @description If a custom constraint name was used to generate the foreign key, use `dropConstraint` instead
@@ -1818,6 +1811,10 @@ type ManyToManyOptions<T extends typeof Model, TM extends ThroughModel<T>> = {
1818
1811
  */
1819
1812
  rightForeignKey?: TM extends ThroughModelString ? string : ModelKey<InstanceType<ExtractModelFromTM<TM>>>;
1820
1813
  };
1814
+ type ManyToManyStringOptions = {
1815
+ leftForeignKey?: string;
1816
+ rightForeignKey?: string;
1817
+ };
1821
1818
  type IndexType = {
1822
1819
  columns: string[];
1823
1820
  name: string;
@@ -3397,6 +3394,9 @@ declare class SqlDataSource extends DataSource {
3397
3394
  get registeredModels(): Record<string, typeof Model>;
3398
3395
  }
3399
3396
 
3397
+ type Sqlite3ConnectionOptions = {
3398
+ mode: number;
3399
+ };
3400
3400
  type SqlDriverSpecificOptions<T extends DataSourceType> = Omit<DriverSpecificOptions<T>, "mongoOptions" | "redisOptions">;
3401
3401
  type MysqlConnectionInstance = Awaited<ReturnType<Mysql2Import["createPool"]>>;
3402
3402
  type PgPoolClientInstance = InstanceType<PgImport["Pool"]>;
@@ -3421,7 +3421,7 @@ type SqlDataSourceModel = typeof Model;
3421
3421
  * @description The connectionPolicies object is used to configure the connection policies for the sql data source
3422
3422
  */
3423
3423
  type SqlDataSourceInput<D extends SqlDataSourceType, T extends Record<string, SqlDataSourceModel> = {}, C extends CacheKeys = {}> = {
3424
- readonly type?: Exclude<DataSourceType, "mongo">;
3424
+ readonly type?: D;
3425
3425
  /**
3426
3426
  * @description Whether to log the sql queries and other debug information
3427
3427
  */
@@ -3443,6 +3443,9 @@ type SqlDataSourceInput<D extends SqlDataSourceType, T extends Record<string, Sq
3443
3443
  * @description The driver specific options to use for the sql data source, it's used to configure the driver specific options for the sql data source
3444
3444
  */
3445
3445
  driverOptions?: SqlDriverSpecificOptions<D>;
3446
+ /**
3447
+ * @description The cache strategy to use for the sql data source, it's used to configure the cache strategy for the sql data source
3448
+ */
3446
3449
  cacheStrategy?: {
3447
3450
  cacheAdapter?: CacheAdapter;
3448
3451
  keys: C;
@@ -3944,7 +3947,7 @@ type AnnotatedModel<T extends Model, A extends object = {}, R extends object = {
3944
3947
  $annotations: A;
3945
3948
  } & R;
3946
3949
  type CommonSqlMethodReturnType<T extends SqlMethod> = T extends "count" | "sum" | "avg" | "min" | "max" ? number : T extends "upper" | "lower" | "trim" ? string : T extends "length" ? number : T extends "cast" | "convert" ? any : T extends "abs" | "round" | "floor" | "ceil" ? number : any;
3947
- type RelatedInstance<M extends Model, K extends ModelRelation<M>> = M[K] extends (infer R)[] ? R extends Model ? R : never : M[K] extends Model ? M[K] : never;
3950
+ type RelatedInstance<M extends Model, K extends ModelRelation<M>> = NonNullable<M[K]> extends (infer R)[] ? R extends Model ? R : never : NonNullable<M[K]> extends Model ? NonNullable<M[K]> : never;
3948
3951
 
3949
3952
  type NullableAndUndefinable<T> = T | (T | null) | (T | undefined) | (T | null | undefined);
3950
3953
  type UpsertOptions<T extends Model> = {
@@ -4280,6 +4283,10 @@ declare abstract class Model extends Entity {
4280
4283
  * @description Gives the correct model manager with the correct connection based on the options provided
4281
4284
  */
4282
4285
  private static dispatchModelManager;
4286
+ /**
4287
+ * @description Merges the provided data with the model instance
4288
+ */
4289
+ mergeProps<T extends Model = this>(this: T, data: Partial<ModelWithoutRelations<T>>): void;
4283
4290
  /**
4284
4291
  * @description inserts or updates the model to the database, must have a primary key in order to work
4285
4292
  * @throws {HysteriaError} If the model has no primary key
@@ -4441,18 +4448,21 @@ declare function getModelColumns(target: typeof Model): ColumnType[];
4441
4448
  * ```
4442
4449
  */
4443
4450
  declare function belongsTo<M extends typeof Model = any, R extends typeof Model = any>(model: () => R, foreignKey?: ModelKey<InstanceType<M>>, options?: BaseModelRelationType): PropertyDecorator;
4451
+ declare function belongsTo<R extends typeof Model = any>(model: () => R, foreignKey?: string, options?: BaseModelRelationType): PropertyDecorator;
4444
4452
  /**
4445
4453
  * @description Establishes a has one relation with the given model
4446
4454
  * @default foreignKey by default will be the singular of the model name plus "_id"
4447
4455
  * @example User will have foreignKey "user_id" on the Post model
4448
4456
  */
4449
4457
  declare function hasOne<T extends typeof Model>(model: () => T, foreignKey?: ModelKey<InstanceType<T>>): PropertyDecorator;
4458
+ declare function hasOne<T extends typeof Model>(model: () => T, foreignKey?: string): PropertyDecorator;
4450
4459
  /**
4451
4460
  * @description Establishes a has many relation with the given model
4452
4461
  * @default foreignKey by default will be the singular of the model name plus "_id"
4453
4462
  * @example User will have foreignKey "user_id" on the Post model
4454
4463
  */
4455
4464
  declare function hasMany<T extends typeof Model>(model: () => T, foreignKey?: ModelKey<InstanceType<T>>): PropertyDecorator;
4465
+ declare function hasMany<T extends typeof Model>(model: () => T, foreignKey?: string): PropertyDecorator;
4456
4466
  /**
4457
4467
  * @description Establishes a many to many relation with the given model
4458
4468
  * @default foreignKey by default will be the singular of the model that establishes the relation name plus "_id"
@@ -4464,6 +4474,7 @@ declare function hasMany<T extends typeof Model>(model: () => T, foreignKey?: Mo
4464
4474
  * @example User will have foreignKey "user_id" on the Join table by default
4465
4475
  */
4466
4476
  declare function manyToMany<R extends typeof Model, T extends typeof Model, TM extends ThroughModel<T>>(model: () => R, throughModel: TM, throughModelKeys?: ManyToManyOptions<T, TM>, options?: BaseModelRelationType): PropertyDecorator;
4477
+ declare function manyToMany<R extends typeof Model>(model: () => R, throughModel: string | (() => typeof Model), throughModelKeys?: ManyToManyStringOptions, options?: BaseModelRelationType): PropertyDecorator;
4467
4478
  declare function getRelationsMetadata(target: typeof Model): LazyRelationType[];
4468
4479
  /**
4469
4480
  * @description Returns the relations of the model
@@ -5378,4 +5389,4 @@ declare const generateOpenApiModelWithMetadata: <T extends new () => Model>(mode
5378
5389
  $id?: string;
5379
5390
  }>;
5380
5391
 
5381
- export { type AnnotatedModel, type AsymmetricEncryptionOptions, type AugmentedSqlDataSource, AutogeneratedModel, type BaseModelMethodOptions, type BaseModelRelationType, type CacheAdapter, type CacheKeys, ClientMigrator, Collection, type ColumnDataTypeOption, type ColumnDataTypeOptionSimple, type ColumnDataTypeOptionWithBinary, type ColumnDataTypeOptionWithDatePrecision, type ColumnDataTypeOptionWithEnum, type ColumnDataTypeOptionWithLength, type ColumnDataTypeOptionWithPrecision, type ColumnDataTypeOptionWithScaleAndPrecision, type ColumnDataTypeOptionWithText, type ColumnOptions, type ColumnType, type CommonDataSourceInput, type CommonSqlMethodReturnType, type ConnectionPolicies, type DataSourceInput, type DataSourceType, type DateColumnOptions, DryModelQueryBuilder, DryQueryBuilder, type FetchHooks, type GetConnectionReturnType, HysteriaError, InMemoryAdapter, type IndexType, type LazyRelationType, type ManyOptions, type ManyToManyOptions, Migration, Model, type ModelInstanceType, ModelQueryBuilder, type ModelWithoutRelations, MongoDataSource, type MongoDataSourceInput, type MysqlConnectionInstance, type MysqlSqlDataSourceInput, type NotNullableMysqlSqlDataSourceInput, type NotNullablePostgresSqlDataSourceInput, type NotNullableSqliteDataSourceInput, type NumberModelKey, type OneOptions, type PgPoolClientInstance, type PostgresSqlDataSourceInput, QueryBuilder, type RawModelOptions, RedisCacheAdapter, type RedisFetchable, type RedisStorable, type RelatedInstance, type RelationQueryBuilderType, type SqlCloneOptions, type SqlDataSourceInput, type SqlDataSourceModel, type SqlDataSourceType, type SqlDataSourceWithoutTransaction, type SqlDriverSpecificOptions, type SqlPoolType, type SqliteConnectionInstance, type SqliteDataSourceInput, type StartTransactionOptions, type SymmetricEncryptionOptions, type TableFormat, type ThroughModel, TimestampedModel, Transaction, type TransactionExecutionOptions, type UniqueType, type UseCacheReturnType, type UseConnectionInput, UserMixin, UuidModel, belongsTo, column, createModelFactory, defineMigrator, generateOpenApiModel, generateOpenApiModelSchema, generateOpenApiModelWithMetadata, getCollectionProperties, getIndexes, getModelColumns, type getPoolReturnType, getPrimaryKey, getRelations, getRelationsMetadata, getUniques, hasMany, hasOne, index, HysteriaLogger as logger, manyToMany, MongoDataSource as mongo, property, RedisDataSource as redis, SqlDataSource as sql, unique, view, withPerformance };
5392
+ export { type AnnotatedModel, type AsymmetricEncryptionOptions, type AugmentedSqlDataSource, AutogeneratedModel, type BaseModelMethodOptions, type BaseModelRelationType, type CacheAdapter, type CacheKeys, ClientMigrator, Collection, type ColumnDataTypeOption, type ColumnDataTypeOptionSimple, type ColumnDataTypeOptionWithBinary, type ColumnDataTypeOptionWithDatePrecision, type ColumnDataTypeOptionWithEnum, type ColumnDataTypeOptionWithLength, type ColumnDataTypeOptionWithPrecision, type ColumnDataTypeOptionWithScaleAndPrecision, type ColumnDataTypeOptionWithText, type ColumnOptions, type ColumnType, type CommonDataSourceInput, type CommonSqlMethodReturnType, type ConnectionPolicies, type DataSourceInput, type DataSourceType, type DateColumnOptions, DryModelQueryBuilder, DryQueryBuilder, type FetchHooks, type GetConnectionReturnType, HysteriaError, InMemoryAdapter, type IndexType, type LazyRelationType, type ManyOptions, type ManyToManyOptions, type ManyToManyStringOptions, Migration, Model, type ModelInstanceType, ModelQueryBuilder, type ModelWithoutRelations, MongoDataSource, type MongoDataSourceInput, type MysqlConnectionInstance, type MysqlSqlDataSourceInput, type NotNullableMysqlSqlDataSourceInput, type NotNullablePostgresSqlDataSourceInput, type NotNullableSqliteDataSourceInput, type NumberModelKey, type OneOptions, type PgPoolClientInstance, type PostgresSqlDataSourceInput, QueryBuilder, type RawModelOptions, RedisCacheAdapter, type RedisFetchable, type RedisStorable, type RelatedInstance, type RelationQueryBuilderType, type SqlCloneOptions, type SqlDataSourceInput, type SqlDataSourceModel, type SqlDataSourceType, type SqlDataSourceWithoutTransaction, type SqlDriverSpecificOptions, type SqlPoolType, type Sqlite3ConnectionOptions, type SqliteConnectionInstance, type SqliteDataSourceInput, type StartTransactionOptions, type SymmetricEncryptionOptions, type TableFormat, type ThroughModel, TimestampedModel, Transaction, type TransactionExecutionOptions, type UniqueType, type UseCacheReturnType, type UseConnectionInput, UserMixin, UuidModel, belongsTo, column, createModelFactory, defineMigrator, generateOpenApiModel, generateOpenApiModelSchema, generateOpenApiModelWithMetadata, getCollectionProperties, getIndexes, getModelColumns, type getPoolReturnType, getPrimaryKey, getRelations, getRelationsMetadata, getUniques, hasMany, hasOne, index, HysteriaLogger as logger, manyToMany, MongoDataSource as mongo, property, RedisDataSource as redis, SqlDataSource as sql, unique, view, withPerformance };
package/lib/index.d.ts CHANGED
@@ -2,9 +2,9 @@ import * as mongodb from 'mongodb';
2
2
  import { Collection as Collection$1 } from 'mongodb';
3
3
  import * as sqlite3 from 'sqlite3';
4
4
  import * as pg from 'pg';
5
- import { PoolClient } from 'pg';
5
+ import { ClientConfig, PoolClient } from 'pg';
6
6
  import * as mysql2_promise from 'mysql2/promise';
7
- import { PoolConnection } from 'mysql2/promise';
7
+ import { PoolOptions, PoolConnection } from 'mysql2/promise';
8
8
  import { RedisOptions, Redis } from 'ioredis';
9
9
  import { PassThrough } from 'node:stream';
10
10
  import { FormatOptionsWithLanguage } from 'sql-formatter';
@@ -49,7 +49,6 @@ interface PostgresSqlDataSourceInput extends CommonDataSourceInput {
49
49
  readonly username?: string;
50
50
  readonly password?: string;
51
51
  readonly database?: string;
52
- readonly driverOptions?: PgClientOptions;
53
52
  }
54
53
  interface NotNullablePostgresSqlDataSourceInput extends PostgresSqlDataSourceInput {
55
54
  readonly type?: "postgres" | "cockroachdb";
@@ -58,7 +57,6 @@ interface NotNullablePostgresSqlDataSourceInput extends PostgresSqlDataSourceInp
58
57
  readonly password: string;
59
58
  readonly database: string;
60
59
  readonly port?: number;
61
- readonly driverOptions?: PgClientOptions;
62
60
  }
63
61
  interface MysqlSqlDataSourceInput extends CommonDataSourceInput {
64
62
  readonly type?: "mysql" | "mariadb";
@@ -67,7 +65,6 @@ interface MysqlSqlDataSourceInput extends CommonDataSourceInput {
67
65
  readonly username?: string;
68
66
  readonly password?: string;
69
67
  readonly database?: string;
70
- readonly driverOptions?: MysqlCreateConnectionOptions;
71
68
  }
72
69
  interface NotNullableMysqlSqlDataSourceInput extends MysqlSqlDataSourceInput {
73
70
  readonly type?: "mysql" | "mariadb";
@@ -76,7 +73,6 @@ interface NotNullableMysqlSqlDataSourceInput extends MysqlSqlDataSourceInput {
76
73
  readonly password: string;
77
74
  readonly database: string;
78
75
  readonly port?: number;
79
- readonly driverOptions?: MysqlCreateConnectionOptions;
80
76
  }
81
77
  interface SqliteDataSourceInput extends CommonDataSourceInput {
82
78
  readonly type?: "sqlite";
@@ -95,11 +91,10 @@ type Mysql2Import = typeof mysql2_promise;
95
91
  type PgImport = typeof pg;
96
92
  type Sqlite3Import = typeof sqlite3;
97
93
  type MongoClientImport = typeof mongodb;
98
- type ExcludeStringFromOptions<T> = T extends string ? never : T;
99
- type MysqlCreateConnectionOptions = Parameters<Mysql2Import["createPool"]>[0];
100
- type PgClientOptions = ExcludeStringFromOptions<ConstructorParameters<PgImport["Pool"]>[0]>;
94
+ type MysqlCreateConnectionOptions = PoolOptions;
95
+ type PgClientOptions = ClientConfig;
101
96
  type MongoConnectionOptions = NonNullable<ConstructorParameters<MongoClientImport["MongoClient"]>[1]>;
102
- type DriverSpecificOptions<T extends DataSourceType> = T extends "mongo" ? MongoConnectionOptions : T extends "cockroachdb" ? PgClientOptions : T extends "redis" ? RedisOptions : T extends "postgres" ? PgClientOptions : T extends "mongo" ? MongoConnectionOptions : T extends "mariadb" ? MysqlCreateConnectionOptions : T extends "mysql" ? MysqlCreateConnectionOptions : never;
97
+ type DriverSpecificOptions<T extends DataSourceType> = T extends "mongo" ? MongoConnectionOptions : T extends "cockroachdb" | "postgres" ? PgClientOptions : T extends "redis" ? RedisOptions : T extends "mysql" | "mariadb" ? MysqlCreateConnectionOptions : never;
103
98
 
104
99
  type MongoCollectionKey<T> = T extends Collection ? T : never;
105
100
  type BaseModelMethodOptions$1 = {
@@ -1237,11 +1232,11 @@ declare class AlterTableBuilder extends BaseBuilder {
1237
1232
  */
1238
1233
  dropDefault(columnName: string): void;
1239
1234
  /**
1240
- * @description Adds a primary key to a column
1235
+ * @description Adds a primary key constraint to a column
1236
+ * @param columnName is the column name to add the primary key to
1241
1237
  * @sqlite not supported and will throw error
1242
- * @private Used internally by alterColumn
1243
1238
  */
1244
- private addPrimaryKey;
1239
+ addPrimaryKey(columnName: string): void;
1245
1240
  /**
1246
1241
  * @description Raw non type safe way builder to add a constraint
1247
1242
  * @sqlite not supported and will throw error
@@ -1249,23 +1244,21 @@ declare class AlterTableBuilder extends BaseBuilder {
1249
1244
  addConstraint(...options: ConstructorParameters<typeof ConstraintNode>): void;
1250
1245
  /**
1251
1246
  * @description Adds a foreign key constraint to a column
1247
+ * @param columnName is the column name in the current table
1248
+ * @param foreignTable is the referenced table name
1249
+ * @param foreignColumn is the referenced column name
1250
+ * @param options optional foreign key options (constraintName, onDelete, onUpdate)
1252
1251
  * @sqlite not supported and will throw error
1253
- * @private Used internally by alterColumn
1254
1252
  */
1255
- private addForeignKey;
1253
+ foreignKey(columnName: string, foreignTable: string, foreignColumn: string, options?: ForeignKeyOptions): void;
1256
1254
  /**
1257
1255
  * @description Adds a unique constraint to a column
1258
1256
  * @description By default generates a constraint name using standard pattern: uq_${table}_${column}
1257
+ * @param columnName is the column name in the current table
1258
+ * @param options optional constraint options (constraintName)
1259
1259
  * @sqlite not supported and will throw error
1260
- * @private Used internally by alterColumn
1261
1260
  */
1262
- private unique;
1263
- /**
1264
- * @description Sets a default value for a column
1265
- * @sqlite not supported and will throw error
1266
- * @private Used internally by alterColumn
1267
- */
1268
- private setDefault;
1261
+ unique(columnName: string, options?: CommonConstraintOptions): void;
1269
1262
  /**
1270
1263
  * @description Drops a foreign key by column name and referenced column, generates constraint name using standard pattern: fk_${table}_${leftColumn}_${rightColumn}
1271
1264
  * @description If a custom constraint name was used to generate the foreign key, use `dropConstraint` instead
@@ -1818,6 +1811,10 @@ type ManyToManyOptions<T extends typeof Model, TM extends ThroughModel<T>> = {
1818
1811
  */
1819
1812
  rightForeignKey?: TM extends ThroughModelString ? string : ModelKey<InstanceType<ExtractModelFromTM<TM>>>;
1820
1813
  };
1814
+ type ManyToManyStringOptions = {
1815
+ leftForeignKey?: string;
1816
+ rightForeignKey?: string;
1817
+ };
1821
1818
  type IndexType = {
1822
1819
  columns: string[];
1823
1820
  name: string;
@@ -3397,6 +3394,9 @@ declare class SqlDataSource extends DataSource {
3397
3394
  get registeredModels(): Record<string, typeof Model>;
3398
3395
  }
3399
3396
 
3397
+ type Sqlite3ConnectionOptions = {
3398
+ mode: number;
3399
+ };
3400
3400
  type SqlDriverSpecificOptions<T extends DataSourceType> = Omit<DriverSpecificOptions<T>, "mongoOptions" | "redisOptions">;
3401
3401
  type MysqlConnectionInstance = Awaited<ReturnType<Mysql2Import["createPool"]>>;
3402
3402
  type PgPoolClientInstance = InstanceType<PgImport["Pool"]>;
@@ -3421,7 +3421,7 @@ type SqlDataSourceModel = typeof Model;
3421
3421
  * @description The connectionPolicies object is used to configure the connection policies for the sql data source
3422
3422
  */
3423
3423
  type SqlDataSourceInput<D extends SqlDataSourceType, T extends Record<string, SqlDataSourceModel> = {}, C extends CacheKeys = {}> = {
3424
- readonly type?: Exclude<DataSourceType, "mongo">;
3424
+ readonly type?: D;
3425
3425
  /**
3426
3426
  * @description Whether to log the sql queries and other debug information
3427
3427
  */
@@ -3443,6 +3443,9 @@ type SqlDataSourceInput<D extends SqlDataSourceType, T extends Record<string, Sq
3443
3443
  * @description The driver specific options to use for the sql data source, it's used to configure the driver specific options for the sql data source
3444
3444
  */
3445
3445
  driverOptions?: SqlDriverSpecificOptions<D>;
3446
+ /**
3447
+ * @description The cache strategy to use for the sql data source, it's used to configure the cache strategy for the sql data source
3448
+ */
3446
3449
  cacheStrategy?: {
3447
3450
  cacheAdapter?: CacheAdapter;
3448
3451
  keys: C;
@@ -3944,7 +3947,7 @@ type AnnotatedModel<T extends Model, A extends object = {}, R extends object = {
3944
3947
  $annotations: A;
3945
3948
  } & R;
3946
3949
  type CommonSqlMethodReturnType<T extends SqlMethod> = T extends "count" | "sum" | "avg" | "min" | "max" ? number : T extends "upper" | "lower" | "trim" ? string : T extends "length" ? number : T extends "cast" | "convert" ? any : T extends "abs" | "round" | "floor" | "ceil" ? number : any;
3947
- type RelatedInstance<M extends Model, K extends ModelRelation<M>> = M[K] extends (infer R)[] ? R extends Model ? R : never : M[K] extends Model ? M[K] : never;
3950
+ type RelatedInstance<M extends Model, K extends ModelRelation<M>> = NonNullable<M[K]> extends (infer R)[] ? R extends Model ? R : never : NonNullable<M[K]> extends Model ? NonNullable<M[K]> : never;
3948
3951
 
3949
3952
  type NullableAndUndefinable<T> = T | (T | null) | (T | undefined) | (T | null | undefined);
3950
3953
  type UpsertOptions<T extends Model> = {
@@ -4280,6 +4283,10 @@ declare abstract class Model extends Entity {
4280
4283
  * @description Gives the correct model manager with the correct connection based on the options provided
4281
4284
  */
4282
4285
  private static dispatchModelManager;
4286
+ /**
4287
+ * @description Merges the provided data with the model instance
4288
+ */
4289
+ mergeProps<T extends Model = this>(this: T, data: Partial<ModelWithoutRelations<T>>): void;
4283
4290
  /**
4284
4291
  * @description inserts or updates the model to the database, must have a primary key in order to work
4285
4292
  * @throws {HysteriaError} If the model has no primary key
@@ -4441,18 +4448,21 @@ declare function getModelColumns(target: typeof Model): ColumnType[];
4441
4448
  * ```
4442
4449
  */
4443
4450
  declare function belongsTo<M extends typeof Model = any, R extends typeof Model = any>(model: () => R, foreignKey?: ModelKey<InstanceType<M>>, options?: BaseModelRelationType): PropertyDecorator;
4451
+ declare function belongsTo<R extends typeof Model = any>(model: () => R, foreignKey?: string, options?: BaseModelRelationType): PropertyDecorator;
4444
4452
  /**
4445
4453
  * @description Establishes a has one relation with the given model
4446
4454
  * @default foreignKey by default will be the singular of the model name plus "_id"
4447
4455
  * @example User will have foreignKey "user_id" on the Post model
4448
4456
  */
4449
4457
  declare function hasOne<T extends typeof Model>(model: () => T, foreignKey?: ModelKey<InstanceType<T>>): PropertyDecorator;
4458
+ declare function hasOne<T extends typeof Model>(model: () => T, foreignKey?: string): PropertyDecorator;
4450
4459
  /**
4451
4460
  * @description Establishes a has many relation with the given model
4452
4461
  * @default foreignKey by default will be the singular of the model name plus "_id"
4453
4462
  * @example User will have foreignKey "user_id" on the Post model
4454
4463
  */
4455
4464
  declare function hasMany<T extends typeof Model>(model: () => T, foreignKey?: ModelKey<InstanceType<T>>): PropertyDecorator;
4465
+ declare function hasMany<T extends typeof Model>(model: () => T, foreignKey?: string): PropertyDecorator;
4456
4466
  /**
4457
4467
  * @description Establishes a many to many relation with the given model
4458
4468
  * @default foreignKey by default will be the singular of the model that establishes the relation name plus "_id"
@@ -4464,6 +4474,7 @@ declare function hasMany<T extends typeof Model>(model: () => T, foreignKey?: Mo
4464
4474
  * @example User will have foreignKey "user_id" on the Join table by default
4465
4475
  */
4466
4476
  declare function manyToMany<R extends typeof Model, T extends typeof Model, TM extends ThroughModel<T>>(model: () => R, throughModel: TM, throughModelKeys?: ManyToManyOptions<T, TM>, options?: BaseModelRelationType): PropertyDecorator;
4477
+ declare function manyToMany<R extends typeof Model>(model: () => R, throughModel: string | (() => typeof Model), throughModelKeys?: ManyToManyStringOptions, options?: BaseModelRelationType): PropertyDecorator;
4467
4478
  declare function getRelationsMetadata(target: typeof Model): LazyRelationType[];
4468
4479
  /**
4469
4480
  * @description Returns the relations of the model
@@ -5378,4 +5389,4 @@ declare const generateOpenApiModelWithMetadata: <T extends new () => Model>(mode
5378
5389
  $id?: string;
5379
5390
  }>;
5380
5391
 
5381
- export { type AnnotatedModel, type AsymmetricEncryptionOptions, type AugmentedSqlDataSource, AutogeneratedModel, type BaseModelMethodOptions, type BaseModelRelationType, type CacheAdapter, type CacheKeys, ClientMigrator, Collection, type ColumnDataTypeOption, type ColumnDataTypeOptionSimple, type ColumnDataTypeOptionWithBinary, type ColumnDataTypeOptionWithDatePrecision, type ColumnDataTypeOptionWithEnum, type ColumnDataTypeOptionWithLength, type ColumnDataTypeOptionWithPrecision, type ColumnDataTypeOptionWithScaleAndPrecision, type ColumnDataTypeOptionWithText, type ColumnOptions, type ColumnType, type CommonDataSourceInput, type CommonSqlMethodReturnType, type ConnectionPolicies, type DataSourceInput, type DataSourceType, type DateColumnOptions, DryModelQueryBuilder, DryQueryBuilder, type FetchHooks, type GetConnectionReturnType, HysteriaError, InMemoryAdapter, type IndexType, type LazyRelationType, type ManyOptions, type ManyToManyOptions, Migration, Model, type ModelInstanceType, ModelQueryBuilder, type ModelWithoutRelations, MongoDataSource, type MongoDataSourceInput, type MysqlConnectionInstance, type MysqlSqlDataSourceInput, type NotNullableMysqlSqlDataSourceInput, type NotNullablePostgresSqlDataSourceInput, type NotNullableSqliteDataSourceInput, type NumberModelKey, type OneOptions, type PgPoolClientInstance, type PostgresSqlDataSourceInput, QueryBuilder, type RawModelOptions, RedisCacheAdapter, type RedisFetchable, type RedisStorable, type RelatedInstance, type RelationQueryBuilderType, type SqlCloneOptions, type SqlDataSourceInput, type SqlDataSourceModel, type SqlDataSourceType, type SqlDataSourceWithoutTransaction, type SqlDriverSpecificOptions, type SqlPoolType, type SqliteConnectionInstance, type SqliteDataSourceInput, type StartTransactionOptions, type SymmetricEncryptionOptions, type TableFormat, type ThroughModel, TimestampedModel, Transaction, type TransactionExecutionOptions, type UniqueType, type UseCacheReturnType, type UseConnectionInput, UserMixin, UuidModel, belongsTo, column, createModelFactory, defineMigrator, generateOpenApiModel, generateOpenApiModelSchema, generateOpenApiModelWithMetadata, getCollectionProperties, getIndexes, getModelColumns, type getPoolReturnType, getPrimaryKey, getRelations, getRelationsMetadata, getUniques, hasMany, hasOne, index, HysteriaLogger as logger, manyToMany, MongoDataSource as mongo, property, RedisDataSource as redis, SqlDataSource as sql, unique, view, withPerformance };
5392
+ export { type AnnotatedModel, type AsymmetricEncryptionOptions, type AugmentedSqlDataSource, AutogeneratedModel, type BaseModelMethodOptions, type BaseModelRelationType, type CacheAdapter, type CacheKeys, ClientMigrator, Collection, type ColumnDataTypeOption, type ColumnDataTypeOptionSimple, type ColumnDataTypeOptionWithBinary, type ColumnDataTypeOptionWithDatePrecision, type ColumnDataTypeOptionWithEnum, type ColumnDataTypeOptionWithLength, type ColumnDataTypeOptionWithPrecision, type ColumnDataTypeOptionWithScaleAndPrecision, type ColumnDataTypeOptionWithText, type ColumnOptions, type ColumnType, type CommonDataSourceInput, type CommonSqlMethodReturnType, type ConnectionPolicies, type DataSourceInput, type DataSourceType, type DateColumnOptions, DryModelQueryBuilder, DryQueryBuilder, type FetchHooks, type GetConnectionReturnType, HysteriaError, InMemoryAdapter, type IndexType, type LazyRelationType, type ManyOptions, type ManyToManyOptions, type ManyToManyStringOptions, Migration, Model, type ModelInstanceType, ModelQueryBuilder, type ModelWithoutRelations, MongoDataSource, type MongoDataSourceInput, type MysqlConnectionInstance, type MysqlSqlDataSourceInput, type NotNullableMysqlSqlDataSourceInput, type NotNullablePostgresSqlDataSourceInput, type NotNullableSqliteDataSourceInput, type NumberModelKey, type OneOptions, type PgPoolClientInstance, type PostgresSqlDataSourceInput, QueryBuilder, type RawModelOptions, RedisCacheAdapter, type RedisFetchable, type RedisStorable, type RelatedInstance, type RelationQueryBuilderType, type SqlCloneOptions, type SqlDataSourceInput, type SqlDataSourceModel, type SqlDataSourceType, type SqlDataSourceWithoutTransaction, type SqlDriverSpecificOptions, type SqlPoolType, type Sqlite3ConnectionOptions, type SqliteConnectionInstance, type SqliteDataSourceInput, type StartTransactionOptions, type SymmetricEncryptionOptions, type TableFormat, type ThroughModel, TimestampedModel, Transaction, type TransactionExecutionOptions, type UniqueType, type UseCacheReturnType, type UseConnectionInput, UserMixin, UuidModel, belongsTo, column, createModelFactory, defineMigrator, generateOpenApiModel, generateOpenApiModelSchema, generateOpenApiModelWithMetadata, getCollectionProperties, getIndexes, getModelColumns, type getPoolReturnType, getPrimaryKey, getRelations, getRelationsMetadata, getUniques, hasMany, hasOne, index, HysteriaLogger as logger, manyToMany, MongoDataSource as mongo, property, RedisDataSource as redis, SqlDataSource as sql, unique, view, withPerformance };