typeorm-extensions 1.2.3 → 1.2.4
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/dist/constants/index.d.ts +5 -0
- package/dist/constants/index.js +8 -0
- package/dist/extensions/get-many-with-totals.extension.d.ts +16 -0
- package/dist/extensions/get-many-with-totals.extension.js +30 -0
- package/dist/extensions/index.js +20 -0
- package/dist/extensions/order.extension.d.ts +15 -0
- package/dist/extensions/order.extension.js +48 -0
- package/dist/extensions/ordering.extension.js +48 -0
- package/dist/extensions/pagination.extension.d.ts +10 -0
- package/dist/extensions/pagination.extension.js +13 -0
- package/{src/extensions/typed/index.ts → dist/extensions/typed/index.d.ts} +0 -5
- package/dist/extensions/typed/index.js +27 -0
- package/dist/extensions/typed/typed-distinct/typed-distinct.extension.d.ts +14 -0
- package/dist/extensions/typed/typed-distinct/typed-distinct.extension.js +11 -0
- package/dist/extensions/typed/typed-joins/typed-joins.extension.d.ts +10 -0
- package/dist/extensions/typed/typed-joins/typed-joins.extension.js +32 -0
- package/dist/extensions/typed/typed-order-by/typed-order-by.extension.d.ts +17 -0
- package/dist/extensions/typed/typed-order-by/typed-order-by.extension.js +25 -0
- package/dist/extensions/typed/typed-select/typed-select.extension.d.ts +33 -0
- package/dist/extensions/typed/typed-select/typed-select.extension.js +31 -0
- package/dist/extensions/typed/typed-where/typed-where.extension.d.ts +89 -0
- package/dist/extensions/typed/typed-where/typed-where.extension.js +33 -0
- package/dist/extensions/typed/typeorm-querybuilder.types.d.ts +22 -0
- package/dist/extensions/typed/typeorm-querybuilder.types.js +56 -0
- package/{src/extensions/typed/typeorm.types.ts → dist/extensions/typed/typeorm.types.d.ts} +7 -20
- package/dist/extensions/typed/typeorm.types.js +2 -0
- package/{src/index.ts → dist/index.d.ts} +0 -1
- package/dist/index.js +18 -0
- package/dist/types/interfaces/index.js +18 -0
- package/{src/types/interfaces/ordering.interface.ts → dist/types/interfaces/ordering.interface.d.ts} +7 -12
- package/dist/types/interfaces/ordering.interface.js +2 -0
- package/dist/types/interfaces/pagination.interface.d.ts +6 -0
- package/dist/types/interfaces/pagination.interface.js +2 -0
- package/{src/types/modules/column.types.ts → dist/types/modules/column.types.d.ts} +1 -3
- package/dist/types/modules/column.types.js +2 -0
- package/{src/types/modules/proxy-types/proxy-callback.types.ts → dist/types/modules/proxy-types/proxy-callback.types.d.ts} +2 -7
- package/dist/types/modules/proxy-types/proxy-callback.types.js +2 -0
- package/dist/types/modules/relations.types.d.ts +16 -0
- package/dist/types/modules/relations.types.js +2 -0
- package/dist/types/util-types/index.d.ts +7 -0
- package/dist/types/util-types/index.js +2 -0
- package/dist/utils/common.utils.d.ts +1 -0
- package/dist/utils/common.utils.js +5 -0
- package/dist/utils/identifier.utils.d.ts +15 -0
- package/dist/utils/identifier.utils.js +45 -0
- package/dist/utils/pagination.utils.d.ts +5 -0
- package/dist/utils/pagination.utils.js +16 -0
- package/dist/utils/proxy-key.utils.d.ts +22 -0
- package/dist/utils/proxy-key.utils.js +100 -0
- package/dist/utils/sql.utils.d.ts +5 -0
- package/dist/utils/sql.utils.js +18 -0
- package/dist/utils/string.utils.js +11 -0
- package/package.json +4 -1
- package/.eslintignore +0 -2
- package/.eslintrc +0 -12
- package/docs/api_reference/index.html +0 -21
- package/docs/api_reference/order/applyOrderFilter.html +0 -77
- package/docs/api_reference/order/index.html +0 -36
- package/docs/api_reference/pagination/applyPaginationFilter.html +0 -78
- package/docs/api_reference/pagination/index.html +0 -35
- package/docs/api_reference/typed/index.html +0 -37
- package/docs/examples/index.html +0 -21
- package/docs/index.html +0 -78
- package/src/constants/index.ts +0 -9
- package/src/extensions/get-many-with-totals.extension.ts +0 -62
- package/src/extensions/order.extension.ts +0 -123
- package/src/extensions/pagination.extension.ts +0 -35
- package/src/extensions/typed/typed-distinct/typed-distinct.extension.ts +0 -38
- package/src/extensions/typed/typed-joins/typed-joins.extension.ts +0 -141
- package/src/extensions/typed/typed-order-by/typed-order-by.extension.ts +0 -73
- package/src/extensions/typed/typed-select/typed-select.extension.ts +0 -124
- package/src/extensions/typed/typed-where/typed-where.extension.ts +0 -268
- package/src/extensions/typed/typeorm-querybuilder.types.ts +0 -75
- package/src/types/interfaces/pagination.interface.ts +0 -8
- package/src/types/modules/relations.types.ts +0 -34
- package/src/types/util-types/index.ts +0 -8
- package/src/utils/common.utils.ts +0 -2
- package/src/utils/identifier.utils.ts +0 -60
- package/src/utils/pagination.utils.ts +0 -17
- package/src/utils/proxy-key.utils.ts +0 -133
- package/src/utils/sql.utils.ts +0 -24
- package/tsconfig.json +0 -109
- /package/{src/extensions/index.ts → dist/extensions/index.d.ts} +0 -0
- /package/{src/types/interfaces/index.ts → dist/types/interfaces/index.d.ts} +0 -0
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.defaultNullsOrder = exports.defaultOrderDirection = exports.defaultUseDoubleQuotes = exports.defaultUseTakeAndSkip = exports.defaultPageSize = void 0;
|
|
4
|
+
exports.defaultPageSize = 10;
|
|
5
|
+
exports.defaultUseTakeAndSkip = false;
|
|
6
|
+
exports.defaultUseDoubleQuotes = true;
|
|
7
|
+
exports.defaultOrderDirection = 'ASC';
|
|
8
|
+
exports.defaultNullsOrder = undefined;
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { PaginationFilter } from '../types/interfaces/pagination.interface';
|
|
2
|
+
export type GetManyWithTotalsOptions = {
|
|
3
|
+
disableTotalsCalculation?: boolean;
|
|
4
|
+
loadAll?: boolean;
|
|
5
|
+
};
|
|
6
|
+
export interface ListWithTotals<Entity> {
|
|
7
|
+
list: Entity[];
|
|
8
|
+
totalCount: number | null;
|
|
9
|
+
limit: number | null;
|
|
10
|
+
offset: number | null;
|
|
11
|
+
}
|
|
12
|
+
declare module 'typeorm/query-builder/SelectQueryBuilder' {
|
|
13
|
+
interface SelectQueryBuilder<Entity> {
|
|
14
|
+
getManyWithTotals(paginationFilter: PaginationFilter, options?: GetManyWithTotalsOptions): Promise<ListWithTotals<Entity>>;
|
|
15
|
+
}
|
|
16
|
+
}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const SelectQueryBuilder_1 = require("typeorm/query-builder/SelectQueryBuilder");
|
|
4
|
+
const pagination_utils_1 = require("../utils/pagination.utils");
|
|
5
|
+
SelectQueryBuilder_1.SelectQueryBuilder.prototype.getManyWithTotals = async function (paginationFilter, options) {
|
|
6
|
+
const { disableTotalsCalculation = false, loadAll = false } = options || {};
|
|
7
|
+
const { limit, offset } = loadAll
|
|
8
|
+
? { limit: null, offset: null }
|
|
9
|
+
: (0, pagination_utils_1.getLimitAndOffset)(paginationFilter);
|
|
10
|
+
const requests = [];
|
|
11
|
+
if (!disableTotalsCalculation) {
|
|
12
|
+
requests[0] = this.getCount();
|
|
13
|
+
}
|
|
14
|
+
else {
|
|
15
|
+
requests[0] = Promise.resolve(null);
|
|
16
|
+
}
|
|
17
|
+
if (loadAll) {
|
|
18
|
+
requests[1] = this.getMany();
|
|
19
|
+
}
|
|
20
|
+
else {
|
|
21
|
+
requests[1] = this.applyPaginationFilter(paginationFilter).getMany();
|
|
22
|
+
}
|
|
23
|
+
const [totalCount, list] = (await Promise.all(requests));
|
|
24
|
+
return {
|
|
25
|
+
list,
|
|
26
|
+
totalCount: totalCount,
|
|
27
|
+
limit,
|
|
28
|
+
offset,
|
|
29
|
+
};
|
|
30
|
+
};
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("./get-many-with-totals.extension"), exports);
|
|
18
|
+
__exportStar(require("./order.extension"), exports);
|
|
19
|
+
__exportStar(require("./pagination.extension"), exports);
|
|
20
|
+
__exportStar(require("./typed"), exports);
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import type { OrderParam, OrderFilter, OrderType } from '../types/interfaces/ordering.interface';
|
|
2
|
+
export type ApplyOrderOptions = {
|
|
3
|
+
useDoubleQuotes?: boolean;
|
|
4
|
+
alias?: string;
|
|
5
|
+
alwaysAliasFields?: string[];
|
|
6
|
+
resetPreviousOrder?: boolean;
|
|
7
|
+
};
|
|
8
|
+
declare module 'typeorm/query-builder/SelectQueryBuilder' {
|
|
9
|
+
interface SelectQueryBuilder<Entity> {
|
|
10
|
+
applyOrder<OrderEntity>(orderBy: OrderParam<OrderEntity>, options?: ApplyOrderOptions): SelectQueryBuilder<Entity>;
|
|
11
|
+
applyOrderFilter<OrderEntity>(orderFilter: OrderFilter<OrderEntity>, options?: ApplyOrderOptions): SelectQueryBuilder<Entity>;
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
export declare const getOrderOption: <OrderEntity>(orderBy: OrderParam<OrderEntity>, defaultAlias: string, options?: ApplyOrderOptions) => OrderType;
|
|
15
|
+
export {};
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getOrderOption = void 0;
|
|
4
|
+
const SelectQueryBuilder_1 = require("typeorm/query-builder/SelectQueryBuilder");
|
|
5
|
+
const constants_1 = require("../constants");
|
|
6
|
+
const common_utils_1 = require("../utils/common.utils");
|
|
7
|
+
const identifier_utils_1 = require("../utils/identifier.utils");
|
|
8
|
+
const alwaysAliasWhiteList = [
|
|
9
|
+
'id',
|
|
10
|
+
'createdAt',
|
|
11
|
+
'created_at',
|
|
12
|
+
'updatedAt',
|
|
13
|
+
'updated_at',
|
|
14
|
+
'deletedAt',
|
|
15
|
+
'deleted_at',
|
|
16
|
+
];
|
|
17
|
+
SelectQueryBuilder_1.SelectQueryBuilder.prototype.applyOrder = function (orderBy, options) {
|
|
18
|
+
const { resetPreviousOrder = false } = options !== null && options !== void 0 ? options : {};
|
|
19
|
+
const orderOption = (0, exports.getOrderOption)(orderBy, this.alias, options);
|
|
20
|
+
const query = resetPreviousOrder ? this.orderBy() : this;
|
|
21
|
+
return query.addOrderBy(orderOption.selector, orderOption.order, orderOption.nulls);
|
|
22
|
+
};
|
|
23
|
+
SelectQueryBuilder_1.SelectQueryBuilder.prototype.applyOrderFilter = function (orderFilter, options) {
|
|
24
|
+
if (!(0, common_utils_1.isNil)(orderFilter === null || orderFilter === void 0 ? void 0 : orderFilter.orderBy)) {
|
|
25
|
+
return orderFilter.orderBy.reduce((acc, order, index) => acc.applyOrder(order, {
|
|
26
|
+
...options,
|
|
27
|
+
resetPreviousOrder: index === 0 ? options === null || options === void 0 ? void 0 : options.resetPreviousOrder : false,
|
|
28
|
+
}), this);
|
|
29
|
+
}
|
|
30
|
+
return this;
|
|
31
|
+
};
|
|
32
|
+
const getOrderOption = (orderBy, defaultAlias, options) => {
|
|
33
|
+
const { useDoubleQuotes = constants_1.defaultUseDoubleQuotes, alias: customAlias, alwaysAliasFields = alwaysAliasWhiteList, } = options !== null && options !== void 0 ? options : {};
|
|
34
|
+
const { field, direction = constants_1.defaultOrderDirection, nulls: nullsOrder = constants_1.defaultNullsOrder, } = orderBy;
|
|
35
|
+
const alias = customAlias !== null && customAlias !== void 0 ? customAlias : (alwaysAliasFields.includes(field) ? defaultAlias : undefined);
|
|
36
|
+
const identifier = new identifier_utils_1.Identifier(field, alias, useDoubleQuotes);
|
|
37
|
+
const selector = identifier.fieldIdentifier();
|
|
38
|
+
const order = direction.toUpperCase();
|
|
39
|
+
const nulls = nullsOrder
|
|
40
|
+
? `NULLS ${nullsOrder.toUpperCase()}`
|
|
41
|
+
: undefined;
|
|
42
|
+
return {
|
|
43
|
+
selector,
|
|
44
|
+
order,
|
|
45
|
+
nulls,
|
|
46
|
+
};
|
|
47
|
+
};
|
|
48
|
+
exports.getOrderOption = getOrderOption;
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getOrderOption = void 0;
|
|
4
|
+
const SelectQueryBuilder_1 = require("typeorm/query-builder/SelectQueryBuilder");
|
|
5
|
+
const constants_1 = require("../constants");
|
|
6
|
+
const common_utils_1 = require("../utils/common.utils");
|
|
7
|
+
const identifier_utils_1 = require("../utils/identifier.utils");
|
|
8
|
+
const alwaysAliasWhiteList = [
|
|
9
|
+
'id',
|
|
10
|
+
'createdAt',
|
|
11
|
+
'created_at',
|
|
12
|
+
'updatedAt',
|
|
13
|
+
'updated_at',
|
|
14
|
+
'deletedAt',
|
|
15
|
+
'deleted_at',
|
|
16
|
+
];
|
|
17
|
+
SelectQueryBuilder_1.SelectQueryBuilder.prototype.applyOrder = function (orderBy, options) {
|
|
18
|
+
const { resetPreviousOrder = false } = options !== null && options !== void 0 ? options : {};
|
|
19
|
+
const orderOption = (0, exports.getOrderOption)(orderBy, this.alias, options);
|
|
20
|
+
const query = resetPreviousOrder ? this.orderBy() : this;
|
|
21
|
+
return query.addOrderBy(orderOption.selector, orderOption.order, orderOption.nulls);
|
|
22
|
+
};
|
|
23
|
+
SelectQueryBuilder_1.SelectQueryBuilder.prototype.applyOrderFilter = function (orderFilter, options) {
|
|
24
|
+
if (!(0, common_utils_1.isNil)(orderFilter === null || orderFilter === void 0 ? void 0 : orderFilter.orderBy)) {
|
|
25
|
+
return orderFilter.orderBy.reduce((acc, order, index) => acc.applyOrder(order, {
|
|
26
|
+
...options,
|
|
27
|
+
resetPreviousOrder: index === 0 ? options === null || options === void 0 ? void 0 : options.resetPreviousOrder : false,
|
|
28
|
+
}), this);
|
|
29
|
+
}
|
|
30
|
+
return this;
|
|
31
|
+
};
|
|
32
|
+
const getOrderOption = (orderBy, defaultAlias, options) => {
|
|
33
|
+
const { useDoubleQuotes = constants_1.defaultUseDoubleQuotes, alias: customAlias, alwaysAliasFields = alwaysAliasWhiteList, } = options !== null && options !== void 0 ? options : {};
|
|
34
|
+
const { field, direction = constants_1.defaultOrderDirection, nulls: nullsOrder = constants_1.defaultNullsOrder, } = orderBy;
|
|
35
|
+
const alias = customAlias !== null && customAlias !== void 0 ? customAlias : (alwaysAliasFields.includes(field) ? defaultAlias : undefined);
|
|
36
|
+
const identifier = new identifier_utils_1.Identifier(field, alias, useDoubleQuotes);
|
|
37
|
+
const selector = identifier.fieldIdentifier();
|
|
38
|
+
const order = direction.toUpperCase();
|
|
39
|
+
const nulls = nullsOrder
|
|
40
|
+
? `NULLS ${nullsOrder.toUpperCase()}`
|
|
41
|
+
: undefined;
|
|
42
|
+
return {
|
|
43
|
+
selector,
|
|
44
|
+
order,
|
|
45
|
+
nulls,
|
|
46
|
+
};
|
|
47
|
+
};
|
|
48
|
+
exports.getOrderOption = getOrderOption;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { PaginationFilter } from '../types/interfaces/pagination.interface';
|
|
2
|
+
export type ApplyPaginationOptions = {
|
|
3
|
+
useTakeAndSkip?: boolean;
|
|
4
|
+
};
|
|
5
|
+
declare module 'typeorm/query-builder/SelectQueryBuilder' {
|
|
6
|
+
interface SelectQueryBuilder<Entity> {
|
|
7
|
+
applyPaginationFilter(paginationFilter: PaginationFilter, options?: ApplyPaginationOptions): SelectQueryBuilder<Entity>;
|
|
8
|
+
}
|
|
9
|
+
}
|
|
10
|
+
export {};
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const SelectQueryBuilder_1 = require("typeorm/query-builder/SelectQueryBuilder");
|
|
4
|
+
const constants_1 = require("../constants");
|
|
5
|
+
const pagination_utils_1 = require("../utils/pagination.utils");
|
|
6
|
+
SelectQueryBuilder_1.SelectQueryBuilder.prototype.applyPaginationFilter = function (paginationFilter, options) {
|
|
7
|
+
const { useTakeAndSkip = constants_1.defaultUseTakeAndSkip } = options || {};
|
|
8
|
+
const { limit, offset } = (0, pagination_utils_1.getLimitAndOffset)(paginationFilter);
|
|
9
|
+
if (useTakeAndSkip) {
|
|
10
|
+
return this.take(limit).skip(offset);
|
|
11
|
+
}
|
|
12
|
+
return this.limit(limit).offset(offset);
|
|
13
|
+
};
|
|
@@ -1,12 +1,7 @@
|
|
|
1
|
-
//Extensions
|
|
2
1
|
export * from './typed-distinct/typed-distinct.extension';
|
|
3
|
-
// export * from './typed/typed-group-by/typed-group-by.extension';
|
|
4
|
-
// export * from './typed/typed-having/typed-having.extension';
|
|
5
2
|
export * from './typed-joins/typed-joins.extension';
|
|
6
3
|
export * from './typed-order-by/typed-order-by.extension';
|
|
7
4
|
export * from './typed-select/typed-select.extension';
|
|
8
5
|
export * from './typed-where/typed-where.extension';
|
|
9
|
-
|
|
10
|
-
// Types
|
|
11
6
|
export * from './typeorm-querybuilder.types';
|
|
12
7
|
export * from './typeorm.types';
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
//Extensions
|
|
18
|
+
__exportStar(require("./typed-distinct/typed-distinct.extension"), exports);
|
|
19
|
+
// export * from './typed/typed-group-by/typed-group-by.extension';
|
|
20
|
+
// export * from './typed/typed-having/typed-having.extension';
|
|
21
|
+
__exportStar(require("./typed-joins/typed-joins.extension"), exports);
|
|
22
|
+
__exportStar(require("./typed-order-by/typed-order-by.extension"), exports);
|
|
23
|
+
__exportStar(require("./typed-select/typed-select.extension"), exports);
|
|
24
|
+
__exportStar(require("./typed-where/typed-where.extension"), exports);
|
|
25
|
+
// Types
|
|
26
|
+
__exportStar(require("./typeorm-querybuilder.types"), exports);
|
|
27
|
+
__exportStar(require("./typeorm.types"), exports);
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { ObjectLiteral } from 'typeorm';
|
|
2
|
+
import { ColumnValueType } from '../typeorm.types';
|
|
3
|
+
declare module 'typeorm/query-builder/SelectQueryBuilder' {
|
|
4
|
+
interface SelectQueryBuilder<Entity> {
|
|
5
|
+
/**
|
|
6
|
+
* Sets the distinct on clause for Postgres.
|
|
7
|
+
*/
|
|
8
|
+
distinctOnTyped<Type extends ObjectLiteral = Entity>(this: SelectQueryBuilder<Entity>, ...distinctOn: Array<(proxy: Type) => ColumnValueType>): SelectQueryBuilder<Entity>;
|
|
9
|
+
/**
|
|
10
|
+
* Sets the distinct on clause for Postgres.
|
|
11
|
+
*/
|
|
12
|
+
distinctOnTyped<Type extends ObjectLiteral = Entity>(this: SelectQueryBuilder<Entity>, distinctOn: (proxy: Type) => Array<ColumnValueType>): SelectQueryBuilder<Entity>;
|
|
13
|
+
}
|
|
14
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
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
|
+
typeorm_1.SelectQueryBuilder.prototype.distinctOnTyped = function (...distinctOn) {
|
|
6
|
+
if (Array.isArray(distinctOn) && distinctOn.length) {
|
|
7
|
+
const keys = distinctOn.map((callback) => (0, proxy_key_utils_1.getSqlKey)(callback, this.alias)).flat(3);
|
|
8
|
+
return this.distinctOn(keys);
|
|
9
|
+
}
|
|
10
|
+
return this;
|
|
11
|
+
};
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { ObjectLiteral } from 'typeorm';
|
|
2
|
+
import { RelationalKeyProxyCallback } from '../typeorm-querybuilder.types';
|
|
3
|
+
declare module 'typeorm/query-builder/SelectQueryBuilder' {
|
|
4
|
+
interface SelectQueryBuilder<Entity> {
|
|
5
|
+
leftJoinTyped<Type extends ObjectLiteral = Entity>(this: SelectQueryBuilder<Entity>, selection: RelationalKeyProxyCallback<Type>, alias: string, condition?: string, parameters?: ObjectLiteral): SelectQueryBuilder<Entity>;
|
|
6
|
+
innerJoinTyped<Type extends ObjectLiteral = Entity>(this: SelectQueryBuilder<Entity>, selection: RelationalKeyProxyCallback<Type>, alias: string, condition?: string, parameters?: ObjectLiteral): SelectQueryBuilder<Entity>;
|
|
7
|
+
leftJoinAndSelectTyped<Type extends ObjectLiteral = Entity>(this: SelectQueryBuilder<Entity>, selection: RelationalKeyProxyCallback<Type>, alias: string, condition?: string, parameters?: ObjectLiteral): SelectQueryBuilder<Entity>;
|
|
8
|
+
innerJoinAndSelectTyped<Type extends ObjectLiteral = Entity>(this: SelectQueryBuilder<Entity>, selection: RelationalKeyProxyCallback<Type>, alias: string, condition?: string, parameters?: ObjectLiteral): SelectQueryBuilder<Entity>;
|
|
9
|
+
}
|
|
10
|
+
}
|
|
@@ -0,0 +1,32 @@
|
|
|
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
|
+
typeorm_1.SelectQueryBuilder.prototype.leftJoinTyped = function (selection, alias, condition, parameters) {
|
|
6
|
+
if (typeof selection === 'function') {
|
|
7
|
+
return addJoin(this, 'leftJoin', selection, alias, condition, parameters);
|
|
8
|
+
}
|
|
9
|
+
return this;
|
|
10
|
+
};
|
|
11
|
+
typeorm_1.SelectQueryBuilder.prototype.innerJoinTyped = function (selection, alias, condition, parameters) {
|
|
12
|
+
if (typeof selection === 'function') {
|
|
13
|
+
return addJoin(this, 'innerJoin', selection, alias, condition, parameters);
|
|
14
|
+
}
|
|
15
|
+
return this;
|
|
16
|
+
};
|
|
17
|
+
typeorm_1.SelectQueryBuilder.prototype.leftJoinAndSelectTyped = function (selection, alias, condition, parameters) {
|
|
18
|
+
if (typeof selection === 'function') {
|
|
19
|
+
return addJoin(this, 'leftJoinAndSelect', selection, alias, condition, parameters);
|
|
20
|
+
}
|
|
21
|
+
return this;
|
|
22
|
+
};
|
|
23
|
+
typeorm_1.SelectQueryBuilder.prototype.innerJoinAndSelectTyped = function (selection, alias, condition, parameters) {
|
|
24
|
+
if (typeof selection === 'function') {
|
|
25
|
+
return addJoin(this, 'innerJoinAndSelect', selection, alias, condition, parameters);
|
|
26
|
+
}
|
|
27
|
+
return this;
|
|
28
|
+
};
|
|
29
|
+
function addJoin(query, method, selection, alias, condition, parameters) {
|
|
30
|
+
const key = (0, proxy_key_utils_1.getSqlKey)(selection, query.alias);
|
|
31
|
+
return query[method](key, alias, condition, parameters);
|
|
32
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { ObjectLiteral } from 'typeorm';
|
|
2
|
+
import { ColumnValueType } from '../typeorm.types';
|
|
3
|
+
import { KeyHolder } from '../typeorm-querybuilder.types';
|
|
4
|
+
declare module 'typeorm/query-builder/SelectQueryBuilder' {
|
|
5
|
+
interface SelectQueryBuilder<Entity> {
|
|
6
|
+
/**
|
|
7
|
+
* Sets ORDER BY condition in the query builder.
|
|
8
|
+
* If you had previously ORDER BY expression defined,
|
|
9
|
+
* calling this function will override previously set ORDER BY conditions.
|
|
10
|
+
*/
|
|
11
|
+
orderByTyped<Type extends ObjectLiteral = Entity>(this: SelectQueryBuilder<Entity>, selection: (proxy: Type) => ColumnValueType | KeyHolder, order?: 'ASC' | 'DESC', nulls?: 'NULLS FIRST' | 'NULLS LAST'): SelectQueryBuilder<Entity>;
|
|
12
|
+
/**
|
|
13
|
+
* Adds ORDER BY condition in the query builder.
|
|
14
|
+
*/
|
|
15
|
+
addOrderByTyped<Type extends ObjectLiteral = Entity>(this: SelectQueryBuilder<Entity>, selection: (proxy: Type) => ColumnValueType | KeyHolder, order?: 'ASC' | 'DESC', nulls?: 'NULLS FIRST' | 'NULLS LAST'): SelectQueryBuilder<Entity>;
|
|
16
|
+
}
|
|
17
|
+
}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const typeorm_1 = require("typeorm");
|
|
4
|
+
const typeorm_querybuilder_types_1 = require("../typeorm-querybuilder.types");
|
|
5
|
+
const proxy_key_utils_1 = require("../../../utils/proxy-key.utils");
|
|
6
|
+
typeorm_1.SelectQueryBuilder.prototype.orderByTyped = function (selection, order, nulls) {
|
|
7
|
+
if (selection instanceof typeorm_querybuilder_types_1.KeyHolder) {
|
|
8
|
+
return this.orderBy(selection.toSql(), order, nulls);
|
|
9
|
+
}
|
|
10
|
+
if (typeof selection === 'function') {
|
|
11
|
+
const key = (0, proxy_key_utils_1.getSqlKey)(selection, this.alias);
|
|
12
|
+
return this.orderBy(key, order, nulls);
|
|
13
|
+
}
|
|
14
|
+
return this;
|
|
15
|
+
};
|
|
16
|
+
typeorm_1.SelectQueryBuilder.prototype.addOrderByTyped = function (selection, order, nulls) {
|
|
17
|
+
if (selection instanceof typeorm_querybuilder_types_1.KeyHolder) {
|
|
18
|
+
return this.addOrderBy(selection.toSql(), order, nulls);
|
|
19
|
+
}
|
|
20
|
+
if (typeof selection === 'function') {
|
|
21
|
+
const key = (0, proxy_key_utils_1.getSqlKey)(selection, this.alias);
|
|
22
|
+
return this.addOrderBy(key, order, nulls);
|
|
23
|
+
}
|
|
24
|
+
return this;
|
|
25
|
+
};
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { ObjectLiteral } from 'typeorm';
|
|
2
|
+
import { KeyHolder, KeyProxyCallback } from '../typeorm-querybuilder.types';
|
|
3
|
+
declare module 'typeorm/query-builder/SelectQueryBuilder' {
|
|
4
|
+
interface SelectQueryBuilder<Entity> {
|
|
5
|
+
/**
|
|
6
|
+
* Creates SELECT query.
|
|
7
|
+
* Replaces all previous selections if they exist.
|
|
8
|
+
*/
|
|
9
|
+
selectTyped<Type extends ObjectLiteral = Entity>(this: SelectQueryBuilder<Entity>, selection: KeyProxyCallback<Type>, selectionAliasName?: string): SelectQueryBuilder<Entity>;
|
|
10
|
+
/**
|
|
11
|
+
* Creates SELECT query and selects given data.
|
|
12
|
+
* Replaces all previous selections if they exist.
|
|
13
|
+
*/
|
|
14
|
+
selectTyped(this: SelectQueryBuilder<Entity>, selection: string | KeyHolder, selectionAliasName?: string): SelectQueryBuilder<Entity>;
|
|
15
|
+
/**
|
|
16
|
+
* Creates SELECT query and selects given data.
|
|
17
|
+
* Replaces all previous selections if they exist.
|
|
18
|
+
*/
|
|
19
|
+
selectTyped<Type extends ObjectLiteral = Entity>(this: SelectQueryBuilder<Entity>, selection: string[] | KeyHolder[] | Array<KeyProxyCallback<Type>>): SelectQueryBuilder<Entity>;
|
|
20
|
+
/**
|
|
21
|
+
* Adds new selection to the SELECT query.
|
|
22
|
+
*/
|
|
23
|
+
addSelectTyped<Type extends ObjectLiteral = Entity>(this: SelectQueryBuilder<Entity>, selection: KeyProxyCallback<Type>, selectionAliasName?: string): SelectQueryBuilder<Entity>;
|
|
24
|
+
/**
|
|
25
|
+
* Adds new selection to the SELECT query.
|
|
26
|
+
*/
|
|
27
|
+
addSelectTyped(this: SelectQueryBuilder<Entity>, selection: string | KeyHolder, selectionAliasName?: string): SelectQueryBuilder<Entity>;
|
|
28
|
+
/**
|
|
29
|
+
* Adds new selection to the SELECT query.
|
|
30
|
+
*/
|
|
31
|
+
addSelectTyped<Type extends ObjectLiteral = Entity>(this: SelectQueryBuilder<Entity>, selection: string[] | KeyHolder[] | Array<KeyProxyCallback<Type>>): SelectQueryBuilder<Entity>;
|
|
32
|
+
}
|
|
33
|
+
}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const typeorm_1 = require("typeorm");
|
|
4
|
+
const typeorm_querybuilder_types_1 = require("../typeorm-querybuilder.types");
|
|
5
|
+
const proxy_key_utils_1 = require("../../../utils/proxy-key.utils");
|
|
6
|
+
typeorm_1.SelectQueryBuilder.prototype.selectTyped = function (selection, selectionAliasName) {
|
|
7
|
+
return attachSelectMethod(this, 'select', selection, selectionAliasName);
|
|
8
|
+
};
|
|
9
|
+
typeorm_1.SelectQueryBuilder.prototype.addSelectTyped = function (selection, selectionAliasName) {
|
|
10
|
+
return attachSelectMethod(this, 'addSelect', selection, selectionAliasName);
|
|
11
|
+
};
|
|
12
|
+
const attachSelectMethod = (query, method, selection, selectionAliasName) => {
|
|
13
|
+
if (selection instanceof typeorm_querybuilder_types_1.KeyHolder) {
|
|
14
|
+
return query[method](selection.toSql(), selectionAliasName);
|
|
15
|
+
}
|
|
16
|
+
if (Array.isArray(selection)) {
|
|
17
|
+
const arrayOfKeys = selection.map((value) => (0, proxy_key_utils_1.getSqlKey)(value, query.alias));
|
|
18
|
+
return query[method](arrayOfKeys);
|
|
19
|
+
}
|
|
20
|
+
else if (typeof selection === 'function') {
|
|
21
|
+
const keyArrayOrSingleKey = (0, proxy_key_utils_1.getSqlKey)(selection, query.alias);
|
|
22
|
+
if (Array.isArray(keyArrayOrSingleKey)) {
|
|
23
|
+
return query[method](keyArrayOrSingleKey);
|
|
24
|
+
}
|
|
25
|
+
return query[method](keyArrayOrSingleKey, selectionAliasName);
|
|
26
|
+
}
|
|
27
|
+
else if (typeof selection === 'string') {
|
|
28
|
+
return query[method](selection, selectionAliasName);
|
|
29
|
+
}
|
|
30
|
+
return query;
|
|
31
|
+
};
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
import { ObjectLiteral } from 'typeorm';
|
|
2
|
+
import { ColumnValueType } from '../typeorm.types';
|
|
3
|
+
export interface TypedWhereOptions {
|
|
4
|
+
useDoubleQuotes?: boolean;
|
|
5
|
+
}
|
|
6
|
+
declare module 'typeorm/query-builder/WhereExpressionBuilder' {
|
|
7
|
+
interface WhereExpressionBuilder {
|
|
8
|
+
/**
|
|
9
|
+
* Sets WHERE condition in the query builder.
|
|
10
|
+
* If you had previously WHERE expression defined,
|
|
11
|
+
* calling this function will override previously set WHERE conditions.
|
|
12
|
+
* Additionally you can add parameters used in where expression.
|
|
13
|
+
*/
|
|
14
|
+
whereTyped<Type extends ObjectLiteral>(subQuery: (proxy: Type) => ColumnValueType, conditions: string, parameters?: ObjectLiteral, options?: TypedWhereOptions): this;
|
|
15
|
+
/**
|
|
16
|
+
* Adds new AND WHERE condition in the query builder.
|
|
17
|
+
* Additionally you can add parameters used in where expression.
|
|
18
|
+
*/
|
|
19
|
+
andWhereTyped<Type extends ObjectLiteral>(subQuery: (proxy: Type) => ColumnValueType, conditions: string, parameters?: ObjectLiteral, options?: TypedWhereOptions): this;
|
|
20
|
+
/**
|
|
21
|
+
* Adds new OR WHERE condition in the query builder.
|
|
22
|
+
* Additionally you can add parameters used in where expression.
|
|
23
|
+
*/
|
|
24
|
+
orWhereTyped<Type extends ObjectLiteral>(subQuery: (proxy: Type) => ColumnValueType, conditions: string, parameters?: ObjectLiteral, options?: TypedWhereOptions): this;
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
declare module 'typeorm/query-builder/SelectQueryBuilder' {
|
|
28
|
+
interface SelectQueryBuilder<Entity> {
|
|
29
|
+
/**
|
|
30
|
+
* Sets WHERE condition in the query builder.
|
|
31
|
+
* If you had previously WHERE expression defined,
|
|
32
|
+
* calling this function will override previously set WHERE conditions.
|
|
33
|
+
* Additionally you can add parameters used in where expression.
|
|
34
|
+
*/
|
|
35
|
+
whereTyped<Type extends ObjectLiteral = Entity>(where: (proxy: Type) => ColumnValueType, conditions: string, parameters?: ObjectLiteral, options?: TypedWhereOptions): this;
|
|
36
|
+
/**
|
|
37
|
+
* Adds new AND WHERE condition in the query builder.
|
|
38
|
+
* Additionally you can add parameters used in where expression.
|
|
39
|
+
*/
|
|
40
|
+
andWhereTyped<Type extends ObjectLiteral = Entity>(where: (proxy: Type) => ColumnValueType, conditions: string, parameters?: ObjectLiteral, options?: TypedWhereOptions): this;
|
|
41
|
+
/**
|
|
42
|
+
* Adds new OR WHERE condition in the query builder.
|
|
43
|
+
* Additionally you can add parameters used in where expression.
|
|
44
|
+
*/
|
|
45
|
+
orWhereTyped<Type extends ObjectLiteral = Entity>(where: (proxy: Type) => ColumnValueType, conditions: string, parameters?: ObjectLiteral, options?: TypedWhereOptions): this;
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
declare module 'typeorm/query-builder/UpdateQueryBuilder' {
|
|
49
|
+
interface UpdateQueryBuilder<Entity> {
|
|
50
|
+
/**
|
|
51
|
+
* Sets WHERE condition in the query builder.
|
|
52
|
+
* If you had previously WHERE expression defined,
|
|
53
|
+
* calling this function will override previously set WHERE conditions.
|
|
54
|
+
* Additionally you can add parameters used in where expression.
|
|
55
|
+
*/
|
|
56
|
+
whereTyped<Type extends ObjectLiteral = Entity>(where: (proxy: Type) => ColumnValueType, conditions: string, parameters?: ObjectLiteral, options?: TypedWhereOptions): this;
|
|
57
|
+
/**
|
|
58
|
+
* Adds new AND WHERE condition in the query builder.
|
|
59
|
+
* Additionally you can add parameters used in where expression.
|
|
60
|
+
*/
|
|
61
|
+
andWhereTyped<Type extends ObjectLiteral = Entity>(where: (proxy: Type) => ColumnValueType, conditions: string, parameters?: ObjectLiteral, options?: TypedWhereOptions): this;
|
|
62
|
+
/**
|
|
63
|
+
* Adds new OR WHERE condition in the query builder.
|
|
64
|
+
* Additionally you can add parameters used in where expression.
|
|
65
|
+
*/
|
|
66
|
+
orWhereTyped<Type extends ObjectLiteral = Entity>(where: (proxy: Type) => ColumnValueType, conditions: string, parameters?: ObjectLiteral, options?: TypedWhereOptions): this;
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
declare module 'typeorm/query-builder/DeleteQueryBuilder' {
|
|
70
|
+
interface DeleteQueryBuilder<Entity> {
|
|
71
|
+
/**
|
|
72
|
+
* Sets WHERE condition in the query builder.
|
|
73
|
+
* If you had previously WHERE expression defined,
|
|
74
|
+
* calling this function will override previously set WHERE conditions.
|
|
75
|
+
* Additionally you can add parameters used in where expression.
|
|
76
|
+
*/
|
|
77
|
+
whereTyped<Type extends ObjectLiteral = Entity>(where: (proxy: Type) => ColumnValueType, conditions: string, parameters?: ObjectLiteral, options?: TypedWhereOptions): this;
|
|
78
|
+
/**
|
|
79
|
+
* Adds new AND WHERE condition in the query builder.
|
|
80
|
+
* Additionally you can add parameters used in where expression.
|
|
81
|
+
*/
|
|
82
|
+
andWhereTyped<Type extends ObjectLiteral = Entity>(where: (proxy: Type) => ColumnValueType, conditions: string, parameters?: ObjectLiteral, options?: TypedWhereOptions): this;
|
|
83
|
+
/**
|
|
84
|
+
* Adds new OR WHERE condition in the query builder.
|
|
85
|
+
* Additionally you can add parameters used in where expression.
|
|
86
|
+
*/
|
|
87
|
+
orWhereTyped<Type extends ObjectLiteral = Entity>(where: (proxy: Type) => ColumnValueType, conditions: string, parameters?: ObjectLiteral, options?: TypedWhereOptions): this;
|
|
88
|
+
}
|
|
89
|
+
}
|
|
@@ -0,0 +1,33 @@
|
|
|
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 queryBuilders = [
|
|
6
|
+
typeorm_1.SelectQueryBuilder,
|
|
7
|
+
typeorm_1.UpdateQueryBuilder,
|
|
8
|
+
typeorm_1.DeleteQueryBuilder,
|
|
9
|
+
];
|
|
10
|
+
const extension = {
|
|
11
|
+
prototype: {
|
|
12
|
+
whereTyped: function (where, conditions, parameters, options) {
|
|
13
|
+
return attachWhere(this, 'where', where, conditions, parameters, options);
|
|
14
|
+
},
|
|
15
|
+
andWhereTyped: function (where, conditions, parameters, options) {
|
|
16
|
+
return attachWhere(this, 'andWhere', where, conditions, parameters, options);
|
|
17
|
+
},
|
|
18
|
+
orWhereTyped: function (where, conditions, parameters, options) {
|
|
19
|
+
return attachWhere(this, 'orWhere', where, conditions, parameters, options);
|
|
20
|
+
},
|
|
21
|
+
},
|
|
22
|
+
};
|
|
23
|
+
queryBuilders.forEach((builder) => {
|
|
24
|
+
Object.assign(builder, extension);
|
|
25
|
+
});
|
|
26
|
+
function attachWhere(builder, method, where, conditions, parameters, options) {
|
|
27
|
+
if (typeof where === 'function') {
|
|
28
|
+
const key = (0, proxy_key_utils_1.getSqlKey)(where, builder.alias, options === null || options === void 0 ? void 0 : options.useDoubleQuotes);
|
|
29
|
+
// .andWhere(`"table"."column" IN (:...values)`, { values: ['value'] })
|
|
30
|
+
return builder[method](`${key} ${conditions}`, parameters);
|
|
31
|
+
}
|
|
32
|
+
return builder;
|
|
33
|
+
}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { ObjectLiteral } from 'typeorm';
|
|
2
|
+
import { ColumnValueType, EntityOnlyWithRelations, EntityWithoutRelations } from './typeorm.types';
|
|
3
|
+
export declare class KeyHolder {
|
|
4
|
+
keys: string[];
|
|
5
|
+
constructor(keys?: string[]);
|
|
6
|
+
toSql(length?: number, addDobleQuotes?: boolean): string;
|
|
7
|
+
toString(length?: number): string;
|
|
8
|
+
valueOf(): string;
|
|
9
|
+
[Symbol.toPrimitive](): string;
|
|
10
|
+
add(key: string | symbol): this;
|
|
11
|
+
}
|
|
12
|
+
export declare class TypedProxy {
|
|
13
|
+
static defaultHandler: {};
|
|
14
|
+
static create<T extends ObjectLiteral>(obj: object, handler?: {}): T;
|
|
15
|
+
}
|
|
16
|
+
export declare class KeyProxy {
|
|
17
|
+
static defaultHandler: ProxyHandler<KeyHolder>;
|
|
18
|
+
static create<T extends ObjectLiteral>(): T;
|
|
19
|
+
}
|
|
20
|
+
export type KeyProxyCallback<T extends ObjectLiteral> = (proxy: T) => ColumnValueType | Array<ColumnValueType>;
|
|
21
|
+
export type RelationalKeyProxyCallback<T extends ObjectLiteral> = (proxy: EntityOnlyWithRelations<T>) => ColumnValueType;
|
|
22
|
+
export type NonRelationalKeyProxyCallback<T extends ObjectLiteral> = (proxy: EntityWithoutRelations<T>) => ColumnValueType;
|