typeorm-extensions 2.2.0-rc.0 → 2.2.0-rc.10

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.
Files changed (112) hide show
  1. package/README.md +70 -39
  2. package/dist/decorators/calculated-column.decorator.d.ts +7 -3
  3. package/dist/decorators/calculated-column.decorator.js +35 -6
  4. package/dist/decorators/generated-column.decorator.d.ts +17 -0
  5. package/dist/decorators/generated-column.decorator.js +15 -0
  6. package/dist/decorators/index.d.ts +1 -0
  7. package/dist/decorators/index.js +1 -0
  8. package/dist/extensions/calculated-column.extension.d.ts +3 -3
  9. package/dist/extensions/calculated-column.extension.js +3 -16
  10. package/dist/extensions/cursor-pagination.extension.d.ts +2 -1
  11. package/dist/extensions/cursor-pagination.extension.js +7 -13
  12. package/dist/extensions/get-many-with-totals.extension.js +13 -31
  13. package/dist/extensions/join-lateral.extension.js +4 -6
  14. package/dist/extensions/order.extension.d.ts +2 -2
  15. package/dist/extensions/pagination.extension.d.ts +1 -1
  16. package/dist/extensions/period-filter.extension.d.ts +4 -0
  17. package/dist/extensions/period-filter.extension.js +1 -9
  18. package/dist/extensions/typed/index.d.ts +2 -0
  19. package/dist/extensions/typed/index.js +2 -0
  20. package/dist/extensions/typed/typed-calculated/typed-calculated-column.extension.d.ts +19 -0
  21. package/dist/extensions/typed/typed-calculated/typed-calculated-column.extension.js +17 -0
  22. package/dist/extensions/typed/typed-distinct/typed-distinct.extension.d.ts +6 -4
  23. package/dist/extensions/typed/typed-distinct/typed-distinct.extension.js +9 -2
  24. package/dist/extensions/typed/typed-group-by/typed-group-by.extension.d.ts +8 -7
  25. package/dist/extensions/typed/typed-group-by/typed-group-by.extension.js +1 -1
  26. package/dist/extensions/typed/typed-having/typed-having.extension.d.ts +4 -4
  27. package/dist/extensions/typed/typed-having/typed-having.extension.js +1 -1
  28. package/dist/extensions/typed/typed-joins/typed-join-and-map.extension.d.ts +19 -0
  29. package/dist/extensions/typed/typed-joins/typed-join-and-map.extension.js +23 -0
  30. package/dist/extensions/typed/typed-joins/typed-joins.extension.d.ts +4 -4
  31. package/dist/extensions/typed/typed-joins/typed-joins.extension.js +11 -22
  32. package/dist/extensions/typed/typed-order-by/typed-order-by-array-position.extension.d.ts +2 -2
  33. package/dist/extensions/typed/typed-order-by/typed-order-by.extension.d.ts +4 -2
  34. package/dist/extensions/typed/typed-order-by/typed-order-by.extension.js +18 -17
  35. package/dist/extensions/typed/typed-returning/typed-returning.extension.js +1 -9
  36. package/dist/extensions/typed/typed-root.extension.d.ts +26 -4
  37. package/dist/extensions/typed/typed-select/typed-select.extension.d.ts +6 -6
  38. package/dist/extensions/typed/typed-select/typed-select.extension.js +3 -9
  39. package/dist/extensions/typed/typed-where/typed-period-filter.extension.d.ts +5 -1
  40. package/dist/extensions/typed/typed-where/typed-period-filter.extension.js +1 -9
  41. package/dist/extensions/typed/typed-where/typed-where-array.extension.d.ts +13 -9
  42. package/dist/extensions/typed/typed-where/typed-where-array.extension.js +4 -16
  43. package/dist/extensions/typed/typed-where/typed-where-ilike.extension.d.ts +10 -6
  44. package/dist/extensions/typed/typed-where/typed-where-ilike.extension.js +1 -9
  45. package/dist/extensions/typed/typed-where/typed-where-is-any.extension.d.ts +10 -6
  46. package/dist/extensions/typed/typed-where/typed-where-is-any.extension.js +3 -20
  47. package/dist/extensions/typed/typed-where/typed-where-is-distinct-from.extension.d.ts +10 -6
  48. package/dist/extensions/typed/typed-where/typed-where-is-distinct-from.extension.js +3 -20
  49. package/dist/extensions/typed/typed-where/typed-where-is-in.extension.d.ts +10 -6
  50. package/dist/extensions/typed/typed-where/typed-where-is-in.extension.js +3 -21
  51. package/dist/extensions/typed/typed-where/typed-where-json.extension.d.ts +10 -6
  52. package/dist/extensions/typed/typed-where/typed-where-json.extension.js +4 -21
  53. package/dist/extensions/typed/typed-where/typed-where-lower.extension.d.ts +10 -6
  54. package/dist/extensions/typed/typed-where/typed-where-lower.extension.js +1 -9
  55. package/dist/extensions/typed/typed-where/typed-where-similar.extension.d.ts +8 -4
  56. package/dist/extensions/typed/typed-where/typed-where-similar.extension.js +1 -8
  57. package/dist/extensions/typed/typed-where/typed-where.extension.d.ts +7 -3
  58. package/dist/extensions/typed/typed-where/typed-where.extension.js +2 -10
  59. package/dist/extensions/union.extension.js +1 -1
  60. package/dist/extensions/where-array.extension.d.ts +4 -0
  61. package/dist/extensions/where-array.extension.js +1 -9
  62. package/dist/extensions/where-exists.extension.js +4 -15
  63. package/dist/extensions/where-is-any.extension.d.ts +41 -128
  64. package/dist/extensions/where-is-any.extension.js +1 -9
  65. package/dist/extensions/where-is-distinct-from.extension.d.ts +4 -0
  66. package/dist/extensions/where-is-distinct-from.extension.js +1 -9
  67. package/dist/extensions/where-is-in.extension.d.ts +38 -116
  68. package/dist/extensions/where-is-in.extension.js +11 -27
  69. package/dist/extensions/where-json.extension.d.ts +4 -0
  70. package/dist/extensions/where-json.extension.js +1 -9
  71. package/dist/extensions/where-relation-exists.extension.d.ts +6 -6
  72. package/dist/extensions/where-relation-exists.extension.js +5 -25
  73. package/dist/helpers.d.ts +5 -0
  74. package/dist/helpers.js +12 -3
  75. package/dist/index.d.ts +1 -2
  76. package/dist/index.js +1 -4
  77. package/dist/types/extensions/cursor-pagination.types.d.ts +5 -0
  78. package/dist/types/extensions/get-many-with-totals.types.d.ts +4 -0
  79. package/dist/types/extensions/index.d.ts +1 -0
  80. package/dist/types/extensions/index.js +1 -0
  81. package/dist/types/extensions/typed-group-by.types.d.ts +2 -2
  82. package/dist/types/extensions/typed-join-and-map.types.d.ts +6 -0
  83. package/dist/types/extensions/typed-join-and-map.types.js +2 -0
  84. package/dist/types/modules/typed-root.types.d.ts +13 -7
  85. package/dist/utils/calculated-column.utils.d.ts +11 -0
  86. package/dist/utils/calculated-column.utils.js +33 -4
  87. package/dist/utils/common.utils.d.ts +2 -0
  88. package/dist/utils/common.utils.js +4 -1
  89. package/dist/utils/cursor.utils.js +4 -6
  90. package/dist/utils/json-path.utils.js +2 -2
  91. package/dist/utils/pagination.utils.d.ts +7 -0
  92. package/dist/utils/pagination.utils.js +20 -10
  93. package/dist/utils/parameter.utils.d.ts +10 -0
  94. package/dist/utils/parameter.utils.js +22 -1
  95. package/dist/utils/period.utils.js +2 -1
  96. package/dist/utils/prototype.utils.d.ts +9 -0
  97. package/dist/utils/prototype.utils.js +12 -2
  98. package/dist/utils/query-builder.utils.d.ts +43 -4
  99. package/dist/utils/query-builder.utils.js +239 -36
  100. package/dist/utils/reserved-qualifier-guard.utils.d.ts +36 -0
  101. package/dist/utils/reserved-qualifier-guard.utils.js +98 -0
  102. package/dist/utils/reserved-qualifier.utils.d.ts +33 -0
  103. package/dist/utils/reserved-qualifier.utils.js +252 -0
  104. package/dist/utils/table.utils.d.ts +27 -11
  105. package/dist/utils/table.utils.js +58 -23
  106. package/dist/utils/time-zone.utils.d.ts +8 -0
  107. package/dist/utils/time-zone.utils.js +15 -5
  108. package/dist/utils/typed-where.utils.d.ts +9 -0
  109. package/dist/utils/typed-where.utils.js +17 -0
  110. package/dist/utils/where.utils.d.ts +2 -0
  111. package/dist/utils/where.utils.js +21 -14
  112. package/package.json +2 -2
