typeorm-extensions 1.3.5 → 2.1.0
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 +12 -10
- package/dist/constants/index.d.ts +1 -1
- package/dist/constants/index.js +2 -2
- package/dist/extensions/cursor-pagination.extension.d.ts +18 -0
- package/dist/extensions/cursor-pagination.extension.js +108 -0
- package/dist/extensions/index.d.ts +7 -0
- package/dist/extensions/index.js +7 -0
- package/dist/extensions/order-by-array-position.extension.d.ts +24 -0
- package/dist/extensions/order-by-array-position.extension.js +18 -0
- package/dist/extensions/order.extension.d.ts +3 -2
- package/dist/extensions/order.extension.js +16 -13
- package/dist/extensions/period-filter.extension.d.ts +29 -0
- package/dist/extensions/period-filter.extension.js +23 -0
- package/dist/extensions/typed/index.d.ts +10 -0
- package/dist/extensions/typed/index.js +10 -0
- package/dist/extensions/typed/typed-distinct/typed-distinct.extension.js +2 -2
- package/dist/extensions/typed/typed-joins/typed-joins.extension.js +2 -1
- package/dist/extensions/typed/typed-order-by/typed-order-by-array-position.extension.d.ts +20 -0
- package/dist/extensions/typed/typed-order-by/typed-order-by-array-position.extension.js +21 -0
- package/dist/extensions/typed/typed-order-by/typed-order-by.extension.d.ts +4 -3
- package/dist/extensions/typed/typed-order-by/typed-order-by.extension.js +7 -6
- package/dist/extensions/typed/typed-returning/typed-returning.extension.d.ts +27 -0
- package/dist/extensions/typed/typed-returning/typed-returning.extension.js +38 -0
- package/dist/extensions/typed/typed-select/typed-select.extension.d.ts +6 -6
- package/dist/extensions/typed/typed-select/typed-select.extension.js +11 -8
- package/dist/extensions/typed/typed-where/typed-period-filter.extension.d.ts +31 -0
- package/dist/extensions/typed/typed-where/typed-period-filter.extension.js +25 -0
- package/dist/extensions/typed/typed-where/typed-where-array.extension.d.ts +68 -0
- package/dist/extensions/typed/typed-where/typed-where-array.extension.js +41 -0
- package/dist/extensions/typed/typed-where/typed-where-ilike.extension.d.ts +62 -0
- package/dist/extensions/typed/typed-where/typed-where-ilike.extension.js +84 -0
- package/dist/extensions/typed/typed-where/typed-where-is-any.extension.d.ts +53 -0
- package/dist/extensions/typed/typed-where/typed-where-is-any.extension.js +38 -0
- package/dist/extensions/typed/typed-where/typed-where-is-distinct-from.extension.d.ts +53 -0
- package/dist/extensions/typed/typed-where/typed-where-is-distinct-from.extension.js +38 -0
- package/dist/extensions/typed/typed-where/typed-where-is-in.extension.d.ts +36 -119
- package/dist/extensions/typed/typed-where/typed-where-is-in.extension.js +14 -29
- package/dist/extensions/typed/typed-where/typed-where-json.extension.d.ts +53 -0
- package/dist/extensions/typed/typed-where/typed-where-json.extension.js +39 -0
- package/dist/extensions/typed/typed-where/typed-where-lower.extension.d.ts +59 -0
- package/dist/extensions/typed/typed-where/typed-where-lower.extension.js +86 -0
- package/dist/extensions/typed/typed-where/typed-where-similar.extension.d.ts +54 -0
- package/dist/extensions/typed/typed-where/typed-where-similar.extension.js +73 -0
- package/dist/extensions/typed/typed-where/typed-where.extension.d.ts +30 -74
- package/dist/extensions/typed/typed-where/typed-where.extension.js +13 -21
- package/dist/extensions/where-array.extension.d.ts +70 -0
- package/dist/extensions/where-array.extension.js +47 -0
- package/dist/extensions/where-is-any.extension.d.ts +142 -0
- package/dist/extensions/where-is-any.extension.js +44 -0
- package/dist/extensions/where-is-distinct-from.extension.d.ts +56 -0
- package/dist/extensions/where-is-distinct-from.extension.js +55 -0
- package/dist/extensions/where-json.extension.d.ts +55 -0
- package/dist/extensions/where-json.extension.js +64 -0
- package/dist/helpers.d.ts +2 -0
- package/dist/helpers.js +23 -0
- package/dist/index.d.ts +3 -0
- package/dist/index.js +4 -0
- package/dist/types/extensions/cursor-pagination.types.d.ts +16 -0
- package/dist/types/extensions/cursor-pagination.types.js +2 -0
- package/dist/types/extensions/get-many-with-totals.types.d.ts +3 -1
- package/dist/types/extensions/index.d.ts +4 -0
- package/dist/types/extensions/index.js +4 -0
- package/dist/types/extensions/order.types.d.ts +1 -1
- package/dist/types/extensions/period.types.d.ts +15 -0
- package/dist/types/extensions/period.types.js +2 -0
- package/dist/types/extensions/search.types.d.ts +68 -0
- package/dist/types/extensions/search.types.js +2 -0
- package/dist/types/extensions/typed-order-by.types.d.ts +3 -0
- package/dist/types/extensions/typed-order-by.types.js +2 -0
- package/dist/types/extensions/typed-where.types.d.ts +4 -4
- package/dist/types/extensions/where.types.d.ts +1 -0
- package/dist/types/interfaces/config.interface.d.ts +17 -0
- package/dist/types/interfaces/config.interface.js +2 -0
- package/dist/types/interfaces/cursor-pagination.interface.d.ts +16 -0
- package/dist/types/interfaces/cursor-pagination.interface.js +2 -0
- package/dist/types/interfaces/index.d.ts +3 -0
- package/dist/types/interfaces/index.js +3 -0
- package/dist/types/interfaces/period.interface.d.ts +12 -0
- package/dist/types/interfaces/period.interface.js +2 -0
- package/dist/types/modules/proxy-callback.types.d.ts +50 -3
- package/dist/types/modules/typed-params.types.d.ts +45 -0
- package/dist/types/modules/typed-params.types.js +2 -0
- package/dist/types/util-types/index.d.ts +3 -1
- package/dist/utils/cursor.utils.d.ts +31 -0
- package/dist/utils/cursor.utils.js +130 -0
- package/dist/utils/json-path.utils.d.ts +22 -0
- package/dist/utils/json-path.utils.js +57 -0
- package/dist/utils/order.utils.d.ts +15 -0
- package/dist/utils/order.utils.js +45 -0
- package/dist/utils/period.utils.d.ts +9 -0
- package/dist/utils/period.utils.js +82 -0
- package/dist/utils/proxy-key.utils.d.ts +19 -3
- package/dist/utils/proxy-key.utils.js +40 -15
- package/dist/utils/query-builder.utils.d.ts +48 -0
- package/dist/utils/query-builder.utils.js +257 -0
- package/dist/utils/search.utils.d.ts +27 -0
- package/dist/utils/search.utils.js +83 -0
- package/dist/utils/sql.utils.d.ts +29 -1
- package/dist/utils/sql.utils.js +91 -9
- package/dist/utils/table.utils.d.ts +86 -0
- package/dist/utils/table.utils.js +124 -0
- package/dist/utils/where.utils.d.ts +18 -1
- package/dist/utils/where.utils.js +62 -9
- package/helpers/package.json +7 -0
- package/package.json +5 -4
- package/dist/utils/identifier.utils.d.ts +0 -15
- package/dist/utils/identifier.utils.js +0 -45
|
@@ -0,0 +1,124 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.tableHelper = void 0;
|
|
4
|
+
const sql_utils_1 = require("./sql.utils");
|
|
5
|
+
const json_path_utils_1 = require("./json-path.utils");
|
|
6
|
+
/**
|
|
7
|
+
* Creates a type-safe SQL helper for building column references, WHERE expressions,
|
|
8
|
+
* JOIN clauses, and JSONB accessors for a given entity type.
|
|
9
|
+
*
|
|
10
|
+
* @example
|
|
11
|
+
* const t = tableHelper<UserEntity>('user');
|
|
12
|
+
* t.column('email') // → "user"."email"
|
|
13
|
+
* t.where('id', '= :id') // → "user"."id" = :id
|
|
14
|
+
* t.jsonColumn('metadata', '->>', 'role') // → "user"."metadata" ->> 'role'
|
|
15
|
+
*/
|
|
16
|
+
const tableHelper = (alias, options = {}) => ({
|
|
17
|
+
alias,
|
|
18
|
+
/**
|
|
19
|
+
* Returns a quoted SQL column identifier, e.g. `"alias"."column"`. The column is always quoted as one
|
|
20
|
+
* identifier, so names with other characters work too: `"user"."first-name"`.
|
|
21
|
+
*/
|
|
22
|
+
column(columnName, alias) {
|
|
23
|
+
const { useQuotes = true } = options;
|
|
24
|
+
const tableAlias = alias !== null && alias !== void 0 ? alias : this.alias;
|
|
25
|
+
const column = String(columnName);
|
|
26
|
+
if (!useQuotes) {
|
|
27
|
+
return [tableAlias, column].filter(Boolean).join('.');
|
|
28
|
+
}
|
|
29
|
+
return [tableAlias ? (0, sql_utils_1.quoteIdentifierPath)(tableAlias) : undefined, (0, sql_utils_1.quoteIdentifier)(column)]
|
|
30
|
+
.filter(Boolean)
|
|
31
|
+
.join('.');
|
|
32
|
+
},
|
|
33
|
+
/** Returns a column identifier optionally followed by an expression, e.g. `"user"."id" = :id`. */
|
|
34
|
+
where(columnName, expression) {
|
|
35
|
+
const column = this.column(columnName);
|
|
36
|
+
return [column, expression].filter(Boolean).join(' ');
|
|
37
|
+
},
|
|
38
|
+
/** Returns an unquoted join path, e.g. `user.images`. Needs the helper's alias, or `alias`. */
|
|
39
|
+
join(relation, alias) {
|
|
40
|
+
const tableAlias = alias !== null && alias !== void 0 ? alias : this.alias;
|
|
41
|
+
if (!tableAlias) {
|
|
42
|
+
throw new TypeError(`tableHelper().join('${String(relation)}') needs an alias: tableHelper('user').join('${String(relation)}')`);
|
|
43
|
+
}
|
|
44
|
+
return `${tableAlias}.${String(relation)}`;
|
|
45
|
+
},
|
|
46
|
+
/**
|
|
47
|
+
* Returns a column with a JOIN ON expression, e.g. `"user"."id" = "images"."userId"`.
|
|
48
|
+
* The expression is inserted as is: build its columns with another `tableHelper`
|
|
49
|
+
* (`t.joinOn('id', '= ' + images.column('userId'))`), since unquoted camelCase names
|
|
50
|
+
* like `images.userId` are folded to lowercase by PostgreSQL unless TypeORM rewrites them.
|
|
51
|
+
*/
|
|
52
|
+
joinOn(thisColumn, expression) {
|
|
53
|
+
return this.where(thisColumn, expression);
|
|
54
|
+
},
|
|
55
|
+
/** Returns `"alias"."column" IS NULL`. */
|
|
56
|
+
isNull(columnName) {
|
|
57
|
+
return this.where(columnName, 'IS NULL');
|
|
58
|
+
},
|
|
59
|
+
/** Returns `"alias"."column" IS NOT NULL`. */
|
|
60
|
+
isNotNull(columnName) {
|
|
61
|
+
return this.where(columnName, 'IS NOT NULL');
|
|
62
|
+
},
|
|
63
|
+
/**
|
|
64
|
+
* Returns `CAST(COUNT("alias"."column") AS integer)`: the rows where the column isn't `NULL`.
|
|
65
|
+
* Without a column it is `COUNT(*)`, all the rows of the result, in every database. To count the rows
|
|
66
|
+
* of a table joined with LEFT JOIN, count one of its non-null columns: `images.count('id')`.
|
|
67
|
+
* @example
|
|
68
|
+
* t.count('email', { distinct: true }) // CAST(COUNT(DISTINCT "user"."email") AS integer)
|
|
69
|
+
* t.count(undefined, { filter: t.where('status', "= 'active'") })
|
|
70
|
+
* // CAST(COUNT(CASE WHEN "user"."status" = 'active' THEN 1 END) AS integer)
|
|
71
|
+
* t.count(undefined, { filter: t.where('status', "= 'active'"), syntax: 'filter' })
|
|
72
|
+
* // CAST(COUNT(*) FILTER (WHERE "user"."status" = 'active') AS integer)
|
|
73
|
+
*/
|
|
74
|
+
count(columnName, countOptions = {}) {
|
|
75
|
+
if (typeof countOptions !== 'object' || countOptions === null) {
|
|
76
|
+
throw new TypeError('tableHelper.count(): the second argument is an options object, e.g. { distinct: true } or { filter: "…" }');
|
|
77
|
+
}
|
|
78
|
+
const { distinct = false, filter, syntax = 'case' } = countOptions;
|
|
79
|
+
if (syntax !== 'case' && syntax !== 'filter') {
|
|
80
|
+
throw new TypeError(`tableHelper.count(): syntax is 'case' or 'filter', got "${String(syntax)}"`);
|
|
81
|
+
}
|
|
82
|
+
const column = columnName ? this.column(columnName) : undefined;
|
|
83
|
+
if (distinct && !column) {
|
|
84
|
+
throw new TypeError("tableHelper.count({ distinct: true }) needs a column, e.g. count('email', { distinct: true })");
|
|
85
|
+
}
|
|
86
|
+
// `COUNT(*)`, not `COUNT("alias".*)`, which only PostgreSQL accepts;
|
|
87
|
+
// a CASE can't return `*`: without a column, it counts 1 per matching row
|
|
88
|
+
const counted = filter && syntax === 'case' ? `CASE WHEN ${filter} THEN ${column !== null && column !== void 0 ? column : '1'} END` : column !== null && column !== void 0 ? column : '*';
|
|
89
|
+
let expression = `COUNT(${distinct ? 'DISTINCT ' : ''}${counted})`;
|
|
90
|
+
if (filter && syntax === 'filter') {
|
|
91
|
+
expression += ` FILTER (WHERE ${filter})`;
|
|
92
|
+
}
|
|
93
|
+
return this.cast(expression, 'integer');
|
|
94
|
+
},
|
|
95
|
+
/** Returns `CAST(expression AS type)`. */
|
|
96
|
+
cast(expression, type) {
|
|
97
|
+
return `CAST(${expression} AS ${type})`;
|
|
98
|
+
},
|
|
99
|
+
/**
|
|
100
|
+
* Returns a full JSONB column access expression.
|
|
101
|
+
* @example
|
|
102
|
+
* t.jsonColumn('metadata', '->>', 'role') // → "user"."metadata" ->> 'role'
|
|
103
|
+
* t.jsonColumn('metadata', '->>', 'settings', 'theme') // → "user"."metadata" -> 'settings' ->> 'theme'
|
|
104
|
+
*/
|
|
105
|
+
jsonColumn(columnName, jsonOperator, ...fieldNames) {
|
|
106
|
+
const column = this.column(columnName);
|
|
107
|
+
const path = (0, json_path_utils_1.buildJsonPath)(fieldNames, jsonOperator);
|
|
108
|
+
return `${column} ${path}`;
|
|
109
|
+
},
|
|
110
|
+
/**
|
|
111
|
+
* Returns only the JSONB operator fragment (without the column).
|
|
112
|
+
* Useful inside `whereTyped` conditions strings.
|
|
113
|
+
* @example
|
|
114
|
+
* t.jsonPath('metadata', '->>', 'role') // → ->> 'role'
|
|
115
|
+
* t.jsonPath('metadata', '->>', 'settings', 'theme') // → -> 'settings' ->> 'theme'
|
|
116
|
+
*
|
|
117
|
+
* // Combined with whereTyped:
|
|
118
|
+
* qb.whereTyped(u => u.metadata, `${t.jsonPath('metadata', '->>', 'role')} =`, 'admin')
|
|
119
|
+
*/
|
|
120
|
+
jsonPath(_columnName, jsonOperator, ...fieldNames) {
|
|
121
|
+
return (0, json_path_utils_1.buildJsonPath)(fieldNames, jsonOperator);
|
|
122
|
+
}
|
|
123
|
+
});
|
|
124
|
+
exports.tableHelper = tableHelper;
|
|
@@ -1,6 +1,23 @@
|
|
|
1
|
-
import type { WhereExpressionBuilder } from 'typeorm';
|
|
1
|
+
import type { ObjectLiteral, WhereExpressionBuilder } from 'typeorm';
|
|
2
2
|
import type { WhereMethods } from '../types/extensions/where.types';
|
|
3
3
|
export declare function getValuePlaceholder<T>(value: T, paramName?: string): string;
|
|
4
|
+
/**
|
|
5
|
+
* Whether `params` is a `{ name: value }` params object (a plain object or a class instance such
|
|
6
|
+
* as a DTO), rather than the value itself (a primitive, an array, a `Date`, a `Buffer`).
|
|
7
|
+
*/
|
|
8
|
+
export declare function isParamsObject(params: unknown): params is Record<string, unknown>;
|
|
9
|
+
/**
|
|
10
|
+
* Checks whether `conditions` already references a key of `params` as a TypeORM
|
|
11
|
+
* named parameter (`:key` or `:...key`). Matches parameters the same way TypeORM does,
|
|
12
|
+
* so `::type` casts and colons inside literals don't count unless they name a `params` key.
|
|
13
|
+
*/
|
|
14
|
+
export declare function hasParamPlaceholder(conditions: string, params?: unknown): boolean;
|
|
4
15
|
export declare function attachWhere<QB extends WhereExpressionBuilder>(builder: QB, method: WhereMethods, field: string, conditions: string, params?: unknown, options?: {
|
|
5
16
|
addValue?: boolean;
|
|
6
17
|
}): QB;
|
|
18
|
+
/**
|
|
19
|
+
* Adds an AND condition that narrows the whole WHERE clause. TypeORM's `andWhere` doesn't group
|
|
20
|
+
* the conditions before it, so after `.where(a).orWhere(b)` it gives `a OR b AND c`, i.e.
|
|
21
|
+
* `a OR (b AND c)`. Existing conditions with an OR are wrapped first: `(a OR b) AND c`.
|
|
22
|
+
*/
|
|
23
|
+
export declare function andWhereNarrowing<QB extends WhereExpressionBuilder>(builder: QB, condition: string, parameters?: ObjectLiteral): QB;
|
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.attachWhere = exports.getValuePlaceholder = void 0;
|
|
3
|
+
exports.andWhereNarrowing = exports.attachWhere = exports.hasParamPlaceholder = exports.isParamsObject = exports.getValuePlaceholder = void 0;
|
|
4
4
|
const sql_utils_1 = require("./sql.utils");
|
|
5
|
+
const query_builder_utils_1 = require("./query-builder.utils");
|
|
5
6
|
function getValuePlaceholder(value, paramName) {
|
|
6
7
|
if (value === undefined || value === null || paramName === undefined) {
|
|
7
8
|
return 'NULL';
|
|
@@ -12,20 +13,57 @@ function getValuePlaceholder(value, paramName) {
|
|
|
12
13
|
return `:${paramName}`;
|
|
13
14
|
}
|
|
14
15
|
exports.getValuePlaceholder = getValuePlaceholder;
|
|
16
|
+
const isDate = (value) => Object.prototype.toString.call(value) === '[object Date]';
|
|
17
|
+
/**
|
|
18
|
+
* Objects that are parameter values themselves, not `{ name: value }` params objects:
|
|
19
|
+
* `Date`, and binary data (`Buffer`, typed arrays, `ArrayBuffer`).
|
|
20
|
+
*/
|
|
21
|
+
const isValueObject = (value) => isDate(value) || ArrayBuffer.isView(value) || value instanceof ArrayBuffer;
|
|
22
|
+
/**
|
|
23
|
+
* Whether `params` is a `{ name: value }` params object (a plain object or a class instance such
|
|
24
|
+
* as a DTO), rather than the value itself (a primitive, an array, a `Date`, a `Buffer`).
|
|
25
|
+
*/
|
|
26
|
+
function isParamsObject(params) {
|
|
27
|
+
return (params !== null &&
|
|
28
|
+
typeof params === 'object' &&
|
|
29
|
+
!Array.isArray(params) &&
|
|
30
|
+
!isValueObject(params));
|
|
31
|
+
}
|
|
32
|
+
exports.isParamsObject = isParamsObject;
|
|
33
|
+
/**
|
|
34
|
+
* Checks whether `conditions` already references a key of `params` as a TypeORM
|
|
35
|
+
* named parameter (`:key` or `:...key`). Matches parameters the same way TypeORM does,
|
|
36
|
+
* so `::type` casts and colons inside literals don't count unless they name a `params` key.
|
|
37
|
+
*/
|
|
38
|
+
function hasParamPlaceholder(conditions, params) {
|
|
39
|
+
if (!isParamsObject(params)) {
|
|
40
|
+
return false;
|
|
41
|
+
}
|
|
42
|
+
const placeholderRegex = /:(?:\.\.\.)?([A-Za-z0-9_.]+)/g;
|
|
43
|
+
let match;
|
|
44
|
+
while ((match = placeholderRegex.exec(conditions)) !== null) {
|
|
45
|
+
if (Object.prototype.hasOwnProperty.call(params, match[1])) {
|
|
46
|
+
return true;
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
return false;
|
|
50
|
+
}
|
|
51
|
+
exports.hasParamPlaceholder = hasParamPlaceholder;
|
|
15
52
|
function attachWhere(builder, method, field, conditions, params, options) {
|
|
16
|
-
|
|
53
|
+
let { addValue } = options || {};
|
|
17
54
|
if (method && typeof field === 'string' && typeof conditions === 'string') {
|
|
18
|
-
field = (0,
|
|
55
|
+
field = (0, query_builder_utils_1.toFieldSql)(builder, field);
|
|
19
56
|
const hasParams = typeof params !== 'undefined';
|
|
57
|
+
// `addValue` defaults to `true` unless `conditions` already references one of the `params` keys
|
|
58
|
+
addValue = addValue !== null && addValue !== void 0 ? addValue : !hasParamPlaceholder(conditions, params);
|
|
20
59
|
if (addValue && hasParams) {
|
|
21
|
-
// pick first value from params object or pass as is
|
|
22
|
-
const firstValue = params
|
|
23
|
-
? Object.values(params)[0]
|
|
24
|
-
: params;
|
|
60
|
+
// pick first value from params object or pass as is (a Date or a Buffer is a value too)
|
|
61
|
+
const firstValue = isParamsObject(params) ? Object.values(params)[0] : params;
|
|
25
62
|
// 0, false, '' are valid values like any other
|
|
26
|
-
// null, undefined and
|
|
63
|
+
// null, undefined, NaN and invalid dates are equal to NULL
|
|
27
64
|
const valueIsValid = firstValue !== undefined &&
|
|
28
|
-
(typeof firstValue === 'number' ? !isNaN(firstValue) : true)
|
|
65
|
+
(typeof firstValue === 'number' ? !isNaN(firstValue) : true) &&
|
|
66
|
+
(isDate(firstValue) ? !isNaN(firstValue.getTime()) : true);
|
|
29
67
|
const paramName = valueIsValid
|
|
30
68
|
? (0, sql_utils_1.createUniqueParameterName)(method)
|
|
31
69
|
: undefined;
|
|
@@ -40,3 +78,18 @@ function attachWhere(builder, method, field, conditions, params, options) {
|
|
|
40
78
|
return builder;
|
|
41
79
|
}
|
|
42
80
|
exports.attachWhere = attachWhere;
|
|
81
|
+
/**
|
|
82
|
+
* Adds an AND condition that narrows the whole WHERE clause. TypeORM's `andWhere` doesn't group
|
|
83
|
+
* the conditions before it, so after `.where(a).orWhere(b)` it gives `a OR b AND c`, i.e.
|
|
84
|
+
* `a OR (b AND c)`. Existing conditions with an OR are wrapped first: `(a OR b) AND c`.
|
|
85
|
+
*/
|
|
86
|
+
function andWhereNarrowing(builder, condition, parameters) {
|
|
87
|
+
const expressionMap = builder.expressionMap;
|
|
88
|
+
const wheres = expressionMap === null || expressionMap === void 0 ? void 0 : expressionMap.wheres;
|
|
89
|
+
if (wheres === null || wheres === void 0 ? void 0 : wheres.some((where) => where.type === 'or')) {
|
|
90
|
+
// a nested clause list is rendered in parentheses
|
|
91
|
+
expressionMap.wheres = [{ type: 'simple', condition: wheres }];
|
|
92
|
+
}
|
|
93
|
+
return builder.andWhere(condition, parameters);
|
|
94
|
+
}
|
|
95
|
+
exports.andWhereNarrowing = andWhereNarrowing;
|
package/package.json
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "typeorm-extensions",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "2.1.0",
|
|
4
4
|
"description": "typeorm commonly used extensions",
|
|
5
5
|
"main": "./dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
7
|
-
"files": ["dist", "LICENSE", "README.md", "package.json"],
|
|
7
|
+
"files": ["dist", "helpers", "LICENSE", "README.md", "package.json"],
|
|
8
8
|
"type": "commonjs",
|
|
9
9
|
"homepage": "https://koenigstag.github.io/typeorm-extensions/",
|
|
10
10
|
"repository": {
|
|
@@ -13,7 +13,8 @@
|
|
|
13
13
|
},
|
|
14
14
|
"scripts": {
|
|
15
15
|
"build": "tsc -p .",
|
|
16
|
-
"lint": "eslint . --ext .ts"
|
|
16
|
+
"lint": "eslint . --ext .ts",
|
|
17
|
+
"test:types": "tsc -p test/types"
|
|
17
18
|
},
|
|
18
19
|
"keywords": [
|
|
19
20
|
"typeorm",
|
|
@@ -25,7 +26,7 @@
|
|
|
25
26
|
"author": "koenigstag",
|
|
26
27
|
"license": "ISC",
|
|
27
28
|
"peerDependencies": {
|
|
28
|
-
"typeorm": "^0.3.12"
|
|
29
|
+
"typeorm": "^0.3.12 || ^1.0.0"
|
|
29
30
|
},
|
|
30
31
|
"devDependencies": {
|
|
31
32
|
"@typescript-eslint/eslint-plugin": "^7.1.1",
|
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
export declare class Identifier {
|
|
2
|
-
readonly field: string;
|
|
3
|
-
readonly alias?: string | undefined;
|
|
4
|
-
private readonly useDoubleQuotes?;
|
|
5
|
-
private readonly useAlias;
|
|
6
|
-
constructor(field: string, alias?: string | undefined, useDoubleQuotes?: boolean | undefined);
|
|
7
|
-
fieldAsAlias(): string;
|
|
8
|
-
fieldIdentifier(): string;
|
|
9
|
-
get aliasSql(): string | undefined;
|
|
10
|
-
get fieldSql(): string;
|
|
11
|
-
private calcUseAlias;
|
|
12
|
-
static fieldToSql(field: string, useDoubleQuotes?: boolean): string;
|
|
13
|
-
static aliasToSql(alias: string | undefined, useDoubleQuotes?: boolean): string | undefined;
|
|
14
|
-
static toIdentifier(value: string, useDoubleQuotes?: boolean): string;
|
|
15
|
-
}
|
|
@@ -1,45 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.Identifier = void 0;
|
|
4
|
-
const sql_utils_1 = require("./sql.utils");
|
|
5
|
-
class Identifier {
|
|
6
|
-
constructor(field, alias, useDoubleQuotes) {
|
|
7
|
-
this.field = field;
|
|
8
|
-
this.alias = alias;
|
|
9
|
-
this.useDoubleQuotes = useDoubleQuotes;
|
|
10
|
-
this.useAlias = this.calcUseAlias();
|
|
11
|
-
}
|
|
12
|
-
fieldAsAlias() {
|
|
13
|
-
if (this.useAlias) {
|
|
14
|
-
return `${this.fieldSql} AS ${this.aliasSql}`;
|
|
15
|
-
}
|
|
16
|
-
return this.fieldSql;
|
|
17
|
-
}
|
|
18
|
-
fieldIdentifier() {
|
|
19
|
-
if (this.useAlias) {
|
|
20
|
-
return `${this.aliasSql}.${this.fieldSql}`;
|
|
21
|
-
}
|
|
22
|
-
return this.fieldSql;
|
|
23
|
-
}
|
|
24
|
-
get aliasSql() {
|
|
25
|
-
return Identifier.aliasToSql(this.alias, this.useDoubleQuotes);
|
|
26
|
-
}
|
|
27
|
-
get fieldSql() {
|
|
28
|
-
return Identifier.fieldToSql(this.field, this.useDoubleQuotes);
|
|
29
|
-
}
|
|
30
|
-
/* PRIVATE */
|
|
31
|
-
calcUseAlias() {
|
|
32
|
-
return !!this.alias && !this.field.includes('.');
|
|
33
|
-
}
|
|
34
|
-
/* STATIC */
|
|
35
|
-
static fieldToSql(field, useDoubleQuotes) {
|
|
36
|
-
return this.toIdentifier(field, useDoubleQuotes);
|
|
37
|
-
}
|
|
38
|
-
static aliasToSql(alias, useDoubleQuotes) {
|
|
39
|
-
return alias ? this.toIdentifier(alias, useDoubleQuotes) : undefined;
|
|
40
|
-
}
|
|
41
|
-
static toIdentifier(value, useDoubleQuotes) {
|
|
42
|
-
return useDoubleQuotes ? (0, sql_utils_1.stringToSQLIdentifier)(value) : value;
|
|
43
|
-
}
|
|
44
|
-
}
|
|
45
|
-
exports.Identifier = Identifier;
|