typeorm-extensions 1.2.2 → 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/README.md +1 -1
- 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
|
@@ -1,141 +0,0 @@
|
|
|
1
|
-
import { ObjectLiteral, SelectQueryBuilder } from 'typeorm';
|
|
2
|
-
import { RelationalKeyProxyCallback } from '../typeorm-querybuilder.types';
|
|
3
|
-
import { getSqlKey } from '../../../utils/proxy-key.utils';
|
|
4
|
-
|
|
5
|
-
declare module 'typeorm/query-builder/SelectQueryBuilder' {
|
|
6
|
-
interface SelectQueryBuilder<Entity> {
|
|
7
|
-
leftJoinTyped<Type extends ObjectLiteral = Entity>(
|
|
8
|
-
this: SelectQueryBuilder<Entity>,
|
|
9
|
-
selection: RelationalKeyProxyCallback<Type>,
|
|
10
|
-
alias: string,
|
|
11
|
-
condition?: string,
|
|
12
|
-
parameters?: ObjectLiteral
|
|
13
|
-
): SelectQueryBuilder<Entity>;
|
|
14
|
-
innerJoinTyped<Type extends ObjectLiteral = Entity>(
|
|
15
|
-
this: SelectQueryBuilder<Entity>,
|
|
16
|
-
selection: RelationalKeyProxyCallback<Type>,
|
|
17
|
-
alias: string,
|
|
18
|
-
condition?: string,
|
|
19
|
-
parameters?: ObjectLiteral
|
|
20
|
-
): SelectQueryBuilder<Entity>;
|
|
21
|
-
|
|
22
|
-
leftJoinAndSelectTyped<Type extends ObjectLiteral = Entity>(
|
|
23
|
-
this: SelectQueryBuilder<Entity>,
|
|
24
|
-
selection: RelationalKeyProxyCallback<Type>,
|
|
25
|
-
alias: string,
|
|
26
|
-
condition?: string,
|
|
27
|
-
parameters?: ObjectLiteral
|
|
28
|
-
): SelectQueryBuilder<Entity>;
|
|
29
|
-
innerJoinAndSelectTyped<Type extends ObjectLiteral = Entity>(
|
|
30
|
-
this: SelectQueryBuilder<Entity>,
|
|
31
|
-
selection: RelationalKeyProxyCallback<Type>,
|
|
32
|
-
alias: string,
|
|
33
|
-
condition?: string,
|
|
34
|
-
parameters?: ObjectLiteral
|
|
35
|
-
): SelectQueryBuilder<Entity>;
|
|
36
|
-
}
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
SelectQueryBuilder.prototype.leftJoinTyped = function <
|
|
40
|
-
Entity extends ObjectLiteral,
|
|
41
|
-
Type extends ObjectLiteral = Entity
|
|
42
|
-
>(
|
|
43
|
-
this: SelectQueryBuilder<Entity>,
|
|
44
|
-
selection: RelationalKeyProxyCallback<Type>,
|
|
45
|
-
alias: string,
|
|
46
|
-
condition?: string,
|
|
47
|
-
parameters?: ObjectLiteral
|
|
48
|
-
) {
|
|
49
|
-
if (typeof selection === 'function') {
|
|
50
|
-
return addJoin(this, 'leftJoin', selection, alias, condition, parameters);
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
return this;
|
|
54
|
-
};
|
|
55
|
-
|
|
56
|
-
SelectQueryBuilder.prototype.innerJoinTyped = function <
|
|
57
|
-
Entity extends ObjectLiteral,
|
|
58
|
-
Type extends ObjectLiteral = Entity
|
|
59
|
-
>(
|
|
60
|
-
this: SelectQueryBuilder<Entity>,
|
|
61
|
-
selection: RelationalKeyProxyCallback<Type>,
|
|
62
|
-
alias: string,
|
|
63
|
-
condition?: string,
|
|
64
|
-
parameters?: ObjectLiteral
|
|
65
|
-
) {
|
|
66
|
-
if (typeof selection === 'function') {
|
|
67
|
-
return addJoin(this, 'innerJoin', selection, alias, condition, parameters);
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
return this;
|
|
71
|
-
};
|
|
72
|
-
|
|
73
|
-
SelectQueryBuilder.prototype.leftJoinAndSelectTyped = function <
|
|
74
|
-
Entity extends ObjectLiteral,
|
|
75
|
-
Type extends ObjectLiteral = Entity
|
|
76
|
-
>(
|
|
77
|
-
this: SelectQueryBuilder<Entity>,
|
|
78
|
-
selection: RelationalKeyProxyCallback<Type>,
|
|
79
|
-
alias: string,
|
|
80
|
-
condition?: string,
|
|
81
|
-
parameters?: ObjectLiteral
|
|
82
|
-
) {
|
|
83
|
-
if (typeof selection === 'function') {
|
|
84
|
-
return addJoin(
|
|
85
|
-
this,
|
|
86
|
-
'leftJoinAndSelect',
|
|
87
|
-
selection,
|
|
88
|
-
alias,
|
|
89
|
-
condition,
|
|
90
|
-
parameters
|
|
91
|
-
);
|
|
92
|
-
}
|
|
93
|
-
|
|
94
|
-
return this;
|
|
95
|
-
};
|
|
96
|
-
|
|
97
|
-
SelectQueryBuilder.prototype.innerJoinAndSelectTyped = function <
|
|
98
|
-
Entity extends ObjectLiteral,
|
|
99
|
-
Type extends ObjectLiteral = Entity
|
|
100
|
-
>(
|
|
101
|
-
this: SelectQueryBuilder<Entity>,
|
|
102
|
-
selection: RelationalKeyProxyCallback<Type>,
|
|
103
|
-
alias: string,
|
|
104
|
-
condition?: string,
|
|
105
|
-
parameters?: ObjectLiteral
|
|
106
|
-
) {
|
|
107
|
-
if (typeof selection === 'function') {
|
|
108
|
-
return addJoin(
|
|
109
|
-
this,
|
|
110
|
-
'innerJoinAndSelect',
|
|
111
|
-
selection,
|
|
112
|
-
alias,
|
|
113
|
-
condition,
|
|
114
|
-
parameters
|
|
115
|
-
);
|
|
116
|
-
}
|
|
117
|
-
|
|
118
|
-
return this;
|
|
119
|
-
};
|
|
120
|
-
|
|
121
|
-
type JoinMethod =
|
|
122
|
-
| 'leftJoin'
|
|
123
|
-
| 'innerJoin'
|
|
124
|
-
| 'leftJoinAndSelect'
|
|
125
|
-
| 'innerJoinAndSelect';
|
|
126
|
-
|
|
127
|
-
function addJoin<
|
|
128
|
-
Entity extends ObjectLiteral,
|
|
129
|
-
Type extends ObjectLiteral = Entity
|
|
130
|
-
>(
|
|
131
|
-
query: SelectQueryBuilder<Entity>,
|
|
132
|
-
method: JoinMethod,
|
|
133
|
-
selection: RelationalKeyProxyCallback<Type>,
|
|
134
|
-
alias: string,
|
|
135
|
-
condition?: string,
|
|
136
|
-
parameters?: ObjectLiteral
|
|
137
|
-
) {
|
|
138
|
-
const key = getSqlKey<Type>(selection, query.alias) as string;
|
|
139
|
-
|
|
140
|
-
return query[method](key, alias, condition, parameters);
|
|
141
|
-
}
|
|
@@ -1,73 +0,0 @@
|
|
|
1
|
-
import { ObjectLiteral, SelectQueryBuilder } from 'typeorm';
|
|
2
|
-
import { ColumnValueType } from '../typeorm.types';
|
|
3
|
-
import { KeyHolder } from '../typeorm-querybuilder.types';
|
|
4
|
-
import { getSqlKey } from '../../../utils/proxy-key.utils';
|
|
5
|
-
|
|
6
|
-
declare module 'typeorm/query-builder/SelectQueryBuilder' {
|
|
7
|
-
interface SelectQueryBuilder<Entity> {
|
|
8
|
-
/**
|
|
9
|
-
* Sets ORDER BY condition in the query builder.
|
|
10
|
-
* If you had previously ORDER BY expression defined,
|
|
11
|
-
* calling this function will override previously set ORDER BY conditions.
|
|
12
|
-
*/
|
|
13
|
-
orderByTyped<Type extends ObjectLiteral = Entity>(
|
|
14
|
-
this: SelectQueryBuilder<Entity>,
|
|
15
|
-
selection: (proxy: Type) => ColumnValueType | KeyHolder,
|
|
16
|
-
order?: 'ASC' | 'DESC',
|
|
17
|
-
nulls?: 'NULLS FIRST' | 'NULLS LAST'
|
|
18
|
-
): SelectQueryBuilder<Entity>;
|
|
19
|
-
/**
|
|
20
|
-
* Adds ORDER BY condition in the query builder.
|
|
21
|
-
*/
|
|
22
|
-
addOrderByTyped<Type extends ObjectLiteral = Entity>(
|
|
23
|
-
this: SelectQueryBuilder<Entity>,
|
|
24
|
-
selection: (proxy: Type) => ColumnValueType | KeyHolder,
|
|
25
|
-
order?: 'ASC' | 'DESC',
|
|
26
|
-
nulls?: 'NULLS FIRST' | 'NULLS LAST'
|
|
27
|
-
): SelectQueryBuilder<Entity>;
|
|
28
|
-
}
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
SelectQueryBuilder.prototype.orderByTyped = function <
|
|
32
|
-
Entity extends ObjectLiteral,
|
|
33
|
-
Type extends ObjectLiteral = Entity
|
|
34
|
-
>(
|
|
35
|
-
this: SelectQueryBuilder<Entity>,
|
|
36
|
-
selection?: (proxy: Type) => ColumnValueType | KeyHolder,
|
|
37
|
-
order?: 'ASC' | 'DESC',
|
|
38
|
-
nulls?: 'NULLS FIRST' | 'NULLS LAST'
|
|
39
|
-
): SelectQueryBuilder<Entity> {
|
|
40
|
-
if (selection instanceof KeyHolder) {
|
|
41
|
-
return this.orderBy(selection.toSql(), order, nulls);
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
if (typeof selection === 'function') {
|
|
45
|
-
const key = getSqlKey<Type>(selection, this.alias) as string;
|
|
46
|
-
|
|
47
|
-
return this.orderBy(key, order, nulls);
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
return this;
|
|
51
|
-
};
|
|
52
|
-
|
|
53
|
-
SelectQueryBuilder.prototype.addOrderByTyped = function <
|
|
54
|
-
Entity extends ObjectLiteral,
|
|
55
|
-
Type extends ObjectLiteral = Entity
|
|
56
|
-
>(
|
|
57
|
-
this: SelectQueryBuilder<Entity>,
|
|
58
|
-
selection?: (proxy: Type) => ColumnValueType | KeyHolder,
|
|
59
|
-
order?: 'ASC' | 'DESC',
|
|
60
|
-
nulls?: 'NULLS FIRST' | 'NULLS LAST'
|
|
61
|
-
): SelectQueryBuilder<Entity> {
|
|
62
|
-
if (selection instanceof KeyHolder) {
|
|
63
|
-
return this.addOrderBy(selection.toSql(), order, nulls);
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
if (typeof selection === 'function') {
|
|
67
|
-
const key = getSqlKey<Type>(selection, this.alias) as string;
|
|
68
|
-
|
|
69
|
-
return this.addOrderBy(key, order, nulls);
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
return this;
|
|
73
|
-
};
|
|
@@ -1,124 +0,0 @@
|
|
|
1
|
-
import { ObjectLiteral, SelectQueryBuilder } from 'typeorm';
|
|
2
|
-
import { KeyHolder, KeyProxyCallback } from '../typeorm-querybuilder.types';
|
|
3
|
-
import { getSqlKey } from '../../../utils/proxy-key.utils';
|
|
4
|
-
|
|
5
|
-
declare module 'typeorm/query-builder/SelectQueryBuilder' {
|
|
6
|
-
interface SelectQueryBuilder<Entity> {
|
|
7
|
-
/**
|
|
8
|
-
* Creates SELECT query.
|
|
9
|
-
* Replaces all previous selections if they exist.
|
|
10
|
-
*/
|
|
11
|
-
selectTyped<Type extends ObjectLiteral = Entity>(
|
|
12
|
-
this: SelectQueryBuilder<Entity>,
|
|
13
|
-
selection: KeyProxyCallback<Type>,
|
|
14
|
-
selectionAliasName?: string
|
|
15
|
-
): SelectQueryBuilder<Entity>;
|
|
16
|
-
/**
|
|
17
|
-
* Creates SELECT query and selects given data.
|
|
18
|
-
* Replaces all previous selections if they exist.
|
|
19
|
-
*/
|
|
20
|
-
selectTyped(
|
|
21
|
-
this: SelectQueryBuilder<Entity>,
|
|
22
|
-
selection: string | KeyHolder,
|
|
23
|
-
selectionAliasName?: string
|
|
24
|
-
): SelectQueryBuilder<Entity>;
|
|
25
|
-
/**
|
|
26
|
-
* Creates SELECT query and selects given data.
|
|
27
|
-
* Replaces all previous selections if they exist.
|
|
28
|
-
*/
|
|
29
|
-
selectTyped<Type extends ObjectLiteral = Entity>(
|
|
30
|
-
this: SelectQueryBuilder<Entity>,
|
|
31
|
-
selection: string[] | KeyHolder[] | Array<KeyProxyCallback<Type>>
|
|
32
|
-
): SelectQueryBuilder<Entity>;
|
|
33
|
-
|
|
34
|
-
/**
|
|
35
|
-
* Adds new selection to the SELECT query.
|
|
36
|
-
*/
|
|
37
|
-
addSelectTyped<Type extends ObjectLiteral = Entity>(
|
|
38
|
-
this: SelectQueryBuilder<Entity>,
|
|
39
|
-
selection: KeyProxyCallback<Type>,
|
|
40
|
-
selectionAliasName?: string
|
|
41
|
-
): SelectQueryBuilder<Entity>;
|
|
42
|
-
/**
|
|
43
|
-
* Adds new selection to the SELECT query.
|
|
44
|
-
*/
|
|
45
|
-
addSelectTyped(
|
|
46
|
-
this: SelectQueryBuilder<Entity>,
|
|
47
|
-
selection: string | KeyHolder,
|
|
48
|
-
selectionAliasName?: string
|
|
49
|
-
): SelectQueryBuilder<Entity>;
|
|
50
|
-
/**
|
|
51
|
-
* Adds new selection to the SELECT query.
|
|
52
|
-
*/
|
|
53
|
-
addSelectTyped<Type extends ObjectLiteral = Entity>(
|
|
54
|
-
this: SelectQueryBuilder<Entity>,
|
|
55
|
-
selection: string[] | KeyHolder[] | Array<KeyProxyCallback<Type>>
|
|
56
|
-
): SelectQueryBuilder<Entity>;
|
|
57
|
-
}
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
SelectQueryBuilder.prototype.selectTyped = function <Entity extends ObjectLiteral, Type extends ObjectLiteral = Entity>(
|
|
61
|
-
this: SelectQueryBuilder<Entity>,
|
|
62
|
-
selection?:
|
|
63
|
-
| string
|
|
64
|
-
| KeyHolder
|
|
65
|
-
| KeyProxyCallback<Type>
|
|
66
|
-
| string[]
|
|
67
|
-
| KeyHolder[]
|
|
68
|
-
| Array<KeyProxyCallback<Type>>,
|
|
69
|
-
selectionAliasName?: string
|
|
70
|
-
): SelectQueryBuilder<Entity> {
|
|
71
|
-
return attachSelectMethod<Entity, Type>(this, 'select', selection, selectionAliasName);
|
|
72
|
-
};
|
|
73
|
-
|
|
74
|
-
SelectQueryBuilder.prototype.addSelectTyped = function <
|
|
75
|
-
Entity extends ObjectLiteral,
|
|
76
|
-
Type extends ObjectLiteral = Entity
|
|
77
|
-
>(
|
|
78
|
-
this: SelectQueryBuilder<Entity>,
|
|
79
|
-
selection?:
|
|
80
|
-
| string
|
|
81
|
-
| KeyHolder
|
|
82
|
-
| KeyProxyCallback<Type>
|
|
83
|
-
| string[]
|
|
84
|
-
| KeyHolder[]
|
|
85
|
-
| Array<KeyProxyCallback<Type>>,
|
|
86
|
-
selectionAliasName?: string
|
|
87
|
-
): SelectQueryBuilder<Entity> {
|
|
88
|
-
return attachSelectMethod<Entity, Type>(this, 'addSelect', selection, selectionAliasName);
|
|
89
|
-
};
|
|
90
|
-
|
|
91
|
-
const attachSelectMethod = <Entity extends ObjectLiteral, Type extends ObjectLiteral = Entity>(
|
|
92
|
-
query: SelectQueryBuilder<Entity>,
|
|
93
|
-
method: 'select' | 'addSelect',
|
|
94
|
-
selection?:
|
|
95
|
-
| string
|
|
96
|
-
| KeyHolder
|
|
97
|
-
| KeyProxyCallback<Type>
|
|
98
|
-
| string[]
|
|
99
|
-
| KeyHolder[]
|
|
100
|
-
| Array<KeyProxyCallback<Type>>,
|
|
101
|
-
selectionAliasName?: string
|
|
102
|
-
): SelectQueryBuilder<Entity> => {
|
|
103
|
-
if (selection instanceof KeyHolder) {
|
|
104
|
-
return query[method](selection.toSql(), selectionAliasName);
|
|
105
|
-
}
|
|
106
|
-
|
|
107
|
-
if (Array.isArray(selection)) {
|
|
108
|
-
const arrayOfKeys = selection.map((value) => getSqlKey<Type>(value, query.alias) as string);
|
|
109
|
-
|
|
110
|
-
return query[method](arrayOfKeys);
|
|
111
|
-
} else if (typeof selection === 'function') {
|
|
112
|
-
const keyArrayOrSingleKey = getSqlKey<Type>(selection, query.alias);
|
|
113
|
-
|
|
114
|
-
if (Array.isArray(keyArrayOrSingleKey)) {
|
|
115
|
-
return query[method](keyArrayOrSingleKey);
|
|
116
|
-
}
|
|
117
|
-
|
|
118
|
-
return query[method](keyArrayOrSingleKey, selectionAliasName);
|
|
119
|
-
} else if (typeof selection === 'string') {
|
|
120
|
-
return query[method](selection, selectionAliasName);
|
|
121
|
-
}
|
|
122
|
-
|
|
123
|
-
return query;
|
|
124
|
-
};
|
|
@@ -1,268 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
ObjectLiteral,
|
|
3
|
-
SelectQueryBuilder,
|
|
4
|
-
WhereExpressionBuilder,
|
|
5
|
-
UpdateQueryBuilder,
|
|
6
|
-
DeleteQueryBuilder,
|
|
7
|
-
} from 'typeorm';
|
|
8
|
-
import { ColumnValueType } from '../typeorm.types';
|
|
9
|
-
import { getSqlKey } from '../../../utils/proxy-key.utils';
|
|
10
|
-
|
|
11
|
-
export interface TypedWhereOptions {
|
|
12
|
-
useDoubleQuotes?: boolean;
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
declare module 'typeorm/query-builder/WhereExpressionBuilder' {
|
|
16
|
-
interface WhereExpressionBuilder {
|
|
17
|
-
/**
|
|
18
|
-
* Sets WHERE condition in the query builder.
|
|
19
|
-
* If you had previously WHERE expression defined,
|
|
20
|
-
* calling this function will override previously set WHERE conditions.
|
|
21
|
-
* Additionally you can add parameters used in where expression.
|
|
22
|
-
*/
|
|
23
|
-
whereTyped<Type extends ObjectLiteral>(
|
|
24
|
-
subQuery: (proxy: Type) => ColumnValueType,
|
|
25
|
-
conditions: string,
|
|
26
|
-
parameters?: ObjectLiteral,
|
|
27
|
-
options?: TypedWhereOptions
|
|
28
|
-
): this;
|
|
29
|
-
|
|
30
|
-
/**
|
|
31
|
-
* Adds new AND WHERE condition in the query builder.
|
|
32
|
-
* Additionally you can add parameters used in where expression.
|
|
33
|
-
*/
|
|
34
|
-
andWhereTyped<Type extends ObjectLiteral>(
|
|
35
|
-
subQuery: (proxy: Type) => ColumnValueType,
|
|
36
|
-
conditions: string,
|
|
37
|
-
parameters?: ObjectLiteral,
|
|
38
|
-
options?: TypedWhereOptions
|
|
39
|
-
): this;
|
|
40
|
-
|
|
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>(
|
|
46
|
-
subQuery: (proxy: Type) => ColumnValueType,
|
|
47
|
-
conditions: string,
|
|
48
|
-
parameters?: ObjectLiteral,
|
|
49
|
-
options?: TypedWhereOptions
|
|
50
|
-
): this;
|
|
51
|
-
}
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
declare module 'typeorm/query-builder/SelectQueryBuilder' {
|
|
55
|
-
interface SelectQueryBuilder<Entity> {
|
|
56
|
-
/**
|
|
57
|
-
* Sets WHERE condition in the query builder.
|
|
58
|
-
* If you had previously WHERE expression defined,
|
|
59
|
-
* calling this function will override previously set WHERE conditions.
|
|
60
|
-
* Additionally you can add parameters used in where expression.
|
|
61
|
-
*/
|
|
62
|
-
whereTyped<Type extends ObjectLiteral = Entity>(
|
|
63
|
-
where: (proxy: Type) => ColumnValueType,
|
|
64
|
-
conditions: string,
|
|
65
|
-
parameters?: ObjectLiteral,
|
|
66
|
-
options?: TypedWhereOptions
|
|
67
|
-
): this;
|
|
68
|
-
|
|
69
|
-
/**
|
|
70
|
-
* Adds new AND WHERE condition in the query builder.
|
|
71
|
-
* Additionally you can add parameters used in where expression.
|
|
72
|
-
*/
|
|
73
|
-
andWhereTyped<Type extends ObjectLiteral = Entity>(
|
|
74
|
-
where: (proxy: Type) => ColumnValueType,
|
|
75
|
-
conditions: string,
|
|
76
|
-
parameters?: ObjectLiteral,
|
|
77
|
-
options?: TypedWhereOptions
|
|
78
|
-
): this;
|
|
79
|
-
|
|
80
|
-
/**
|
|
81
|
-
* Adds new OR WHERE condition in the query builder.
|
|
82
|
-
* Additionally you can add parameters used in where expression.
|
|
83
|
-
*/
|
|
84
|
-
orWhereTyped<Type extends ObjectLiteral = Entity>(
|
|
85
|
-
where: (proxy: Type) => ColumnValueType,
|
|
86
|
-
conditions: string,
|
|
87
|
-
parameters?: ObjectLiteral,
|
|
88
|
-
options?: TypedWhereOptions
|
|
89
|
-
): this;
|
|
90
|
-
}
|
|
91
|
-
}
|
|
92
|
-
|
|
93
|
-
declare module 'typeorm/query-builder/UpdateQueryBuilder' {
|
|
94
|
-
interface UpdateQueryBuilder<Entity> {
|
|
95
|
-
/**
|
|
96
|
-
* Sets WHERE condition in the query builder.
|
|
97
|
-
* If you had previously WHERE expression defined,
|
|
98
|
-
* calling this function will override previously set WHERE conditions.
|
|
99
|
-
* Additionally you can add parameters used in where expression.
|
|
100
|
-
*/
|
|
101
|
-
whereTyped<Type extends ObjectLiteral = Entity>(
|
|
102
|
-
where: (proxy: Type) => ColumnValueType,
|
|
103
|
-
conditions: string,
|
|
104
|
-
parameters?: ObjectLiteral,
|
|
105
|
-
options?: TypedWhereOptions
|
|
106
|
-
): this;
|
|
107
|
-
|
|
108
|
-
/**
|
|
109
|
-
* Adds new AND WHERE condition in the query builder.
|
|
110
|
-
* Additionally you can add parameters used in where expression.
|
|
111
|
-
*/
|
|
112
|
-
andWhereTyped<Type extends ObjectLiteral = Entity>(
|
|
113
|
-
where: (proxy: Type) => ColumnValueType,
|
|
114
|
-
conditions: string,
|
|
115
|
-
parameters?: ObjectLiteral,
|
|
116
|
-
options?: TypedWhereOptions
|
|
117
|
-
): this;
|
|
118
|
-
|
|
119
|
-
/**
|
|
120
|
-
* Adds new OR WHERE condition in the query builder.
|
|
121
|
-
* Additionally you can add parameters used in where expression.
|
|
122
|
-
*/
|
|
123
|
-
orWhereTyped<Type extends ObjectLiteral = Entity>(
|
|
124
|
-
where: (proxy: Type) => ColumnValueType,
|
|
125
|
-
conditions: string,
|
|
126
|
-
parameters?: ObjectLiteral,
|
|
127
|
-
options?: TypedWhereOptions
|
|
128
|
-
): this;
|
|
129
|
-
}
|
|
130
|
-
}
|
|
131
|
-
|
|
132
|
-
declare module 'typeorm/query-builder/DeleteQueryBuilder' {
|
|
133
|
-
interface DeleteQueryBuilder<Entity> {
|
|
134
|
-
/**
|
|
135
|
-
* Sets WHERE condition in the query builder.
|
|
136
|
-
* If you had previously WHERE expression defined,
|
|
137
|
-
* calling this function will override previously set WHERE conditions.
|
|
138
|
-
* Additionally you can add parameters used in where expression.
|
|
139
|
-
*/
|
|
140
|
-
whereTyped<Type extends ObjectLiteral = Entity>(
|
|
141
|
-
where: (proxy: Type) => ColumnValueType,
|
|
142
|
-
conditions: string,
|
|
143
|
-
parameters?: ObjectLiteral,
|
|
144
|
-
options?: TypedWhereOptions
|
|
145
|
-
): this;
|
|
146
|
-
|
|
147
|
-
/**
|
|
148
|
-
* Adds new AND WHERE condition in the query builder.
|
|
149
|
-
* Additionally you can add parameters used in where expression.
|
|
150
|
-
*/
|
|
151
|
-
andWhereTyped<Type extends ObjectLiteral = Entity>(
|
|
152
|
-
where: (proxy: Type) => ColumnValueType,
|
|
153
|
-
conditions: string,
|
|
154
|
-
parameters?: ObjectLiteral,
|
|
155
|
-
options?: TypedWhereOptions
|
|
156
|
-
): this;
|
|
157
|
-
|
|
158
|
-
/**
|
|
159
|
-
* Adds new OR WHERE condition in the query builder.
|
|
160
|
-
* Additionally you can add parameters used in where expression.
|
|
161
|
-
*/
|
|
162
|
-
orWhereTyped<Type extends ObjectLiteral = Entity>(
|
|
163
|
-
where: (proxy: Type) => ColumnValueType,
|
|
164
|
-
conditions: string,
|
|
165
|
-
parameters?: ObjectLiteral,
|
|
166
|
-
options?: TypedWhereOptions
|
|
167
|
-
): this;
|
|
168
|
-
}
|
|
169
|
-
}
|
|
170
|
-
|
|
171
|
-
const queryBuilders = [
|
|
172
|
-
SelectQueryBuilder,
|
|
173
|
-
UpdateQueryBuilder,
|
|
174
|
-
DeleteQueryBuilder,
|
|
175
|
-
];
|
|
176
|
-
|
|
177
|
-
const extension = {
|
|
178
|
-
prototype: {
|
|
179
|
-
whereTyped: function <
|
|
180
|
-
Entity extends ObjectLiteral,
|
|
181
|
-
Type extends ObjectLiteral = Entity
|
|
182
|
-
>(
|
|
183
|
-
this: SelectQueryBuilder<Entity>,
|
|
184
|
-
where: (proxy: Type) => ColumnValueType,
|
|
185
|
-
conditions: string,
|
|
186
|
-
parameters?: ObjectLiteral,
|
|
187
|
-
options?: TypedWhereOptions
|
|
188
|
-
): SelectQueryBuilder<Entity> {
|
|
189
|
-
return attachWhere<Type, SelectQueryBuilder<Entity>>(
|
|
190
|
-
this,
|
|
191
|
-
'where',
|
|
192
|
-
where,
|
|
193
|
-
conditions,
|
|
194
|
-
parameters,
|
|
195
|
-
options
|
|
196
|
-
);
|
|
197
|
-
},
|
|
198
|
-
andWhereTyped: function <
|
|
199
|
-
Entity extends ObjectLiteral,
|
|
200
|
-
Type extends ObjectLiteral = Entity
|
|
201
|
-
>(
|
|
202
|
-
this: SelectQueryBuilder<Entity>,
|
|
203
|
-
where: (proxy: Type) => ColumnValueType,
|
|
204
|
-
conditions: string,
|
|
205
|
-
parameters?: ObjectLiteral,
|
|
206
|
-
options?: TypedWhereOptions
|
|
207
|
-
): SelectQueryBuilder<Entity> {
|
|
208
|
-
return attachWhere<Type, SelectQueryBuilder<Entity>>(
|
|
209
|
-
this,
|
|
210
|
-
'andWhere',
|
|
211
|
-
where,
|
|
212
|
-
conditions,
|
|
213
|
-
parameters,
|
|
214
|
-
options
|
|
215
|
-
);
|
|
216
|
-
},
|
|
217
|
-
orWhereTyped: function <
|
|
218
|
-
Entity extends ObjectLiteral,
|
|
219
|
-
Type extends ObjectLiteral = Entity
|
|
220
|
-
>(
|
|
221
|
-
this: SelectQueryBuilder<Entity>,
|
|
222
|
-
where: (proxy: Type) => ColumnValueType,
|
|
223
|
-
conditions: string,
|
|
224
|
-
parameters?: ObjectLiteral,
|
|
225
|
-
options?: TypedWhereOptions
|
|
226
|
-
): SelectQueryBuilder<Entity> {
|
|
227
|
-
return attachWhere<Type, SelectQueryBuilder<Entity>>(
|
|
228
|
-
this,
|
|
229
|
-
'orWhere',
|
|
230
|
-
where,
|
|
231
|
-
conditions,
|
|
232
|
-
parameters,
|
|
233
|
-
options
|
|
234
|
-
);
|
|
235
|
-
},
|
|
236
|
-
},
|
|
237
|
-
};
|
|
238
|
-
|
|
239
|
-
queryBuilders.forEach((builder) => {
|
|
240
|
-
Object.assign(builder, extension);
|
|
241
|
-
});
|
|
242
|
-
|
|
243
|
-
type WhereMethod = 'where' | 'andWhere' | 'orWhere';
|
|
244
|
-
|
|
245
|
-
function attachWhere<
|
|
246
|
-
Type extends ObjectLiteral,
|
|
247
|
-
Q extends WhereExpressionBuilder = WhereExpressionBuilder
|
|
248
|
-
>(
|
|
249
|
-
builder: Q,
|
|
250
|
-
method: WhereMethod,
|
|
251
|
-
where: (proxy: Type) => ColumnValueType,
|
|
252
|
-
conditions: string,
|
|
253
|
-
parameters?: ObjectLiteral,
|
|
254
|
-
options?: TypedWhereOptions
|
|
255
|
-
): Q {
|
|
256
|
-
if (typeof where === 'function') {
|
|
257
|
-
const key = getSqlKey<Type>(
|
|
258
|
-
where,
|
|
259
|
-
(builder as unknown as SelectQueryBuilder<Type>).alias,
|
|
260
|
-
options?.useDoubleQuotes
|
|
261
|
-
);
|
|
262
|
-
|
|
263
|
-
// .andWhere(`"table"."column" IN (:...values)`, { values: ['value'] })
|
|
264
|
-
return builder[method](`${key} ${conditions}`, parameters);
|
|
265
|
-
}
|
|
266
|
-
|
|
267
|
-
return builder;
|
|
268
|
-
}
|
|
@@ -1,75 +0,0 @@
|
|
|
1
|
-
/* eslint-disable @typescript-eslint/no-explicit-any */
|
|
2
|
-
import { ObjectLiteral } from 'typeorm';
|
|
3
|
-
import { ColumnValueType, EntityOnlyWithRelations, EntityWithoutRelations } from './typeorm.types';
|
|
4
|
-
|
|
5
|
-
export class KeyHolder {
|
|
6
|
-
constructor(public keys: string[] = []) {
|
|
7
|
-
this.keys = [...keys];
|
|
8
|
-
}
|
|
9
|
-
|
|
10
|
-
toSql(length: number = 2, addDobleQuotes = true) {
|
|
11
|
-
const string = this.toString(length);
|
|
12
|
-
const sql = addDobleQuotes ? `"${string.replace(/\./g, '"."')}"` : string;
|
|
13
|
-
|
|
14
|
-
return sql;
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
toString(length = 2) {
|
|
18
|
-
const keys = this.keys.slice(0, length);
|
|
19
|
-
const string = keys.join('.');
|
|
20
|
-
|
|
21
|
-
return string;
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
valueOf() {
|
|
25
|
-
return this.toString();
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
[Symbol.toPrimitive]() {
|
|
29
|
-
return this.toString();
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
add(key: string | symbol) {
|
|
33
|
-
if (
|
|
34
|
-
typeof key !== 'symbol' &&
|
|
35
|
-
!Object.getOwnPropertyNames(this).includes(key) && // check of getOwnPropertyNames(this) is questionable
|
|
36
|
-
!Object.getOwnPropertyNames(KeyHolder.prototype).includes(key)
|
|
37
|
-
) {
|
|
38
|
-
this.keys.push(key);
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
return this;
|
|
42
|
-
}
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
export class TypedProxy {
|
|
46
|
-
public static defaultHandler = {};
|
|
47
|
-
|
|
48
|
-
public static create<T extends ObjectLiteral>(obj: object, handler = TypedProxy.defaultHandler) {
|
|
49
|
-
return new Proxy(obj, handler) as T;
|
|
50
|
-
}
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
export class KeyProxy {
|
|
54
|
-
public static defaultHandler: ProxyHandler<KeyHolder> = {
|
|
55
|
-
get(target, key, receiver) {
|
|
56
|
-
// for each key create new independent layer of KeyProxy
|
|
57
|
-
const newKeyHolder = new KeyHolder(target.keys).add(key);
|
|
58
|
-
const newLayer = TypedProxy.create<ObjectLiteral>(newKeyHolder, KeyProxy.defaultHandler);
|
|
59
|
-
|
|
60
|
-
return Reflect.get(target, key, receiver) ?? newLayer;
|
|
61
|
-
},
|
|
62
|
-
};
|
|
63
|
-
|
|
64
|
-
public static create<T extends ObjectLiteral>() {
|
|
65
|
-
return TypedProxy.create<T>(new KeyHolder(), KeyProxy.defaultHandler);
|
|
66
|
-
}
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
export type KeyProxyCallback<T extends ObjectLiteral> = (proxy: T) => ColumnValueType | Array<ColumnValueType>;
|
|
70
|
-
export type RelationalKeyProxyCallback<T extends ObjectLiteral> = (
|
|
71
|
-
proxy: EntityOnlyWithRelations<T>
|
|
72
|
-
) => ColumnValueType;
|
|
73
|
-
export type NonRelationalKeyProxyCallback<T extends ObjectLiteral> = (
|
|
74
|
-
proxy: EntityWithoutRelations<T>
|
|
75
|
-
) => ColumnValueType;
|