hysteria-orm 10.1.7 → 10.1.9

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
@@ -712,6 +712,16 @@ type ForeignKeyOptions = CommonConstraintOptions & {
712
712
  };
713
713
  type CreateTableContext = "alter_table" | "create_table";
714
714
 
715
+ interface CacheAdapter {
716
+ get<T = void>(key: string): Promise<T>;
717
+ set<T = any>(key: string, data: T, ttl?: number): Promise<void>;
718
+ invalidate(key: string): Promise<void>;
719
+ disconnect?(): Promise<void>;
720
+ }
721
+
722
+ type CacheKeys = Record<string, (...args: any[]) => Promise<any>>;
723
+ type UseCacheReturnType<C extends CacheKeys, K extends keyof C> = K extends never ? never : Awaited<ReturnType<C[K]>>;
724
+
715
725
  type OpenApiModelType = {
716
726
  type: "object";
717
727
  properties: Record<string, OpenApiModelPropertyType>;
@@ -3057,6 +3067,14 @@ declare class SqlDataSource extends DataSource {
3057
3067
  * @description Options provided in the sql data source initialization
3058
3068
  */
3059
3069
  inputDetails: SqlDataSourceInput<SqlDataSourceType>;
3070
+ /**
3071
+ * @description Adapter for `useCache`, uses an in memory strategy by default
3072
+ */
3073
+ cacheAdapter: CacheAdapter;
3074
+ /**
3075
+ * @description Maps global keys to specific handlers for cache handling
3076
+ */
3077
+ cacheKeys: CacheKeys;
3060
3078
  /**
3061
3079
  * @description Establishes the default singleton connection used by default by all the Models, if not configuration is passed, env variables will be used instead
3062
3080
  * @description You can continue to use the global sql class exported by hysteria after the connection without having to rely on the return of this function
@@ -3073,8 +3091,8 @@ declare class SqlDataSource extends DataSource {
3073
3091
  * User.query(); // Will use the default connection
3074
3092
  * ```
3075
3093
  */
3076
- static connect<U extends SqlDataSourceType, T extends Record<string, SqlDataSourceModel> = {}>(input: SqlDataSourceInput<U, T>, cb?: (sqlDataSource: AugmentedSqlDataSource<T>) => Promise<void> | void): Promise<AugmentedSqlDataSource<T>>;
3077
- static connect<T extends Record<string, SqlDataSourceModel> = {}>(cb?: (sqlDataSource: AugmentedSqlDataSource<T>) => Promise<void> | void): Promise<SqlDataSource>;
3094
+ static connect<U extends SqlDataSourceType, T extends Record<string, SqlDataSourceModel> = {}, C extends CacheKeys = {}>(input: SqlDataSourceInput<U, T, C>, cb?: (sqlDataSource: AugmentedSqlDataSource<T, C>) => Promise<void> | void): Promise<AugmentedSqlDataSource<T, C>>;
3095
+ static connect<T extends Record<string, SqlDataSourceModel> = {}, C extends CacheKeys = {}>(cb?: (sqlDataSource: AugmentedSqlDataSource<T, C>) => Promise<void> | void): Promise<AugmentedSqlDataSource<T, C>>;
3078
3096
  /**
3079
3097
  * @description Get's another database connection and return it, this won't be marked as the default connection used by the Models, for that use the static method `connect`
3080
3098
  * @description By default not used by the Models, you have to pass it as a parameter to the Models to use it
@@ -3088,8 +3106,8 @@ declare class SqlDataSource extends DataSource {
3088
3106
  * const user = await User.query({ connection: anotherSql }).many();
3089
3107
  * ```
3090
3108
  */
3091
- static connectToSecondarySource<U extends SqlDataSourceType, T extends Record<string, SqlDataSourceModel> = {}>(input: SqlDataSourceInput<U, T>, cb?: (sqlDataSource: AugmentedSqlDataSource<T>) => Promise<void> | void): Promise<AugmentedSqlDataSource<T>>;
3092
- static connectToSecondarySource<T extends Record<string, SqlDataSourceModel> = {}>(cb?: (sqlDataSource: AugmentedSqlDataSource<T>) => Promise<void> | void): Promise<SqlDataSource>;
3109
+ static connectToSecondarySource<U extends SqlDataSourceType, T extends Record<string, SqlDataSourceModel> = {}, C extends CacheKeys = {}>(input: SqlDataSourceInput<U, T, C>, cb?: (sqlDataSource: AugmentedSqlDataSource<T, C>) => Promise<void> | void): Promise<AugmentedSqlDataSource<T, C>>;
3110
+ static connectToSecondarySource<T extends Record<string, SqlDataSourceModel> = {}, C extends CacheKeys = {}>(cb?: (sqlDataSource: AugmentedSqlDataSource<T, C>) => Promise<void> | void): Promise<AugmentedSqlDataSource<T, C>>;
3093
3111
  /**
3094
3112
  * @description Creates a new connection and executes a callback with the new instance, the connection is automatically closed after the callback is executed, so it's lifespan is only inside the callback
3095
3113
  * @description By default not used by the Models, you have to pass it as a parameter to the Models to use it
@@ -3103,7 +3121,7 @@ declare class SqlDataSource extends DataSource {
3103
3121
  * });
3104
3122
  * ```
3105
3123
  */
3106
- static useConnection<U extends SqlDataSourceType, T extends Record<string, SqlDataSourceModel> = {}>(connectionDetails: UseConnectionInput<U, T>, cb: (sqlDataSource: AugmentedSqlDataSource<T>) => Promise<void>): Promise<void>;
3124
+ static useConnection<U extends SqlDataSourceType, T extends Record<string, SqlDataSourceModel> = {}, C extends CacheKeys = {}>(connectionDetails: UseConnectionInput<U, T, C>, cb: (sqlDataSource: AugmentedSqlDataSource<T, C>) => Promise<void>): Promise<void>;
3107
3125
  /**
3108
3126
  * @description Returns the instance of the SqlDataSource
3109
3127
  * @throws {HysteriaError} If the connection is not established
@@ -3194,6 +3212,25 @@ declare class SqlDataSource extends DataSource {
3194
3212
  */
3195
3213
  static rawStatement(value: string): RawNode;
3196
3214
  private constructor();
3215
+ /**
3216
+ * @description Uses the cache adapter to get a value from the cache
3217
+ * @param key The key to get the value from
3218
+ * @param args The arguments to pass to the key handler
3219
+ */
3220
+ useCache<M extends Record<string, typeof Model>, C extends CacheKeys, K extends keyof C>(this: AugmentedSqlDataSource<M, C>, key: K, ...args: Parameters<C[K]>): Promise<UseCacheReturnType<C, K>>;
3221
+ /**
3222
+ * @description Uses the cache adapter to get a value from the cache
3223
+ * @param key The key to get the value from
3224
+ * @param ttl The time to live for the value in milliseconds
3225
+ * @param args The arguments to pass to the key handler
3226
+ */
3227
+ useCache<M extends Record<string, typeof Model>, C extends CacheKeys, K extends keyof C>(this: AugmentedSqlDataSource<M, C>, key: K, ttl: number, ...args: Parameters<C[K]>): Promise<UseCacheReturnType<C, K>>;
3228
+ /**
3229
+ * @description Invalidates a value from the cache
3230
+ * @param key The key to invalidate the value from
3231
+ * @param args The arguments to pass to the key handler
3232
+ */
3233
+ invalidCache<M extends Record<string, typeof Model>, C extends CacheKeys, K extends keyof C>(this: AugmentedSqlDataSource<M, C>, key: K, ...args: Parameters<C[K]>): Promise<void>;
3197
3234
  /**
3198
3235
  * @description Returns true if the connection is established
3199
3236
  */
@@ -3383,7 +3420,7 @@ type SqlDataSourceModel = typeof Model;
3383
3420
  * @description The input type for the SqlDataSource constructor
3384
3421
  * @description The connectionPolicies object is used to configure the connection policies for the sql data source
3385
3422
  */
3386
- type SqlDataSourceInput<D extends SqlDataSourceType, T extends Record<string, SqlDataSourceModel> = {}> = {
3423
+ type SqlDataSourceInput<D extends SqlDataSourceType, T extends Record<string, SqlDataSourceModel> = {}, C extends CacheKeys = {}> = {
3387
3424
  readonly type?: Exclude<DataSourceType, "mongo">;
3388
3425
  /**
3389
3426
  * @description Whether to log the sql queries and other debug information
@@ -3406,14 +3443,22 @@ type SqlDataSourceInput<D extends SqlDataSourceType, T extends Record<string, Sq
3406
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
3407
3444
  */
3408
3445
  driverOptions?: SqlDriverSpecificOptions<D>;
3446
+ cacheStrategy?: {
3447
+ cacheAdapter?: CacheAdapter;
3448
+ keys: C;
3449
+ };
3409
3450
  } & (MysqlSqlDataSourceInput | PostgresSqlDataSourceInput | SqliteDataSourceInput);
3410
- type UseConnectionInput<D extends SqlDataSourceType, T extends Record<string, SqlDataSourceModel> = {}> = {
3451
+ type UseConnectionInput<D extends SqlDataSourceType, T extends Record<string, SqlDataSourceModel> = {}, C extends CacheKeys = {}> = {
3411
3452
  readonly type: Exclude<DataSourceType, "mongo">;
3412
3453
  readonly logs?: boolean;
3413
3454
  readonly models?: T;
3414
3455
  readonly driverOptions?: SqlDriverSpecificOptions<D>;
3415
3456
  connectionPolicies?: ConnectionPolicies;
3416
3457
  queryFormatOptions?: FormatOptionsWithLanguage;
3458
+ cacheStrategy?: {
3459
+ cacheAdapter: CacheAdapter;
3460
+ keys: C;
3461
+ };
3417
3462
  } & (NotNullableMysqlSqlDataSourceInput | NotNullablePostgresSqlDataSourceInput | NotNullableSqliteDataSourceInput);
3418
3463
  type SqlDataSourceType = Exclude<DataSourceType, "mongo">;
3419
3464
  type SqlCloneOptions = {
@@ -3425,7 +3470,17 @@ type SqlCloneOptions = {
3425
3470
  };
3426
3471
  type getPoolReturnType<T = SqlDataSourceType> = T extends "mysql" ? MysqlConnectionInstance : T extends "mariadb" ? MysqlConnectionInstance : T extends "postgres" ? PgPoolClientInstance : T extends "cockroachdb" ? PgPoolClientInstance : T extends "sqlite" ? SqliteConnectionInstance : never;
3427
3472
  type GetConnectionReturnType<T = SqlDataSourceType> = T extends "mysql" ? PoolConnection : T extends "mariadb" ? PoolConnection : T extends "postgres" ? PoolClient : T extends "cockroachdb" ? PoolClient : T extends "sqlite" ? InstanceType<Sqlite3Import["Database"]> : never;
3428
- type AugmentedSqlDataSource<T extends Record<string, SqlDataSourceModel> = {}> = SqlDataSource & {
3473
+ type UseCacheOverloads<C extends CacheKeys> = {
3474
+ <K extends keyof C>(key: K, ...args: Parameters<C[K]>): Promise<UseCacheReturnType<C, K>>;
3475
+ <K extends keyof C>(key: K, ttl: number, ...args: Parameters<C[K]>): Promise<UseCacheReturnType<C, K>>;
3476
+ };
3477
+ type UseCacheType<C extends CacheKeys> = keyof C extends never ? SqlDataSource["useCache"] : UseCacheOverloads<C>;
3478
+ type InvalidCacheType<C extends CacheKeys> = keyof C extends never ? SqlDataSource["invalidCache"] : <K extends keyof C>(key: K) => Promise<void>;
3479
+ type AugmentedSqlDataSource<T extends Record<string, SqlDataSourceModel> = {}, C extends CacheKeys = {}> = Omit<SqlDataSource, "useCache" | "invalidCache" | "clone"> & {
3480
+ useCache: UseCacheType<C>;
3481
+ invalidCache: InvalidCacheType<C>;
3482
+ clone(options?: SqlCloneOptions): Promise<AugmentedSqlDataSource<T, C>>;
3483
+ } & {
3429
3484
  [key in keyof T]: T[key];
3430
3485
  };
3431
3486
  type SqlDataSourceWithoutTransaction<T extends Record<string, SqlDataSourceModel> = {}> = Pick<SqlDataSource, "sqlPool" | "sqlConnection" | "inputDetails" | "isConnected" | "getDbType" | "clone" | "getModelManager" | "getPool" | "getConnection" | "closeConnection" | "getConnectionDetails" | "disconnect" | "syncSchema" | "rawQuery" | "rawStatement" | "getTableSchema" | "getModelOpenApiSchema" | "getTableInfo" | "getIndexInfo" | "getForeignKeyInfo" | "getPrimaryKeyInfo" | "registeredModels" | "type" | "host" | "port" | "username" | "password" | "database" | "logs" | "query"> & {
@@ -4477,6 +4532,25 @@ declare class UserMixin extends Model {
4477
4532
  deletedAt: Date | null;
4478
4533
  }
4479
4534
 
4535
+ declare class InMemoryAdapter implements CacheAdapter {
4536
+ get<T = void>(key: string): Promise<T>;
4537
+ set<T = any>(key: string, data: T, ttl?: number): Promise<void>;
4538
+ invalidate(key: string): Promise<void>;
4539
+ }
4540
+
4541
+ declare class RedisCacheAdapter implements CacheAdapter {
4542
+ redisInstance: Redis;
4543
+ private ioRedisOptions;
4544
+ constructor(ioRedisOptions: RedisOptions);
4545
+ private getClient;
4546
+ get<T = void>(key: string): Promise<T>;
4547
+ set<T = any>(key: string, data: T, ttl?: number): Promise<void>;
4548
+ invalidate(key: string): Promise<void>;
4549
+ private serializeData;
4550
+ private deserializeData;
4551
+ disconnect(): Promise<void>;
4552
+ }
4553
+
4480
4554
  /**
4481
4555
  * @description The RedisStorable type is a type that can be stored in redis
4482
4556
  */
@@ -5226,7 +5300,7 @@ declare abstract class Migration {
5226
5300
  /**
5227
5301
  * @description This method is called after the migration has been run
5228
5302
  */
5229
- afterMigration?(sqlDataSource: SqlDataSource): Promise<void>;
5303
+ afterMigration?(sqlDataSource: SqlDataSource | AugmentedSqlDataSource): Promise<void>;
5230
5304
  }
5231
5305
 
5232
5306
  /**
@@ -5279,7 +5353,7 @@ type WithPerformanceResult<R = any> = [string, R];
5279
5353
  */
5280
5354
  declare const withPerformance: <A extends any[], R>(fn: (...args: A) => Promise<R>, returnType?: "millis" | "seconds", fix?: number) => (...args: A) => Promise<WithPerformanceResult<R>>;
5281
5355
 
5282
- type HysteriaErrorCode = "ROW_NOT_FOUND" | `UNSUPPORTED_DATABASE_TYPE_${string}` | `RELATION_TYPE_NOT_SUPPORTED_${string}` | `NOT_SUPPORTED_IN_${string}` | `RELATION_NOT_FOUND_IN_MODEL_${string}` | `UNKNOWN_RELATION_TYPE_${string}` | `DISTINCT_ON_NOT_SUPPORTED_IN_${string}` | `CONFLICT_COLUMNS_NOT_PRESENT_IN_DATA` | `CONFLICT_COLUMNS_NOT_PRESENT_IN_DATA_${string}` | `FOREIGN_KEY_VALUES_MISSING_FOR_HAS_ONE_RELATION_${string}` | `FOREIGN_KEY_VALUES_MISSING_FOR_BELONGS_TO_RELATION_${string}` | `PRIMARY_KEY_VALUES_MISSING_FOR_HAS_MANY_RELATION_${string}` | `MANY_TO_MANY_RELATION_NOT_FOUND_FOR_RELATED_MODEL_${string}` | `PRIMARY_KEY_VALUES_MISSING_FOR_MANY_TO_MANY_RELATION_${string}` | `RELATED_MODEL_DOES_NOT_HAVE_A_PRIMARY_KEY_${string}` | `FOR_SHARE_NOT_SUPPORTED_IN_${string}` | `SKIP_LOCKED_NOT_SUPPORTED_IN_${string}` | `LOCK_FOR_UPDATE_NOT_SUPPORTED_${string}` | `SQLITE_NOT_SUPPORTED` | `COCKROACHDB_NOT_SUPPORTED` | `RELATION_NOT_FOUND` | `POSTGRES_TABLE_REQUIRED` | `MODEL_HAS_NO_PRIMARY_KEY_VALUE` | `RELATION_NOT_MANY_TO_MANY` | "MATERIALIZED_CTE_NOT_SUPPORTED" | "DUPLICATE_MODEL_KEYS_WHILE_INSTANTIATING_MODELS" | "INVALID_ONE_PARAMETER_WHERE_CONDITION" | "INVALID_PAGINATION_PARAMETERS" | "MISSING_ALIAS_FOR_SUBQUERY" | "MODEL_HAS_NO_PRIMARY_KEY" | "PRIMARY_KEY_NOT_FOUND" | "SQLITE_ONLY_SUPPORTS_SERIALIZABLE_ISOLATION_LEVEL" | "MUST_CALL_BUILD_CTE_AT_LEAST_ONCE" | "REGEXP_NOT_SUPPORTED_IN_SQLITE" | "MANY_TO_MANY_RELATION_MUST_HAVE_A_THROUGH_MODEL" | "INSERT_FAILED" | "MULTIPLE_PRIMARY_KEYS_NOT_ALLOWED" | "FILE_NOT_A_SQL_OR_TXT_FILE" | "CONNECTION_NOT_ESTABLISHED" | "TRANSACTION_NOT_ACTIVE" | "DEVELOPMENT_ERROR" | "MIGRATION_MODULE_NOT_FOUND" | "DRIVER_NOT_FOUND" | "FILE_NOT_FOUND_OR_NOT_ACCESSIBLE" | "ENV_NOT_SET" | "REQUIRED_VALUE_NOT_SET" | "SET_FAILED" | "GET_FAILED" | "REFERENCES_OPTION_REQUIRED" | "DELETE_FAILED" | "INVALID_DEFAULT_VALUE" | "DISCONNECT_FAILED" | "FLUSH_FAILED" | "LEFT_COLUMN_NOT_PROVIDED_FOR_JOIN" | "RIGHT_COLUMN_NOT_PROVIDED_FOR_JOIN" | "MODEL_HAS_NO_PRIMARY_KEY" | "GLOBAL_TRANSACTION_ALREADY_STARTED" | "GLOBAL_TRANSACTION_NOT_STARTED" | "MYSQL_REQUIRES_TABLE_NAME_FOR_INDEX_DROP" | "INVALID_DATE_OBJECT" | "INVALID_DATE_STRING" | "FAILED_TO_PARSE_DATE" | "MIGRATION_MODULE_REQUIRES_TS_NODE" | "FAILED_TO_ENCRYPT_SYMMETRICALLY" | "FAILED_TO_DECRYPT_SYMMETRICALLY" | "FAILED_TO_ENCRYPT_ASYMMETRICALLY" | "FAILED_TO_DECRYPT_ASYMMETRICALLY" | "UNSUPPORTED_RELATION_TYPE" | "LPUSH_FAILED" | "RPUSH_FAILED" | "LPOP_FAILED" | "RPOP_FAILED" | "LRANGE_FAILED" | "LLEN_FAILED" | "HSET_FAILED" | "HMSET_FAILED" | "HGET_FAILED" | "HGETALL_FAILED" | "HMGET_FAILED" | "HDEL_FAILED" | "HEXISTS_FAILED" | "HKEYS_FAILED" | "HLEN_FAILED" | "SADD_FAILED" | "SMEMBERS_FAILED" | "SREM_FAILED" | "SISMEMBER_FAILED" | "SCARD_FAILED" | "SINTER_FAILED" | "SUNION_FAILED" | "SDIFF_FAILED" | "ZADD_FAILED" | "ZRANGE_FAILED" | "ZREVRANGE_FAILED" | "ZREM_FAILED" | "ZSCORE_FAILED" | "ZCARD_FAILED" | "SUBSCRIBE_FAILED" | "UNSUBSCRIBE_FAILED" | "PUBLISH_FAILED" | "PSUBSCRIBE_FAILED" | "PUNSUBSCRIBE_FAILED" | "EXISTS_FAILED" | "EXPIRE_FAILED" | "EXPIREAT_FAILED" | "PEXPIRE_FAILED" | "TTL_FAILED" | "PTTL_FAILED" | "PERSIST_FAILED" | "KEYS_FAILED" | "RENAME_FAILED" | "TYPE_FAILED" | "SCAN_FAILED";
5356
+ type HysteriaErrorCode = "ROW_NOT_FOUND" | `UNSUPPORTED_DATABASE_TYPE_${string}` | `RELATION_TYPE_NOT_SUPPORTED_${string}` | `NOT_SUPPORTED_IN_${string}` | `RELATION_NOT_FOUND_IN_MODEL_${string}` | `UNKNOWN_RELATION_TYPE_${string}` | `DISTINCT_ON_NOT_SUPPORTED_IN_${string}` | `CONFLICT_COLUMNS_NOT_PRESENT_IN_DATA` | `CONFLICT_COLUMNS_NOT_PRESENT_IN_DATA_${string}` | `FOREIGN_KEY_VALUES_MISSING_FOR_HAS_ONE_RELATION_${string}` | `FOREIGN_KEY_VALUES_MISSING_FOR_BELONGS_TO_RELATION_${string}` | `PRIMARY_KEY_VALUES_MISSING_FOR_HAS_MANY_RELATION_${string}` | `MANY_TO_MANY_RELATION_NOT_FOUND_FOR_RELATED_MODEL_${string}` | `PRIMARY_KEY_VALUES_MISSING_FOR_MANY_TO_MANY_RELATION_${string}` | `RELATED_MODEL_DOES_NOT_HAVE_A_PRIMARY_KEY_${string}` | `FOR_SHARE_NOT_SUPPORTED_IN_${string}` | `SKIP_LOCKED_NOT_SUPPORTED_IN_${string}` | `LOCK_FOR_UPDATE_NOT_SUPPORTED_${string}` | `KEY_${string}_HAS_NO_HANDLER_IN_CACHE_KEYS_CONFIG` | `CACHE_ADAPTER_NOT_CONFIGURED` | `SQLITE_NOT_SUPPORTED` | `COCKROACHDB_NOT_SUPPORTED` | `RELATION_NOT_FOUND` | `POSTGRES_TABLE_REQUIRED` | `MODEL_HAS_NO_PRIMARY_KEY_VALUE` | `RELATION_NOT_MANY_TO_MANY` | "MATERIALIZED_CTE_NOT_SUPPORTED" | "DUPLICATE_MODEL_KEYS_WHILE_INSTANTIATING_MODELS" | "INVALID_ONE_PARAMETER_WHERE_CONDITION" | "INVALID_PAGINATION_PARAMETERS" | "MISSING_ALIAS_FOR_SUBQUERY" | "MODEL_HAS_NO_PRIMARY_KEY" | "PRIMARY_KEY_NOT_FOUND" | "SQLITE_ONLY_SUPPORTS_SERIALIZABLE_ISOLATION_LEVEL" | "MUST_CALL_BUILD_CTE_AT_LEAST_ONCE" | "REGEXP_NOT_SUPPORTED_IN_SQLITE" | "MANY_TO_MANY_RELATION_MUST_HAVE_A_THROUGH_MODEL" | "INSERT_FAILED" | "MULTIPLE_PRIMARY_KEYS_NOT_ALLOWED" | "FILE_NOT_A_SQL_OR_TXT_FILE" | "CONNECTION_NOT_ESTABLISHED" | "TRANSACTION_NOT_ACTIVE" | "DEVELOPMENT_ERROR" | "MIGRATION_MODULE_NOT_FOUND" | "DRIVER_NOT_FOUND" | "FILE_NOT_FOUND_OR_NOT_ACCESSIBLE" | "ENV_NOT_SET" | "REQUIRED_VALUE_NOT_SET" | "SET_FAILED" | "GET_FAILED" | "REFERENCES_OPTION_REQUIRED" | "DELETE_FAILED" | "INVALID_DEFAULT_VALUE" | "DISCONNECT_FAILED" | "FLUSH_FAILED" | "LEFT_COLUMN_NOT_PROVIDED_FOR_JOIN" | "RIGHT_COLUMN_NOT_PROVIDED_FOR_JOIN" | "MODEL_HAS_NO_PRIMARY_KEY" | "GLOBAL_TRANSACTION_ALREADY_STARTED" | "GLOBAL_TRANSACTION_NOT_STARTED" | "MYSQL_REQUIRES_TABLE_NAME_FOR_INDEX_DROP" | "INVALID_DATE_OBJECT" | "INVALID_DATE_STRING" | "FAILED_TO_PARSE_DATE" | "MIGRATION_MODULE_REQUIRES_TS_NODE" | "FAILED_TO_ENCRYPT_SYMMETRICALLY" | "FAILED_TO_DECRYPT_SYMMETRICALLY" | "FAILED_TO_ENCRYPT_ASYMMETRICALLY" | "FAILED_TO_DECRYPT_ASYMMETRICALLY" | "UNSUPPORTED_RELATION_TYPE" | "LPUSH_FAILED" | "RPUSH_FAILED" | "LPOP_FAILED" | "RPOP_FAILED" | "LRANGE_FAILED" | "LLEN_FAILED" | "HSET_FAILED" | "HMSET_FAILED" | "HGET_FAILED" | "HGETALL_FAILED" | "HMGET_FAILED" | "HDEL_FAILED" | "HEXISTS_FAILED" | "HKEYS_FAILED" | "HLEN_FAILED" | "SADD_FAILED" | "SMEMBERS_FAILED" | "SREM_FAILED" | "SISMEMBER_FAILED" | "SCARD_FAILED" | "SINTER_FAILED" | "SUNION_FAILED" | "SDIFF_FAILED" | "ZADD_FAILED" | "ZRANGE_FAILED" | "ZREVRANGE_FAILED" | "ZREM_FAILED" | "ZSCORE_FAILED" | "ZCARD_FAILED" | "SUBSCRIBE_FAILED" | "UNSUBSCRIBE_FAILED" | "PUBLISH_FAILED" | "PSUBSCRIBE_FAILED" | "PUNSUBSCRIBE_FAILED" | "EXISTS_FAILED" | "EXPIRE_FAILED" | "EXPIREAT_FAILED" | "PEXPIRE_FAILED" | "TTL_FAILED" | "PTTL_FAILED" | "PERSIST_FAILED" | "KEYS_FAILED" | "RENAME_FAILED" | "TYPE_FAILED" | "SCAN_FAILED";
5283
5357
 
5284
5358
  declare class HysteriaError extends Error {
5285
5359
  code: HysteriaErrorCode;
@@ -5304,4 +5378,4 @@ declare const generateOpenApiModelWithMetadata: <T extends new () => Model>(mode
5304
5378
  $id?: string;
5305
5379
  }>;
5306
5380
 
5307
- export { type AnnotatedModel, type AsymmetricEncryptionOptions, type AugmentedSqlDataSource, AutogeneratedModel, type BaseModelMethodOptions, type BaseModelRelationType, 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, 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, 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 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 };
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 };
package/lib/index.d.ts CHANGED
@@ -712,6 +712,16 @@ type ForeignKeyOptions = CommonConstraintOptions & {
712
712
  };
713
713
  type CreateTableContext = "alter_table" | "create_table";
714
714
 
715
+ interface CacheAdapter {
716
+ get<T = void>(key: string): Promise<T>;
717
+ set<T = any>(key: string, data: T, ttl?: number): Promise<void>;
718
+ invalidate(key: string): Promise<void>;
719
+ disconnect?(): Promise<void>;
720
+ }
721
+
722
+ type CacheKeys = Record<string, (...args: any[]) => Promise<any>>;
723
+ type UseCacheReturnType<C extends CacheKeys, K extends keyof C> = K extends never ? never : Awaited<ReturnType<C[K]>>;
724
+
715
725
  type OpenApiModelType = {
716
726
  type: "object";
717
727
  properties: Record<string, OpenApiModelPropertyType>;
@@ -3057,6 +3067,14 @@ declare class SqlDataSource extends DataSource {
3057
3067
  * @description Options provided in the sql data source initialization
3058
3068
  */
3059
3069
  inputDetails: SqlDataSourceInput<SqlDataSourceType>;
3070
+ /**
3071
+ * @description Adapter for `useCache`, uses an in memory strategy by default
3072
+ */
3073
+ cacheAdapter: CacheAdapter;
3074
+ /**
3075
+ * @description Maps global keys to specific handlers for cache handling
3076
+ */
3077
+ cacheKeys: CacheKeys;
3060
3078
  /**
3061
3079
  * @description Establishes the default singleton connection used by default by all the Models, if not configuration is passed, env variables will be used instead
3062
3080
  * @description You can continue to use the global sql class exported by hysteria after the connection without having to rely on the return of this function
@@ -3073,8 +3091,8 @@ declare class SqlDataSource extends DataSource {
3073
3091
  * User.query(); // Will use the default connection
3074
3092
  * ```
3075
3093
  */
3076
- static connect<U extends SqlDataSourceType, T extends Record<string, SqlDataSourceModel> = {}>(input: SqlDataSourceInput<U, T>, cb?: (sqlDataSource: AugmentedSqlDataSource<T>) => Promise<void> | void): Promise<AugmentedSqlDataSource<T>>;
3077
- static connect<T extends Record<string, SqlDataSourceModel> = {}>(cb?: (sqlDataSource: AugmentedSqlDataSource<T>) => Promise<void> | void): Promise<SqlDataSource>;
3094
+ static connect<U extends SqlDataSourceType, T extends Record<string, SqlDataSourceModel> = {}, C extends CacheKeys = {}>(input: SqlDataSourceInput<U, T, C>, cb?: (sqlDataSource: AugmentedSqlDataSource<T, C>) => Promise<void> | void): Promise<AugmentedSqlDataSource<T, C>>;
3095
+ static connect<T extends Record<string, SqlDataSourceModel> = {}, C extends CacheKeys = {}>(cb?: (sqlDataSource: AugmentedSqlDataSource<T, C>) => Promise<void> | void): Promise<AugmentedSqlDataSource<T, C>>;
3078
3096
  /**
3079
3097
  * @description Get's another database connection and return it, this won't be marked as the default connection used by the Models, for that use the static method `connect`
3080
3098
  * @description By default not used by the Models, you have to pass it as a parameter to the Models to use it
@@ -3088,8 +3106,8 @@ declare class SqlDataSource extends DataSource {
3088
3106
  * const user = await User.query({ connection: anotherSql }).many();
3089
3107
  * ```
3090
3108
  */
3091
- static connectToSecondarySource<U extends SqlDataSourceType, T extends Record<string, SqlDataSourceModel> = {}>(input: SqlDataSourceInput<U, T>, cb?: (sqlDataSource: AugmentedSqlDataSource<T>) => Promise<void> | void): Promise<AugmentedSqlDataSource<T>>;
3092
- static connectToSecondarySource<T extends Record<string, SqlDataSourceModel> = {}>(cb?: (sqlDataSource: AugmentedSqlDataSource<T>) => Promise<void> | void): Promise<SqlDataSource>;
3109
+ static connectToSecondarySource<U extends SqlDataSourceType, T extends Record<string, SqlDataSourceModel> = {}, C extends CacheKeys = {}>(input: SqlDataSourceInput<U, T, C>, cb?: (sqlDataSource: AugmentedSqlDataSource<T, C>) => Promise<void> | void): Promise<AugmentedSqlDataSource<T, C>>;
3110
+ static connectToSecondarySource<T extends Record<string, SqlDataSourceModel> = {}, C extends CacheKeys = {}>(cb?: (sqlDataSource: AugmentedSqlDataSource<T, C>) => Promise<void> | void): Promise<AugmentedSqlDataSource<T, C>>;
3093
3111
  /**
3094
3112
  * @description Creates a new connection and executes a callback with the new instance, the connection is automatically closed after the callback is executed, so it's lifespan is only inside the callback
3095
3113
  * @description By default not used by the Models, you have to pass it as a parameter to the Models to use it
@@ -3103,7 +3121,7 @@ declare class SqlDataSource extends DataSource {
3103
3121
  * });
3104
3122
  * ```
3105
3123
  */
3106
- static useConnection<U extends SqlDataSourceType, T extends Record<string, SqlDataSourceModel> = {}>(connectionDetails: UseConnectionInput<U, T>, cb: (sqlDataSource: AugmentedSqlDataSource<T>) => Promise<void>): Promise<void>;
3124
+ static useConnection<U extends SqlDataSourceType, T extends Record<string, SqlDataSourceModel> = {}, C extends CacheKeys = {}>(connectionDetails: UseConnectionInput<U, T, C>, cb: (sqlDataSource: AugmentedSqlDataSource<T, C>) => Promise<void>): Promise<void>;
3107
3125
  /**
3108
3126
  * @description Returns the instance of the SqlDataSource
3109
3127
  * @throws {HysteriaError} If the connection is not established
@@ -3194,6 +3212,25 @@ declare class SqlDataSource extends DataSource {
3194
3212
  */
3195
3213
  static rawStatement(value: string): RawNode;
3196
3214
  private constructor();
3215
+ /**
3216
+ * @description Uses the cache adapter to get a value from the cache
3217
+ * @param key The key to get the value from
3218
+ * @param args The arguments to pass to the key handler
3219
+ */
3220
+ useCache<M extends Record<string, typeof Model>, C extends CacheKeys, K extends keyof C>(this: AugmentedSqlDataSource<M, C>, key: K, ...args: Parameters<C[K]>): Promise<UseCacheReturnType<C, K>>;
3221
+ /**
3222
+ * @description Uses the cache adapter to get a value from the cache
3223
+ * @param key The key to get the value from
3224
+ * @param ttl The time to live for the value in milliseconds
3225
+ * @param args The arguments to pass to the key handler
3226
+ */
3227
+ useCache<M extends Record<string, typeof Model>, C extends CacheKeys, K extends keyof C>(this: AugmentedSqlDataSource<M, C>, key: K, ttl: number, ...args: Parameters<C[K]>): Promise<UseCacheReturnType<C, K>>;
3228
+ /**
3229
+ * @description Invalidates a value from the cache
3230
+ * @param key The key to invalidate the value from
3231
+ * @param args The arguments to pass to the key handler
3232
+ */
3233
+ invalidCache<M extends Record<string, typeof Model>, C extends CacheKeys, K extends keyof C>(this: AugmentedSqlDataSource<M, C>, key: K, ...args: Parameters<C[K]>): Promise<void>;
3197
3234
  /**
3198
3235
  * @description Returns true if the connection is established
3199
3236
  */
@@ -3383,7 +3420,7 @@ type SqlDataSourceModel = typeof Model;
3383
3420
  * @description The input type for the SqlDataSource constructor
3384
3421
  * @description The connectionPolicies object is used to configure the connection policies for the sql data source
3385
3422
  */
3386
- type SqlDataSourceInput<D extends SqlDataSourceType, T extends Record<string, SqlDataSourceModel> = {}> = {
3423
+ type SqlDataSourceInput<D extends SqlDataSourceType, T extends Record<string, SqlDataSourceModel> = {}, C extends CacheKeys = {}> = {
3387
3424
  readonly type?: Exclude<DataSourceType, "mongo">;
3388
3425
  /**
3389
3426
  * @description Whether to log the sql queries and other debug information
@@ -3406,14 +3443,22 @@ type SqlDataSourceInput<D extends SqlDataSourceType, T extends Record<string, Sq
3406
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
3407
3444
  */
3408
3445
  driverOptions?: SqlDriverSpecificOptions<D>;
3446
+ cacheStrategy?: {
3447
+ cacheAdapter?: CacheAdapter;
3448
+ keys: C;
3449
+ };
3409
3450
  } & (MysqlSqlDataSourceInput | PostgresSqlDataSourceInput | SqliteDataSourceInput);
3410
- type UseConnectionInput<D extends SqlDataSourceType, T extends Record<string, SqlDataSourceModel> = {}> = {
3451
+ type UseConnectionInput<D extends SqlDataSourceType, T extends Record<string, SqlDataSourceModel> = {}, C extends CacheKeys = {}> = {
3411
3452
  readonly type: Exclude<DataSourceType, "mongo">;
3412
3453
  readonly logs?: boolean;
3413
3454
  readonly models?: T;
3414
3455
  readonly driverOptions?: SqlDriverSpecificOptions<D>;
3415
3456
  connectionPolicies?: ConnectionPolicies;
3416
3457
  queryFormatOptions?: FormatOptionsWithLanguage;
3458
+ cacheStrategy?: {
3459
+ cacheAdapter: CacheAdapter;
3460
+ keys: C;
3461
+ };
3417
3462
  } & (NotNullableMysqlSqlDataSourceInput | NotNullablePostgresSqlDataSourceInput | NotNullableSqliteDataSourceInput);
3418
3463
  type SqlDataSourceType = Exclude<DataSourceType, "mongo">;
3419
3464
  type SqlCloneOptions = {
@@ -3425,7 +3470,17 @@ type SqlCloneOptions = {
3425
3470
  };
3426
3471
  type getPoolReturnType<T = SqlDataSourceType> = T extends "mysql" ? MysqlConnectionInstance : T extends "mariadb" ? MysqlConnectionInstance : T extends "postgres" ? PgPoolClientInstance : T extends "cockroachdb" ? PgPoolClientInstance : T extends "sqlite" ? SqliteConnectionInstance : never;
3427
3472
  type GetConnectionReturnType<T = SqlDataSourceType> = T extends "mysql" ? PoolConnection : T extends "mariadb" ? PoolConnection : T extends "postgres" ? PoolClient : T extends "cockroachdb" ? PoolClient : T extends "sqlite" ? InstanceType<Sqlite3Import["Database"]> : never;
3428
- type AugmentedSqlDataSource<T extends Record<string, SqlDataSourceModel> = {}> = SqlDataSource & {
3473
+ type UseCacheOverloads<C extends CacheKeys> = {
3474
+ <K extends keyof C>(key: K, ...args: Parameters<C[K]>): Promise<UseCacheReturnType<C, K>>;
3475
+ <K extends keyof C>(key: K, ttl: number, ...args: Parameters<C[K]>): Promise<UseCacheReturnType<C, K>>;
3476
+ };
3477
+ type UseCacheType<C extends CacheKeys> = keyof C extends never ? SqlDataSource["useCache"] : UseCacheOverloads<C>;
3478
+ type InvalidCacheType<C extends CacheKeys> = keyof C extends never ? SqlDataSource["invalidCache"] : <K extends keyof C>(key: K) => Promise<void>;
3479
+ type AugmentedSqlDataSource<T extends Record<string, SqlDataSourceModel> = {}, C extends CacheKeys = {}> = Omit<SqlDataSource, "useCache" | "invalidCache" | "clone"> & {
3480
+ useCache: UseCacheType<C>;
3481
+ invalidCache: InvalidCacheType<C>;
3482
+ clone(options?: SqlCloneOptions): Promise<AugmentedSqlDataSource<T, C>>;
3483
+ } & {
3429
3484
  [key in keyof T]: T[key];
3430
3485
  };
3431
3486
  type SqlDataSourceWithoutTransaction<T extends Record<string, SqlDataSourceModel> = {}> = Pick<SqlDataSource, "sqlPool" | "sqlConnection" | "inputDetails" | "isConnected" | "getDbType" | "clone" | "getModelManager" | "getPool" | "getConnection" | "closeConnection" | "getConnectionDetails" | "disconnect" | "syncSchema" | "rawQuery" | "rawStatement" | "getTableSchema" | "getModelOpenApiSchema" | "getTableInfo" | "getIndexInfo" | "getForeignKeyInfo" | "getPrimaryKeyInfo" | "registeredModels" | "type" | "host" | "port" | "username" | "password" | "database" | "logs" | "query"> & {
@@ -4477,6 +4532,25 @@ declare class UserMixin extends Model {
4477
4532
  deletedAt: Date | null;
4478
4533
  }
4479
4534
 
4535
+ declare class InMemoryAdapter implements CacheAdapter {
4536
+ get<T = void>(key: string): Promise<T>;
4537
+ set<T = any>(key: string, data: T, ttl?: number): Promise<void>;
4538
+ invalidate(key: string): Promise<void>;
4539
+ }
4540
+
4541
+ declare class RedisCacheAdapter implements CacheAdapter {
4542
+ redisInstance: Redis;
4543
+ private ioRedisOptions;
4544
+ constructor(ioRedisOptions: RedisOptions);
4545
+ private getClient;
4546
+ get<T = void>(key: string): Promise<T>;
4547
+ set<T = any>(key: string, data: T, ttl?: number): Promise<void>;
4548
+ invalidate(key: string): Promise<void>;
4549
+ private serializeData;
4550
+ private deserializeData;
4551
+ disconnect(): Promise<void>;
4552
+ }
4553
+
4480
4554
  /**
4481
4555
  * @description The RedisStorable type is a type that can be stored in redis
4482
4556
  */
@@ -5226,7 +5300,7 @@ declare abstract class Migration {
5226
5300
  /**
5227
5301
  * @description This method is called after the migration has been run
5228
5302
  */
5229
- afterMigration?(sqlDataSource: SqlDataSource): Promise<void>;
5303
+ afterMigration?(sqlDataSource: SqlDataSource | AugmentedSqlDataSource): Promise<void>;
5230
5304
  }
5231
5305
 
5232
5306
  /**
@@ -5279,7 +5353,7 @@ type WithPerformanceResult<R = any> = [string, R];
5279
5353
  */
5280
5354
  declare const withPerformance: <A extends any[], R>(fn: (...args: A) => Promise<R>, returnType?: "millis" | "seconds", fix?: number) => (...args: A) => Promise<WithPerformanceResult<R>>;
5281
5355
 
5282
- type HysteriaErrorCode = "ROW_NOT_FOUND" | `UNSUPPORTED_DATABASE_TYPE_${string}` | `RELATION_TYPE_NOT_SUPPORTED_${string}` | `NOT_SUPPORTED_IN_${string}` | `RELATION_NOT_FOUND_IN_MODEL_${string}` | `UNKNOWN_RELATION_TYPE_${string}` | `DISTINCT_ON_NOT_SUPPORTED_IN_${string}` | `CONFLICT_COLUMNS_NOT_PRESENT_IN_DATA` | `CONFLICT_COLUMNS_NOT_PRESENT_IN_DATA_${string}` | `FOREIGN_KEY_VALUES_MISSING_FOR_HAS_ONE_RELATION_${string}` | `FOREIGN_KEY_VALUES_MISSING_FOR_BELONGS_TO_RELATION_${string}` | `PRIMARY_KEY_VALUES_MISSING_FOR_HAS_MANY_RELATION_${string}` | `MANY_TO_MANY_RELATION_NOT_FOUND_FOR_RELATED_MODEL_${string}` | `PRIMARY_KEY_VALUES_MISSING_FOR_MANY_TO_MANY_RELATION_${string}` | `RELATED_MODEL_DOES_NOT_HAVE_A_PRIMARY_KEY_${string}` | `FOR_SHARE_NOT_SUPPORTED_IN_${string}` | `SKIP_LOCKED_NOT_SUPPORTED_IN_${string}` | `LOCK_FOR_UPDATE_NOT_SUPPORTED_${string}` | `SQLITE_NOT_SUPPORTED` | `COCKROACHDB_NOT_SUPPORTED` | `RELATION_NOT_FOUND` | `POSTGRES_TABLE_REQUIRED` | `MODEL_HAS_NO_PRIMARY_KEY_VALUE` | `RELATION_NOT_MANY_TO_MANY` | "MATERIALIZED_CTE_NOT_SUPPORTED" | "DUPLICATE_MODEL_KEYS_WHILE_INSTANTIATING_MODELS" | "INVALID_ONE_PARAMETER_WHERE_CONDITION" | "INVALID_PAGINATION_PARAMETERS" | "MISSING_ALIAS_FOR_SUBQUERY" | "MODEL_HAS_NO_PRIMARY_KEY" | "PRIMARY_KEY_NOT_FOUND" | "SQLITE_ONLY_SUPPORTS_SERIALIZABLE_ISOLATION_LEVEL" | "MUST_CALL_BUILD_CTE_AT_LEAST_ONCE" | "REGEXP_NOT_SUPPORTED_IN_SQLITE" | "MANY_TO_MANY_RELATION_MUST_HAVE_A_THROUGH_MODEL" | "INSERT_FAILED" | "MULTIPLE_PRIMARY_KEYS_NOT_ALLOWED" | "FILE_NOT_A_SQL_OR_TXT_FILE" | "CONNECTION_NOT_ESTABLISHED" | "TRANSACTION_NOT_ACTIVE" | "DEVELOPMENT_ERROR" | "MIGRATION_MODULE_NOT_FOUND" | "DRIVER_NOT_FOUND" | "FILE_NOT_FOUND_OR_NOT_ACCESSIBLE" | "ENV_NOT_SET" | "REQUIRED_VALUE_NOT_SET" | "SET_FAILED" | "GET_FAILED" | "REFERENCES_OPTION_REQUIRED" | "DELETE_FAILED" | "INVALID_DEFAULT_VALUE" | "DISCONNECT_FAILED" | "FLUSH_FAILED" | "LEFT_COLUMN_NOT_PROVIDED_FOR_JOIN" | "RIGHT_COLUMN_NOT_PROVIDED_FOR_JOIN" | "MODEL_HAS_NO_PRIMARY_KEY" | "GLOBAL_TRANSACTION_ALREADY_STARTED" | "GLOBAL_TRANSACTION_NOT_STARTED" | "MYSQL_REQUIRES_TABLE_NAME_FOR_INDEX_DROP" | "INVALID_DATE_OBJECT" | "INVALID_DATE_STRING" | "FAILED_TO_PARSE_DATE" | "MIGRATION_MODULE_REQUIRES_TS_NODE" | "FAILED_TO_ENCRYPT_SYMMETRICALLY" | "FAILED_TO_DECRYPT_SYMMETRICALLY" | "FAILED_TO_ENCRYPT_ASYMMETRICALLY" | "FAILED_TO_DECRYPT_ASYMMETRICALLY" | "UNSUPPORTED_RELATION_TYPE" | "LPUSH_FAILED" | "RPUSH_FAILED" | "LPOP_FAILED" | "RPOP_FAILED" | "LRANGE_FAILED" | "LLEN_FAILED" | "HSET_FAILED" | "HMSET_FAILED" | "HGET_FAILED" | "HGETALL_FAILED" | "HMGET_FAILED" | "HDEL_FAILED" | "HEXISTS_FAILED" | "HKEYS_FAILED" | "HLEN_FAILED" | "SADD_FAILED" | "SMEMBERS_FAILED" | "SREM_FAILED" | "SISMEMBER_FAILED" | "SCARD_FAILED" | "SINTER_FAILED" | "SUNION_FAILED" | "SDIFF_FAILED" | "ZADD_FAILED" | "ZRANGE_FAILED" | "ZREVRANGE_FAILED" | "ZREM_FAILED" | "ZSCORE_FAILED" | "ZCARD_FAILED" | "SUBSCRIBE_FAILED" | "UNSUBSCRIBE_FAILED" | "PUBLISH_FAILED" | "PSUBSCRIBE_FAILED" | "PUNSUBSCRIBE_FAILED" | "EXISTS_FAILED" | "EXPIRE_FAILED" | "EXPIREAT_FAILED" | "PEXPIRE_FAILED" | "TTL_FAILED" | "PTTL_FAILED" | "PERSIST_FAILED" | "KEYS_FAILED" | "RENAME_FAILED" | "TYPE_FAILED" | "SCAN_FAILED";
5356
+ type HysteriaErrorCode = "ROW_NOT_FOUND" | `UNSUPPORTED_DATABASE_TYPE_${string}` | `RELATION_TYPE_NOT_SUPPORTED_${string}` | `NOT_SUPPORTED_IN_${string}` | `RELATION_NOT_FOUND_IN_MODEL_${string}` | `UNKNOWN_RELATION_TYPE_${string}` | `DISTINCT_ON_NOT_SUPPORTED_IN_${string}` | `CONFLICT_COLUMNS_NOT_PRESENT_IN_DATA` | `CONFLICT_COLUMNS_NOT_PRESENT_IN_DATA_${string}` | `FOREIGN_KEY_VALUES_MISSING_FOR_HAS_ONE_RELATION_${string}` | `FOREIGN_KEY_VALUES_MISSING_FOR_BELONGS_TO_RELATION_${string}` | `PRIMARY_KEY_VALUES_MISSING_FOR_HAS_MANY_RELATION_${string}` | `MANY_TO_MANY_RELATION_NOT_FOUND_FOR_RELATED_MODEL_${string}` | `PRIMARY_KEY_VALUES_MISSING_FOR_MANY_TO_MANY_RELATION_${string}` | `RELATED_MODEL_DOES_NOT_HAVE_A_PRIMARY_KEY_${string}` | `FOR_SHARE_NOT_SUPPORTED_IN_${string}` | `SKIP_LOCKED_NOT_SUPPORTED_IN_${string}` | `LOCK_FOR_UPDATE_NOT_SUPPORTED_${string}` | `KEY_${string}_HAS_NO_HANDLER_IN_CACHE_KEYS_CONFIG` | `CACHE_ADAPTER_NOT_CONFIGURED` | `SQLITE_NOT_SUPPORTED` | `COCKROACHDB_NOT_SUPPORTED` | `RELATION_NOT_FOUND` | `POSTGRES_TABLE_REQUIRED` | `MODEL_HAS_NO_PRIMARY_KEY_VALUE` | `RELATION_NOT_MANY_TO_MANY` | "MATERIALIZED_CTE_NOT_SUPPORTED" | "DUPLICATE_MODEL_KEYS_WHILE_INSTANTIATING_MODELS" | "INVALID_ONE_PARAMETER_WHERE_CONDITION" | "INVALID_PAGINATION_PARAMETERS" | "MISSING_ALIAS_FOR_SUBQUERY" | "MODEL_HAS_NO_PRIMARY_KEY" | "PRIMARY_KEY_NOT_FOUND" | "SQLITE_ONLY_SUPPORTS_SERIALIZABLE_ISOLATION_LEVEL" | "MUST_CALL_BUILD_CTE_AT_LEAST_ONCE" | "REGEXP_NOT_SUPPORTED_IN_SQLITE" | "MANY_TO_MANY_RELATION_MUST_HAVE_A_THROUGH_MODEL" | "INSERT_FAILED" | "MULTIPLE_PRIMARY_KEYS_NOT_ALLOWED" | "FILE_NOT_A_SQL_OR_TXT_FILE" | "CONNECTION_NOT_ESTABLISHED" | "TRANSACTION_NOT_ACTIVE" | "DEVELOPMENT_ERROR" | "MIGRATION_MODULE_NOT_FOUND" | "DRIVER_NOT_FOUND" | "FILE_NOT_FOUND_OR_NOT_ACCESSIBLE" | "ENV_NOT_SET" | "REQUIRED_VALUE_NOT_SET" | "SET_FAILED" | "GET_FAILED" | "REFERENCES_OPTION_REQUIRED" | "DELETE_FAILED" | "INVALID_DEFAULT_VALUE" | "DISCONNECT_FAILED" | "FLUSH_FAILED" | "LEFT_COLUMN_NOT_PROVIDED_FOR_JOIN" | "RIGHT_COLUMN_NOT_PROVIDED_FOR_JOIN" | "MODEL_HAS_NO_PRIMARY_KEY" | "GLOBAL_TRANSACTION_ALREADY_STARTED" | "GLOBAL_TRANSACTION_NOT_STARTED" | "MYSQL_REQUIRES_TABLE_NAME_FOR_INDEX_DROP" | "INVALID_DATE_OBJECT" | "INVALID_DATE_STRING" | "FAILED_TO_PARSE_DATE" | "MIGRATION_MODULE_REQUIRES_TS_NODE" | "FAILED_TO_ENCRYPT_SYMMETRICALLY" | "FAILED_TO_DECRYPT_SYMMETRICALLY" | "FAILED_TO_ENCRYPT_ASYMMETRICALLY" | "FAILED_TO_DECRYPT_ASYMMETRICALLY" | "UNSUPPORTED_RELATION_TYPE" | "LPUSH_FAILED" | "RPUSH_FAILED" | "LPOP_FAILED" | "RPOP_FAILED" | "LRANGE_FAILED" | "LLEN_FAILED" | "HSET_FAILED" | "HMSET_FAILED" | "HGET_FAILED" | "HGETALL_FAILED" | "HMGET_FAILED" | "HDEL_FAILED" | "HEXISTS_FAILED" | "HKEYS_FAILED" | "HLEN_FAILED" | "SADD_FAILED" | "SMEMBERS_FAILED" | "SREM_FAILED" | "SISMEMBER_FAILED" | "SCARD_FAILED" | "SINTER_FAILED" | "SUNION_FAILED" | "SDIFF_FAILED" | "ZADD_FAILED" | "ZRANGE_FAILED" | "ZREVRANGE_FAILED" | "ZREM_FAILED" | "ZSCORE_FAILED" | "ZCARD_FAILED" | "SUBSCRIBE_FAILED" | "UNSUBSCRIBE_FAILED" | "PUBLISH_FAILED" | "PSUBSCRIBE_FAILED" | "PUNSUBSCRIBE_FAILED" | "EXISTS_FAILED" | "EXPIRE_FAILED" | "EXPIREAT_FAILED" | "PEXPIRE_FAILED" | "TTL_FAILED" | "PTTL_FAILED" | "PERSIST_FAILED" | "KEYS_FAILED" | "RENAME_FAILED" | "TYPE_FAILED" | "SCAN_FAILED";
5283
5357
 
5284
5358
  declare class HysteriaError extends Error {
5285
5359
  code: HysteriaErrorCode;
@@ -5304,4 +5378,4 @@ declare const generateOpenApiModelWithMetadata: <T extends new () => Model>(mode
5304
5378
  $id?: string;
5305
5379
  }>;
5306
5380
 
5307
- export { type AnnotatedModel, type AsymmetricEncryptionOptions, type AugmentedSqlDataSource, AutogeneratedModel, type BaseModelMethodOptions, type BaseModelRelationType, 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, 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, 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 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 };
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 };