typeorm-extensions 2.2.0-rc.6 → 2.2.0-rc.8
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 +73 -34
- 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/cursor-pagination.extension.d.ts +2 -1
- package/dist/extensions/cursor-pagination.extension.js +4 -2
- package/dist/extensions/get-many-with-totals.extension.js +5 -12
- 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 +2 -0
- package/dist/extensions/typed/index.d.ts +1 -0
- package/dist/extensions/typed/index.js +1 -0
- package/dist/extensions/typed/typed-distinct/typed-distinct.extension.d.ts +2 -2
- package/dist/extensions/typed/typed-group-by/typed-group-by.extension.d.ts +2 -2
- package/dist/extensions/typed/typed-having/typed-having.extension.d.ts +4 -4
- 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 +22 -0
- package/dist/extensions/typed/typed-joins/typed-joins.extension.d.ts +4 -4
- 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 +2 -2
- 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-where/typed-period-filter.extension.d.ts +5 -1
- package/dist/extensions/typed/typed-where/typed-period-filter.extension.js +2 -0
- 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 +2 -0
- 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 +2 -0
- 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 +2 -0
- 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 +2 -0
- 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 +2 -0
- 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 +2 -0
- 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 +2 -0
- 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 +2 -0
- package/dist/extensions/typed/typed-where/typed-where.extension.d.ts +7 -3
- package/dist/extensions/typed/typed-where/typed-where.extension.js +2 -0
- package/dist/extensions/where-array.extension.d.ts +4 -0
- package/dist/extensions/where-array.extension.js +2 -0
- package/dist/extensions/where-is-any.extension.d.ts +41 -6
- package/dist/extensions/where-is-any.extension.js +2 -0
- package/dist/extensions/where-is-distinct-from.extension.d.ts +4 -0
- package/dist/extensions/where-is-distinct-from.extension.js +2 -0
- package/dist/extensions/where-is-in.extension.d.ts +38 -6
- package/dist/extensions/where-is-in.extension.js +2 -0
- package/dist/extensions/where-json.extension.d.ts +4 -0
- package/dist/extensions/where-json.extension.js +2 -0
- package/dist/extensions/where-relation-exists.extension.d.ts +6 -6
- package/dist/helpers.d.ts +5 -0
- package/dist/helpers.js +12 -3
- package/dist/index.d.ts +4 -0
- package/dist/index.js +9 -1
- 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-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/pagination.utils.d.ts +2 -0
- package/dist/utils/pagination.utils.js +1 -1
- package/dist/utils/query-builder.utils.d.ts +11 -2
- package/dist/utils/query-builder.utils.js +22 -5
- 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 +49 -12
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -5,62 +5,101 @@
|
|
|
5
5
|
[](https://github.com/koenigstag/typeorm-extensions/issues)
|
|
6
6
|
[](https://github.com/koenigstag/typeorm-extensions/pulls)
|
|
7
7
|
|
|
8
|
-
|
|
8
|
+
**Type-safe extensions for the TypeORM QueryBuilder.** Write selects, joins, conditions and ordering as property callbacks the compiler checks against your entities, page through results with totals or cursors, and build the raw SQL you still need with helpers that quote it for the database.
|
|
9
9
|
|
|
10
|
-
|
|
10
|
+
```typescript
|
|
11
|
+
import 'typeorm-extensions';
|
|
11
12
|
|
|
12
|
-
|
|
13
|
+
const { list, total, hasMore } = await dataSource
|
|
14
|
+
.getRepository(UserEntity)
|
|
15
|
+
.createQueryBuilder('user')
|
|
16
|
+
.leftJoinTyped(user => user.images, 'images')
|
|
17
|
+
.whereTyped(user => user.createdAt, '>', since)
|
|
18
|
+
// a key inside a JSON column: "user"."metadata" ->> 'role' = :param
|
|
19
|
+
.andWhereTyped(user => user.metadata.role, '=', 'admin')
|
|
20
|
+
.orderByTyped(user => user.images.url, 'ASC', 'NULLS LAST')
|
|
21
|
+
.getManyWithTotals({ page: 1, pageSize: 20 });
|
|
22
|
+
```
|
|
13
23
|
|
|
14
|
-
|
|
15
|
-
- Type Safety: the library is written in TypeScript and provides type-safe QueryBuilder methods based on Entity metadata.
|
|
16
|
-
- Flexibility: the library is designed to be flexible and can be used with any TypeORM entity.
|
|
24
|
+
Try it in the [playground](https://koenigstag.github.io/typeorm-extensions/playground/): an editor and a database in the browser.
|
|
17
25
|
|
|
18
|
-
##
|
|
26
|
+
## Why
|
|
19
27
|
|
|
20
|
-
|
|
28
|
+
The QueryBuilder takes columns as strings. A renamed property, a typo or a half-quoted alias compiles and then fails at runtime:
|
|
21
29
|
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
30
|
+
```typescript
|
|
31
|
+
.where('user.createdAt > :since', { since }) // still compiles after createdAt is renamed
|
|
32
|
+
.andWhere('order."userId" = :userId', { userId }) // PostgreSQL: syntax error at or near "order"
|
|
25
33
|
```
|
|
26
34
|
|
|
27
|
-
|
|
35
|
+
With the extensions a column is a property of the entity type, so the compiler catches the rename, and the SQL is built and quoted for you:
|
|
28
36
|
|
|
29
37
|
```typescript
|
|
30
|
-
|
|
38
|
+
.whereTyped(user => user.createdAt, '>', since)
|
|
31
39
|
|
|
32
|
-
|
|
40
|
+
const orders = tableHelper(OrderEntity, 'order');
|
|
41
|
+
.andWhere(`${orders.userId} = :userId`, { userId }) // "order"."userId" = :userId
|
|
42
|
+
```
|
|
33
43
|
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
.leftJoinTyped(user => user.images, 'images')
|
|
39
|
-
// Select type-safe properties
|
|
40
|
-
.selectTyped(user => [
|
|
41
|
-
user.id,
|
|
42
|
-
user.name,
|
|
43
|
-
user.email,
|
|
44
|
-
user.images.url,
|
|
45
|
-
])
|
|
46
|
-
.whereTyped(user => user.name, 'ILIKE', 'John')
|
|
47
|
-
// Paths into JSON columns: "users"."metadata" ->> 'role' = :param
|
|
48
|
-
.andWhereTyped(user => user.metadata.role, '=', 'admin')
|
|
49
|
-
// Order by type-safe own and relation properties
|
|
50
|
-
.orderByTyped(user => user.images.url, 'ASC', 'NULLS LAST')
|
|
51
|
-
// Use pagination as simple as that
|
|
52
|
-
.applyPaginationFilter({ page: 1, pageSize: 10 }, { useTakeAndSkip: true });
|
|
44
|
+
## Installation
|
|
45
|
+
|
|
46
|
+
```bash
|
|
47
|
+
npm install typeorm-extensions
|
|
53
48
|
```
|
|
54
49
|
|
|
50
|
+
`typeorm` 0.3.12 or later, or 1.x, is a peer dependency. Release candidates of the next version are published under the `next` tag: `npm install typeorm-extensions@next`.
|
|
51
|
+
|
|
52
|
+
## Features
|
|
53
|
+
|
|
54
|
+
**Typed queries** ([docs](https://koenigstag.github.io/typeorm-extensions/docs/api/typed/))
|
|
55
|
+
- `selectTyped`, `whereTyped` (keys inside JSON columns too; `strictParams` checks the parameter against the column type), `orderByTyped`, `groupByTyped` / `havingTyped`, `distinctOnTyped`, `returningTyped`
|
|
56
|
+
- typed joins and map joins (`leftJoinTyped`, `innerJoinAndMapOneTyped`, …), `typed<Root>()` for the aliases a query joins, `whereRelationExists` built from the relation metadata
|
|
57
|
+
|
|
58
|
+
**Pagination** ([docs](https://koenigstag.github.io/typeorm-extensions/docs/api/pagination/))
|
|
59
|
+
- `getManyWithTotals` and `getRawManyWithTotals`: the rows of a page, the total, `page` / `pageSize`, `hasMore` and the order it was read in
|
|
60
|
+
- `getManyWithCursor`: keyset pagination with an opaque cursor
|
|
61
|
+
- `applyPaginationFilter` for a page of any query
|
|
62
|
+
|
|
63
|
+
**Filters and ordering** ([docs](https://koenigstag.github.io/typeorm-extensions/docs/api/where/))
|
|
64
|
+
- `whereIsIn` / `whereIsNotIn` that handle empty arrays, `whereIsAny`, null-safe `whereIsDistinctFrom`
|
|
65
|
+
- case-insensitive search with escaped wildcards, `applyPeriodFilter` in a time zone
|
|
66
|
+
- `applyOrder` from a client's order filter, `orderByArrayPosition`
|
|
67
|
+
|
|
68
|
+
**Subqueries and joins**
|
|
69
|
+
- `whereExists` / `whereNotExists`, with the subquery's parameters renamed so they never clash with the outer query's
|
|
70
|
+
- `leftJoinLateral` / `innerJoinLateral`, `innerJoinUnnest`, `fromUnion` and CTE unions
|
|
71
|
+
|
|
72
|
+
**SQL helpers** ([docs](https://koenigstag.github.io/typeorm-extensions/docs/api/utils/tableHelper/))
|
|
73
|
+
- `tableHelper`: quoted column references, conditions, counts, sums, JSON objects and paths, time zones. Given the entity class it writes the database name of a renamed column
|
|
74
|
+
- the reserved qualifier guard: catches SQL like `order."userId"` before PostgreSQL rejects it
|
|
75
|
+
|
|
76
|
+
**Columns** ([docs](https://koenigstag.github.io/typeorm-extensions/docs/api/columns/generatedColumn/))
|
|
77
|
+
- `@CalculatedColumn` with `addSelectCalculated` / `orderByCalculated`: a value each query computes
|
|
78
|
+
- `@GeneratedColumn`: a column the database generates, which TypeORM reads and never writes
|
|
79
|
+
|
|
80
|
+
## Entry points
|
|
81
|
+
|
|
82
|
+
| Import | Gives |
|
|
83
|
+
|---|---|
|
|
84
|
+
| `import 'typeorm-extensions'` | every QueryBuilder extension, and all exports |
|
|
85
|
+
| `import 'typeorm-extensions/dist/extensions/pagination.extension'` | one extension |
|
|
86
|
+
| `import { tableHelper, GeneratedColumn } from 'typeorm-extensions/helpers'` | the helpers, with no side effects |
|
|
87
|
+
|
|
88
|
+
## Compatibility
|
|
89
|
+
|
|
90
|
+
TypeORM 0.3.12 and later, and 1.x. CI runs the test suite on SQLite with TypeORM 0.3.12, the latest 0.3 and 1.x, and on MySQL 8.4. Features that only work on some databases (array and JSON operators, `DISTINCT ON`, `orderByArrayPosition`, …) say so in their docs.
|
|
91
|
+
|
|
55
92
|
## Documentation
|
|
56
93
|
|
|
57
|
-
|
|
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.
|
|
58
95
|
|
|
59
96
|
## ToDo list
|
|
60
97
|
|
|
61
98
|
- [x] Add tests for pagination and order extensions
|
|
62
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
|
|
63
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
|
|
64
103
|
|
|
65
104
|
## License
|
|
66
105
|
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { ColumnOptions, ColumnType } from 'typeorm';
|
|
2
|
+
/** The options of `@Column`, without those that would let TypeORM write the column. */
|
|
3
|
+
export type GeneratedColumnOptions = Omit<ColumnOptions, 'insert' | 'update' | 'readonly'>;
|
|
4
|
+
/**
|
|
5
|
+
* A column of the table that the database computes: `GENERATED ALWAYS AS (…) STORED`. TypeORM reads it like any
|
|
6
|
+
* column and never writes it. `asExpression` alone doesn't stop TypeORM (0.3 and 1.x) from sending the column in
|
|
7
|
+
* `save`, `insert` and `update`, which the database rejects for a generated column.
|
|
8
|
+
*
|
|
9
|
+
* Pass `asExpression` and `generatedType: 'STORED'` when TypeORM creates the schema (synchronize, generated
|
|
10
|
+
* migrations); a column created by a hand-written migration needs neither.
|
|
11
|
+
*
|
|
12
|
+
* @example
|
|
13
|
+
* \@GeneratedColumn({ type: 'integer', asExpression: 'price * quantity', generatedType: 'STORED' })
|
|
14
|
+
* total: number;
|
|
15
|
+
*/
|
|
16
|
+
export declare function GeneratedColumn(options?: GeneratedColumnOptions): PropertyDecorator;
|
|
17
|
+
export declare function GeneratedColumn(type: ColumnType, options?: GeneratedColumnOptions): PropertyDecorator;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.GeneratedColumn = void 0;
|
|
4
|
+
const typeorm_1 = require("typeorm");
|
|
5
|
+
function GeneratedColumn(typeOrOptions, options = {}) {
|
|
6
|
+
const columnOptions = typeof typeOrOptions === 'object'
|
|
7
|
+
? { ...typeOrOptions }
|
|
8
|
+
: typeOrOptions === undefined
|
|
9
|
+
? { ...options }
|
|
10
|
+
: { ...options, type: typeOrOptions };
|
|
11
|
+
// TypeORM 0.3 applies `readonly` after `update`: `readonly: false` from an untyped caller would turn writes back on
|
|
12
|
+
delete columnOptions.readonly;
|
|
13
|
+
return (0, typeorm_1.Column)({ ...columnOptions, insert: false, update: false });
|
|
14
|
+
}
|
|
15
|
+
exports.GeneratedColumn = GeneratedColumn;
|
package/dist/decorators/index.js
CHANGED
|
@@ -15,3 +15,4 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
15
15
|
};
|
|
16
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
17
|
__exportStar(require("./calculated-column.decorator"), exports);
|
|
18
|
+
__exportStar(require("./generated-column.decorator"), exports);
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { ObjectLiteral } from 'typeorm';
|
|
1
2
|
import type { CursorPaginationFilter } from '../types/interfaces/cursor-pagination.interface';
|
|
2
3
|
import type { GetManyWithCursorOptions, ListWithCursor } from '../types/extensions/cursor-pagination.types';
|
|
3
4
|
export { InvalidCursorError } from '../utils/cursor.utils';
|
|
@@ -14,6 +15,6 @@ declare module 'typeorm/query-builder/SelectQueryBuilder' {
|
|
|
14
15
|
* The query builder itself is not changed. Throws `InvalidCursorError` for a cursor that can't
|
|
15
16
|
* be decoded or was made for another order.
|
|
16
17
|
*/
|
|
17
|
-
getManyWithCursor(cursorFilter: CursorPaginationFilter | null | undefined, options: GetManyWithCursorOptions<
|
|
18
|
+
getManyWithCursor<CursorEntity extends ObjectLiteral = Entity>(this: SelectQueryBuilder<CursorEntity>, cursorFilter: CursorPaginationFilter | null | undefined, options: GetManyWithCursorOptions<CursorEntity>): Promise<ListWithCursor<CursorEntity>>;
|
|
18
19
|
}
|
|
19
20
|
}
|
|
@@ -7,6 +7,7 @@ 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");
|
|
9
9
|
const sql_utils_1 = require("../utils/sql.utils");
|
|
10
|
+
const query_builder_utils_1 = require("../utils/query-builder.utils");
|
|
10
11
|
const cursor_utils_1 = require("../utils/cursor.utils");
|
|
11
12
|
var cursor_utils_2 = require("../utils/cursor.utils");
|
|
12
13
|
Object.defineProperty(exports, "InvalidCursorError", { enumerable: true, get: function () { return cursor_utils_2.InvalidCursorError; } });
|
|
@@ -68,6 +69,7 @@ async function getManyWithCursor(builder, cursorFilter, options) {
|
|
|
68
69
|
}
|
|
69
70
|
query.orderBy();
|
|
70
71
|
keys.forEach((key) => query.addOrderBy(`${alias}.${key.column.propertyPath}`, key.direction));
|
|
72
|
+
const appliedOrderBy = (0, query_builder_utils_1.getAppliedOrderBy)(query);
|
|
71
73
|
// the key values of the last row are read from the raw result: dates and times as text, so the
|
|
72
74
|
// cursor keeps the database's precision (PostgreSQL timestamps have microseconds, a JS Date has not)
|
|
73
75
|
const keyAliases = keys.map((key, i) => {
|
|
@@ -90,7 +92,7 @@ async function getManyWithCursor(builder, cursorFilter, options) {
|
|
|
90
92
|
const { entities, raw } = await query.getRawAndEntities();
|
|
91
93
|
const list = entities.slice(0, pageSize);
|
|
92
94
|
if (entities.length <= pageSize) {
|
|
93
|
-
return { list, nextCursor: null, hasMore: false };
|
|
95
|
+
return { list, nextCursor: null, hasMore: false, pageSize, orderBy: appliedOrderBy };
|
|
94
96
|
}
|
|
95
97
|
// with joined collections there are several raw rows per entity: find one of the last entity's
|
|
96
98
|
const last = list[list.length - 1];
|
|
@@ -105,5 +107,5 @@ async function getManyWithCursor(builder, cursorFilter, options) {
|
|
|
105
107
|
}
|
|
106
108
|
return value;
|
|
107
109
|
});
|
|
108
|
-
return { list, nextCursor: (0, cursor_utils_1.encodeCursor)(fields, values), hasMore: true };
|
|
110
|
+
return { list, nextCursor: (0, cursor_utils_1.encodeCursor)(fields, values), hasMore: true, pageSize, orderBy: appliedOrderBy };
|
|
109
111
|
}
|
|
@@ -58,10 +58,9 @@ function getRawManyWithTotals(builder, paginationFilter, options) {
|
|
|
58
58
|
});
|
|
59
59
|
}
|
|
60
60
|
async function readWithTotals(builder, paginationFilter, options, read) {
|
|
61
|
-
var _a;
|
|
62
61
|
const { disableTotalsCalculation = false, loadAll = false, ...paginationOptions } = options || {};
|
|
63
|
-
const { limit, offset } = loadAll
|
|
64
|
-
? { limit: null, offset: null }
|
|
62
|
+
const { limit, offset, page, pageSize } = loadAll
|
|
63
|
+
? { limit: null, offset: null, page: null, pageSize: null }
|
|
65
64
|
: (0, pagination_utils_1.getLimitAndOffset)(paginationFilter);
|
|
66
65
|
// without a total, one row past the page is what tells whether more rows follow
|
|
67
66
|
const probeForMore = disableTotalsCalculation && !loadAll && limit !== null;
|
|
@@ -110,21 +109,15 @@ async function readWithTotals(builder, paginationFilter, options, read) {
|
|
|
110
109
|
hasMore =
|
|
111
110
|
total !== null && offset !== null ? offset + rows.length < total : null;
|
|
112
111
|
}
|
|
113
|
-
// allOrderBys, not orderBys: it is what the SQL is built from, so without an explicit order it
|
|
114
|
-
// falls back to the `orderBy` of @Entity, and respects the `disable-global-order` option
|
|
115
|
-
const orderBy = Object.entries((_a = builder.expressionMap.allOrderBys) !== null && _a !== void 0 ? _a : {}).map(([key, value]) => {
|
|
116
|
-
const selector = (0, query_builder_utils_1.resolveDeferredKeys)(builder, key);
|
|
117
|
-
return typeof value === 'string'
|
|
118
|
-
? { selector, order: value }
|
|
119
|
-
: { selector, order: value.order, nulls: value.nulls };
|
|
120
|
-
});
|
|
121
112
|
return {
|
|
122
113
|
list,
|
|
123
114
|
total,
|
|
115
|
+
page,
|
|
116
|
+
pageSize,
|
|
124
117
|
limit,
|
|
125
118
|
offset,
|
|
126
119
|
hasMore,
|
|
127
|
-
orderBy,
|
|
120
|
+
orderBy: (0, query_builder_utils_1.getAppliedOrderBy)(builder),
|
|
128
121
|
};
|
|
129
122
|
}
|
|
130
123
|
/**
|
|
@@ -3,7 +3,7 @@ import { ObjectLiteral } from 'typeorm';
|
|
|
3
3
|
import type { ApplyOrderOptions } from '../types/extensions/order.types';
|
|
4
4
|
declare module 'typeorm/query-builder/SelectQueryBuilder' {
|
|
5
5
|
interface SelectQueryBuilder<Entity> {
|
|
6
|
-
applyOrder<OrderEntity extends ObjectLiteral>(orderBy: OrderParam<OrderEntity>, options?: ApplyOrderOptions):
|
|
7
|
-
applyOrderFilter<OrderEntity extends ObjectLiteral>(orderFilter: OrderFilter<OrderEntity>, options?: ApplyOrderOptions):
|
|
6
|
+
applyOrder<OrderEntity extends ObjectLiteral>(orderBy: OrderParam<OrderEntity>, options?: ApplyOrderOptions): this;
|
|
7
|
+
applyOrderFilter<OrderEntity extends ObjectLiteral>(orderFilter: OrderFilter<OrderEntity>, options?: ApplyOrderOptions): this;
|
|
8
8
|
}
|
|
9
9
|
}
|
|
@@ -3,6 +3,6 @@ import { ObjectLiteral } from 'typeorm';
|
|
|
3
3
|
import { ApplyPaginationOptions } from '../types/extensions/pagination.types';
|
|
4
4
|
declare module 'typeorm/query-builder/SelectQueryBuilder' {
|
|
5
5
|
interface SelectQueryBuilder<Entity extends ObjectLiteral> {
|
|
6
|
-
applyPaginationFilter(paginationFilter: PaginationFilter, options?: ApplyPaginationOptions):
|
|
6
|
+
applyPaginationFilter(paginationFilter: PaginationFilter, options?: ApplyPaginationOptions): this;
|
|
7
7
|
}
|
|
8
8
|
}
|
|
@@ -27,3 +27,7 @@ declare module 'typeorm/query-builder/DeleteQueryBuilder' {
|
|
|
27
27
|
interface DeleteQueryBuilder<Entity extends ObjectLiteral> extends PeriodFilterMethods {
|
|
28
28
|
}
|
|
29
29
|
}
|
|
30
|
+
declare module 'typeorm/query-builder/SoftDeleteQueryBuilder' {
|
|
31
|
+
interface SoftDeleteQueryBuilder<Entity extends ObjectLiteral> extends PeriodFilterMethods {
|
|
32
|
+
}
|
|
33
|
+
}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
const typeorm_1 = require("typeorm");
|
|
4
|
+
const SoftDeleteQueryBuilder_1 = require("typeorm/query-builder/SoftDeleteQueryBuilder");
|
|
4
5
|
const prototype_utils_1 = require("../utils/prototype.utils");
|
|
5
6
|
const query_builder_utils_1 = require("../utils/query-builder.utils");
|
|
6
7
|
const period_utils_1 = require("../utils/period.utils");
|
|
@@ -17,6 +18,7 @@ const queryBuilders = [
|
|
|
17
18
|
typeorm_1.SelectQueryBuilder,
|
|
18
19
|
typeorm_1.UpdateQueryBuilder,
|
|
19
20
|
typeorm_1.DeleteQueryBuilder,
|
|
21
|
+
SoftDeleteQueryBuilder_1.SoftDeleteQueryBuilder,
|
|
20
22
|
];
|
|
21
23
|
queryBuilders.forEach((builder) => {
|
|
22
24
|
(0, prototype_utils_1.patchPrototype)(builder, extension);
|
|
@@ -2,6 +2,7 @@ export * from './typed-distinct/typed-distinct.extension';
|
|
|
2
2
|
export * from './typed-group-by/typed-group-by.extension';
|
|
3
3
|
export * from './typed-having/typed-having.extension';
|
|
4
4
|
export * from './typed-joins/typed-joins.extension';
|
|
5
|
+
export * from './typed-joins/typed-join-and-map.extension';
|
|
5
6
|
export * from './typed-order-by/typed-order-by.extension';
|
|
6
7
|
export * from './typed-select/typed-select.extension';
|
|
7
8
|
export * from './typed-where/typed-where.extension';
|
|
@@ -19,6 +19,7 @@ __exportStar(require("./typed-distinct/typed-distinct.extension"), exports);
|
|
|
19
19
|
__exportStar(require("./typed-group-by/typed-group-by.extension"), exports);
|
|
20
20
|
__exportStar(require("./typed-having/typed-having.extension"), exports);
|
|
21
21
|
__exportStar(require("./typed-joins/typed-joins.extension"), exports);
|
|
22
|
+
__exportStar(require("./typed-joins/typed-join-and-map.extension"), exports);
|
|
22
23
|
__exportStar(require("./typed-order-by/typed-order-by.extension"), exports);
|
|
23
24
|
__exportStar(require("./typed-select/typed-select.extension"), exports);
|
|
24
25
|
__exportStar(require("./typed-where/typed-where.extension"), exports);
|
|
@@ -6,10 +6,10 @@ declare module 'typeorm/query-builder/SelectQueryBuilder' {
|
|
|
6
6
|
/**
|
|
7
7
|
* Sets the distinct on clause for Postgres.
|
|
8
8
|
*/
|
|
9
|
-
distinctOnTyped<Type extends ObjectLiteral = TypedRoot<Entity>>(this: SelectQueryBuilder<Entity>, ...distinctOn: Array<KeyProxyCallback<Type>>):
|
|
9
|
+
distinctOnTyped<Type extends ObjectLiteral = TypedRoot<Entity, this>>(this: SelectQueryBuilder<Entity>, ...distinctOn: Array<KeyProxyCallback<Type>>): this;
|
|
10
10
|
/**
|
|
11
11
|
* Sets the distinct on clause for Postgres.
|
|
12
12
|
*/
|
|
13
|
-
distinctOnTyped<Type extends ObjectLiteral = TypedRoot<Entity>>(this: SelectQueryBuilder<Entity>, distinctOn: KeyProxyCallback<Type>):
|
|
13
|
+
distinctOnTyped<Type extends ObjectLiteral = TypedRoot<Entity, this>>(this: SelectQueryBuilder<Entity>, distinctOn: KeyProxyCallback<Type>): this;
|
|
14
14
|
}
|
|
15
15
|
}
|
|
@@ -12,11 +12,11 @@ export interface TypedGroupByMethods<Entity extends ObjectLiteral> {
|
|
|
12
12
|
* Sets GROUP BY to the columns the callback selects: `user => user.id`, or several at once,
|
|
13
13
|
* `user => [user.id, user.email]`. Replaces previously set GROUP BY.
|
|
14
14
|
*/
|
|
15
|
-
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;
|
|
16
16
|
/**
|
|
17
17
|
* Adds the columns the callback selects to GROUP BY.
|
|
18
18
|
*/
|
|
19
|
-
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;
|
|
20
20
|
}
|
|
21
21
|
declare module 'typeorm/query-builder/SelectQueryBuilder' {
|
|
22
22
|
interface SelectQueryBuilder<Entity extends ObjectLiteral> extends TypedGroupByMethods<Entity> {
|
|
@@ -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> {
|
|
@@ -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,22 @@
|
|
|
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
|
+
// patching
|
|
6
|
+
typeorm_1.SelectQueryBuilder.prototype.leftJoinAndMapOneTyped = function (mapToProperty, entity, alias, condition, parameters) {
|
|
7
|
+
return addJoinAndMap(this, 'leftJoinAndMapOne', mapToProperty, entity, alias, condition, parameters);
|
|
8
|
+
};
|
|
9
|
+
typeorm_1.SelectQueryBuilder.prototype.innerJoinAndMapOneTyped = function (mapToProperty, entity, alias, condition, parameters) {
|
|
10
|
+
return addJoinAndMap(this, 'innerJoinAndMapOne', mapToProperty, entity, alias, condition, parameters);
|
|
11
|
+
};
|
|
12
|
+
typeorm_1.SelectQueryBuilder.prototype.leftJoinAndMapManyTyped = function (mapToProperty, entity, alias, condition, parameters) {
|
|
13
|
+
return addJoinAndMap(this, 'leftJoinAndMapMany', mapToProperty, entity, alias, condition, parameters);
|
|
14
|
+
};
|
|
15
|
+
typeorm_1.SelectQueryBuilder.prototype.innerJoinAndMapManyTyped = function (mapToProperty, entity, alias, condition, parameters) {
|
|
16
|
+
return addJoinAndMap(this, 'innerJoinAndMapMany', mapToProperty, entity, alias, condition, parameters);
|
|
17
|
+
};
|
|
18
|
+
function addJoinAndMap(query, method, mapToProperty, entity, alias, condition, parameters) {
|
|
19
|
+
// `() => query.alias`: `(q) => q.photo.owner` needs no main alias, only `(u) => u.profile` does
|
|
20
|
+
const key = (0, proxy_key_utils_1.getSqlKeyFromProxyCallback)(mapToProperty, () => query.alias, false);
|
|
21
|
+
return query[method](key, entity, alias, condition, parameters);
|
|
22
|
+
}
|
|
@@ -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
|
}
|
|
@@ -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> {
|
|
@@ -10,10 +10,10 @@ declare module 'typeorm/query-builder/SelectQueryBuilder' {
|
|
|
10
10
|
* If you had previously ORDER BY expression defined,
|
|
11
11
|
* calling this function will override previously set ORDER BY conditions.
|
|
12
12
|
*/
|
|
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):
|
|
13
|
+
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
14
|
/**
|
|
15
15
|
* Adds ORDER BY condition in the query builder.
|
|
16
16
|
*/
|
|
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):
|
|
17
|
+
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
18
|
}
|
|
19
19
|
}
|
|
@@ -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
|
}
|
|
@@ -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
|
+
}
|
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
require("../../period-filter.extension");
|
|
4
4
|
const typeorm_1 = require("typeorm");
|
|
5
|
+
const SoftDeleteQueryBuilder_1 = require("typeorm/query-builder/SoftDeleteQueryBuilder");
|
|
5
6
|
const query_builder_utils_1 = require("../../../utils/query-builder.utils");
|
|
6
7
|
const prototype_utils_1 = require("../../../utils/prototype.utils");
|
|
7
8
|
const period_utils_1 = require("../../../utils/period.utils");
|
|
@@ -19,6 +20,7 @@ const queryBuilders = [
|
|
|
19
20
|
typeorm_1.SelectQueryBuilder,
|
|
20
21
|
typeorm_1.UpdateQueryBuilder,
|
|
21
22
|
typeorm_1.DeleteQueryBuilder,
|
|
23
|
+
SoftDeleteQueryBuilder_1.SoftDeleteQueryBuilder,
|
|
22
24
|
];
|
|
23
25
|
queryBuilders.forEach((builder) => {
|
|
24
26
|
(0, prototype_utils_1.patchPrototype)(builder, extension);
|