typeorm-extensions 2.2.0-rc.8 → 2.2.0-rc.9
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +0 -8
- 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.js +3 -11
- package/dist/extensions/get-many-with-totals.extension.js +4 -20
- package/dist/extensions/join-lateral.extension.js +4 -6
- package/dist/extensions/period-filter.extension.js +1 -11
- package/dist/extensions/typed/index.d.ts +1 -0
- package/dist/extensions/typed/index.js +1 -0
- package/dist/extensions/typed/typed-calculated/typed-calculated-column.extension.d.ts +25 -0
- package/dist/extensions/typed/typed-calculated/typed-calculated-column.extension.js +24 -0
- package/dist/extensions/typed/typed-having/typed-having.extension.js +1 -1
- package/dist/extensions/typed/typed-joins/typed-join-and-map.extension.js +11 -10
- package/dist/extensions/typed/typed-joins/typed-joins.extension.js +11 -22
- package/dist/extensions/typed/typed-order-by/typed-order-by.extension.js +11 -17
- package/dist/extensions/typed/typed-returning/typed-returning.extension.js +1 -9
- package/dist/extensions/typed/typed-select/typed-select.extension.js +2 -8
- package/dist/extensions/typed/typed-where/typed-period-filter.extension.js +1 -11
- package/dist/extensions/typed/typed-where/typed-where-array.extension.js +4 -18
- package/dist/extensions/typed/typed-where/typed-where-ilike.extension.js +1 -11
- package/dist/extensions/typed/typed-where/typed-where-is-any.extension.js +3 -22
- package/dist/extensions/typed/typed-where/typed-where-is-distinct-from.extension.js +3 -22
- package/dist/extensions/typed/typed-where/typed-where-is-in.extension.js +3 -23
- package/dist/extensions/typed/typed-where/typed-where-json.extension.js +4 -23
- package/dist/extensions/typed/typed-where/typed-where-lower.extension.js +1 -11
- package/dist/extensions/typed/typed-where/typed-where-similar.extension.js +1 -10
- package/dist/extensions/typed/typed-where/typed-where.extension.js +2 -12
- package/dist/extensions/union.extension.js +1 -1
- package/dist/extensions/where-array.extension.js +1 -11
- package/dist/extensions/where-exists.extension.js +4 -15
- package/dist/extensions/where-is-any.extension.d.ts +38 -160
- package/dist/extensions/where-is-any.extension.js +1 -11
- package/dist/extensions/where-is-distinct-from.extension.js +1 -11
- package/dist/extensions/where-is-in.extension.d.ts +35 -145
- package/dist/extensions/where-is-in.extension.js +11 -29
- package/dist/extensions/where-json.extension.js +1 -11
- package/dist/extensions/where-relation-exists.extension.js +5 -25
- package/dist/index.d.ts +1 -6
- package/dist/index.js +1 -12
- package/dist/utils/calculated-column.utils.d.ts +8 -0
- package/dist/utils/calculated-column.utils.js +20 -3
- 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 +5 -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 +22 -2
- package/dist/utils/query-builder.utils.js +67 -44
- package/dist/utils/table.utils.js +9 -11
- 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 +12 -14
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -93,14 +93,6 @@ TypeORM 0.3.12 and later, and 1.x. CI runs the test suite on SQLite with TypeORM
|
|
|
93
93
|
|
|
94
94
|
The [documentation](https://koenigstag.github.io/typeorm-extensions/) has a page for every method, with its signature, options and examples, and the [playground](https://koenigstag.github.io/typeorm-extensions/playground/) runs them.
|
|
95
95
|
|
|
96
|
-
## ToDo list
|
|
97
|
-
|
|
98
|
-
- [x] Add tests for pagination and order extensions
|
|
99
|
-
- [x] Calculated columns: the `@CalculatedColumn` decorator and `addSelectCalculated`. `getMany`, `getOne` and `getManyWithTotals` fill them as they are, so they need no variants of their own
|
|
100
|
-
- [x] Order by a calculated column: `orderByCalculated`, and `applyOrder` orders a `@CalculatedColumn` field by its value
|
|
101
|
-
- [x] Generated columns: the `@GeneratedColumn` decorator, a `@Column` that TypeORM reads and never writes
|
|
102
|
-
- [x] `tableHelper(Entity, alias)` writes the database names of renamed columns
|
|
103
|
-
|
|
104
96
|
## License
|
|
105
97
|
|
|
106
98
|
[MIT](./LICENSE)
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { ObjectLiteral
|
|
2
|
-
|
|
3
|
-
export type CalculatedSelection
|
|
1
|
+
import { ObjectLiteral } from 'typeorm';
|
|
2
|
+
import { CalculatedSelection } from '../utils/calculated-column.utils';
|
|
3
|
+
export type { CalculatedSelection };
|
|
4
4
|
declare module 'typeorm/query-builder/SelectQueryBuilder' {
|
|
5
5
|
interface SelectQueryBuilder<Entity extends ObjectLiteral> {
|
|
6
6
|
/**
|
|
@@ -7,27 +7,14 @@ const calculated_column_utils_1 = require("../utils/calculated-column.utils");
|
|
|
7
7
|
const extension = {
|
|
8
8
|
prototype: {
|
|
9
9
|
addSelectCalculated(selection, property, alias) {
|
|
10
|
-
return
|
|
10
|
+
return (0, calculated_column_utils_1.addSelectCalculatedColumn)(this, selection, property, alias, 'addSelectCalculated');
|
|
11
11
|
},
|
|
12
12
|
orderByCalculated(property, order, nulls, alias) {
|
|
13
|
-
return
|
|
13
|
+
return (0, calculated_column_utils_1.orderByCalculatedColumn)(this, 'orderBy', property, order, nulls, alias, 'orderByCalculated');
|
|
14
14
|
},
|
|
15
15
|
addOrderByCalculated(property, order, nulls, alias) {
|
|
16
|
-
return
|
|
16
|
+
return (0, calculated_column_utils_1.orderByCalculatedColumn)(this, 'addOrderBy', property, order, nulls, alias, 'addOrderByCalculated');
|
|
17
17
|
},
|
|
18
18
|
},
|
|
19
19
|
};
|
|
20
20
|
(0, prototype_utils_1.patchPrototype)(typeorm_1.SelectQueryBuilder, extension);
|
|
21
|
-
// implementation
|
|
22
|
-
function addSelectCalculated(builder, selection, property, aliasName) {
|
|
23
|
-
const { key } = (0, calculated_column_utils_1.resolveCalculatedColumn)(builder, property, aliasName, 'addSelectCalculated');
|
|
24
|
-
// two calls: addSelect's overloads take a string or a factory, not their union
|
|
25
|
-
if (typeof selection === 'function') {
|
|
26
|
-
return builder.addSelect(selection, key);
|
|
27
|
-
}
|
|
28
|
-
return builder.addSelect(selection, key);
|
|
29
|
-
}
|
|
30
|
-
function attachOrderByCalculated(builder, method, property, order, nulls, aliasName) {
|
|
31
|
-
const orderAlias = (0, calculated_column_utils_1.selectCalculatedForOrder)(builder, property, aliasName, `${method}Calculated`);
|
|
32
|
-
return builder[method](orderAlias, order, nulls);
|
|
33
|
-
}
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.InvalidCursorError = void 0;
|
|
4
4
|
const SelectQueryBuilder_1 = require("typeorm/query-builder/SelectQueryBuilder");
|
|
5
|
-
const
|
|
5
|
+
const pagination_utils_1 = require("../utils/pagination.utils");
|
|
6
6
|
const prototype_utils_1 = require("../utils/prototype.utils");
|
|
7
7
|
const order_utils_1 = require("../utils/order.utils");
|
|
8
8
|
const where_utils_1 = require("../utils/where.utils");
|
|
@@ -45,14 +45,11 @@ function getCursorKeys(builder, orderBy) {
|
|
|
45
45
|
}
|
|
46
46
|
return keys;
|
|
47
47
|
}
|
|
48
|
-
const getPageSize = (pageSize) => typeof pageSize === 'number' && Number.isFinite(pageSize) && pageSize >= 1
|
|
49
|
-
? Math.floor(pageSize)
|
|
50
|
-
: constants_1.defaultPageSize;
|
|
51
48
|
async function getManyWithCursor(builder, cursorFilter, options) {
|
|
52
49
|
const { orderBy, useTakeAndSkip = false } = options !== null && options !== void 0 ? options : {};
|
|
53
50
|
const keys = getCursorKeys(builder, orderBy);
|
|
54
51
|
const fields = keys.map((key) => key.column.propertyPath);
|
|
55
|
-
const pageSize =
|
|
52
|
+
const pageSize = (0, pagination_utils_1.normalizePageSize)(cursorFilter === null || cursorFilter === void 0 ? void 0 : cursorFilter.pageSize);
|
|
56
53
|
const query = builder.clone();
|
|
57
54
|
const alias = query.alias;
|
|
58
55
|
const driver = query.connection.driver.options.type;
|
|
@@ -83,12 +80,7 @@ async function getManyWithCursor(builder, cursorFilter, options) {
|
|
|
83
80
|
.map((key, i) => ({ key, i }))
|
|
84
81
|
.filter(({ key }) => key.column.isPrimary)
|
|
85
82
|
.map(({ key, i }) => ({ column: key.column, keyAlias: keyAliases[i] }));
|
|
86
|
-
|
|
87
|
-
query.take(pageSize + 1);
|
|
88
|
-
}
|
|
89
|
-
else {
|
|
90
|
-
query.limit(pageSize + 1);
|
|
91
|
-
}
|
|
83
|
+
(0, pagination_utils_1.setPageLimit)(query, pageSize + 1, useTakeAndSkip);
|
|
92
84
|
const { entities, raw } = await query.getRawAndEntities();
|
|
93
85
|
const list = entities.slice(0, pageSize);
|
|
94
86
|
if (entities.length <= pageSize) {
|
|
@@ -31,8 +31,7 @@ const extension = {
|
|
|
31
31
|
* runner, so the one that starts second finds a transaction active and does not open its own.
|
|
32
32
|
*/
|
|
33
33
|
function canCountConcurrently(builder) {
|
|
34
|
-
|
|
35
|
-
return !queryBuilder.queryRunner;
|
|
34
|
+
return !(0, query_builder_utils_1.getQueryRunner)(builder);
|
|
36
35
|
}
|
|
37
36
|
function getManyWithTotals(builder, paginationFilter, options) {
|
|
38
37
|
return readWithTotals(builder, paginationFilter, options, {
|
|
@@ -70,15 +69,9 @@ async function readWithTotals(builder, paginationFilter, options, read) {
|
|
|
70
69
|
}
|
|
71
70
|
const paged = builder.applyPaginationFilter(paginationFilter, paginationOptions);
|
|
72
71
|
if (probeForMore) {
|
|
73
|
-
const probeLimit = limit + 1;
|
|
74
72
|
const { useTakeAndSkip = constants_1.defaultUseTakeAndSkip } = paginationOptions;
|
|
75
73
|
// replaces the limit applyPaginationFilter just set, keeping its offset
|
|
76
|
-
|
|
77
|
-
paged.take(probeLimit);
|
|
78
|
-
}
|
|
79
|
-
else {
|
|
80
|
-
paged.limit(probeLimit);
|
|
81
|
-
}
|
|
74
|
+
(0, pagination_utils_1.setPageLimit)(paged, limit + 1, useTakeAndSkip);
|
|
82
75
|
}
|
|
83
76
|
return read.rows(paged);
|
|
84
77
|
};
|
|
@@ -140,9 +133,6 @@ async function bothOrFirstError(first, second) {
|
|
|
140
133
|
function settle(promise) {
|
|
141
134
|
return promise.then((value) => ({ fulfilled: true, value }), (reason) => ({ fulfilled: false, reason }));
|
|
142
135
|
}
|
|
143
|
-
function getQueryRunner(builder) {
|
|
144
|
-
return builder.queryRunner;
|
|
145
|
-
}
|
|
146
136
|
/**
|
|
147
137
|
* Counts the rows of a raw query without its pagination and ORDER BY. The query goes into a
|
|
148
138
|
* subquery, so the count is that of its result rows whatever it groups or filters. A
|
|
@@ -151,13 +141,7 @@ function getQueryRunner(builder) {
|
|
|
151
141
|
*/
|
|
152
142
|
async function countRawRows(builder, countExpression) {
|
|
153
143
|
var _a;
|
|
154
|
-
const unpaged = cloneForCount(builder)
|
|
155
|
-
.orderBy()
|
|
156
|
-
.offset(undefined)
|
|
157
|
-
.limit(undefined)
|
|
158
|
-
.skip(undefined)
|
|
159
|
-
.take(undefined)
|
|
160
|
-
.setOption('disable-global-order');
|
|
144
|
+
const unpaged = (0, query_builder_utils_1.withoutPaging)(cloneForCount(builder));
|
|
161
145
|
let counting;
|
|
162
146
|
if (countExpression) {
|
|
163
147
|
// the expression counts on its own: DISTINCT ON next to an aggregate is an error
|
|
@@ -168,7 +152,7 @@ async function countRawRows(builder, countExpression) {
|
|
|
168
152
|
else {
|
|
169
153
|
// on the builder's query runner, if it has one: inside its transaction
|
|
170
154
|
const counter = builder.connection
|
|
171
|
-
.createQueryBuilder(getQueryRunner(builder))
|
|
155
|
+
.createQueryBuilder((0, query_builder_utils_1.getQueryRunner)(builder))
|
|
172
156
|
.select('COUNT(*)', 'count')
|
|
173
157
|
.from(`(${unpaged.getQuery()})`, 'counted')
|
|
174
158
|
.setParameters(unpaged.getParameters());
|
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
const typeorm_1 = require("typeorm");
|
|
4
4
|
const parameter_utils_1 = require("../utils/parameter.utils");
|
|
5
|
+
const query_builder_utils_1 = require("../utils/query-builder.utils");
|
|
5
6
|
const prototype_utils_1 = require("../utils/prototype.utils");
|
|
6
7
|
/* eslint-enable @typescript-eslint/no-empty-interface, @typescript-eslint/no-unused-vars */
|
|
7
8
|
// patching
|
|
@@ -32,18 +33,15 @@ function toLateralSql(builder, subQuery) {
|
|
|
32
33
|
return { sql: `(${subQuery})`, parameters: {} };
|
|
33
34
|
}
|
|
34
35
|
const subBuilder = typeof subQuery === 'function' ? subQuery(detachedSubQuery(builder)) : subQuery;
|
|
35
|
-
const
|
|
36
|
-
|
|
37
|
-
const wrapped = subBuilder.expressionMap.subQuery ? query : `(${query})`;
|
|
38
|
-
const [sql, parameters] = (0, parameter_utils_1.withUniqueParameterNames)(wrapped, subBuilder.getParameters());
|
|
39
|
-
return { sql, parameters };
|
|
36
|
+
const [sql, parameters] = (0, parameter_utils_1.toSubQuerySql)(subBuilder);
|
|
37
|
+
return { sql: `(${sql})`, parameters };
|
|
40
38
|
}
|
|
41
39
|
/**
|
|
42
40
|
* A subquery builder for a factory, as TypeORM's `subQuery()` but without a parent: TypeORM's would
|
|
43
41
|
* set the factory's parameters on the outer query under their own names, before they can be renamed.
|
|
44
42
|
*/
|
|
45
43
|
function detachedSubQuery(builder) {
|
|
46
|
-
const queryRunner = builder
|
|
44
|
+
const queryRunner = (0, query_builder_utils_1.getQueryRunner)(builder);
|
|
47
45
|
const subQuery = builder.connection.createQueryBuilder(queryRunner);
|
|
48
46
|
subQuery.expressionMap.subQuery = true;
|
|
49
47
|
return subQuery;
|
|
@@ -1,7 +1,5 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
const typeorm_1 = require("typeorm");
|
|
4
|
-
const SoftDeleteQueryBuilder_1 = require("typeorm/query-builder/SoftDeleteQueryBuilder");
|
|
5
3
|
const prototype_utils_1 = require("../utils/prototype.utils");
|
|
6
4
|
const query_builder_utils_1 = require("../utils/query-builder.utils");
|
|
7
5
|
const period_utils_1 = require("../utils/period.utils");
|
|
@@ -14,12 +12,4 @@ const extension = {
|
|
|
14
12
|
},
|
|
15
13
|
},
|
|
16
14
|
};
|
|
17
|
-
|
|
18
|
-
typeorm_1.SelectQueryBuilder,
|
|
19
|
-
typeorm_1.UpdateQueryBuilder,
|
|
20
|
-
typeorm_1.DeleteQueryBuilder,
|
|
21
|
-
SoftDeleteQueryBuilder_1.SoftDeleteQueryBuilder,
|
|
22
|
-
];
|
|
23
|
-
queryBuilders.forEach((builder) => {
|
|
24
|
-
(0, prototype_utils_1.patchPrototype)(builder, extension);
|
|
25
|
-
});
|
|
15
|
+
(0, prototype_utils_1.patchPrototypes)(prototype_utils_1.WHERE_QUERY_BUILDERS, extension);
|
|
@@ -17,4 +17,5 @@ export * from './typed-where/typed-where-lower.extension';
|
|
|
17
17
|
export * from './typed-where/typed-where-similar.extension';
|
|
18
18
|
export * from './typed-returning/typed-returning.extension';
|
|
19
19
|
export * from './typed-order-by/typed-order-by-array-position.extension';
|
|
20
|
+
export * from './typed-calculated/typed-calculated-column.extension';
|
|
20
21
|
export * from './typed-root.extension';
|
|
@@ -34,4 +34,5 @@ __exportStar(require("./typed-where/typed-where-lower.extension"), exports);
|
|
|
34
34
|
__exportStar(require("./typed-where/typed-where-similar.extension"), exports);
|
|
35
35
|
__exportStar(require("./typed-returning/typed-returning.extension"), exports);
|
|
36
36
|
__exportStar(require("./typed-order-by/typed-order-by-array-position.extension"), exports);
|
|
37
|
+
__exportStar(require("./typed-calculated/typed-calculated-column.extension"), exports);
|
|
37
38
|
__exportStar(require("./typed-root.extension"), exports);
|
|
@@ -0,0 +1,25 @@
|
|
|
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
|
+
*/
|
|
12
|
+
addSelectCalculatedTyped<Type extends ObjectLiteral = TypedRoot<Entity, this>, SubEntity extends ObjectLiteral = ObjectLiteral>(selection: CalculatedSelection<SubEntity>, property: CalculatedPropertyCallback<Type>): this;
|
|
13
|
+
/**
|
|
14
|
+
* `orderByCalculated` with the `@CalculatedColumn` picked by a typed callback: ORDER BY its value, selected with
|
|
15
|
+
* `addSelectCalculated` / `addSelectCalculatedTyped` first. Replaces the previous ORDER BY, like `orderBy`.
|
|
16
|
+
*/
|
|
17
|
+
orderByCalculatedTyped<Type extends ObjectLiteral = TypedRoot<Entity, this>>(property: CalculatedPropertyCallback<Type>, order?: 'ASC' | 'DESC', nulls?: 'NULLS FIRST' | 'NULLS LAST'): this;
|
|
18
|
+
/** `addOrderByCalculated` with the `@CalculatedColumn` picked by a typed callback, like `addOrderBy`. */
|
|
19
|
+
addOrderByCalculatedTyped<Type extends ObjectLiteral = TypedRoot<Entity, this>>(property: CalculatedPropertyCallback<Type>, order?: 'ASC' | 'DESC', nulls?: 'NULLS FIRST' | 'NULLS LAST'): this;
|
|
20
|
+
}
|
|
21
|
+
declare module 'typeorm/query-builder/SelectQueryBuilder' {
|
|
22
|
+
interface SelectQueryBuilder<Entity extends ObjectLiteral> extends TypedCalculatedColumnMethods<Entity> {
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
export {};
|
|
@@ -0,0 +1,24 @@
|
|
|
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 createOrderByCalculatedTypedMethod = (method) => function (property, order, nulls) {
|
|
10
|
+
const methodName = `${method}CalculatedTyped`;
|
|
11
|
+
const { aliasName, propertyPath } = (0, query_builder_utils_1.resolveTypedProperty)(this, property, methodName);
|
|
12
|
+
return (0, calculated_column_utils_1.orderByCalculatedColumn)(this, method, propertyPath, order, nulls, aliasName, methodName);
|
|
13
|
+
};
|
|
14
|
+
const extension = {
|
|
15
|
+
prototype: {
|
|
16
|
+
addSelectCalculatedTyped(selection, property) {
|
|
17
|
+
const { aliasName, propertyPath } = (0, query_builder_utils_1.resolveTypedProperty)(this, property, 'addSelectCalculatedTyped');
|
|
18
|
+
return (0, calculated_column_utils_1.addSelectCalculatedColumn)(this, selection, propertyPath, aliasName, 'addSelectCalculatedTyped');
|
|
19
|
+
},
|
|
20
|
+
orderByCalculatedTyped: createOrderByCalculatedTypedMethod('orderBy'),
|
|
21
|
+
addOrderByCalculatedTyped: createOrderByCalculatedTypedMethod('addOrderBy'),
|
|
22
|
+
},
|
|
23
|
+
};
|
|
24
|
+
(0, prototype_utils_1.patchPrototype)(SelectQueryBuilder_1.SelectQueryBuilder, extension);
|
|
@@ -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
|
}
|
|
@@ -2,19 +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
|
-
return addJoinAndMap(this,
|
|
7
|
+
const createJoinAndMapTypedMethod = (method) => function (mapToProperty, entity, alias, condition, parameters) {
|
|
8
|
+
return addJoinAndMap(this, method, mapToProperty, entity, alias, condition, parameters);
|
|
8
9
|
};
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
return addJoinAndMap(this, 'innerJoinAndMapMany', mapToProperty, entity, alias, condition, parameters);
|
|
10
|
+
const extension = {
|
|
11
|
+
prototype: {
|
|
12
|
+
leftJoinAndMapOneTyped: createJoinAndMapTypedMethod('leftJoinAndMapOne'),
|
|
13
|
+
innerJoinAndMapOneTyped: createJoinAndMapTypedMethod('innerJoinAndMapOne'),
|
|
14
|
+
leftJoinAndMapManyTyped: createJoinAndMapTypedMethod('leftJoinAndMapMany'),
|
|
15
|
+
innerJoinAndMapManyTyped: createJoinAndMapTypedMethod('innerJoinAndMapMany'),
|
|
16
|
+
},
|
|
17
17
|
};
|
|
18
|
+
(0, prototype_utils_1.patchPrototype)(typeorm_1.SelectQueryBuilder, extension);
|
|
18
19
|
function addJoinAndMap(query, method, mapToProperty, entity, alias, condition, parameters) {
|
|
19
20
|
// `() => query.alias`: `(q) => q.photo.owner` needs no main alias, only `(u) => u.profile` does
|
|
20
21
|
const key = (0, proxy_key_utils_1.getSqlKeyFromProxyCallback)(mapToProperty, () => query.alias, false);
|
|
@@ -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);
|
|
@@ -3,25 +3,19 @@ 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 prototype_utils_1 = require("../../../utils/prototype.utils");
|
|
7
7
|
// patching and implementation
|
|
8
|
-
|
|
9
|
-
if (selection instanceof proxy_key_utils_1.KeyHolder) {
|
|
10
|
-
|
|
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, 'orderByTyped');
|
|
14
|
-
return this.orderBy(key, order, nulls);
|
|
8
|
+
const createOrderByTypedMethod = (method) => function (selection, order, nulls, options) {
|
|
9
|
+
if (selection instanceof proxy_key_utils_1.KeyHolder || typeof selection === 'function') {
|
|
10
|
+
const key = (0, query_builder_utils_1.getTypedSelectionKey)(this, selection, options === null || options === void 0 ? void 0 : options.useQuotes, `${method}Typed`);
|
|
11
|
+
return this[method](key, order, nulls);
|
|
15
12
|
}
|
|
16
13
|
return this;
|
|
17
14
|
};
|
|
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, 'addOrderByTyped');
|
|
24
|
-
return this.addOrderBy(key, order, nulls);
|
|
25
|
-
}
|
|
26
|
-
return this;
|
|
15
|
+
const extension = {
|
|
16
|
+
prototype: {
|
|
17
|
+
orderByTyped: createOrderByTypedMethod('orderBy'),
|
|
18
|
+
addOrderByTyped: createOrderByTypedMethod('addOrderBy'),
|
|
19
|
+
},
|
|
27
20
|
};
|
|
21
|
+
(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);
|
|
@@ -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,16 +22,11 @@ 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, `${method}Typed`));
|
|
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') {
|
|
29
|
+
else if (selection instanceof proxy_key_utils_1.KeyHolder || typeof selection === 'function') {
|
|
36
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);
|
|
@@ -1,8 +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
|
-
const SoftDeleteQueryBuilder_1 = require("typeorm/query-builder/SoftDeleteQueryBuilder");
|
|
6
4
|
const query_builder_utils_1 = require("../../../utils/query-builder.utils");
|
|
7
5
|
const prototype_utils_1 = require("../../../utils/prototype.utils");
|
|
8
6
|
const period_utils_1 = require("../../../utils/period.utils");
|
|
@@ -16,12 +14,4 @@ const extension = {
|
|
|
16
14
|
},
|
|
17
15
|
},
|
|
18
16
|
};
|
|
19
|
-
|
|
20
|
-
typeorm_1.SelectQueryBuilder,
|
|
21
|
-
typeorm_1.UpdateQueryBuilder,
|
|
22
|
-
typeorm_1.DeleteQueryBuilder,
|
|
23
|
-
SoftDeleteQueryBuilder_1.SoftDeleteQueryBuilder,
|
|
24
|
-
];
|
|
25
|
-
queryBuilders.forEach((builder) => {
|
|
26
|
-
(0, prototype_utils_1.patchPrototype)(builder, extension);
|
|
27
|
-
});
|
|
17
|
+
(0, prototype_utils_1.patchPrototypes)(prototype_utils_1.WHERE_QUERY_BUILDERS, extension);
|
|
@@ -1,11 +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
|
-
const SoftDeleteQueryBuilder_1 = require("typeorm/query-builder/SoftDeleteQueryBuilder");
|
|
6
4
|
const query_builder_utils_1 = require("../../../utils/query-builder.utils");
|
|
7
5
|
const sql_utils_1 = require("../../../utils/sql.utils");
|
|
8
6
|
const prototype_utils_1 = require("../../../utils/prototype.utils");
|
|
7
|
+
const typed_where_utils_1 = require("../../../utils/typed-where.utils");
|
|
9
8
|
/* eslint-enable @typescript-eslint/no-empty-interface */
|
|
10
9
|
// patching
|
|
11
10
|
const createWhereArrayTypedMethod = (method) => function (where, values, arrayType) {
|
|
@@ -24,26 +23,13 @@ const extension = {
|
|
|
24
23
|
orWhereArrayOverlapsTyped: createWhereArrayTypedMethod('orWhereArrayOverlaps'),
|
|
25
24
|
},
|
|
26
25
|
};
|
|
27
|
-
|
|
28
|
-
typeorm_1.SelectQueryBuilder,
|
|
29
|
-
typeorm_1.UpdateQueryBuilder,
|
|
30
|
-
typeorm_1.DeleteQueryBuilder,
|
|
31
|
-
SoftDeleteQueryBuilder_1.SoftDeleteQueryBuilder,
|
|
32
|
-
];
|
|
33
|
-
queryBuilders.forEach((builder) => {
|
|
34
|
-
(0, prototype_utils_1.patchPrototype)(builder, extension);
|
|
35
|
-
});
|
|
26
|
+
(0, prototype_utils_1.patchPrototypes)(prototype_utils_1.WHERE_QUERY_BUILDERS, extension);
|
|
36
27
|
// implementation
|
|
37
28
|
function attachWhereArrayTyped(builder, method, where, values, arrayType) {
|
|
38
|
-
if (typeof where
|
|
39
|
-
return builder;
|
|
40
|
-
}
|
|
41
|
-
const key = (0, query_builder_utils_1.getTypedSingleColumnKey)(builder, where, `${method}Typed`);
|
|
42
|
-
if ((0, query_builder_utils_1.isTypedJsonPath)(builder, where)) {
|
|
29
|
+
if (typeof where === 'function' && (0, query_builder_utils_1.isTypedJsonPath)(builder, where)) {
|
|
43
30
|
return attachWhereJsonArray(builder, method, where, values, arrayType);
|
|
44
31
|
}
|
|
45
|
-
|
|
46
|
-
return builder[method](key, values, arrayType);
|
|
32
|
+
return (0, typed_where_utils_1.attachTypedColumnWhere)(builder, method, where, undefined, values, arrayType);
|
|
47
33
|
}
|
|
48
34
|
const JSON_ARRAY_METHOD = /^(where|andWhere|orWhere)Array(Contains|ContainedBy|Overlaps)$/;
|
|
49
35
|
const JSON_ARRAY_OPERATORS = { Contains: '@>', ContainedBy: '<@', Overlaps: '?|' };
|
|
@@ -1,7 +1,5 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
const typeorm_1 = require("typeorm");
|
|
4
|
-
const SoftDeleteQueryBuilder_1 = require("typeorm/query-builder/SoftDeleteQueryBuilder");
|
|
5
3
|
const query_builder_utils_1 = require("../../../utils/query-builder.utils");
|
|
6
4
|
const prototype_utils_1 = require("../../../utils/prototype.utils");
|
|
7
5
|
const sql_utils_1 = require("../../../utils/sql.utils");
|
|
@@ -43,15 +41,7 @@ const extension = {
|
|
|
43
41
|
orWhereSearchTyped: createWhereSearchTypedMethod('orWhere'),
|
|
44
42
|
},
|
|
45
43
|
};
|
|
46
|
-
|
|
47
|
-
typeorm_1.SelectQueryBuilder,
|
|
48
|
-
typeorm_1.UpdateQueryBuilder,
|
|
49
|
-
typeorm_1.DeleteQueryBuilder,
|
|
50
|
-
SoftDeleteQueryBuilder_1.SoftDeleteQueryBuilder,
|
|
51
|
-
];
|
|
52
|
-
queryBuilders.forEach((builder) => {
|
|
53
|
-
(0, prototype_utils_1.patchPrototype)(builder, extension);
|
|
54
|
-
});
|
|
44
|
+
(0, prototype_utils_1.patchPrototypes)(prototype_utils_1.WHERE_QUERY_BUILDERS, extension);
|
|
55
45
|
// implementation
|
|
56
46
|
/** Quoted columns and raw expressions of the search selectors, in order. */
|
|
57
47
|
function getSearchColumns(builder, selectors, methodName) {
|
|
@@ -1,14 +1,12 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
require("../../where-is-any.extension");
|
|
4
|
-
const typeorm_1 = require("typeorm");
|
|
5
|
-
const SoftDeleteQueryBuilder_1 = require("typeorm/query-builder/SoftDeleteQueryBuilder");
|
|
6
|
-
const query_builder_utils_1 = require("../../../utils/query-builder.utils");
|
|
7
4
|
const prototype_utils_1 = require("../../../utils/prototype.utils");
|
|
5
|
+
const typed_where_utils_1 = require("../../../utils/typed-where.utils");
|
|
8
6
|
/* eslint-enable @typescript-eslint/no-empty-interface */
|
|
9
7
|
// patching
|
|
10
8
|
const createWhereIsAnyTypedMethod = (method) => function (where, array, arrayType) {
|
|
11
|
-
return
|
|
9
|
+
return (0, typed_where_utils_1.attachTypedColumnWhere)(this, method, where, { value: array }, array, arrayType);
|
|
12
10
|
};
|
|
13
11
|
const extension = {
|
|
14
12
|
prototype: {
|
|
@@ -20,21 +18,4 @@ const extension = {
|
|
|
20
18
|
orWhereIsNotAnyTyped: createWhereIsAnyTypedMethod('orWhereIsNotAny'),
|
|
21
19
|
},
|
|
22
20
|
};
|
|
23
|
-
|
|
24
|
-
typeorm_1.SelectQueryBuilder,
|
|
25
|
-
typeorm_1.UpdateQueryBuilder,
|
|
26
|
-
typeorm_1.DeleteQueryBuilder,
|
|
27
|
-
SoftDeleteQueryBuilder_1.SoftDeleteQueryBuilder,
|
|
28
|
-
];
|
|
29
|
-
queryBuilders.forEach((builder) => {
|
|
30
|
-
(0, prototype_utils_1.patchPrototype)(builder, extension);
|
|
31
|
-
});
|
|
32
|
-
// implementation
|
|
33
|
-
function attachWhereIsAnyTyped(builder, method, where, array, arrayType) {
|
|
34
|
-
if (typeof where !== 'function') {
|
|
35
|
-
return builder;
|
|
36
|
-
}
|
|
37
|
-
const key = (0, query_builder_utils_1.getTypedSingleColumnKey)(builder, where, `${method}Typed`, { value: array });
|
|
38
|
-
// .andWhere(`"table"."column" = ANY(:param)`, { param: ['value'] })
|
|
39
|
-
return builder[method](key, array, arrayType);
|
|
40
|
-
}
|
|
21
|
+
(0, prototype_utils_1.patchPrototypes)(prototype_utils_1.WHERE_QUERY_BUILDERS, extension);
|
|
@@ -1,14 +1,12 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
require("../../where-is-distinct-from.extension");
|
|
4
|
-
const typeorm_1 = require("typeorm");
|
|
5
|
-
const SoftDeleteQueryBuilder_1 = require("typeorm/query-builder/SoftDeleteQueryBuilder");
|
|
6
|
-
const query_builder_utils_1 = require("../../../utils/query-builder.utils");
|
|
7
4
|
const prototype_utils_1 = require("../../../utils/prototype.utils");
|
|
5
|
+
const typed_where_utils_1 = require("../../../utils/typed-where.utils");
|
|
8
6
|
/* eslint-enable @typescript-eslint/no-empty-interface */
|
|
9
7
|
// patching
|
|
10
8
|
const createWhereDistinctTypedMethod = (method) => function (where, value) {
|
|
11
|
-
return
|
|
9
|
+
return (0, typed_where_utils_1.attachTypedColumnWhere)(this, method, where, { value }, value);
|
|
12
10
|
};
|
|
13
11
|
const extension = {
|
|
14
12
|
prototype: {
|
|
@@ -20,21 +18,4 @@ const extension = {
|
|
|
20
18
|
orWhereIsNotDistinctFromTyped: createWhereDistinctTypedMethod('orWhereIsNotDistinctFrom'),
|
|
21
19
|
},
|
|
22
20
|
};
|
|
23
|
-
|
|
24
|
-
typeorm_1.SelectQueryBuilder,
|
|
25
|
-
typeorm_1.UpdateQueryBuilder,
|
|
26
|
-
typeorm_1.DeleteQueryBuilder,
|
|
27
|
-
SoftDeleteQueryBuilder_1.SoftDeleteQueryBuilder,
|
|
28
|
-
];
|
|
29
|
-
queryBuilders.forEach((builder) => {
|
|
30
|
-
(0, prototype_utils_1.patchPrototype)(builder, extension);
|
|
31
|
-
});
|
|
32
|
-
// implementation
|
|
33
|
-
function attachWhereDistinctTyped(builder, method, where, value) {
|
|
34
|
-
if (typeof where !== 'function') {
|
|
35
|
-
return builder;
|
|
36
|
-
}
|
|
37
|
-
const key = (0, query_builder_utils_1.getTypedSingleColumnKey)(builder, where, `${method}Typed`, { value });
|
|
38
|
-
// .andWhereIsDistinctFrom(`"table"."column"`, value)
|
|
39
|
-
return builder[method](key, value);
|
|
40
|
-
}
|
|
21
|
+
(0, prototype_utils_1.patchPrototypes)(prototype_utils_1.WHERE_QUERY_BUILDERS, extension);
|