@mikro-orm/sql 7.1.2-dev.1 → 7.1.2-dev.3

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mikro-orm/sql",
3
- "version": "7.1.2-dev.1",
3
+ "version": "7.1.2-dev.3",
4
4
  "description": "TypeScript ORM for Node.js based on Data Mapper, Unit of Work and Identity Map patterns. Supports MongoDB, MySQL, PostgreSQL and SQLite databases as well as usage with vanilla JavaScript.",
5
5
  "keywords": [
6
6
  "data-mapper",
@@ -53,7 +53,7 @@
53
53
  "@mikro-orm/core": "^7.1.1"
54
54
  },
55
55
  "peerDependencies": {
56
- "@mikro-orm/core": "7.1.2-dev.1"
56
+ "@mikro-orm/core": "7.1.2-dev.3"
57
57
  },
58
58
  "engines": {
59
59
  "node": ">= 22.17.0"
@@ -826,8 +826,9 @@ export declare class QueryBuilder<Entity extends object = AnyEntity, RootAlias e
826
826
  getResultAndCount(): Promise<[Loaded<Entity, Hint, Fields>[], number]>;
827
827
  /**
828
828
  * Returns native query builder instance with sub-query aliased with given alias.
829
+ * The alias literal is preserved in the type so `addSelect()` exposes it on `execute()` results.
829
830
  */
830
- as(alias: string): NativeQueryBuilder;
831
+ as<Alias extends string>(alias: Alias): NativeQueryBuilder & RawQueryFragment<Alias>;
831
832
  /**
832
833
  * Returns native query builder instance with sub-query aliased with given alias.
833
834
  * You can provide the target entity name as the first parameter and use the second parameter to point to an existing property to infer its field name.
@@ -1050,17 +1051,28 @@ type PopulatedDTO<T, K extends keyof T> = NonNullable<T[K]> extends Collection<i
1050
1051
  type SubFields<F extends string, Rel extends string> = F extends `${Rel}.${infer Sub}` ? Sub : never;
1051
1052
  type RootFields<F extends string, H extends string> = F extends `${string}.${string}` ? F extends `${H}.${string}` ? never : F : F;
1052
1053
  type JoinDTO<T, K extends keyof T, F extends string> = NonNullable<T[K]> extends Collection<infer U> ? SubFields<F, K & string> extends never ? EntityDTOProp<T, Collection<U>> : DirectDTO<U, (SubFields<F, K & string> | PrimaryProperty<U>) & keyof U>[] : SubFields<F, K & string> extends never ? EntityDTOProp<T, T[K]> : DirectDTO<NonNullable<T[K]>, (SubFields<F, K & string> | PrimaryProperty<NonNullable<T[K]>>) & keyof NonNullable<T[K]>> | Extract<T[K], null | undefined>;
1053
- type ExecuteDTO<T, H extends string, F extends string> = [H] extends [never] ? [F] extends ['*'] ? EntityDTOFlat<T> : DirectDTO<T, F & keyof T> : [F] extends ['*'] ? true extends (H extends `${string}.${string}` ? true : false) ? SerializeDTO<T, H> : Omit<EntityDTOFlat<T>, H & keyof EntityDTOFlat<T>> & {
1054
+ /**
1055
+ * Raw aliases (`sql`...`.as('x')`, `'col as x'`, or aliased sub-queries) are not entity keys,
1056
+ * so they never appear in the selected-fields DTO. They are tracked in the `RawAliases` generic
1057
+ * (preserved across joins), so expose them on the result as `unknown` — their value type is not
1058
+ * known at the type level. Only intersected when raw aliases are present, to keep the plain DTO
1059
+ * untouched when there are none.
1060
+ */
1061
+ type WithRawAliases<DTO, RawAliases extends string> = [RawAliases] extends [never] ? DTO : DTO & {
1062
+ [K in RawAliases]: unknown;
1063
+ };
1064
+ type ExecuteDTOInner<T, H extends string, F extends string> = [H] extends [never] ? [F] extends ['*'] ? EntityDTOFlat<T> : DirectDTO<T, F & keyof T> : [F] extends ['*'] ? true extends (H extends `${string}.${string}` ? true : false) ? SerializeDTO<T, H> : Omit<EntityDTOFlat<T>, H & keyof EntityDTOFlat<T>> & {
1054
1065
  [K in H & keyof T as K & keyof EntityDTOFlat<T>]: PopulatedDTO<T, K> | Extract<T[K], null | undefined>;
1055
1066
  } : true extends (H extends `${string}.${string}` ? true : false) ? EntityDTOFlat<Loaded<T, H, F>> : DirectDTO<T, (RootFields<F, H> | PrimaryProperty<T>) & keyof T> & {
1056
1067
  [K in H & keyof T]: JoinDTO<T, K, F>;
1057
1068
  };
1069
+ type ExecuteDTO<T, H extends string, F extends string, RawAliases extends string = never> = WithRawAliases<ExecuteDTOInner<T, H, F>, RawAliases>;
1058
1070
  /** Shorthand for `QueryBuilder` with all generic parameters set to `any`. */
1059
1071
  export type AnyQueryBuilder<T extends object = AnyEntity> = QueryBuilder<T, any, any, any, any, any, any>;
1060
1072
  export interface SelectQueryBuilder<Entity extends object = AnyEntity, RootAlias extends string = never, Hint extends string = never, Context extends object = never, RawAliases extends string = never, Fields extends string = '*', CTEs extends Record<string, object> = {}> extends QueryBuilder<Entity, RootAlias, Hint, Context, RawAliases, Fields, CTEs> {
1061
- execute<Result = ExecuteDTO<Entity, Hint, Fields>[]>(method?: 'all' | 'get' | 'run', mapResults?: boolean): Promise<Result>;
1062
- execute<Result = ExecuteDTO<Entity, Hint, Fields>[]>(method: 'all', mapResults?: boolean): Promise<Result>;
1063
- execute<Result = ExecuteDTO<Entity, Hint, Fields>>(method: 'get', mapResults?: boolean): Promise<Result>;
1073
+ execute<Result = ExecuteDTO<Entity, Hint, Fields, RawAliases>[]>(method?: 'all' | 'get' | 'run', mapResults?: boolean): Promise<Result>;
1074
+ execute<Result = ExecuteDTO<Entity, Hint, Fields, RawAliases>[]>(method: 'all', mapResults?: boolean): Promise<Result>;
1075
+ execute<Result = ExecuteDTO<Entity, Hint, Fields, RawAliases>>(method: 'get', mapResults?: boolean): Promise<Result>;
1064
1076
  execute<Result = QueryResult<Entity>>(method: 'run', mapResults?: boolean): Promise<Result>;
1065
1077
  }
1066
1078
  export interface CountQueryBuilder<Entity extends object> extends QueryBuilder<Entity, any, any> {