typeorm-extensions 2.2.0-rc.1 → 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.
- package/README.md +70 -39
- package/dist/decorators/calculated-column.decorator.d.ts +7 -3
- package/dist/decorators/calculated-column.decorator.js +35 -6
- package/dist/decorators/generated-column.decorator.d.ts +17 -0
- package/dist/decorators/generated-column.decorator.js +15 -0
- package/dist/decorators/index.d.ts +1 -0
- package/dist/decorators/index.js +1 -0
- package/dist/extensions/calculated-column.extension.d.ts +3 -3
- package/dist/extensions/calculated-column.extension.js +3 -16
- package/dist/extensions/cursor-pagination.extension.d.ts +2 -1
- package/dist/extensions/cursor-pagination.extension.js +7 -13
- package/dist/extensions/get-many-with-totals.extension.js +10 -29
- package/dist/extensions/join-lateral.extension.js +4 -6
- package/dist/extensions/order.extension.d.ts +2 -2
- package/dist/extensions/pagination.extension.d.ts +1 -1
- package/dist/extensions/period-filter.extension.d.ts +4 -0
- package/dist/extensions/period-filter.extension.js +1 -9
- package/dist/extensions/typed/index.d.ts +2 -0
- package/dist/extensions/typed/index.js +2 -0
- package/dist/extensions/typed/typed-calculated/typed-calculated-column.extension.d.ts +19 -0
- package/dist/extensions/typed/typed-calculated/typed-calculated-column.extension.js +17 -0
- package/dist/extensions/typed/typed-distinct/typed-distinct.extension.d.ts +6 -4
- package/dist/extensions/typed/typed-distinct/typed-distinct.extension.js +9 -2
- package/dist/extensions/typed/typed-group-by/typed-group-by.extension.d.ts +8 -7
- package/dist/extensions/typed/typed-group-by/typed-group-by.extension.js +1 -1
- package/dist/extensions/typed/typed-having/typed-having.extension.d.ts +4 -4
- package/dist/extensions/typed/typed-having/typed-having.extension.js +1 -1
- package/dist/extensions/typed/typed-joins/typed-join-and-map.extension.d.ts +19 -0
- package/dist/extensions/typed/typed-joins/typed-join-and-map.extension.js +23 -0
- package/dist/extensions/typed/typed-joins/typed-joins.extension.d.ts +4 -4
- package/dist/extensions/typed/typed-joins/typed-joins.extension.js +11 -22
- package/dist/extensions/typed/typed-order-by/typed-order-by-array-position.extension.d.ts +2 -2
- package/dist/extensions/typed/typed-order-by/typed-order-by.extension.d.ts +4 -2
- package/dist/extensions/typed/typed-order-by/typed-order-by.extension.js +18 -17
- package/dist/extensions/typed/typed-returning/typed-returning.extension.js +1 -9
- package/dist/extensions/typed/typed-root.extension.d.ts +26 -4
- package/dist/extensions/typed/typed-select/typed-select.extension.d.ts +6 -6
- package/dist/extensions/typed/typed-select/typed-select.extension.js +3 -9
- package/dist/extensions/typed/typed-where/typed-period-filter.extension.d.ts +5 -1
- package/dist/extensions/typed/typed-where/typed-period-filter.extension.js +1 -9
- package/dist/extensions/typed/typed-where/typed-where-array.extension.d.ts +13 -9
- package/dist/extensions/typed/typed-where/typed-where-array.extension.js +4 -16
- package/dist/extensions/typed/typed-where/typed-where-ilike.extension.d.ts +10 -6
- package/dist/extensions/typed/typed-where/typed-where-ilike.extension.js +1 -9
- package/dist/extensions/typed/typed-where/typed-where-is-any.extension.d.ts +10 -6
- package/dist/extensions/typed/typed-where/typed-where-is-any.extension.js +3 -20
- package/dist/extensions/typed/typed-where/typed-where-is-distinct-from.extension.d.ts +10 -6
- package/dist/extensions/typed/typed-where/typed-where-is-distinct-from.extension.js +3 -20
- package/dist/extensions/typed/typed-where/typed-where-is-in.extension.d.ts +10 -6
- package/dist/extensions/typed/typed-where/typed-where-is-in.extension.js +3 -21
- package/dist/extensions/typed/typed-where/typed-where-json.extension.d.ts +10 -6
- package/dist/extensions/typed/typed-where/typed-where-json.extension.js +4 -21
- package/dist/extensions/typed/typed-where/typed-where-lower.extension.d.ts +10 -6
- package/dist/extensions/typed/typed-where/typed-where-lower.extension.js +1 -9
- package/dist/extensions/typed/typed-where/typed-where-similar.extension.d.ts +8 -4
- package/dist/extensions/typed/typed-where/typed-where-similar.extension.js +1 -8
- package/dist/extensions/typed/typed-where/typed-where.extension.d.ts +7 -3
- package/dist/extensions/typed/typed-where/typed-where.extension.js +2 -10
- package/dist/extensions/union.extension.js +1 -1
- package/dist/extensions/where-array.extension.d.ts +4 -0
- package/dist/extensions/where-array.extension.js +1 -9
- package/dist/extensions/where-exists.extension.js +4 -15
- package/dist/extensions/where-is-any.extension.d.ts +41 -128
- package/dist/extensions/where-is-any.extension.js +1 -9
- package/dist/extensions/where-is-distinct-from.extension.d.ts +4 -0
- package/dist/extensions/where-is-distinct-from.extension.js +1 -9
- package/dist/extensions/where-is-in.extension.d.ts +38 -116
- package/dist/extensions/where-is-in.extension.js +11 -27
- package/dist/extensions/where-json.extension.d.ts +4 -0
- package/dist/extensions/where-json.extension.js +1 -9
- package/dist/extensions/where-relation-exists.extension.d.ts +6 -6
- package/dist/extensions/where-relation-exists.extension.js +5 -25
- package/dist/helpers.d.ts +5 -0
- package/dist/helpers.js +12 -3
- package/dist/index.d.ts +1 -2
- package/dist/index.js +1 -4
- package/dist/types/extensions/cursor-pagination.types.d.ts +5 -0
- package/dist/types/extensions/get-many-with-totals.types.d.ts +4 -0
- package/dist/types/extensions/index.d.ts +1 -0
- package/dist/types/extensions/index.js +1 -0
- package/dist/types/extensions/typed-group-by.types.d.ts +2 -2
- package/dist/types/extensions/typed-join-and-map.types.d.ts +6 -0
- package/dist/types/extensions/typed-join-and-map.types.js +2 -0
- package/dist/types/modules/typed-root.types.d.ts +11 -9
- package/dist/utils/calculated-column.utils.d.ts +11 -0
- package/dist/utils/calculated-column.utils.js +33 -4
- package/dist/utils/common.utils.d.ts +2 -0
- package/dist/utils/common.utils.js +4 -1
- package/dist/utils/cursor.utils.js +4 -6
- package/dist/utils/json-path.utils.js +2 -2
- package/dist/utils/pagination.utils.d.ts +7 -0
- package/dist/utils/pagination.utils.js +20 -10
- package/dist/utils/parameter.utils.d.ts +10 -0
- package/dist/utils/parameter.utils.js +22 -1
- package/dist/utils/period.utils.js +2 -1
- package/dist/utils/prototype.utils.d.ts +9 -0
- package/dist/utils/prototype.utils.js +12 -2
- package/dist/utils/query-builder.utils.d.ts +43 -4
- package/dist/utils/query-builder.utils.js +239 -36
- package/dist/utils/reserved-qualifier-guard.utils.d.ts +36 -0
- package/dist/utils/reserved-qualifier-guard.utils.js +98 -0
- package/dist/utils/reserved-qualifier.utils.d.ts +33 -0
- package/dist/utils/reserved-qualifier.utils.js +252 -0
- package/dist/utils/table.utils.d.ts +27 -11
- package/dist/utils/table.utils.js +58 -23
- package/dist/utils/time-zone.utils.d.ts +8 -0
- package/dist/utils/time-zone.utils.js +15 -5
- package/dist/utils/typed-where.utils.d.ts +9 -0
- package/dist/utils/typed-where.utils.js +17 -0
- package/dist/utils/where.utils.d.ts +2 -0
- package/dist/utils/where.utils.js +21 -14
- package/package.json +2 -2
|
@@ -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>>):
|
|
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>):
|
|
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.
|
|
9
|
-
|
|
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 {
|
|
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
|
-
/**
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
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<
|
|
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.
|
|
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):
|
|
7
|
-
innerJoinTyped<Type extends ObjectLiteral = TypedRoot<Entity>>(this: SelectQueryBuilder<Entity>, selection: RelationalKeyProxyCallback<Type>, alias: string, condition?: string, parameters?: ObjectLiteral):
|
|
8
|
-
leftJoinAndSelectTyped<Type extends ObjectLiteral = TypedRoot<Entity>>(this: SelectQueryBuilder<Entity>, selection: RelationalKeyProxyCallback<Type>, alias: string, condition?: string, parameters?: ObjectLiteral):
|
|
9
|
-
innerJoinAndSelectTyped<Type extends ObjectLiteral = TypedRoot<Entity>>(this: SelectQueryBuilder<Entity>, selection: RelationalKeyProxyCallback<Type>, alias: string, condition?: string, parameters?: ObjectLiteral):
|
|
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
|
-
|
|
7
|
-
|
|
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
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
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):
|
|
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):
|
|
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
|
|
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
|
-
|
|
9
|
-
if (selection instanceof proxy_key_utils_1.KeyHolder) {
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
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
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
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
|
-
|
|
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
|
|
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>():
|
|
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):
|
|
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):
|
|
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):
|
|
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):
|
|
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):
|
|
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):
|
|
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
|
|
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
|
-
|
|
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
|
+
}
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
require("../../where-array.extension");
|
|
4
|
-
const typeorm_1 = require("typeorm");
|
|
5
4
|
const query_builder_utils_1 = require("../../../utils/query-builder.utils");
|
|
6
5
|
const sql_utils_1 = require("../../../utils/sql.utils");
|
|
7
6
|
const prototype_utils_1 = require("../../../utils/prototype.utils");
|
|
7
|
+
const typed_where_utils_1 = require("../../../utils/typed-where.utils");
|
|
8
8
|
/* eslint-enable @typescript-eslint/no-empty-interface */
|
|
9
9
|
// patching
|
|
10
10
|
const createWhereArrayTypedMethod = (method) => function (where, values, arrayType) {
|
|
@@ -23,25 +23,13 @@ const extension = {
|
|
|
23
23
|
orWhereArrayOverlapsTyped: createWhereArrayTypedMethod('orWhereArrayOverlaps'),
|
|
24
24
|
},
|
|
25
25
|
};
|
|
26
|
-
|
|
27
|
-
typeorm_1.SelectQueryBuilder,
|
|
28
|
-
typeorm_1.UpdateQueryBuilder,
|
|
29
|
-
typeorm_1.DeleteQueryBuilder,
|
|
30
|
-
];
|
|
31
|
-
queryBuilders.forEach((builder) => {
|
|
32
|
-
(0, prototype_utils_1.patchPrototype)(builder, extension);
|
|
33
|
-
});
|
|
26
|
+
(0, prototype_utils_1.patchPrototypes)(prototype_utils_1.WHERE_QUERY_BUILDERS, extension);
|
|
34
27
|
// implementation
|
|
35
28
|
function attachWhereArrayTyped(builder, method, where, values, arrayType) {
|
|
36
|
-
if (typeof where
|
|
37
|
-
return builder;
|
|
38
|
-
}
|
|
39
|
-
const key = (0, query_builder_utils_1.getTypedSingleColumnKey)(builder, where, `${method}Typed`);
|
|
40
|
-
if ((0, query_builder_utils_1.isTypedJsonPath)(builder, where)) {
|
|
29
|
+
if (typeof where === 'function' && (0, query_builder_utils_1.isTypedJsonPath)(builder, where)) {
|
|
41
30
|
return attachWhereJsonArray(builder, method, where, values, arrayType);
|
|
42
31
|
}
|
|
43
|
-
|
|
44
|
-
return builder[method](key, values, arrayType);
|
|
32
|
+
return (0, typed_where_utils_1.attachTypedColumnWhere)(builder, method, where, undefined, values, arrayType);
|
|
45
33
|
}
|
|
46
34
|
const JSON_ARRAY_METHOD = /^(where|andWhere|orWhere)Array(Contains|ContainedBy|Overlaps)$/;
|
|
47
35
|
const JSON_ARRAY_OPERATORS = { Contains: '@>', ContainedBy: '<@', Overlaps: '?|' };
|