typeorm-extensions 2.2.0-rc.1 → 2.2.0-rc.11
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 +70 -39
- package/dist/decorators/calculated-column.decorator.d.ts +7 -3
- package/dist/decorators/calculated-column.decorator.js +35 -6
- package/dist/decorators/generated-column.decorator.d.ts +17 -0
- package/dist/decorators/generated-column.decorator.js +15 -0
- package/dist/decorators/index.d.ts +1 -0
- package/dist/decorators/index.js +1 -0
- package/dist/extensions/calculated-column.extension.d.ts +3 -3
- package/dist/extensions/calculated-column.extension.js +3 -16
- package/dist/extensions/cursor-pagination.extension.d.ts +15 -2
- package/dist/extensions/cursor-pagination.extension.js +90 -13
- package/dist/extensions/get-many-with-totals.extension.js +12 -31
- package/dist/extensions/join-lateral.extension.js +4 -6
- package/dist/extensions/order.extension.d.ts +2 -2
- package/dist/extensions/pagination.extension.d.ts +7 -1
- package/dist/extensions/pagination.extension.js +5 -12
- package/dist/extensions/period-filter.extension.d.ts +4 -0
- package/dist/extensions/period-filter.extension.js +1 -9
- package/dist/extensions/typed/index.d.ts +2 -0
- package/dist/extensions/typed/index.js +2 -0
- package/dist/extensions/typed/typed-calculated/typed-calculated-column.extension.d.ts +19 -0
- package/dist/extensions/typed/typed-calculated/typed-calculated-column.extension.js +17 -0
- package/dist/extensions/typed/typed-distinct/typed-distinct.extension.d.ts +6 -4
- package/dist/extensions/typed/typed-distinct/typed-distinct.extension.js +9 -2
- package/dist/extensions/typed/typed-group-by/typed-group-by.extension.d.ts +8 -7
- package/dist/extensions/typed/typed-group-by/typed-group-by.extension.js +1 -1
- package/dist/extensions/typed/typed-having/typed-having.extension.d.ts +4 -4
- package/dist/extensions/typed/typed-having/typed-having.extension.js +1 -1
- package/dist/extensions/typed/typed-joins/typed-join-and-map.extension.d.ts +19 -0
- package/dist/extensions/typed/typed-joins/typed-join-and-map.extension.js +23 -0
- package/dist/extensions/typed/typed-joins/typed-joins.extension.d.ts +4 -4
- package/dist/extensions/typed/typed-joins/typed-joins.extension.js +11 -22
- package/dist/extensions/typed/typed-order-by/typed-order-by-array-position.extension.d.ts +2 -2
- package/dist/extensions/typed/typed-order-by/typed-order-by.extension.d.ts +4 -2
- package/dist/extensions/typed/typed-order-by/typed-order-by.extension.js +18 -17
- package/dist/extensions/typed/typed-returning/typed-returning.extension.js +1 -9
- package/dist/extensions/typed/typed-root.extension.d.ts +26 -4
- package/dist/extensions/typed/typed-select/typed-select.extension.d.ts +6 -6
- package/dist/extensions/typed/typed-select/typed-select.extension.js +3 -9
- package/dist/extensions/typed/typed-where/typed-period-filter.extension.d.ts +5 -1
- package/dist/extensions/typed/typed-where/typed-period-filter.extension.js +1 -9
- package/dist/extensions/typed/typed-where/typed-where-array.extension.d.ts +13 -9
- package/dist/extensions/typed/typed-where/typed-where-array.extension.js +4 -16
- package/dist/extensions/typed/typed-where/typed-where-ilike.extension.d.ts +10 -6
- package/dist/extensions/typed/typed-where/typed-where-ilike.extension.js +1 -9
- package/dist/extensions/typed/typed-where/typed-where-is-any.extension.d.ts +10 -6
- package/dist/extensions/typed/typed-where/typed-where-is-any.extension.js +3 -20
- package/dist/extensions/typed/typed-where/typed-where-is-distinct-from.extension.d.ts +10 -6
- package/dist/extensions/typed/typed-where/typed-where-is-distinct-from.extension.js +3 -20
- package/dist/extensions/typed/typed-where/typed-where-is-in.extension.d.ts +10 -6
- package/dist/extensions/typed/typed-where/typed-where-is-in.extension.js +3 -21
- package/dist/extensions/typed/typed-where/typed-where-json.extension.d.ts +10 -6
- package/dist/extensions/typed/typed-where/typed-where-json.extension.js +4 -21
- package/dist/extensions/typed/typed-where/typed-where-lower.extension.d.ts +10 -6
- package/dist/extensions/typed/typed-where/typed-where-lower.extension.js +1 -9
- package/dist/extensions/typed/typed-where/typed-where-similar.extension.d.ts +8 -4
- package/dist/extensions/typed/typed-where/typed-where-similar.extension.js +1 -8
- package/dist/extensions/typed/typed-where/typed-where.extension.d.ts +7 -3
- package/dist/extensions/typed/typed-where/typed-where.extension.js +2 -10
- package/dist/extensions/union.extension.js +1 -1
- package/dist/extensions/where-array.extension.d.ts +4 -0
- package/dist/extensions/where-array.extension.js +1 -9
- package/dist/extensions/where-exists.extension.js +4 -15
- package/dist/extensions/where-is-any.extension.d.ts +41 -128
- package/dist/extensions/where-is-any.extension.js +1 -9
- package/dist/extensions/where-is-distinct-from.extension.d.ts +4 -0
- package/dist/extensions/where-is-distinct-from.extension.js +1 -9
- package/dist/extensions/where-is-in.extension.d.ts +38 -116
- package/dist/extensions/where-is-in.extension.js +11 -27
- package/dist/extensions/where-json.extension.d.ts +4 -0
- package/dist/extensions/where-json.extension.js +1 -9
- package/dist/extensions/where-relation-exists.extension.d.ts +6 -6
- package/dist/extensions/where-relation-exists.extension.js +5 -25
- package/dist/helpers.d.ts +5 -0
- package/dist/helpers.js +12 -3
- package/dist/index.d.ts +1 -2
- package/dist/index.js +1 -4
- package/dist/types/extensions/cursor-pagination.types.d.ts +16 -1
- package/dist/types/extensions/get-many-with-totals.types.d.ts +4 -0
- package/dist/types/extensions/index.d.ts +1 -0
- package/dist/types/extensions/index.js +1 -0
- package/dist/types/extensions/typed-group-by.types.d.ts +2 -2
- package/dist/types/extensions/typed-join-and-map.types.d.ts +6 -0
- package/dist/types/extensions/typed-join-and-map.types.js +2 -0
- package/dist/types/interfaces/cursor-pagination.interface.d.ts +11 -0
- package/dist/types/modules/typed-root.types.d.ts +11 -9
- package/dist/utils/calculated-column.utils.d.ts +11 -0
- package/dist/utils/calculated-column.utils.js +33 -4
- package/dist/utils/common.utils.d.ts +2 -0
- package/dist/utils/common.utils.js +4 -1
- package/dist/utils/cursor.utils.d.ts +5 -0
- package/dist/utils/cursor.utils.js +18 -7
- package/dist/utils/json-path.utils.js +2 -2
- package/dist/utils/pagination.utils.d.ts +10 -0
- package/dist/utils/pagination.utils.js +27 -10
- package/dist/utils/parameter.utils.d.ts +10 -0
- package/dist/utils/parameter.utils.js +22 -1
- package/dist/utils/period.utils.js +2 -1
- package/dist/utils/prototype.utils.d.ts +9 -0
- package/dist/utils/prototype.utils.js +12 -2
- package/dist/utils/query-builder.utils.d.ts +43 -4
- package/dist/utils/query-builder.utils.js +239 -36
- package/dist/utils/reserved-qualifier-guard.utils.d.ts +36 -0
- package/dist/utils/reserved-qualifier-guard.utils.js +98 -0
- package/dist/utils/reserved-qualifier.utils.d.ts +33 -0
- package/dist/utils/reserved-qualifier.utils.js +252 -0
- package/dist/utils/table.utils.d.ts +27 -11
- package/dist/utils/table.utils.js +58 -23
- package/dist/utils/time-zone.utils.d.ts +8 -0
- package/dist/utils/time-zone.utils.js +15 -5
- package/dist/utils/typed-where.utils.d.ts +9 -0
- package/dist/utils/typed-where.utils.js +17 -0
- package/dist/utils/where.utils.d.ts +2 -0
- package/dist/utils/where.utils.js +21 -14
- package/package.json +2 -2
|
@@ -5,6 +5,8 @@ export declare function getValuePlaceholder<T>(value: T, paramName?: string): st
|
|
|
5
5
|
* Whether `params` is a `{ name: value }` params object (a plain object or a class instance such
|
|
6
6
|
* as a DTO), rather than the value itself (a primitive, an array, a `Date`, a `Buffer`).
|
|
7
7
|
*/
|
|
8
|
+
/** The value a condition compares with: the value of a one-key params object, or the params themselves (a Date or a Buffer is a value too). */
|
|
9
|
+
export declare function getComparedValue(params: unknown): unknown;
|
|
8
10
|
export declare function isParamsObject(params: unknown): params is Record<string, unknown>;
|
|
9
11
|
/**
|
|
10
12
|
* Checks whether `conditions` already references a key of `params` as a TypeORM
|
|
@@ -1,8 +1,10 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.andWhereNarrowing = exports.attachWhere = exports.hasParamPlaceholder = exports.isParamsObject = exports.getValuePlaceholder = void 0;
|
|
3
|
+
exports.andWhereNarrowing = exports.attachWhere = exports.hasParamPlaceholder = exports.isParamsObject = exports.getComparedValue = exports.getValuePlaceholder = void 0;
|
|
4
4
|
const sql_utils_1 = require("./sql.utils");
|
|
5
5
|
const query_builder_utils_1 = require("./query-builder.utils");
|
|
6
|
+
const parameter_utils_1 = require("./parameter.utils");
|
|
7
|
+
const common_utils_1 = require("./common.utils");
|
|
6
8
|
function getValuePlaceholder(value, paramName) {
|
|
7
9
|
if (value === undefined || value === null || paramName === undefined) {
|
|
8
10
|
return 'NULL';
|
|
@@ -13,16 +15,25 @@ function getValuePlaceholder(value, paramName) {
|
|
|
13
15
|
return `:${paramName}`;
|
|
14
16
|
}
|
|
15
17
|
exports.getValuePlaceholder = getValuePlaceholder;
|
|
16
|
-
|
|
18
|
+
/**
|
|
19
|
+
* A condition that ends with an operator, `=`, `>=`, `LIKE`, `IN`, `@>`: it needs a value after it. A word after
|
|
20
|
+
* `:` or `.` is a parameter or a column (`ILIKE :like`, `= t.in`), not an operator.
|
|
21
|
+
*/
|
|
22
|
+
const OPERATOR_AT_END = /(?:[=<>!~@&|?]|(?<![\w$:.])(?:LIKE|ILIKE|IN|SIMILAR TO|DISTINCT FROM|BETWEEN|ANY|ALL))\s*$/i;
|
|
17
23
|
/**
|
|
18
24
|
* Objects that are parameter values themselves, not `{ name: value }` params objects:
|
|
19
25
|
* `Date`, and binary data (`Buffer`, typed arrays, `ArrayBuffer`).
|
|
20
26
|
*/
|
|
21
|
-
const isValueObject = (value) => isDate(value) || ArrayBuffer.isView(value) || value instanceof ArrayBuffer;
|
|
27
|
+
const isValueObject = (value) => (0, common_utils_1.isDate)(value) || ArrayBuffer.isView(value) || value instanceof ArrayBuffer;
|
|
22
28
|
/**
|
|
23
29
|
* Whether `params` is a `{ name: value }` params object (a plain object or a class instance such
|
|
24
30
|
* as a DTO), rather than the value itself (a primitive, an array, a `Date`, a `Buffer`).
|
|
25
31
|
*/
|
|
32
|
+
/** The value a condition compares with: the value of a one-key params object, or the params themselves (a Date or a Buffer is a value too). */
|
|
33
|
+
function getComparedValue(params) {
|
|
34
|
+
return isParamsObject(params) ? Object.values(params)[0] : params;
|
|
35
|
+
}
|
|
36
|
+
exports.getComparedValue = getComparedValue;
|
|
26
37
|
function isParamsObject(params) {
|
|
27
38
|
return (params !== null &&
|
|
28
39
|
typeof params === 'object' &&
|
|
@@ -39,14 +50,7 @@ function hasParamPlaceholder(conditions, params) {
|
|
|
39
50
|
if (!isParamsObject(params)) {
|
|
40
51
|
return false;
|
|
41
52
|
}
|
|
42
|
-
|
|
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;
|
|
53
|
+
return (0, parameter_utils_1.getPlaceholderNames)(conditions).some((name) => Object.prototype.hasOwnProperty.call(params, name));
|
|
50
54
|
}
|
|
51
55
|
exports.hasParamPlaceholder = hasParamPlaceholder;
|
|
52
56
|
/**
|
|
@@ -76,15 +80,18 @@ function attachWhere(builder, method, field, conditions, params, options) {
|
|
|
76
80
|
const hasParams = typeof params !== 'undefined';
|
|
77
81
|
// `addValue` defaults to `true` unless `conditions` already references one of the `params` keys
|
|
78
82
|
addValue = addValue !== null && addValue !== void 0 ? addValue : !hasParamPlaceholder(conditions, params);
|
|
83
|
+
if (addValue && !hasParams && OPERATOR_AT_END.test(conditions)) {
|
|
84
|
+
throw new TypeError(`The value after "${fieldName} ${conditions.trim()}" is undefined, which leaves the condition without ` +
|
|
85
|
+
`an operand. Pass the value, null to compare with NULL, or a condition without one ('IS NULL')`);
|
|
86
|
+
}
|
|
79
87
|
if (addValue && hasParams) {
|
|
80
88
|
assertSingleValueParams(fieldName, params);
|
|
81
|
-
|
|
82
|
-
const firstValue = isParamsObject(params) ? Object.values(params)[0] : params;
|
|
89
|
+
const firstValue = getComparedValue(params);
|
|
83
90
|
// 0, false, '' are valid values like any other
|
|
84
91
|
// null, undefined, NaN and invalid dates are equal to NULL
|
|
85
92
|
const valueIsValid = firstValue !== undefined &&
|
|
86
93
|
(typeof firstValue === 'number' ? !isNaN(firstValue) : true) &&
|
|
87
|
-
(isDate(firstValue) ? !isNaN(firstValue.getTime()) : true);
|
|
94
|
+
((0, common_utils_1.isDate)(firstValue) ? !isNaN(firstValue.getTime()) : true);
|
|
88
95
|
const paramName = valueIsValid
|
|
89
96
|
? (0, sql_utils_1.createUniqueParameterName)(method)
|
|
90
97
|
: undefined;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "typeorm-extensions",
|
|
3
|
-
"version": "2.2.0-rc.
|
|
3
|
+
"version": "2.2.0-rc.11",
|
|
4
4
|
"description": "typeorm commonly used extensions",
|
|
5
5
|
"main": "./dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
@@ -14,7 +14,7 @@
|
|
|
14
14
|
"scripts": {
|
|
15
15
|
"build": "tsc -p .",
|
|
16
16
|
"lint": "eslint . --ext .ts",
|
|
17
|
-
"test:types": "tsc -p test/types && tsc -p test/types/tsconfig.loose.json"
|
|
17
|
+
"test:types": "tsc -p test/types && tsc -p test/types/tsconfig.loose.json && tsc -p test/types/typed-imports && tsc -p test/types/typed-imports/tsconfig.loose.json"
|
|
18
18
|
},
|
|
19
19
|
"keywords": [
|
|
20
20
|
"typeorm",
|