@@ -0,0 +1,19 @@
1
+ import { ObjectLiteral } from 'typeorm';
2
+ import { DeepUnwrapArray, ProxyColumnValueType } from '../../../types/modules/proxy-callback.types';
3
+ import type { TypedRoot } from '../../../types/modules/typed-root.types';
4
+ import { CalculatedSelection } from '../../../utils/calculated-column.utils';
5
+ type CalculatedPropertyCallback<Type extends ObjectLiteral> = (proxy: DeepUnwrapArray<Type>) => ProxyColumnValueType;
6
+ export interface TypedCalculatedColumnMethods<Entity extends ObjectLiteral> {
7
+ /**
8
+ * `addSelectCalculated` with the `@CalculatedColumn` picked by a typed callback: `(user) => user.imagesCount`, or
9
+ * `(q) => q.owner.imagesCount` for the entity of the joined alias `owner`. The callback starts at the root set with
10
+ * `typed<Root>()`, else at the entity. Throws a `TypeError` if the property isn't a `@CalculatedColumn`.
11
+ * `orderByTyped` / `addOrderByTyped` then order by its value.
12
+ */
13
+ addSelectCalculatedTyped<Type extends ObjectLiteral = TypedRoot<Entity, this>, SubEntity extends ObjectLiteral = ObjectLiteral>(selection: CalculatedSelection<SubEntity>, property: CalculatedPropertyCallback<Type>): this;
14
+ }
15
+ declare module 'typeorm/query-builder/SelectQueryBuilder' {
16
+ interface SelectQueryBuilder<Entity extends ObjectLiteral> extends TypedCalculatedColumnMethods<Entity> {
17
+ }
18
+ }
19
+ export {};
@@ -0,0 +1,17 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const SelectQueryBuilder_1 = require("typeorm/query-builder/SelectQueryBuilder");
4
+ const calculated_column_utils_1 = require("../../../utils/calculated-column.utils");
5
+ const query_builder_utils_1 = require("../../../utils/query-builder.utils");
6
+ const prototype_utils_1 = require("../../../utils/prototype.utils");
7
+ /* eslint-enable @typescript-eslint/no-empty-interface */
8
+ // patching
9
+ const extension = {
10
+ prototype: {
11
+ addSelectCalculatedTyped(selection, property) {
12
+ const { aliasName, propertyPath } = (0, query_builder_utils_1.resolveTypedProperty)(this, property, 'addSelectCalculatedTyped');
13
+ return (0, calculated_column_utils_1.addSelectCalculatedColumn)(this, selection, propertyPath, aliasName, 'addSelectCalculatedTyped');
14
+ },
15
+ },
16
+ };
17
+ (0, prototype_utils_1.patchPrototype)(SelectQueryBuilder_1.SelectQueryBuilder, extension);
@@ -4,12 +4,14 @@ import type { TypedRoot } from '../../../types/modules/typed-root.types';
4
4
  declare module 'typeorm/query-builder/SelectQueryBuilder' {
5
5
  interface SelectQueryBuilder<Entity extends ObjectLiteral> {
6
6
  /**
7
- * Sets the distinct on clause for Postgres.
7
+ * Sets the distinct on clause for Postgres. A `@CalculatedColumn` selected with `addSelectCalculated`
8
+ * goes in under the alias `orderByCalculated` orders it by, as DISTINCT ON has to match the leading ORDER BY.
8
9
  */
9
- distinctOnTyped<Type extends ObjectLiteral = TypedRoot<Entity>>(this: SelectQueryBuilder<Entity>, ...distinctOn: Array<KeyProxyCallback<Type>>): SelectQueryBuilder<Entity>;
10
+ distinctOnTyped<Type extends ObjectLiteral = TypedRoot<Entity, this>>(this: SelectQueryBuilder<Entity>, ...distinctOn: Array<KeyProxyCallback<Type>>): this;
10
11
  /**
11
- * Sets the distinct on clause for Postgres.
12
+ * Sets the distinct on clause for Postgres. A `@CalculatedColumn` selected with `addSelectCalculated`
13
+ * goes in under the alias `orderByCalculated` orders it by, as DISTINCT ON has to match the leading ORDER BY.
12
14
  */
13
- distinctOnTyped<Type extends ObjectLiteral = TypedRoot<Entity>>(this: SelectQueryBuilder<Entity>, distinctOn: KeyProxyCallback<Type>): SelectQueryBuilder<Entity>;
15
+ distinctOnTyped<Type extends ObjectLiteral = TypedRoot<Entity, this>>(this: SelectQueryBuilder<Entity>, distinctOn: KeyProxyCallback<Type>): this;
14
16
  }
15
17
  }
@@ -2,11 +2,18 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  const typeorm_1 = require("typeorm");
4
4
  const query_builder_utils_1 = require("../../../utils/query-builder.utils");
5
+ const proxy_key_utils_1 = require("../../../utils/proxy-key.utils");
6
+ const calculated_column_utils_1 = require("../../../utils/calculated-column.utils");
5
7
  // patching and implementation
6
8
  typeorm_1.SelectQueryBuilder.prototype.distinctOnTyped = function (...distinctOn) {
7
9
  if (Array.isArray(distinctOn) && distinctOn.length) {
8
- const keys = distinctOn.map((callback) => (0, query_builder_utils_1.getTypedSelectionKey)(this, callback)).flat();
9
- return this.distinctOn(keys);
10
+ const keys = distinctOn.flatMap((callback) => [(0, proxy_key_utils_1.getKeyHolder)(callback)].flat().map((keyHolder) => {
11
+ const calculated = (0, query_builder_utils_1.findTypedCalculatedProperty)(this, keyHolder);
12
+ return calculated
13
+ ? (0, calculated_column_utils_1.selectCalculatedForOrder)(this, calculated.propertyPath, calculated.aliasName, 'distinctOnTyped')
14
+ : (0, query_builder_utils_1.getTypedSelectionKey)(this, keyHolder, undefined, 'distinctOnTyped');
15
+ }));
16
+ return this.distinctOn(keys.flat());
10
17
  }
11
18
  return this;
12
19
  };
