metal-orm 1.0.34 → 1.0.36

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/dist/index.d.cts CHANGED
@@ -24,11 +24,13 @@ interface ForeignKeyReference {
24
24
  /**
25
25
  * Definition of a database column
26
26
  */
27
- interface ColumnDef<T extends ColumnType = ColumnType> {
27
+ interface ColumnDef<T extends ColumnType = ColumnType, TRuntime = unknown> {
28
28
  /** Column name (filled at runtime by defineTable) */
29
29
  name: string;
30
30
  /** Data type of the column */
31
31
  type: T;
32
+ /** Optional override for the inferred TypeScript type */
33
+ tsType?: TRuntime;
32
34
  /** Whether this column is a primary key */
33
35
  primary?: boolean;
34
36
  /** Whether this column cannot be null */
@@ -102,19 +104,19 @@ declare const col: {
102
104
  /**
103
105
  * Creates a timestamp column definition
104
106
  */
105
- timestamp: () => ColumnDef<"TIMESTAMP">;
107
+ timestamp: <TRuntime = string>() => ColumnDef<"TIMESTAMP", TRuntime>;
106
108
  /**
107
109
  * Creates a timestamptz column definition
108
110
  */
109
- timestamptz: () => ColumnDef<"TIMESTAMPTZ">;
111
+ timestamptz: <TRuntime = string>() => ColumnDef<"TIMESTAMPTZ", TRuntime>;
110
112
  /**
111
113
  * Creates a date column definition
112
114
  */
113
- date: () => ColumnDef<"DATE">;
115
+ date: <TRuntime = string>() => ColumnDef<"DATE", TRuntime>;
114
116
  /**
115
117
  * Creates a datetime column definition
116
118
  */
117
- datetime: () => ColumnDef<"DATETIME">;
119
+ datetime: <TRuntime = string>() => ColumnDef<"DATETIME", TRuntime>;
118
120
  /**
119
121
  * Creates a JSON column definition
120
122
  * @returns ColumnDef with JSON type
@@ -371,7 +373,9 @@ type RelationTargetTable<TRel extends RelationDef> = TRel extends HasManyRelatio
371
373
  /**
372
374
  * Maps a ColumnDef to its TypeScript type representation
373
375
  */
374
- type ColumnToTs<T extends ColumnDef> = T['type'] extends 'INT' | 'INTEGER' | 'int' | 'integer' ? number : T['type'] extends 'BIGINT' | 'bigint' ? number | bigint : T['type'] extends 'DECIMAL' | 'decimal' | 'FLOAT' | 'float' | 'DOUBLE' | 'double' ? number : T['type'] extends 'BOOLEAN' | 'boolean' ? boolean : T['type'] extends 'JSON' | 'json' ? unknown : T['type'] extends 'BLOB' | 'blob' | 'BINARY' | 'binary' | 'VARBINARY' | 'varbinary' | 'BYTEA' | 'bytea' ? Buffer : T['type'] extends 'DATE' | 'date' | 'DATETIME' | 'datetime' | 'TIMESTAMP' | 'timestamp' | 'TIMESTAMPTZ' | 'timestamptz' ? string : string;
376
+ type ColumnToTs<T extends ColumnDef> = [
377
+ unknown
378
+ ] extends [T['tsType']] ? T['type'] extends 'INT' | 'INTEGER' | 'int' | 'integer' ? number : T['type'] extends 'BIGINT' | 'bigint' ? number | bigint : T['type'] extends 'DECIMAL' | 'decimal' | 'FLOAT' | 'float' | 'DOUBLE' | 'double' ? number : T['type'] extends 'BOOLEAN' | 'boolean' ? boolean : T['type'] extends 'JSON' | 'json' ? unknown : T['type'] extends 'BLOB' | 'blob' | 'BINARY' | 'binary' | 'VARBINARY' | 'varbinary' | 'BYTEA' | 'bytea' ? Buffer : T['type'] extends 'DATE' | 'date' | 'DATETIME' | 'datetime' | 'TIMESTAMP' | 'timestamp' | 'TIMESTAMPTZ' | 'timestamptz' ? string : string : Exclude<T['tsType'], undefined>;
375
379
  /**
376
380
  * Infers a row shape from a table definition
377
381
  */
@@ -3619,7 +3623,7 @@ declare class TypeScriptGenerator implements ExpressionVisitor<string>, OperandV
3619
3623
  }
3620
3624
 
3621
3625
  declare const createEntityProxy: <TTable extends TableDef, TLazy extends keyof RelationMap<TTable> = keyof RelationMap<TTable>>(ctx: EntityContext, table: TTable, row: Record<string, any>, lazyRelations?: TLazy[]) => EntityInstance<TTable>;
3622
- declare const createEntityFromRow: <TTable extends TableDef>(ctx: EntityContext, table: TTable, row: Record<string, any>, lazyRelations?: (keyof RelationMap<TTable>)[]) => EntityInstance<TTable>;
3626
+ declare const createEntityFromRow: <TTable extends TableDef, TResult extends EntityInstance<TTable> = EntityInstance<TTable>>(ctx: EntityContext, table: TTable, row: Record<string, any>, lazyRelations?: (keyof RelationMap<TTable>)[]) => TResult;
3623
3627
 
3624
3628
  type Rows$3 = Record<string, any>[];
3625
3629
  declare const loadHasManyRelation: (ctx: EntityContext, rootTable: TableDef, _relationName: string, relation: HasManyRelation) => Promise<Map<string, Rows$3>>;
@@ -3753,8 +3757,9 @@ interface ColumnOptions {
3753
3757
  args?: ColumnDef['args'];
3754
3758
  notNull?: boolean;
3755
3759
  primary?: boolean;
3760
+ tsType?: ColumnDef['tsType'];
3756
3761
  }
3757
- type ColumnInput = ColumnOptions | ColumnDef;
3762
+ type ColumnInput = ColumnOptions | ColumnDef<any, any>;
3758
3763
  declare function Column(definition: ColumnInput): DualModePropertyDecorator;
3759
3764
  declare function PrimaryKey(definition: ColumnInput): DualModePropertyDecorator;
3760
3765
 
@@ -3789,8 +3794,8 @@ declare function BelongsTo(options: BelongsToOptions): DualModePropertyDecorator
3789
3794
  declare function BelongsToMany(options: BelongsToManyOptions): DualModePropertyDecorator;
3790
3795
 
3791
3796
  declare const bootstrapEntities: () => TableDef[];
3792
- declare const getTableDefFromEntity: (ctor: EntityConstructor) => TableDef | undefined;
3793
- declare const selectFromEntity: <TTable extends TableDef>(ctor: EntityConstructor) => SelectQueryBuilder<any, TTable>;
3797
+ declare const getTableDefFromEntity: <TTable extends TableDef = TableDef>(ctor: EntityConstructor) => TTable | undefined;
3798
+ declare const selectFromEntity: <TTable extends TableDef = TableDef>(ctor: EntityConstructor) => SelectQueryBuilder<any, TTable>;
3794
3799
 
3795
3800
  interface PostgresClientLike {
3796
3801
  query(text: string, params?: unknown[]): Promise<{
package/dist/index.d.ts CHANGED
@@ -24,11 +24,13 @@ interface ForeignKeyReference {
24
24
  /**
25
25
  * Definition of a database column
26
26
  */
27
- interface ColumnDef<T extends ColumnType = ColumnType> {
27
+ interface ColumnDef<T extends ColumnType = ColumnType, TRuntime = unknown> {
28
28
  /** Column name (filled at runtime by defineTable) */
29
29
  name: string;
30
30
  /** Data type of the column */
31
31
  type: T;
32
+ /** Optional override for the inferred TypeScript type */
33
+ tsType?: TRuntime;
32
34
  /** Whether this column is a primary key */
33
35
  primary?: boolean;
34
36
  /** Whether this column cannot be null */
@@ -102,19 +104,19 @@ declare const col: {
102
104
  /**
103
105
  * Creates a timestamp column definition
104
106
  */
105
- timestamp: () => ColumnDef<"TIMESTAMP">;
107
+ timestamp: <TRuntime = string>() => ColumnDef<"TIMESTAMP", TRuntime>;
106
108
  /**
107
109
  * Creates a timestamptz column definition
108
110
  */
109
- timestamptz: () => ColumnDef<"TIMESTAMPTZ">;
111
+ timestamptz: <TRuntime = string>() => ColumnDef<"TIMESTAMPTZ", TRuntime>;
110
112
  /**
111
113
  * Creates a date column definition
112
114
  */
113
- date: () => ColumnDef<"DATE">;
115
+ date: <TRuntime = string>() => ColumnDef<"DATE", TRuntime>;
114
116
  /**
115
117
  * Creates a datetime column definition
116
118
  */
117
- datetime: () => ColumnDef<"DATETIME">;
119
+ datetime: <TRuntime = string>() => ColumnDef<"DATETIME", TRuntime>;
118
120
  /**
119
121
  * Creates a JSON column definition
120
122
  * @returns ColumnDef with JSON type
@@ -371,7 +373,9 @@ type RelationTargetTable<TRel extends RelationDef> = TRel extends HasManyRelatio
371
373
  /**
372
374
  * Maps a ColumnDef to its TypeScript type representation
373
375
  */
374
- type ColumnToTs<T extends ColumnDef> = T['type'] extends 'INT' | 'INTEGER' | 'int' | 'integer' ? number : T['type'] extends 'BIGINT' | 'bigint' ? number | bigint : T['type'] extends 'DECIMAL' | 'decimal' | 'FLOAT' | 'float' | 'DOUBLE' | 'double' ? number : T['type'] extends 'BOOLEAN' | 'boolean' ? boolean : T['type'] extends 'JSON' | 'json' ? unknown : T['type'] extends 'BLOB' | 'blob' | 'BINARY' | 'binary' | 'VARBINARY' | 'varbinary' | 'BYTEA' | 'bytea' ? Buffer : T['type'] extends 'DATE' | 'date' | 'DATETIME' | 'datetime' | 'TIMESTAMP' | 'timestamp' | 'TIMESTAMPTZ' | 'timestamptz' ? string : string;
376
+ type ColumnToTs<T extends ColumnDef> = [
377
+ unknown
378
+ ] extends [T['tsType']] ? T['type'] extends 'INT' | 'INTEGER' | 'int' | 'integer' ? number : T['type'] extends 'BIGINT' | 'bigint' ? number | bigint : T['type'] extends 'DECIMAL' | 'decimal' | 'FLOAT' | 'float' | 'DOUBLE' | 'double' ? number : T['type'] extends 'BOOLEAN' | 'boolean' ? boolean : T['type'] extends 'JSON' | 'json' ? unknown : T['type'] extends 'BLOB' | 'blob' | 'BINARY' | 'binary' | 'VARBINARY' | 'varbinary' | 'BYTEA' | 'bytea' ? Buffer : T['type'] extends 'DATE' | 'date' | 'DATETIME' | 'datetime' | 'TIMESTAMP' | 'timestamp' | 'TIMESTAMPTZ' | 'timestamptz' ? string : string : Exclude<T['tsType'], undefined>;
375
379
  /**
376
380
  * Infers a row shape from a table definition
377
381
  */
@@ -3619,7 +3623,7 @@ declare class TypeScriptGenerator implements ExpressionVisitor<string>, OperandV
3619
3623
  }
3620
3624
 
3621
3625
  declare const createEntityProxy: <TTable extends TableDef, TLazy extends keyof RelationMap<TTable> = keyof RelationMap<TTable>>(ctx: EntityContext, table: TTable, row: Record<string, any>, lazyRelations?: TLazy[]) => EntityInstance<TTable>;
3622
- declare const createEntityFromRow: <TTable extends TableDef>(ctx: EntityContext, table: TTable, row: Record<string, any>, lazyRelations?: (keyof RelationMap<TTable>)[]) => EntityInstance<TTable>;
3626
+ declare const createEntityFromRow: <TTable extends TableDef, TResult extends EntityInstance<TTable> = EntityInstance<TTable>>(ctx: EntityContext, table: TTable, row: Record<string, any>, lazyRelations?: (keyof RelationMap<TTable>)[]) => TResult;
3623
3627
 
3624
3628
  type Rows$3 = Record<string, any>[];
3625
3629
  declare const loadHasManyRelation: (ctx: EntityContext, rootTable: TableDef, _relationName: string, relation: HasManyRelation) => Promise<Map<string, Rows$3>>;
@@ -3753,8 +3757,9 @@ interface ColumnOptions {
3753
3757
  args?: ColumnDef['args'];
3754
3758
  notNull?: boolean;
3755
3759
  primary?: boolean;
3760
+ tsType?: ColumnDef['tsType'];
3756
3761
  }
3757
- type ColumnInput = ColumnOptions | ColumnDef;
3762
+ type ColumnInput = ColumnOptions | ColumnDef<any, any>;
3758
3763
  declare function Column(definition: ColumnInput): DualModePropertyDecorator;
3759
3764
  declare function PrimaryKey(definition: ColumnInput): DualModePropertyDecorator;
3760
3765
 
@@ -3789,8 +3794,8 @@ declare function BelongsTo(options: BelongsToOptions): DualModePropertyDecorator
3789
3794
  declare function BelongsToMany(options: BelongsToManyOptions): DualModePropertyDecorator;
3790
3795
 
3791
3796
  declare const bootstrapEntities: () => TableDef[];
3792
- declare const getTableDefFromEntity: (ctor: EntityConstructor) => TableDef | undefined;
3793
- declare const selectFromEntity: <TTable extends TableDef>(ctor: EntityConstructor) => SelectQueryBuilder<any, TTable>;
3797
+ declare const getTableDefFromEntity: <TTable extends TableDef = TableDef>(ctor: EntityConstructor) => TTable | undefined;
3798
+ declare const selectFromEntity: <TTable extends TableDef = TableDef>(ctor: EntityConstructor) => SelectQueryBuilder<any, TTable>;
3794
3799
 
3795
3800
  interface PostgresClientLike {
3796
3801
  query(text: string, params?: unknown[]): Promise<{
package/dist/index.js CHANGED
@@ -7576,6 +7576,7 @@ var normalizeColumnInput = (input) => {
7576
7576
  args: asOptions.args ?? asDefinition.args,
7577
7577
  notNull: asOptions.notNull ?? asDefinition.notNull,
7578
7578
  primary: asOptions.primary ?? asDefinition.primary,
7579
+ tsType: asDefinition.tsType ?? asOptions.tsType,
7579
7580
  unique: asDefinition.unique,
7580
7581
  default: asDefinition.default,
7581
7582
  autoIncrement: asDefinition.autoIncrement,