@@ -1,21 +1,22 @@
1
1
  import { ObjectLiteral } from 'typeorm';
2
- import type { DeepUnwrapArray } from '../../../types/modules/proxy-callback.types';
2
+ import type { KeyProxyCallback } from '../../../types/modules/proxy-callback.types';
3
3
  import type { TypedGroupByOptions } from '../../../types/extensions/typed-group-by.types';
4
4
  import type { TypedRoot } from '../../../types/modules/typed-root.types';
5
- /** A value a column holds: a relation (`u => u.images`) or a JSON object is no column to group by. */
6
- type GroupedColumn = string | number | boolean | Date | ArrayBufferView | ArrayBuffer | null | undefined;
7
- /** One column, `user => user.id`, or several, `user => [user.id, user.email]`. */
8
- type GroupBySelection<Type extends ObjectLiteral> = (proxy: DeepUnwrapArray<Type>) => GroupedColumn | GroupedColumn[];
5
+ /**
6
+ * One column, `user => user.id`, or several, `user => [user.id, user.email]`. A JSON column groups as a whole;
7
+ * a relation without a join column in its table, or an embedded entity, throws a `TypeError`.
8
+ */
9
+ type GroupBySelection<Type extends ObjectLiteral> = KeyProxyCallback<Type>;
9
10
  export interface TypedGroupByMethods<Entity extends ObjectLiteral> {
10
11
  /**
11
12
  * Sets GROUP BY to the columns the callback selects: `user => user.id`, or several at once,
12
13
  * `user => [user.id, user.email]`. Replaces previously set GROUP BY.
13
14
  */
14
- groupByTyped<Type extends ObjectLiteral = TypedRoot<Entity>>(selection: GroupBySelection<Type>, options?: TypedGroupByOptions): this;
15
+ groupByTyped<Type extends ObjectLiteral = TypedRoot<Entity, this>>(selection: GroupBySelection<Type>, options?: TypedGroupByOptions): this;
15
16
  /**
16
17
  * Adds the columns the callback selects to GROUP BY.
17
18
  */
18
- addGroupByTyped<Type extends ObjectLiteral = TypedRoot<Entity>>(selection: GroupBySelection<Type>, options?: TypedGroupByOptions): this;
19
+ addGroupByTyped<Type extends ObjectLiteral = TypedRoot<Entity, this>>(selection: GroupBySelection<Type>, options?: TypedGroupByOptions): this;
19
20
  }
20
21
  declare module 'typeorm/query-builder/SelectQueryBuilder' {
21
22
  interface SelectQueryBuilder<Entity extends ObjectLiteral> extends TypedGroupByMethods<Entity> {
@@ -23,7 +23,7 @@ const extension = {
23
23
  (0, prototype_utils_1.patchPrototype)(typeorm_1.SelectQueryBuilder, extension);
24
24
  // implementation
25
25
  function toGroupByKeys(builder, selection, options) {
26
- const keys = (0, query_builder_utils_1.getTypedSelectionKey)(builder, selection, options === null || options === void 0 ? void 0 : options.useQuotes);
26
+ const keys = (0, query_builder_utils_1.getTypedSelectionKey)(builder, selection, options === null || options === void 0 ? void 0 : options.useQuotes, 'groupByTyped');
27
27
  return Array.isArray(keys) ? keys : [keys];
28
28
  }
29
29
  function addGroupByKeys(builder, keys) {
@@ -3,7 +3,7 @@ import { DeepUnwrapArray, ProxyColumnValueType } from '../../../types/modules/pr
3
3
  import { TypedWhereArgs, TypeOrDefault, UnsetType } from '../../../types/modules/typed-params.types';
4
4
  import type { TypedAggregate } from '../../../types/extensions/typed-having.types';
5
5
  import type { TypedRoot } from '../../../types/modules/typed-root.types';
6
- type Selection<Entity extends ObjectLiteral, Type, Value> = (proxy: DeepUnwrapArray<TypeOrDefault<Type, TypedRoot<Entity>>>) => Value;
6
+ type Selection<Root extends ObjectLiteral, Type, Value> = (proxy: DeepUnwrapArray<TypeOrDefault<Type, Root>>) => Value;
7
7
  /**
8
8
  * A value a column holds. A relation (`u => u.images`), the end of a key path or a JSON object is no column:
9
9
  * `COUNT("user"."images")` would fail in the database.
@@ -23,11 +23,11 @@ type AggregateValue<Aggregate, Value> = Aggregate extends 'MIN' | 'MAX' ? Value
23
23
  */
24
24
  export interface TypedHavingMethods<Entity extends ObjectLiteral> {
25
25
  /** Sets HAVING `aggregate(column) condition`, replacing the previous HAVING. */
26
- havingTyped<Type extends ObjectLiteral = UnsetType, Aggregate extends TypedAggregate = TypedAggregate, Value extends ProxyColumnValueType = ProxyColumnValueType, Operator extends string = string>(aggregate: Aggregate, selection: Selection<Entity, Type, Value & AggregatedColumn> | CountAll<Aggregate>, conditions: Operator, ...args: TypedWhereArgs<Type, Operator, AggregateValue<Aggregate, Value>>): this;
26
+ havingTyped<Type extends ObjectLiteral = UnsetType, Aggregate extends TypedAggregate = TypedAggregate, Value extends ProxyColumnValueType = ProxyColumnValueType, Operator extends string = string>(aggregate: Aggregate, selection: Selection<TypedRoot<Entity, this>, Type, Value & AggregatedColumn> | CountAll<Aggregate>, conditions: Operator, ...args: TypedWhereArgs<Type, Operator, AggregateValue<Aggregate, Value>>): this;
27
27
  /** Adds AND HAVING `aggregate(column) condition`. */
28
- andHavingTyped<Type extends ObjectLiteral = UnsetType, Aggregate extends TypedAggregate = TypedAggregate, Value extends ProxyColumnValueType = ProxyColumnValueType, Operator extends string = string>(aggregate: Aggregate, selection: Selection<Entity, Type, Value & AggregatedColumn> | CountAll<Aggregate>, conditions: Operator, ...args: TypedWhereArgs<Type, Operator, AggregateValue<Aggregate, Value>>): this;
28
+ andHavingTyped<Type extends ObjectLiteral = UnsetType, Aggregate extends TypedAggregate = TypedAggregate, Value extends ProxyColumnValueType = ProxyColumnValueType, Operator extends string = string>(aggregate: Aggregate, selection: Selection<TypedRoot<Entity, this>, Type, Value & AggregatedColumn> | CountAll<Aggregate>, conditions: Operator, ...args: TypedWhereArgs<Type, Operator, AggregateValue<Aggregate, Value>>): this;
29
29
  /** Adds OR HAVING `aggregate(column) condition`. */
30
- orHavingTyped<Type extends ObjectLiteral = UnsetType, Aggregate extends TypedAggregate = TypedAggregate, Value extends ProxyColumnValueType = ProxyColumnValueType, Operator extends string = string>(aggregate: Aggregate, selection: Selection<Entity, Type, Value & AggregatedColumn> | CountAll<Aggregate>, conditions: Operator, ...args: TypedWhereArgs<Type, Operator, AggregateValue<Aggregate, Value>>): this;
30
+ orHavingTyped<Type extends ObjectLiteral = UnsetType, Aggregate extends TypedAggregate = TypedAggregate, Value extends ProxyColumnValueType = ProxyColumnValueType, Operator extends string = string>(aggregate: Aggregate, selection: Selection<TypedRoot<Entity, this>, Type, Value & AggregatedColumn> | CountAll<Aggregate>, conditions: Operator, ...args: TypedWhereArgs<Type, Operator, AggregateValue<Aggregate, Value>>): this;
31
31
  }
32
32
  declare module 'typeorm/query-builder/SelectQueryBuilder' {
33
33
  interface SelectQueryBuilder<Entity extends ObjectLiteral> extends TypedHavingMethods<Entity> {
@@ -33,7 +33,7 @@ function attachTypedHaving(builder, method, aggregate, selection, conditions, pa
33
33
  else {
34
34
  // a path into a JSON column is cast: to a number to add it up, and for MIN / MAX to the type of the
35
35
  // value it is compared with, as in whereTyped; a count needs no cast
36
- const compared = (0, where_utils_1.isParamsObject)(parameters) ? Object.values(parameters)[0] : parameters;
36
+ const compared = (0, where_utils_1.getComparedValue)(parameters);
37
37
  const value = aggregate === 'SUM' || aggregate === 'AVG' ? 0 : aggregate === 'MIN' || aggregate === 'MAX' ? compared : undefined;
38
38
  argument = (0, query_builder_utils_1.getTypedSingleColumnKey)(builder, selection, methodName, { value });
39
39
  }
@@ -0,0 +1,19 @@
1
+ import { ObjectLiteral } from 'typeorm';
2
+ import { KeyProxyCallback } from '../../../types/modules/proxy-callback.types';
3
+ import type { JoinAndMapTarget } from '../../../types/extensions/typed-join-and-map.types';
4
+ import type { TypedRoot } from '../../../types/modules/typed-root.types';
5
+ declare module 'typeorm/query-builder/SelectQueryBuilder' {
6
+ interface SelectQueryBuilder<Entity extends ObjectLiteral> {
7
+ /**
8
+ * TypeORM's `leftJoinAndMapOne` with the property to map to picked by a typed callback: `(u) => u.profile` is
9
+ * `'user.profile'` on the main alias, `(q) => q.photo.owner` is `'photo.owner'` with an alias-keyed root.
10
+ */
11
+ leftJoinAndMapOneTyped<Type extends ObjectLiteral = TypedRoot<Entity, this>>(this: SelectQueryBuilder<Entity>, mapToProperty: KeyProxyCallback<Type>, entity: JoinAndMapTarget, alias: string, condition?: string, parameters?: ObjectLiteral): this;
12
+ /** TypeORM's `innerJoinAndMapOne` with the property to map to picked by a typed callback. */
13
+ innerJoinAndMapOneTyped<Type extends ObjectLiteral = TypedRoot<Entity, this>>(this: SelectQueryBuilder<Entity>, mapToProperty: KeyProxyCallback<Type>, entity: JoinAndMapTarget, alias: string, condition?: string, parameters?: ObjectLiteral): this;
14
+ /** TypeORM's `leftJoinAndMapMany` with the property to map to picked by a typed callback. */
15
+ leftJoinAndMapManyTyped<Type extends ObjectLiteral = TypedRoot<Entity, this>>(this: SelectQueryBuilder<Entity>, mapToProperty: KeyProxyCallback<Type>, entity: JoinAndMapTarget, alias: string, condition?: string, parameters?: ObjectLiteral): this;
16
+ /** TypeORM's `innerJoinAndMapMany` with the property to map to picked by a typed callback. */
17
+ innerJoinAndMapManyTyped<Type extends ObjectLiteral = TypedRoot<Entity, this>>(this: SelectQueryBuilder<Entity>, mapToProperty: KeyProxyCallback<Type>, entity: JoinAndMapTarget, alias: string, condition?: string, parameters?: ObjectLiteral): this;
18
+ }
19
+ }
@@ -0,0 +1,23 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const typeorm_1 = require("typeorm");
4
+ const proxy_key_utils_1 = require("../../../utils/proxy-key.utils");
5
+ const prototype_utils_1 = require("../../../utils/prototype.utils");
6
+ // patching
7
+ const createJoinAndMapTypedMethod = (method) => function (mapToProperty, entity, alias, condition, parameters) {
8
+ return addJoinAndMap(this, method, mapToProperty, entity, alias, condition, parameters);
9
+ };
10
+ const extension = {
11
+ prototype: {
12
+ leftJoinAndMapOneTyped: createJoinAndMapTypedMethod('leftJoinAndMapOne'),
13
+ innerJoinAndMapOneTyped: createJoinAndMapTypedMethod('innerJoinAndMapOne'),
14
+ leftJoinAndMapManyTyped: createJoinAndMapTypedMethod('leftJoinAndMapMany'),
15
+ innerJoinAndMapManyTyped: createJoinAndMapTypedMethod('innerJoinAndMapMany'),
16
+ },
17
+ };
18
+ (0, prototype_utils_1.patchPrototype)(typeorm_1.SelectQueryBuilder, extension);
19
+ function addJoinAndMap(query, method, mapToProperty, entity, alias, condition, parameters) {
20
+ // `() => query.alias`: `(q) => q.photo.owner` needs no main alias, only `(u) => u.profile` does
21
+ const key = (0, proxy_key_utils_1.getSqlKeyFromProxyCallback)(mapToProperty, () => query.alias, false);
22
+ return query[method](key, entity, alias, condition, parameters);
23
+ }
@@ -3,9 +3,9 @@ import { RelationalKeyProxyCallback } from '../../../types/modules/proxy-callbac
3
3
  import type { TypedRoot } from '../../../types/modules/typed-root.types';
4
4
  declare module 'typeorm/query-builder/SelectQueryBuilder' {
5
5
  interface SelectQueryBuilder<Entity extends ObjectLiteral> {
6
- leftJoinTyped<Type extends ObjectLiteral = TypedRoot<Entity>>(this: SelectQueryBuilder<Entity>, selection: RelationalKeyProxyCallback<Type>, alias: string, condition?: string, parameters?: ObjectLiteral): SelectQueryBuilder<Entity>;
7
- innerJoinTyped<Type extends ObjectLiteral = TypedRoot<Entity>>(this: SelectQueryBuilder<Entity>, selection: RelationalKeyProxyCallback<Type>, alias: string, condition?: string, parameters?: ObjectLiteral): SelectQueryBuilder<Entity>;
8
- leftJoinAndSelectTyped<Type extends ObjectLiteral = TypedRoot<Entity>>(this: SelectQueryBuilder<Entity>, selection: RelationalKeyProxyCallback<Type>, alias: string, condition?: string, parameters?: ObjectLiteral): SelectQueryBuilder<Entity>;
9
- innerJoinAndSelectTyped<Type extends ObjectLiteral = TypedRoot<Entity>>(this: SelectQueryBuilder<Entity>, selection: RelationalKeyProxyCallback<Type>, alias: string, condition?: string, parameters?: ObjectLiteral): SelectQueryBuilder<Entity>;
6
+ leftJoinTyped<Type extends ObjectLiteral = TypedRoot<Entity, this>>(this: SelectQueryBuilder<Entity>, selection: RelationalKeyProxyCallback<Type>, alias: string, condition?: string, parameters?: ObjectLiteral): this;
7
+ innerJoinTyped<Type extends ObjectLiteral = TypedRoot<Entity, this>>(this: SelectQueryBuilder<Entity>, selection: RelationalKeyProxyCallback<Type>, alias: string, condition?: string, parameters?: ObjectLiteral): this;
8
+ leftJoinAndSelectTyped<Type extends ObjectLiteral = TypedRoot<Entity, this>>(this: SelectQueryBuilder<Entity>, selection: RelationalKeyProxyCallback<Type>, alias: string, condition?: string, parameters?: ObjectLiteral): this;
9
+ innerJoinAndSelectTyped<Type extends ObjectLiteral = TypedRoot<Entity, this>>(this: SelectQueryBuilder<Entity>, selection: RelationalKeyProxyCallback<Type>, alias: string, condition?: string, parameters?: ObjectLiteral): this;
10
10
  }
11
11
  }
@@ -2,31 +2,20 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  const typeorm_1 = require("typeorm");
4
4
  const proxy_key_utils_1 = require("../../../utils/proxy-key.utils");
5
+ const prototype_utils_1 = require("../../../utils/prototype.utils");
5
6
  // patching
6
- typeorm_1.SelectQueryBuilder.prototype.leftJoinTyped = function (selection, alias, condition, parameters) {
7
- if (typeof selection === 'function') {
8
- return addJoin(this, 'leftJoin', selection, alias, condition, parameters);
9
- }
10
- return this;
7
+ const createJoinTypedMethod = (method) => function (selection, alias, condition, parameters) {
8
+ return addJoin(this, method, selection, alias, condition, parameters);
11
9
  };
12
- typeorm_1.SelectQueryBuilder.prototype.innerJoinTyped = function (selection, alias, condition, parameters) {
13
- if (typeof selection === 'function') {
14
- return addJoin(this, 'innerJoin', selection, alias, condition, parameters);
15
- }
16
- return this;
17
- };
18
- typeorm_1.SelectQueryBuilder.prototype.leftJoinAndSelectTyped = function (selection, alias, condition, parameters) {
19
- if (typeof selection === 'function') {
20
- return addJoin(this, 'leftJoinAndSelect', selection, alias, condition, parameters);
21
- }
22
- return this;
23
- };
24
- typeorm_1.SelectQueryBuilder.prototype.innerJoinAndSelectTyped = function (selection, alias, condition, parameters) {
25
- if (typeof selection === 'function') {
26
- return addJoin(this, 'innerJoinAndSelect', selection, alias, condition, parameters);
27
- }
28
- return this;
10
+ const extension = {
11
+ prototype: {
12
+ leftJoinTyped: createJoinTypedMethod('leftJoin'),
13
+ innerJoinTyped: createJoinTypedMethod('innerJoin'),
14
+ leftJoinAndSelectTyped: createJoinTypedMethod('leftJoinAndSelect'),
15
+ innerJoinAndSelectTyped: createJoinTypedMethod('innerJoinAndSelect'),
16
+ },
29
17
  };
18
+ (0, prototype_utils_1.patchPrototype)(typeorm_1.SelectQueryBuilder, extension);
30
19
  function addJoin(query, method, selection, alias, condition, parameters) {
31
20
  // `() => query.alias`: `(q) => q.base.images` needs no main alias, only `(u) => u.images` does
32
21
  const key = (0, proxy_key_utils_1.getSqlKeyFromProxyCallback)(selection, () => query.alias, false);
@@ -9,11 +9,11 @@ export interface TypedOrderByArrayPositionMethods<Entity extends ObjectLiteral>
9
9
  * `array_position(:values, column)`. Rows whose value isn't in `values` come last.
10
10
  * Like `orderBy`, it replaces the previous ORDER BY. See `orderByArrayPosition`.
11
11
  */
12
- orderByArrayPositionTyped<Type extends ObjectLiteral = TypedRoot<Entity>>(selection: (proxy: DeepUnwrapArray<Type>) => ProxyColumnValueType, values: ArgsType, arrayType?: string): this;
12
+ orderByArrayPositionTyped<Type extends ObjectLiteral = TypedRoot<Entity, this>>(selection: (proxy: DeepUnwrapArray<Type>) => ProxyColumnValueType, values: ArgsType, arrayType?: string): this;
13
13
  /**
14
14
  * Adds ORDER BY the position of the property's column value in `values` (PostgreSQL), like `addOrderBy`.
15
15
  */
16
- addOrderByArrayPositionTyped<Type extends ObjectLiteral = TypedRoot<Entity>>(selection: (proxy: DeepUnwrapArray<Type>) => ProxyColumnValueType, values: ArgsType, arrayType?: string): this;
16
+ addOrderByArrayPositionTyped<Type extends ObjectLiteral = TypedRoot<Entity, this>>(selection: (proxy: DeepUnwrapArray<Type>) => ProxyColumnValueType, values: ArgsType, arrayType?: string): this;
17
17
  }
18
18
  declare module 'typeorm/query-builder/SelectQueryBuilder' {
19
19
  interface SelectQueryBuilder<Entity extends ObjectLiteral> extends TypedOrderByArrayPositionMethods<Entity> {
@@ -9,11 +9,13 @@ declare module 'typeorm/query-builder/SelectQueryBuilder' {
9
9
  * Sets ORDER BY condition in the query builder.
10
10
  * If you had previously ORDER BY expression defined,
11
11
  * calling this function will override previously set ORDER BY conditions.
12
+ * A `@CalculatedColumn` is ordered by its value, selected with `addSelectCalculated` first.
12
13
  */
13
- orderByTyped<Type extends ObjectLiteral = TypedRoot<Entity>>(this: SelectQueryBuilder<Entity>, selection: (proxy: DeepUnwrapArray<Type>) => ProxyColumnValueType | KeyHolder, order?: 'ASC' | 'DESC', nulls?: 'NULLS FIRST' | 'NULLS LAST', options?: TypedOrderByOptions): SelectQueryBuilder<Entity>;
14
+ orderByTyped<Type extends ObjectLiteral = TypedRoot<Entity, this>>(this: SelectQueryBuilder<Entity>, selection: (proxy: DeepUnwrapArray<Type>) => ProxyColumnValueType | KeyHolder, order?: 'ASC' | 'DESC', nulls?: 'NULLS FIRST' | 'NULLS LAST', options?: TypedOrderByOptions): this;
14
15
  /**
15
16
  * Adds ORDER BY condition in the query builder.
17
+ * A `@CalculatedColumn` is ordered by its value, selected with `addSelectCalculated` first.
16
18
  */
17
- addOrderByTyped<Type extends ObjectLiteral = TypedRoot<Entity>>(this: SelectQueryBuilder<Entity>, selection: (proxy: DeepUnwrapArray<Type>) => ProxyColumnValueType | KeyHolder, order?: 'ASC' | 'DESC', nulls?: 'NULLS FIRST' | 'NULLS LAST', options?: TypedOrderByOptions): SelectQueryBuilder<Entity>;
19
+ addOrderByTyped<Type extends ObjectLiteral = TypedRoot<Entity, this>>(this: SelectQueryBuilder<Entity>, selection: (proxy: DeepUnwrapArray<Type>) => ProxyColumnValueType | KeyHolder, order?: 'ASC' | 'DESC', nulls?: 'NULLS FIRST' | 'NULLS LAST', options?: TypedOrderByOptions): this;
18
20
  }
19
21
  }
@@ -3,25 +3,26 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  const typeorm_1 = require("typeorm");
4
4
  const proxy_key_utils_1 = require("../../../utils/proxy-key.utils");
5
5
  const query_builder_utils_1 = require("../../../utils/query-builder.utils");
6
- const sql_utils_1 = require("../../../utils/sql.utils");
6
+ const calculated_column_utils_1 = require("../../../utils/calculated-column.utils");
7
+ const prototype_utils_1 = require("../../../utils/prototype.utils");
7
8
  // patching and implementation
8
- typeorm_1.SelectQueryBuilder.prototype.orderByTyped = function (selection, order, nulls, options) {
9
- if (selection instanceof proxy_key_utils_1.KeyHolder) {
10
- return this.orderBy(selection.toSql(undefined, options === null || options === void 0 ? void 0 : options.useQuotes, (0, sql_utils_1.getDriverType)(this)), order, nulls);
11
- }
12
- if (typeof selection === 'function') {
13
- const key = (0, query_builder_utils_1.getTypedSelectionKey)(this, selection, options === null || options === void 0 ? void 0 : options.useQuotes);
14
- return this.orderBy(key, order, nulls);
9
+ const createOrderByTypedMethod = (method) => function (selection, order, nulls, options) {
10
+ if (selection instanceof proxy_key_utils_1.KeyHolder || typeof selection === 'function') {
11
+ const methodName = `${method}Typed`;
12
+ const keyHolder = (0, proxy_key_utils_1.getKeyHolder)(selection);
13
+ const calculated = keyHolder instanceof proxy_key_utils_1.KeyHolder ? (0, query_builder_utils_1.findTypedCalculatedProperty)(this, keyHolder) : undefined;
14
+ // a @CalculatedColumn is ordered by its value, which has to be selected with addSelectCalculated first
15
+ const key = calculated
16
+ ? (0, calculated_column_utils_1.selectCalculatedForOrder)(this, calculated.propertyPath, calculated.aliasName, methodName)
17
+ : (0, query_builder_utils_1.getTypedSelectionKey)(this, selection, options === null || options === void 0 ? void 0 : options.useQuotes, methodName);
18
+ return this[method](key, order, nulls);
15
19
  }
16
20
  return this;
17
21
  };
18
- typeorm_1.SelectQueryBuilder.prototype.addOrderByTyped = function (selection, order, nulls, options) {
19
- if (selection instanceof proxy_key_utils_1.KeyHolder) {
20
- return this.addOrderBy(selection.toSql(undefined, options === null || options === void 0 ? void 0 : options.useQuotes, (0, sql_utils_1.getDriverType)(this)), order, nulls);
21
- }
22
- if (typeof selection === 'function') {
23
- const key = (0, query_builder_utils_1.getTypedSelectionKey)(this, selection, options === null || options === void 0 ? void 0 : options.useQuotes);
24
- return this.addOrderBy(key, order, nulls);
25
- }
26
- return this;
22
+ const extension = {
23
+ prototype: {
24
+ orderByTyped: createOrderByTypedMethod('orderBy'),
25
+ addOrderByTyped: createOrderByTypedMethod('addOrderBy'),
26
+ },
27
27
  };
28
+ (0, prototype_utils_1.patchPrototype)(typeorm_1.SelectQueryBuilder, extension);
@@ -27,12 +27,4 @@ const extension = {
27
27
  },
28
28
  },
29
29
  };
30
- const queryBuilders = [
31
- typeorm_1.InsertQueryBuilder,
32
- typeorm_1.UpdateQueryBuilder,
33
- typeorm_1.DeleteQueryBuilder,
34
- SoftDeleteQueryBuilder_1.SoftDeleteQueryBuilder,
35
- ];
36
- queryBuilders.forEach((builder) => {
37
- (0, prototype_utils_1.patchPrototype)(builder, extension);
38
- });
30
+ (0, prototype_utils_1.patchPrototypes)([typeorm_1.InsertQueryBuilder, typeorm_1.UpdateQueryBuilder, typeorm_1.DeleteQueryBuilder, SoftDeleteQueryBuilder_1.SoftDeleteQueryBuilder], extension);
@@ -1,13 +1,14 @@
1
1
  import { ObjectLiteral } from 'typeorm';
2
+ import type { EntityTarget } from 'typeorm';
2
3
  import type { WithTypedRoot } from '../../types/modules/typed-root.types';
3
- type KnownEntity<Entity> = 0 extends 1 & Entity ? ObjectLiteral : Entity;
4
4
  declare module 'typeorm/query-builder/SelectQueryBuilder' {
5
5
  interface SelectQueryBuilder<Entity extends ObjectLiteral> {
6
6
  /**
7
7
  * Sets the root of the typed callbacks of the calls that follow, instead of passing it to each of them:
8
8
  * the aliases of the query and their entities.
9
9
  *
10
- * Type-only: returns the builder itself. Call it once; a second call merges the roots.
10
+ * Type-only: returns the builder itself, marked with the root; its entity type stays. `from()` and `addFrom()`
11
+ * keep the root, so it may go before them; a second call replaces it.
11
12
  *
12
13
  * @example
13
14
  * type Joins = { checkin: CheckIn; event: Event };
@@ -19,7 +20,28 @@ declare module 'typeorm/query-builder/SelectQueryBuilder' {
19
20
  * .selectTyped((q) => q.checkin.customerId, 'customerId')
20
21
  * .whereTyped((q) => q.event.eventType, '=', type) // instead of whereTyped<Joins>(…)
21
22
  */
22
- typed<Root extends ObjectLiteral>(): SelectQueryBuilder<WithTypedRoot<KnownEntity<Entity>, Root>>;
23
+ typed<Root extends ObjectLiteral>(): WithTypedRoot<SelectQueryBuilder<Entity>, Root>;
24
+ /**
25
+ * Specifies FROM which entity's table select/update/delete will be executed.
26
+ * Also sets a main string alias of the selection data.
27
+ * Removes all previously set from-s. Keeps the root set with `typed()`.
28
+ */
29
+ from<T extends ObjectLiteral, Root extends ObjectLiteral>(this: WithTypedRoot<unknown, Root>, entityTarget: (qb: SelectQueryBuilder<any>) => SelectQueryBuilder<any>, aliasName: string): WithTypedRoot<SelectQueryBuilder<T>, Root>;
30
+ /**
31
+ * Specifies FROM which entity's table select/update/delete will be executed.
32
+ * Also sets a main string alias of the selection data.
33
+ * Removes all previously set from-s. Keeps the root set with `typed()`.
34
+ */
35
+ from<T extends ObjectLiteral, Root extends ObjectLiteral>(this: WithTypedRoot<unknown, Root>, entityTarget: EntityTarget<T>, aliasName: string): WithTypedRoot<SelectQueryBuilder<T>, Root>;
36
+ /**
37
+ * Specifies FROM which entity's table select/update/delete will be executed.
38
+ * Also sets a main string alias of the selection data. Keeps the root set with `typed()`.
39
+ */
40
+ addFrom<T extends ObjectLiteral, Root extends ObjectLiteral>(this: WithTypedRoot<unknown, Root>, entityTarget: (qb: SelectQueryBuilder<any>) => SelectQueryBuilder<any>, aliasName: string): WithTypedRoot<SelectQueryBuilder<T>, Root>;
41
+ /**
42
+ * Specifies FROM which entity's table select/update/delete will be executed.
43
+ * Also sets a main string alias of the selection data. Keeps the root set with `typed()`.
44
+ */
45
+ addFrom<T extends ObjectLiteral, Root extends ObjectLiteral>(this: WithTypedRoot<unknown, Root>, entityTarget: EntityTarget<T>, aliasName: string): WithTypedRoot<SelectQueryBuilder<T>, Root>;
23
46
  }
24
47
  }
25
- export {};
@@ -8,28 +8,28 @@ declare module 'typeorm/query-builder/SelectQueryBuilder' {
8
8
  * Creates SELECT query.
9
9
  * Replaces all previous selections if they exist.
10
10
  */
11
- selectTyped<Type extends ObjectLiteral = TypedRoot<Entity>>(this: SelectQueryBuilder<Entity>, selection: KeyProxyCallback<Type>, selectionAliasName?: string, useQuotes?: boolean): SelectQueryBuilder<Entity>;
11
+ selectTyped<Type extends ObjectLiteral = TypedRoot<Entity, this>>(this: SelectQueryBuilder<Entity>, selection: KeyProxyCallback<Type>, selectionAliasName?: string, useQuotes?: boolean): this;
12
12
  /**
13
13
  * Creates SELECT query and selects given data.
14
14
  * Replaces all previous selections if they exist.
15
15
  */
16
- selectTyped(this: SelectQueryBuilder<Entity>, selection: string | KeyHolder, selectionAliasName?: string, useQuotes?: boolean): SelectQueryBuilder<Entity>;
16
+ selectTyped(this: SelectQueryBuilder<Entity>, selection: string | KeyHolder, selectionAliasName?: string, useQuotes?: boolean): this;
17
17
  /**
18
18
  * Creates SELECT query and selects given data.
19
19
  * Replaces all previous selections if they exist.
20
20
  */
21
- selectTyped<Type extends ObjectLiteral = TypedRoot<Entity>>(this: SelectQueryBuilder<Entity>, selection: string[] | KeyHolder[] | Array<KeyProxyCallback<Type>>, useQuotes?: boolean): SelectQueryBuilder<Entity>;
21
+ selectTyped<Type extends ObjectLiteral = TypedRoot<Entity, this>>(this: SelectQueryBuilder<Entity>, selection: string[] | KeyHolder[] | Array<KeyProxyCallback<Type>>, useQuotes?: boolean): this;
22
22
  /**
23
23
  * Adds new selection to the SELECT query.
24
24
  */
25
- addSelectTyped<Type extends ObjectLiteral = TypedRoot<Entity>>(this: SelectQueryBuilder<Entity>, selection: KeyProxyCallback<Type>, selectionAliasName?: string, useQuotes?: boolean): SelectQueryBuilder<Entity>;
25
+ addSelectTyped<Type extends ObjectLiteral = TypedRoot<Entity, this>>(this: SelectQueryBuilder<Entity>, selection: KeyProxyCallback<Type>, selectionAliasName?: string, useQuotes?: boolean): this;
26
26
  /**
27
27
  * Adds new selection to the SELECT query.
28
28
  */
29
- addSelectTyped(this: SelectQueryBuilder<Entity>, selection: string | KeyHolder, selectionAliasName?: string, useQuotes?: boolean): SelectQueryBuilder<Entity>;
29
+ addSelectTyped(this: SelectQueryBuilder<Entity>, selection: string | KeyHolder, selectionAliasName?: string, useQuotes?: boolean): this;
30
30
  /**
31
31
  * Adds new selection to the SELECT query.
32
32
  */
33
- addSelectTyped<Type extends ObjectLiteral = TypedRoot<Entity>>(this: SelectQueryBuilder<Entity>, selection: string[] | KeyHolder[] | Array<KeyProxyCallback<Type>>, useQuotes?: boolean): SelectQueryBuilder<Entity>;
33
+ addSelectTyped<Type extends ObjectLiteral = TypedRoot<Entity, this>>(this: SelectQueryBuilder<Entity>, selection: string[] | KeyHolder[] | Array<KeyProxyCallback<Type>>, useQuotes?: boolean): this;
34
34
  }
35
35
  }
@@ -3,7 +3,6 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  const typeorm_1 = require("typeorm");
4
4
  const proxy_key_utils_1 = require("../../../utils/proxy-key.utils");
5
5
  const query_builder_utils_1 = require("../../../utils/query-builder.utils");
6
- const sql_utils_1 = require("../../../utils/sql.utils");
7
6
  const prototype_utils_1 = require("../../../utils/prototype.utils");
8
7
  // patching
9
8
  const extension = {
@@ -23,17 +22,12 @@ const extension = {
23
22
  (0, prototype_utils_1.patchPrototype)(typeorm_1.SelectQueryBuilder, extension);
24
23
  // implementation
25
24
  const attachSelectMethod = (query, method, selection, selectionAliasName, useQuotes) => {
26
- if (selection instanceof proxy_key_utils_1.KeyHolder) {
27
- return query[method](selection.toSql(undefined, useQuotes, (0, sql_utils_1.getDriverType)(query)), selectionAliasName);
28
- }
29
25
  if (Array.isArray(selection)) {
30
- const arrayOfKeys = selection.flatMap((select) => select instanceof proxy_key_utils_1.KeyHolder
31
- ? (0, proxy_key_utils_1.getSqlKeyFromProxyCallback)(select, () => query.alias, useQuotes, (0, sql_utils_1.getDriverType)(query))
32
- : (0, query_builder_utils_1.getTypedSelectionKey)(query, select, useQuotes));
26
+ const arrayOfKeys = selection.flatMap((select) => (0, query_builder_utils_1.getTypedSelectionKey)(query, select, useQuotes, `${method}Typed`));
33
27
  return query[method](arrayOfKeys);
34
28
  }
35
- else if (typeof selection === 'function') {
36
- const keyArrayOrSingleKey = (0, query_builder_utils_1.getTypedSelectionKey)(query, selection, useQuotes);
29
+ else if (selection instanceof proxy_key_utils_1.KeyHolder || typeof selection === 'function') {
30
+ const keyArrayOrSingleKey = (0, query_builder_utils_1.getTypedSelectionKey)(query, selection, useQuotes, `${method}Typed`);
37
31
  if (Array.isArray(keyArrayOrSingleKey)) {
38
32
  return query[method](keyArrayOrSingleKey);
39
33
  }
@@ -12,7 +12,7 @@ export interface TypedPeriodFilterMethods<Entity extends ObjectLiteral> {
12
12
  * Both ends are inclusive unless `options.includeFrom` / `options.includeTo` is `false`.
13
13
  * A date-only string (`'2024-01-31'`) stands for the whole day: `periodTo: '2024-01-31'` → `column < '2024-02-01'`.
14
14
  */
15
- applyPeriodFilterTyped<Type extends ObjectLiteral = TypedRoot<Entity>>(selection: (proxy: DeepUnwrapArray<Type>) => ProxyColumnValueType, periodFilter: PeriodFilter | null | undefined, options?: ApplyPeriodOptions): this;
15
+ applyPeriodFilterTyped<Type extends ObjectLiteral = TypedRoot<Entity, this>>(selection: (proxy: DeepUnwrapArray<Type>) => ProxyColumnValueType, periodFilter: PeriodFilter | null | undefined, options?: ApplyPeriodOptions): this;
16
16
  }
17
17
  declare module 'typeorm/query-builder/WhereExpressionBuilder' {
18
18
  interface WhereExpressionBuilder extends TypedPeriodFilterMethods<ObjectLiteral> {
@@ -30,3 +30,7 @@ declare module 'typeorm/query-builder/DeleteQueryBuilder' {
30
30
  interface DeleteQueryBuilder<Entity extends ObjectLiteral> extends TypedPeriodFilterMethods<Entity> {
31
31
  }
32
32
  }
33
+ declare module 'typeorm/query-builder/SoftDeleteQueryBuilder' {
34
+ interface SoftDeleteQueryBuilder<Entity extends ObjectLiteral> extends TypedPeriodFilterMethods<Entity> {
35
+ }
36
+ }
@@ -1,7 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  require("../../period-filter.extension");
4
- const typeorm_1 = require("typeorm");
5
4
  const query_builder_utils_1 = require("../../../utils/query-builder.utils");
6
5
  const prototype_utils_1 = require("../../../utils/prototype.utils");
7
6
  const period_utils_1 = require("../../../utils/period.utils");
@@ -15,11 +14,4 @@ const extension = {
15
14
  },
16
15
  },
17
16
  };
18
- const queryBuilders = [
19
- typeorm_1.SelectQueryBuilder,
20
- typeorm_1.UpdateQueryBuilder,
21
- typeorm_1.DeleteQueryBuilder,
22
- ];
23
- queryBuilders.forEach((builder) => {
24
- (0, prototype_utils_1.patchPrototype)(builder, extension);
25
- });
17
+ (0, prototype_utils_1.patchPrototypes)(prototype_utils_1.WHERE_QUERY_BUILDERS, extension);
@@ -13,43 +13,43 @@ export interface TypedWhereArrayMethods<Entity extends ObjectLiteral> {
13
13
  * If you had previously WHERE expression defined,
14
14
  * calling this function will override previously set WHERE conditions.
15
15
  */
16
- whereArrayContainsTyped<Type extends ObjectLiteral = TypedRoot<Entity>>(where: (proxy: DeepUnwrapArray<Type>) => ProxyColumnValueType, values: ArgsType, arrayType?: string): this;
16
+ whereArrayContainsTyped<Type extends ObjectLiteral = TypedRoot<Entity, this>>(where: (proxy: DeepUnwrapArray<Type>) => ProxyColumnValueType, values: ArgsType, arrayType?: string): this;
17
17
  /**
18
18
  * Adds new AND WHERE `column @> :values` condition (PostgreSQL): the array column contains every value.
19
19
  */
20
- andWhereArrayContainsTyped<Type extends ObjectLiteral = TypedRoot<Entity>>(where: (proxy: DeepUnwrapArray<Type>) => ProxyColumnValueType, values: ArgsType, arrayType?: string): this;
20
+ andWhereArrayContainsTyped<Type extends ObjectLiteral = TypedRoot<Entity, this>>(where: (proxy: DeepUnwrapArray<Type>) => ProxyColumnValueType, values: ArgsType, arrayType?: string): this;
21
21
  /**
22
22
  * Adds new OR WHERE `column @> :values` condition (PostgreSQL): the array column contains every value.
23
23
  */
24
- orWhereArrayContainsTyped<Type extends ObjectLiteral = TypedRoot<Entity>>(where: (proxy: DeepUnwrapArray<Type>) => ProxyColumnValueType, values: ArgsType, arrayType?: string): this;
24
+ orWhereArrayContainsTyped<Type extends ObjectLiteral = TypedRoot<Entity, this>>(where: (proxy: DeepUnwrapArray<Type>) => ProxyColumnValueType, values: ArgsType, arrayType?: string): this;
25
25
  /**
26
26
  * Sets WHERE `column <@ :values` condition (PostgreSQL): every element of the array column is one of the values.
27
27
  * If you had previously WHERE expression defined,
28
28
  * calling this function will override previously set WHERE conditions.
29
29
  */
30
- whereArrayContainedByTyped<Type extends ObjectLiteral = TypedRoot<Entity>>(where: (proxy: DeepUnwrapArray<Type>) => ProxyColumnValueType, values: ArgsType, arrayType?: string): this;
30
+ whereArrayContainedByTyped<Type extends ObjectLiteral = TypedRoot<Entity, this>>(where: (proxy: DeepUnwrapArray<Type>) => ProxyColumnValueType, values: ArgsType, arrayType?: string): this;
31
31
  /**
32
32
  * Adds new AND WHERE `column <@ :values` condition (PostgreSQL): every element of the array column is one of the values.
33
33
  */
34
- andWhereArrayContainedByTyped<Type extends ObjectLiteral = TypedRoot<Entity>>(where: (proxy: DeepUnwrapArray<Type>) => ProxyColumnValueType, values: ArgsType, arrayType?: string): this;
34
+ andWhereArrayContainedByTyped<Type extends ObjectLiteral = TypedRoot<Entity, this>>(where: (proxy: DeepUnwrapArray<Type>) => ProxyColumnValueType, values: ArgsType, arrayType?: string): this;
35
35
  /**
36
36
  * Adds new OR WHERE `column <@ :values` condition (PostgreSQL): every element of the array column is one of the values.
37
37
  */
38
- orWhereArrayContainedByTyped<Type extends ObjectLiteral = TypedRoot<Entity>>(where: (proxy: DeepUnwrapArray<Type>) => ProxyColumnValueType, values: ArgsType, arrayType?: string): this;
38
+ orWhereArrayContainedByTyped<Type extends ObjectLiteral = TypedRoot<Entity, this>>(where: (proxy: DeepUnwrapArray<Type>) => ProxyColumnValueType, values: ArgsType, arrayType?: string): this;
39
39
  /**
40
40
  * Sets WHERE `column && :values` condition (PostgreSQL): the array column has at least one of the values.
41
41
  * If you had previously WHERE expression defined,
42
42
  * calling this function will override previously set WHERE conditions.
43
43
  */
44
- whereArrayOverlapsTyped<Type extends ObjectLiteral = TypedRoot<Entity>>(where: (proxy: DeepUnwrapArray<Type>) => ProxyColumnValueType, values: ArgsType, arrayType?: string): this;
44
+ whereArrayOverlapsTyped<Type extends ObjectLiteral = TypedRoot<Entity, this>>(where: (proxy: DeepUnwrapArray<Type>) => ProxyColumnValueType, values: ArgsType, arrayType?: string): this;
45
45
  /**
46
46
  * Adds new AND WHERE `column && :values` condition (PostgreSQL): the array column has at least one of the values.
47
47
  */
48
- andWhereArrayOverlapsTyped<Type extends ObjectLiteral = TypedRoot<Entity>>(where: (proxy: DeepUnwrapArray<Type>) => ProxyColumnValueType, values: ArgsType, arrayType?: string): this;
48
+ andWhereArrayOverlapsTyped<Type extends ObjectLiteral = TypedRoot<Entity, this>>(where: (proxy: DeepUnwrapArray<Type>) => ProxyColumnValueType, values: ArgsType, arrayType?: string): this;
49
49
  /**
50
50
  * Adds new OR WHERE `column && :values` condition (PostgreSQL): the array column has at least one of the values.
51
51
  */
52
- orWhereArrayOverlapsTyped<Type extends ObjectLiteral = TypedRoot<Entity>>(where: (proxy: DeepUnwrapArray<Type>) => ProxyColumnValueType, values: ArgsType, arrayType?: string): this;
52
+ orWhereArrayOverlapsTyped<Type extends ObjectLiteral = TypedRoot<Entity, this>>(where: (proxy: DeepUnwrapArray<Type>) => ProxyColumnValueType, values: ArgsType, arrayType?: string): this;
53
53
  }
54
54
  declare module 'typeorm/query-builder/WhereExpressionBuilder' {
55
55
  interface WhereExpressionBuilder extends TypedWhereArrayMethods<ObjectLiteral> {
@@ -67,3 +67,7 @@ declare module 'typeorm/query-builder/DeleteQueryBuilder' {
67
67
  interface DeleteQueryBuilder<Entity extends ObjectLiteral> extends TypedWhereArrayMethods<Entity> {
68
68
  }
69
69
  }
70
+ declare module 'typeorm/query-builder/SoftDeleteQueryBuilder' {
71
+ interface SoftDeleteQueryBuilder<Entity extends ObjectLiteral> extends TypedWhereArrayMethods<Entity> {
72
+ }
73
+ }