typeorm-extensions 2.2.0-rc.1 → 2.2.0-rc.10
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 +2 -1
- package/dist/extensions/cursor-pagination.extension.js +7 -13
- package/dist/extensions/get-many-with-totals.extension.js +10 -29
- 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 +1 -1
- 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 +5 -0
- package/dist/types/extensions/get-many-with-totals.types.d.ts +4 -0
- package/dist/types/extensions/index.d.ts +1 -0
- package/dist/types/extensions/index.js +1 -0
- package/dist/types/extensions/typed-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/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.js +4 -6
- package/dist/utils/json-path.utils.js +2 -2
- package/dist/utils/pagination.utils.d.ts +7 -0
- package/dist/utils/pagination.utils.js +20 -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
package/dist/helpers.d.ts
CHANGED
|
@@ -1,2 +1,7 @@
|
|
|
1
1
|
export * from './utils/table.utils';
|
|
2
|
+
export * from './decorators/generated-column.decorator';
|
|
2
3
|
export { escapeLikePattern } from './utils/search.utils';
|
|
4
|
+
export { COCKROACHDB_RESERVED_KEY_WORDS, findBareReservedQualifiers, POSTGRES_RESERVED_KEY_WORDS, } from './utils/reserved-qualifier.utils';
|
|
5
|
+
export type { ReservedQualifier } from './utils/reserved-qualifier.utils';
|
|
6
|
+
export { disableReservedQualifierGuard, enableReservedQualifierGuard, ReservedQualifierError, } from './utils/reserved-qualifier-guard.utils';
|
|
7
|
+
export type { ReservedQualifierGuardOptions } from './utils/reserved-qualifier-guard.utils';
|
package/dist/helpers.js
CHANGED
|
@@ -14,10 +14,19 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
14
14
|
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
15
|
};
|
|
16
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
-
exports.escapeLikePattern = void 0;
|
|
17
|
+
exports.ReservedQualifierError = exports.enableReservedQualifierGuard = exports.disableReservedQualifierGuard = exports.POSTGRES_RESERVED_KEY_WORDS = exports.findBareReservedQualifiers = exports.COCKROACHDB_RESERVED_KEY_WORDS = exports.escapeLikePattern = void 0;
|
|
18
18
|
// Side-effect-free entry point: `typeorm-extensions/helpers`.
|
|
19
|
-
// Exports helpers (tableHelper, escapeLikePattern) only and patches nothing
|
|
20
|
-
// (`typeorm-extensions`) installs every QueryBuilder extension.
|
|
19
|
+
// Exports helpers (tableHelper, escapeLikePattern, the reserved qualifier guard, @GeneratedColumn) only and patches nothing on import;
|
|
20
|
+
// importing the package root (`typeorm-extensions`) installs every QueryBuilder extension.
|
|
21
21
|
__exportStar(require("./utils/table.utils"), exports);
|
|
22
|
+
__exportStar(require("./decorators/generated-column.decorator"), exports);
|
|
22
23
|
var search_utils_1 = require("./utils/search.utils");
|
|
23
24
|
Object.defineProperty(exports, "escapeLikePattern", { enumerable: true, get: function () { return search_utils_1.escapeLikePattern; } });
|
|
25
|
+
var reserved_qualifier_utils_1 = require("./utils/reserved-qualifier.utils");
|
|
26
|
+
Object.defineProperty(exports, "COCKROACHDB_RESERVED_KEY_WORDS", { enumerable: true, get: function () { return reserved_qualifier_utils_1.COCKROACHDB_RESERVED_KEY_WORDS; } });
|
|
27
|
+
Object.defineProperty(exports, "findBareReservedQualifiers", { enumerable: true, get: function () { return reserved_qualifier_utils_1.findBareReservedQualifiers; } });
|
|
28
|
+
Object.defineProperty(exports, "POSTGRES_RESERVED_KEY_WORDS", { enumerable: true, get: function () { return reserved_qualifier_utils_1.POSTGRES_RESERVED_KEY_WORDS; } });
|
|
29
|
+
var reserved_qualifier_guard_utils_1 = require("./utils/reserved-qualifier-guard.utils");
|
|
30
|
+
Object.defineProperty(exports, "disableReservedQualifierGuard", { enumerable: true, get: function () { return reserved_qualifier_guard_utils_1.disableReservedQualifierGuard; } });
|
|
31
|
+
Object.defineProperty(exports, "enableReservedQualifierGuard", { enumerable: true, get: function () { return reserved_qualifier_guard_utils_1.enableReservedQualifierGuard; } });
|
|
32
|
+
Object.defineProperty(exports, "ReservedQualifierError", { enumerable: true, get: function () { return reserved_qualifier_guard_utils_1.ReservedQualifierError; } });
|
package/dist/index.d.ts
CHANGED
|
@@ -4,5 +4,4 @@ export * from './types/interfaces';
|
|
|
4
4
|
export * from './types/extensions';
|
|
5
5
|
export type { Json } from './types/modules/proxy-callback.types';
|
|
6
6
|
export type { TypedRoot, WithTypedRoot } from './types/modules/typed-root.types';
|
|
7
|
-
export * from './
|
|
8
|
-
export { escapeLikePattern } from './utils/search.utils';
|
|
7
|
+
export * from './helpers';
|
package/dist/index.js
CHANGED
|
@@ -14,11 +14,8 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
14
14
|
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
15
|
};
|
|
16
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
-
exports.escapeLikePattern = void 0;
|
|
18
17
|
__exportStar(require("./extensions"), exports);
|
|
19
18
|
__exportStar(require("./decorators"), exports);
|
|
20
19
|
__exportStar(require("./types/interfaces"), exports);
|
|
21
20
|
__exportStar(require("./types/extensions"), exports);
|
|
22
|
-
__exportStar(require("./
|
|
23
|
-
var search_utils_1 = require("./utils/search.utils");
|
|
24
|
-
Object.defineProperty(exports, "escapeLikePattern", { enumerable: true, get: function () { return search_utils_1.escapeLikePattern; } });
|
|
21
|
+
__exportStar(require("./helpers"), exports);
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import type { CursorOrderParam } from '../interfaces/cursor-pagination.interface';
|
|
2
|
+
import type { OrderType } from '../interfaces/ordering.interface';
|
|
2
3
|
export type GetManyWithCursorOptions<Entity> = {
|
|
3
4
|
/**
|
|
4
5
|
* Columns that order the rows, e.g. `[{ field: 'createdAt', direction: 'DESC' }]`.
|
|
@@ -18,4 +19,8 @@ export interface ListWithCursor<Entity> {
|
|
|
18
19
|
* keyset query loads `pageSize + 1` rows, so it needs no total. Equivalent to `nextCursor !== null`.
|
|
19
20
|
*/
|
|
20
21
|
hasMore: boolean;
|
|
22
|
+
/** The page size used: the `pageSize` given, rounded down, or `10` when it was missing or below 1. */
|
|
23
|
+
pageSize: number;
|
|
24
|
+
/** The ORDER BY the page was read in: the `orderBy` columns, then the primary key columns not among them. */
|
|
25
|
+
orderBy: OrderType[];
|
|
21
26
|
}
|
|
@@ -18,6 +18,10 @@ export type GetRawManyWithTotalsOptions = Omit<GetManyWithTotalsOptions, 'useTak
|
|
|
18
18
|
export interface ListWithTotals<Entity> {
|
|
19
19
|
list: Entity[];
|
|
20
20
|
total: number | null;
|
|
21
|
+
/** The page read, 1-based: the `page` given, or `1` when it was missing or below 1. `null` with `loadAll`. */
|
|
22
|
+
page: number | null;
|
|
23
|
+
/** The page size used: the `pageSize` given, or `10` when it was missing or below 1. `null` with `loadAll`. */
|
|
24
|
+
pageSize: number | null;
|
|
21
25
|
limit: number | null;
|
|
22
26
|
offset: number | null;
|
|
23
27
|
/**
|
|
@@ -26,4 +26,5 @@ __exportStar(require("./search.types"), exports);
|
|
|
26
26
|
__exportStar(require("./typed-having.types"), exports);
|
|
27
27
|
__exportStar(require("./union.types"), exports);
|
|
28
28
|
__exportStar(require("./join-lateral.types"), exports);
|
|
29
|
+
__exportStar(require("./typed-join-and-map.types"), exports);
|
|
29
30
|
__exportStar(require("./query-returning.types"), exports);
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
export type TypedGroupByOptions = {
|
|
2
2
|
/**
|
|
3
3
|
* Group by the quoted database column (`"ticket"."ticket_status"`) instead of `ticket.status`,
|
|
4
|
-
* which TypeORM maps to the column itself.
|
|
5
|
-
*
|
|
4
|
+
* which TypeORM maps to the column itself. Keys of an alias without metadata (a subquery in FROM)
|
|
5
|
+
* are quoted unless this is `false`: PostgreSQL folds an unquoted `sub.firstName` to `firstname`.
|
|
6
6
|
*/
|
|
7
7
|
useQuotes?: boolean;
|
|
8
8
|
};
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import type { SelectQueryBuilder } from 'typeorm';
|
|
2
|
+
/**
|
|
3
|
+
* What a map join joins, as TypeORM's `leftJoinAndMapOne` and the others take it: an entity class or name, a
|
|
4
|
+
* relation (`'user.photos'`), a table name, or a factory that builds a subquery on the query builder it is given.
|
|
5
|
+
*/
|
|
6
|
+
export type JoinAndMapTarget = Function | string | ((qb: SelectQueryBuilder<any>) => SelectQueryBuilder<any>);
|
|
@@ -1,17 +1,19 @@
|
|
|
1
1
|
import type { ObjectLiteral } from 'typeorm';
|
|
2
|
-
declare const typedRoot: unique symbol;
|
|
3
2
|
declare class TypedRootMark<Root> {
|
|
4
|
-
|
|
3
|
+
__typedRoot?(): Root;
|
|
5
4
|
}
|
|
6
5
|
/**
|
|
7
|
-
*
|
|
8
|
-
* with an optional
|
|
6
|
+
* A query builder whose typed callbacks take another root, as `typed<Root>()` returns it:
|
|
7
|
+
* `WithTypedRoot<SelectQueryBuilder<Entity>, Root>`, the builder with an optional `__typedRoot` method that only
|
|
8
|
+
* types carry. A builder of a marked entity, `SelectQueryBuilder<WithTypedRoot<Entity, Root>>`, takes the root too.
|
|
9
9
|
*/
|
|
10
|
-
export type WithTypedRoot<
|
|
10
|
+
export type WithTypedRoot<Marked, Root extends ObjectLiteral> = Marked & TypedRootMark<Root>;
|
|
11
|
+
type IsAny<T> = 0 extends 1 & T ? true : false;
|
|
12
|
+
type BuilderRoot<Builder> = '__typedRoot' extends keyof Builder ? Builder extends TypedRootMark<infer Root> ? Root extends ObjectLiteral ? Root : never : never : never;
|
|
13
|
+
type EntityRoot<Entity> = '__typedRoot' extends keyof Entity ? IsAny<Entity['__typedRoot' & keyof Entity]> extends true ? Entity : Entity extends TypedRootMark<infer Root> ? Root extends ObjectLiteral ? Root : Entity : Entity : Entity;
|
|
11
14
|
/**
|
|
12
|
-
* The root of a builder's typed callbacks: the one set with `typed<Root>()
|
|
13
|
-
*
|
|
14
|
-
* optional mark too, and its root would be inferred as `unknown`.
|
|
15
|
+
* The root of a builder's typed callbacks: the one set with `typed<Root>()` on the builder (`Builder`, which the
|
|
16
|
+
* typed methods pass as `this`) or on its entity, or else the entity.
|
|
15
17
|
*/
|
|
16
|
-
export type TypedRoot<Entity
|
|
18
|
+
export type TypedRoot<Entity, Builder = unknown> = [BuilderRoot<Builder>] extends [never] ? EntityRoot<Entity> : BuilderRoot<Builder>;
|
|
17
19
|
export {};
|
|
@@ -1,10 +1,14 @@
|
|
|
1
1
|
import { ObjectLiteral, SelectQueryBuilder } from 'typeorm';
|
|
2
|
+
import type { ColumnMetadata } from 'typeorm/metadata/ColumnMetadata';
|
|
3
|
+
/** `addSelect`'s selection: an SQL expression, or a factory that builds a subquery on the builder it is given. */
|
|
4
|
+
export type CalculatedSelection<SubEntity extends ObjectLiteral = ObjectLiteral> = string | ((qb: SelectQueryBuilder<ObjectLiteral>) => SelectQueryBuilder<SubEntity>);
|
|
2
5
|
type ResolvedCalculatedColumn = {
|
|
3
6
|
/** The key TypeORM reads the column's value from when it builds the entity. */
|
|
4
7
|
key: string;
|
|
5
8
|
/** `Entity.property`, for error messages. */
|
|
6
9
|
label: string;
|
|
7
10
|
};
|
|
11
|
+
export declare const isCalculated: (column: ColumnMetadata | undefined) => column is ColumnMetadata;
|
|
8
12
|
/** Whether `property` of the entity of `aliasName` (the main alias by default) is a `@CalculatedColumn`. */
|
|
9
13
|
export declare function isCalculatedColumn<Entity extends ObjectLiteral>(builder: SelectQueryBuilder<Entity>, property: string, aliasName?: string): boolean;
|
|
10
14
|
/** The `@CalculatedColumn` `property` of the entity of `aliasName`; throws a `TypeError` for anything else. */
|
|
@@ -16,6 +20,13 @@ export declare function resolveCalculatedColumn<Entity extends ObjectLiteral>(bu
|
|
|
16
20
|
* The alias the entity is built from can't be ordered by: PostgreSQL folds it unquoted
|
|
17
21
|
* (`user_imagesCount` → `user_imagescount`), and quoted it breaks the DISTINCT query TypeORM pages
|
|
18
22
|
* through with `take` / `skip` and joins, which takes only select aliases it knows unquoted.
|
|
23
|
+
*
|
|
24
|
+
* A value already selected for order keeps its alias, so ORDER BY and DISTINCT ON name the same
|
|
25
|
+
* column: PostgreSQL requires DISTINCT ON to match the leading ORDER BY.
|
|
19
26
|
*/
|
|
20
27
|
export declare function selectCalculatedForOrder<Entity extends ObjectLiteral>(builder: SelectQueryBuilder<Entity>, property: string, aliasName: string | undefined, methodName: string): string;
|
|
28
|
+
/** Selects `selection` into the `@CalculatedColumn` `property` of the entity of `aliasName` (the main alias by default). */
|
|
29
|
+
export declare function addSelectCalculatedColumn<Entity extends ObjectLiteral, SubEntity extends ObjectLiteral>(builder: SelectQueryBuilder<Entity>, selection: CalculatedSelection<SubEntity>, property: string, aliasName: string | undefined, methodName: string): SelectQueryBuilder<Entity>;
|
|
30
|
+
/** ORDER BY the value of a `@CalculatedColumn` selected with `addSelectCalculated`, through `orderBy` or `addOrderBy`. */
|
|
31
|
+
export declare function orderByCalculatedColumn<Entity extends ObjectLiteral>(builder: SelectQueryBuilder<Entity>, method: 'orderBy' | 'addOrderBy', property: string, order: 'ASC' | 'DESC' | undefined, nulls: 'NULLS FIRST' | 'NULLS LAST' | undefined, aliasName: string | undefined, methodName: string): SelectQueryBuilder<Entity>;
|
|
21
32
|
export {};
|
|
@@ -1,8 +1,10 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.selectCalculatedForOrder = exports.resolveCalculatedColumn = exports.isCalculatedColumn = void 0;
|
|
3
|
+
exports.orderByCalculatedColumn = exports.addSelectCalculatedColumn = exports.selectCalculatedForOrder = exports.resolveCalculatedColumn = exports.isCalculatedColumn = exports.isCalculated = void 0;
|
|
4
4
|
const DriverUtils_1 = require("typeorm/driver/DriverUtils");
|
|
5
5
|
const sql_utils_1 = require("./sql.utils");
|
|
6
|
+
const ORDER_ALIAS_PREFIX = 'calculated';
|
|
7
|
+
const ORDER_ALIAS_PATTERN = new RegExp(`^${ORDER_ALIAS_PREFIX}_\\w+$`);
|
|
6
8
|
function findCalculatedColumn(builder, property, aliasName) {
|
|
7
9
|
const { expressionMap } = builder;
|
|
8
10
|
const alias = aliasName === undefined
|
|
@@ -19,10 +21,11 @@ function findCalculatedColumn(builder, property, aliasName) {
|
|
|
19
21
|
}
|
|
20
22
|
// @CalculatedColumn: a virtual property without the query of TypeORM's @VirtualColumn
|
|
21
23
|
const isCalculated = (column) => !!(column === null || column === void 0 ? void 0 : column.isVirtualProperty) && !column.query;
|
|
24
|
+
exports.isCalculated = isCalculated;
|
|
22
25
|
/** Whether `property` of the entity of `aliasName` (the main alias by default) is a `@CalculatedColumn`. */
|
|
23
26
|
function isCalculatedColumn(builder, property, aliasName) {
|
|
24
27
|
var _a;
|
|
25
|
-
return isCalculated((_a = findCalculatedColumn(builder, property, aliasName)) === null || _a === void 0 ? void 0 : _a.column);
|
|
28
|
+
return (0, exports.isCalculated)((_a = findCalculatedColumn(builder, property, aliasName)) === null || _a === void 0 ? void 0 : _a.column);
|
|
26
29
|
}
|
|
27
30
|
exports.isCalculatedColumn = isCalculatedColumn;
|
|
28
31
|
/** The `@CalculatedColumn` `property` of the entity of `aliasName`; throws a `TypeError` for anything else. */
|
|
@@ -33,7 +36,7 @@ function resolveCalculatedColumn(builder, property, aliasName, methodName) {
|
|
|
33
36
|
throw new TypeError(`${methodName}: the alias "${aliasName !== null && aliasName !== void 0 ? aliasName : (_a = builder.expressionMap.mainAlias) === null || _a === void 0 ? void 0 : _a.name}" has no entity with "${property}"`);
|
|
34
37
|
}
|
|
35
38
|
const label = `${found.entityName}.${property}`;
|
|
36
|
-
if (!isCalculated(found.column)) {
|
|
39
|
+
if (!(0, exports.isCalculated)(found.column)) {
|
|
37
40
|
throw new TypeError(`${methodName}: ${label} is not a @CalculatedColumn`);
|
|
38
41
|
}
|
|
39
42
|
// shortened past the driver's alias length limit, as TypeORM does it
|
|
@@ -48,6 +51,9 @@ exports.resolveCalculatedColumn = resolveCalculatedColumn;
|
|
|
48
51
|
* The alias the entity is built from can't be ordered by: PostgreSQL folds it unquoted
|
|
49
52
|
* (`user_imagesCount` → `user_imagescount`), and quoted it breaks the DISTINCT query TypeORM pages
|
|
50
53
|
* through with `take` / `skip` and joins, which takes only select aliases it knows unquoted.
|
|
54
|
+
*
|
|
55
|
+
* A value already selected for order keeps its alias, so ORDER BY and DISTINCT ON name the same
|
|
56
|
+
* column: PostgreSQL requires DISTINCT ON to match the leading ORDER BY.
|
|
51
57
|
*/
|
|
52
58
|
function selectCalculatedForOrder(builder, property, aliasName, methodName) {
|
|
53
59
|
const { key, label } = resolveCalculatedColumn(builder, property, aliasName, methodName);
|
|
@@ -55,9 +61,32 @@ function selectCalculatedForOrder(builder, property, aliasName, methodName) {
|
|
|
55
61
|
if (!select) {
|
|
56
62
|
throw new TypeError(`${methodName}: ${label} isn't selected: select it with addSelectCalculated first`);
|
|
57
63
|
}
|
|
58
|
-
|
|
64
|
+
// found by its SQL rather than kept aside, so a clone of the builder finds it too
|
|
65
|
+
const selectedForOrder = builder.expressionMap.selects.find((candidate) => candidate.aliasName !== undefined &&
|
|
66
|
+
ORDER_ALIAS_PATTERN.test(candidate.aliasName) &&
|
|
67
|
+
candidate.selection === select.selection);
|
|
68
|
+
if (selectedForOrder === null || selectedForOrder === void 0 ? void 0 : selectedForOrder.aliasName) {
|
|
69
|
+
return selectedForOrder.aliasName;
|
|
70
|
+
}
|
|
71
|
+
const orderAlias = (0, sql_utils_1.createUniqueParameterName)(ORDER_ALIAS_PREFIX).toLowerCase();
|
|
59
72
|
// TypeORM keeps a subquery selection as its SQL, with its parameters already on the builder
|
|
60
73
|
builder.addSelect(select.selection, orderAlias);
|
|
61
74
|
return orderAlias;
|
|
62
75
|
}
|
|
63
76
|
exports.selectCalculatedForOrder = selectCalculatedForOrder;
|
|
77
|
+
/** Selects `selection` into the `@CalculatedColumn` `property` of the entity of `aliasName` (the main alias by default). */
|
|
78
|
+
function addSelectCalculatedColumn(builder, selection, property, aliasName, methodName) {
|
|
79
|
+
const { key } = resolveCalculatedColumn(builder, property, aliasName, methodName);
|
|
80
|
+
// two calls: addSelect's overloads take a string or a factory, not their union
|
|
81
|
+
if (typeof selection === 'function') {
|
|
82
|
+
return builder.addSelect(selection, key);
|
|
83
|
+
}
|
|
84
|
+
return builder.addSelect(selection, key);
|
|
85
|
+
}
|
|
86
|
+
exports.addSelectCalculatedColumn = addSelectCalculatedColumn;
|
|
87
|
+
/** ORDER BY the value of a `@CalculatedColumn` selected with `addSelectCalculated`, through `orderBy` or `addOrderBy`. */
|
|
88
|
+
function orderByCalculatedColumn(builder, method, property, order, nulls, aliasName, methodName) {
|
|
89
|
+
const orderAlias = selectCalculatedForOrder(builder, property, aliasName, methodName);
|
|
90
|
+
return builder[method](orderAlias, order, nulls);
|
|
91
|
+
}
|
|
92
|
+
exports.orderByCalculatedColumn = orderByCalculatedColumn;
|
|
@@ -1,2 +1,4 @@
|
|
|
1
|
+
/** A Date, also one from another realm (a vm context, a test runner's sandbox), where `instanceof Date` is false. */
|
|
2
|
+
export declare const isDate: (value: unknown) => value is Date;
|
|
1
3
|
export declare const isNil: (val: unknown) => boolean;
|
|
2
4
|
export declare function randomString(length?: number): string;
|
|
@@ -1,6 +1,9 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.randomString = exports.isNil = void 0;
|
|
3
|
+
exports.randomString = exports.isNil = exports.isDate = void 0;
|
|
4
|
+
/** A Date, also one from another realm (a vm context, a test runner's sandbox), where `instanceof Date` is false. */
|
|
5
|
+
const isDate = (value) => Object.prototype.toString.call(value) === '[object Date]';
|
|
6
|
+
exports.isDate = isDate;
|
|
4
7
|
const isNil = (val) => typeof val === 'undefined' || val === null;
|
|
5
8
|
exports.isNil = isNil;
|
|
6
9
|
function randomString(length = 21) {
|
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.buildKeysetCondition = exports.getTextCastType = exports.supportsRowValueComparison = exports.decodeCursor = exports.encodeCursor = exports.InvalidCursorError = void 0;
|
|
4
4
|
const sql_utils_1 = require("./sql.utils");
|
|
5
|
+
const common_utils_1 = require("./common.utils");
|
|
5
6
|
/** A cursor that can't be decoded or doesn't belong to the query's order (e.g. tampered with). */
|
|
6
7
|
class InvalidCursorError extends TypeError {
|
|
7
8
|
constructor(message) {
|
|
@@ -10,9 +11,8 @@ class InvalidCursorError extends TypeError {
|
|
|
10
11
|
}
|
|
11
12
|
}
|
|
12
13
|
exports.InvalidCursorError = InvalidCursorError;
|
|
13
|
-
const isDate = (value) => Object.prototype.toString.call(value) === '[object Date]';
|
|
14
14
|
const toCursorValue = (value) => {
|
|
15
|
-
if (isDate(value)) {
|
|
15
|
+
if ((0, common_utils_1.isDate)(value)) {
|
|
16
16
|
return { $date: value.toISOString() };
|
|
17
17
|
}
|
|
18
18
|
if (typeof value === 'bigint') {
|
|
@@ -77,9 +77,7 @@ function decodeCursor(cursor, fields) {
|
|
|
77
77
|
}
|
|
78
78
|
exports.decodeCursor = decodeCursor;
|
|
79
79
|
/** Databases that compare row values: `(a, b) < (1, 2)`. */
|
|
80
|
-
const supportsRowValueComparison = (driver) => driver
|
|
81
|
-
driver === 'aurora-postgres' ||
|
|
82
|
-
driver === 'cockroachdb' ||
|
|
80
|
+
const supportsRowValueComparison = (driver) => (0, sql_utils_1.isPostgresLikeDriver)(driver) ||
|
|
83
81
|
(0, sql_utils_1.isMysqlLikeDriver)(driver) ||
|
|
84
82
|
(0, sql_utils_1.isSqliteLikeDriver)(driver);
|
|
85
83
|
exports.supportsRowValueComparison = supportsRowValueComparison;
|
|
@@ -88,7 +86,7 @@ exports.supportsRowValueComparison = supportsRowValueComparison;
|
|
|
88
86
|
* (PostgreSQL timestamps have microseconds, a JS Date only milliseconds). `undefined` when unknown.
|
|
89
87
|
*/
|
|
90
88
|
const getTextCastType = (driver) => {
|
|
91
|
-
if (
|
|
89
|
+
if ((0, sql_utils_1.isPostgresLikeDriver)(driver) || (0, sql_utils_1.isSqliteLikeDriver)(driver)) {
|
|
92
90
|
return 'text';
|
|
93
91
|
}
|
|
94
92
|
if ((0, sql_utils_1.isMysqlLikeDriver)(driver)) {
|
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.toJsonPathSql = exports.buildJsonPath = exports.isJsonColumn = void 0;
|
|
4
4
|
const sql_utils_1 = require("./sql.utils");
|
|
5
|
+
const common_utils_1 = require("./common.utils");
|
|
5
6
|
const JSON_COLUMN_TYPES = ['json', 'jsonb', 'simple-json'];
|
|
6
7
|
const isJsonColumn = (column) => JSON_COLUMN_TYPES.includes(String(column.type));
|
|
7
8
|
exports.isJsonColumn = isJsonColumn;
|
|
@@ -14,7 +15,6 @@ function buildJsonPath(fieldNames, jsonOperator) {
|
|
|
14
15
|
.join(' ');
|
|
15
16
|
}
|
|
16
17
|
exports.buildJsonPath = buildJsonPath;
|
|
17
|
-
const isDate = (value) => Object.prototype.toString.call(value) === '[object Date]';
|
|
18
18
|
/**
|
|
19
19
|
* PostgreSQL type to compare a `->>` value (text) with `value` as: text compares `'9' >= '10'` as true.
|
|
20
20
|
* An array (IN, ANY) is typed by its first value; strings and unknown values stay text.
|
|
@@ -27,7 +27,7 @@ function getJsonTextCast(value) {
|
|
|
27
27
|
if (typeof sample === 'boolean') {
|
|
28
28
|
return 'boolean';
|
|
29
29
|
}
|
|
30
|
-
if (isDate(sample)) {
|
|
30
|
+
if ((0, common_utils_1.isDate)(sample)) {
|
|
31
31
|
return 'timestamptz';
|
|
32
32
|
}
|
|
33
33
|
return undefined;
|
|
@@ -1,5 +1,12 @@
|
|
|
1
|
+
import type { ObjectLiteral, SelectQueryBuilder } from "typeorm";
|
|
1
2
|
import { PaginationFilter } from "../types/interfaces/pagination.interface";
|
|
3
|
+
/** The page size to read: a number or a numeric string of at least 1, rounded down; `defaultPageSize` otherwise. */
|
|
4
|
+
export declare const normalizePageSize: (pageSize: unknown) => number;
|
|
5
|
+
/** Limits the rows with `take`, which counts entities rather than rows when the query joins a collection, or with `limit`. */
|
|
6
|
+
export declare const setPageLimit: <Entity extends ObjectLiteral>(builder: SelectQueryBuilder<Entity>, limit: number, useTakeAndSkip: boolean) => SelectQueryBuilder<Entity>;
|
|
2
7
|
export declare const getLimitAndOffset: ({ page, pageSize }: PaginationFilter) => {
|
|
3
8
|
limit: number;
|
|
4
9
|
offset: number;
|
|
10
|
+
page: number;
|
|
11
|
+
pageSize: number;
|
|
5
12
|
};
|
|
@@ -1,16 +1,26 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.getLimitAndOffset = void 0;
|
|
3
|
+
exports.getLimitAndOffset = exports.setPageLimit = exports.normalizePageSize = void 0;
|
|
4
4
|
const constants_1 = require("../constants");
|
|
5
|
+
// an unparsed query parameter is a string: "20" + 1 would be "201"
|
|
6
|
+
const toPositiveInteger = (value, fallback) => {
|
|
7
|
+
const number = typeof value === 'string' && value.trim() !== '' ? Number(value) : value;
|
|
8
|
+
return typeof number === 'number' && Number.isFinite(number) && number >= 1 ? Math.floor(number) : fallback;
|
|
9
|
+
};
|
|
10
|
+
/** The page size to read: a number or a numeric string of at least 1, rounded down; `defaultPageSize` otherwise. */
|
|
11
|
+
const normalizePageSize = (pageSize) => toPositiveInteger(pageSize, constants_1.defaultPageSize);
|
|
12
|
+
exports.normalizePageSize = normalizePageSize;
|
|
13
|
+
/** Limits the rows with `take`, which counts entities rather than rows when the query joins a collection, or with `limit`. */
|
|
14
|
+
const setPageLimit = (builder, limit, useTakeAndSkip) => (useTakeAndSkip ? builder.take(limit) : builder.limit(limit));
|
|
15
|
+
exports.setPageLimit = setPageLimit;
|
|
5
16
|
const getLimitAndOffset = ({ page, pageSize }) => {
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
return { limit, offset };
|
|
17
|
+
const normalizedPage = toPositiveInteger(page, 1);
|
|
18
|
+
const normalizedPageSize = (0, exports.normalizePageSize)(pageSize);
|
|
19
|
+
return {
|
|
20
|
+
limit: normalizedPageSize,
|
|
21
|
+
offset: (normalizedPage - 1) * normalizedPageSize,
|
|
22
|
+
page: normalizedPage,
|
|
23
|
+
pageSize: normalizedPageSize,
|
|
24
|
+
};
|
|
15
25
|
};
|
|
16
26
|
exports.getLimitAndOffset = getLimitAndOffset;
|
|
@@ -1,7 +1,17 @@
|
|
|
1
1
|
import type { ObjectLiteral } from 'typeorm';
|
|
2
|
+
/** The parameter names an SQL fragment refers to, as TypeORM reads its placeholders. */
|
|
3
|
+
export declare function getPlaceholderNames(sql: string): string[];
|
|
2
4
|
/**
|
|
3
5
|
* Renames the parameters of a subquery to unique names, in its SQL and in its parameters. A query
|
|
4
6
|
* has one parameter namespace, so two subqueries with a `:status` each would otherwise both read
|
|
5
7
|
* whichever value was set last. Placeholders that aren't keys of `parameters` stay as they are.
|
|
6
8
|
*/
|
|
7
9
|
export declare function withUniqueParameterNames(sql: string, parameters: ObjectLiteral): [string, ObjectLiteral];
|
|
10
|
+
/**
|
|
11
|
+
* The SQL of a query, without the parentheses a `subQuery()` builder writes around itself, and its parameters, both
|
|
12
|
+
* renamed unique (see `withUniqueParameterNames`).
|
|
13
|
+
*/
|
|
14
|
+
export declare function toSubQuerySql(query: {
|
|
15
|
+
getQuery(): string;
|
|
16
|
+
getParameters(): ObjectLiteral;
|
|
17
|
+
}): [string, ObjectLiteral];
|
|
@@ -1,9 +1,20 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.withUniqueParameterNames = void 0;
|
|
3
|
+
exports.toSubQuerySql = exports.withUniqueParameterNames = exports.getPlaceholderNames = void 0;
|
|
4
4
|
const sql_utils_1 = require("./sql.utils");
|
|
5
5
|
// TypeORM's placeholder syntax, `:name` and `:...name`, as its drivers match it
|
|
6
6
|
const PARAMETER_PLACEHOLDER = /:(\.\.\.)?([A-Za-z0-9_.]+)/g;
|
|
7
|
+
/** The parameter names an SQL fragment refers to, as TypeORM reads its placeholders. */
|
|
8
|
+
function getPlaceholderNames(sql) {
|
|
9
|
+
// a regex of its own: a global regex keeps its position between exec calls
|
|
10
|
+
const placeholder = new RegExp(PARAMETER_PLACEHOLDER.source, 'g');
|
|
11
|
+
const names = [];
|
|
12
|
+
for (let match = placeholder.exec(sql); match !== null; match = placeholder.exec(sql)) {
|
|
13
|
+
names.push(match[2]);
|
|
14
|
+
}
|
|
15
|
+
return names;
|
|
16
|
+
}
|
|
17
|
+
exports.getPlaceholderNames = getPlaceholderNames;
|
|
7
18
|
/**
|
|
8
19
|
* Renames the parameters of a subquery to unique names, in its SQL and in its parameters. A query
|
|
9
20
|
* has one parameter namespace, so two subqueries with a `:status` each would otherwise both read
|
|
@@ -19,3 +30,13 @@ function withUniqueParameterNames(sql, parameters) {
|
|
|
19
30
|
return [renamedSql, renamedParameters];
|
|
20
31
|
}
|
|
21
32
|
exports.withUniqueParameterNames = withUniqueParameterNames;
|
|
33
|
+
/**
|
|
34
|
+
* The SQL of a query, without the parentheses a `subQuery()` builder writes around itself, and its parameters, both
|
|
35
|
+
* renamed unique (see `withUniqueParameterNames`).
|
|
36
|
+
*/
|
|
37
|
+
function toSubQuerySql(query) {
|
|
38
|
+
const sql = query.getQuery();
|
|
39
|
+
const wrapped = 'expressionMap' in query && query.expressionMap.subQuery;
|
|
40
|
+
return withUniqueParameterNames(wrapped ? sql.slice(1, -1) : sql, query.getParameters());
|
|
41
|
+
}
|
|
42
|
+
exports.toSubQuerySql = toSubQuerySql;
|
|
@@ -4,6 +4,7 @@ exports.attachPeriodFilter = void 0;
|
|
|
4
4
|
const sql_utils_1 = require("./sql.utils");
|
|
5
5
|
const where_utils_1 = require("./where.utils");
|
|
6
6
|
const time_zone_utils_1 = require("./time-zone.utils");
|
|
7
|
+
const common_utils_1 = require("./common.utils");
|
|
7
8
|
const DATE_ONLY = /^\d{4}-\d{2}-\d{2}$/;
|
|
8
9
|
/** `'2024-01-31'` as a UTC midnight Date, or a `TypeError` if it is not a calendar date (`'2024-02-30'`). */
|
|
9
10
|
function parseDateOnly(value, name) {
|
|
@@ -18,7 +19,7 @@ function normalizeBoundary(value, name) {
|
|
|
18
19
|
if (value === undefined || value === null || value === '') {
|
|
19
20
|
return undefined;
|
|
20
21
|
}
|
|
21
|
-
if (
|
|
22
|
+
if ((0, common_utils_1.isDate)(value)) {
|
|
22
23
|
if (isNaN(value.getTime())) {
|
|
23
24
|
throw new TypeError(`Invalid ${name}: invalid Date`);
|
|
24
25
|
}
|
|
@@ -1,9 +1,18 @@
|
|
|
1
|
+
import { DeleteQueryBuilder, SelectQueryBuilder, UpdateQueryBuilder } from 'typeorm';
|
|
2
|
+
import { SoftDeleteQueryBuilder } from 'typeorm/query-builder/SoftDeleteQueryBuilder';
|
|
1
3
|
export type PatchPrototypeOptions = {
|
|
2
4
|
/** Leave a method the target already has, own or inherited: TypeORM's, or another library's. */
|
|
3
5
|
onlyMissing?: boolean;
|
|
4
6
|
};
|
|
7
|
+
/** The query builders with a WHERE clause, which the where extensions patch. */
|
|
8
|
+
export declare const WHERE_QUERY_BUILDERS: (typeof SelectQueryBuilder | typeof UpdateQueryBuilder | typeof DeleteQueryBuilder | typeof SoftDeleteQueryBuilder)[];
|
|
5
9
|
export declare function patchPrototype<T extends {
|
|
6
10
|
prototype: any;
|
|
7
11
|
}, S extends {
|
|
8
12
|
prototype: any;
|
|
9
13
|
}>(target: T, source: S, options?: PatchPrototypeOptions): void;
|
|
14
|
+
export declare function patchPrototypes<S extends {
|
|
15
|
+
prototype: any;
|
|
16
|
+
}>(targets: ReadonlyArray<{
|
|
17
|
+
prototype: any;
|
|
18
|
+
}>, source: S, options?: PatchPrototypeOptions): void;
|
|
@@ -1,7 +1,11 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
/* eslint-disable @typescript-eslint/no-explicit-any */
|
|
3
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
-
exports.patchPrototype = void 0;
|
|
3
|
+
exports.patchPrototypes = exports.patchPrototype = exports.WHERE_QUERY_BUILDERS = void 0;
|
|
4
|
+
/* eslint-disable @typescript-eslint/no-explicit-any */
|
|
5
|
+
const typeorm_1 = require("typeorm");
|
|
6
|
+
const SoftDeleteQueryBuilder_1 = require("typeorm/query-builder/SoftDeleteQueryBuilder");
|
|
7
|
+
/** The query builders with a WHERE clause, which the where extensions patch. */
|
|
8
|
+
exports.WHERE_QUERY_BUILDERS = [typeorm_1.SelectQueryBuilder, typeorm_1.UpdateQueryBuilder, typeorm_1.DeleteQueryBuilder, SoftDeleteQueryBuilder_1.SoftDeleteQueryBuilder];
|
|
5
9
|
function patchPrototype(target, source, options = {}) {
|
|
6
10
|
for (const method of Object.keys(source.prototype)) {
|
|
7
11
|
if (options.onlyMissing && method in target.prototype) {
|
|
@@ -11,3 +15,9 @@ function patchPrototype(target, source, options = {}) {
|
|
|
11
15
|
}
|
|
12
16
|
}
|
|
13
17
|
exports.patchPrototype = patchPrototype;
|
|
18
|
+
function patchPrototypes(targets, source, options) {
|
|
19
|
+
for (const target of targets) {
|
|
20
|
+
patchPrototype(target, source, options);
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
exports.patchPrototypes = patchPrototypes;
|
|
@@ -1,7 +1,19 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { QueryBuilder } from 'typeorm';
|
|
2
|
+
import type { ObjectLiteral, QueryRunner, SelectQueryBuilder, WhereExpressionBuilder } from 'typeorm';
|
|
2
3
|
import type { ColumnMetadata } from 'typeorm/metadata/ColumnMetadata';
|
|
4
|
+
import type { Alias } from 'typeorm/query-builder/Alias';
|
|
3
5
|
import type { KeyProxyCallback } from '../types/modules/proxy-callback.types';
|
|
6
|
+
import type { OrderType } from '../types/interfaces/ordering.interface';
|
|
7
|
+
import { KeyHolder } from './proxy-key.utils';
|
|
4
8
|
import { JsonPathSqlOptions } from './json-path.utils';
|
|
9
|
+
/**
|
|
10
|
+
* The aliases of the query and of the queries it is part of, its own first. The builder of a `Brackets` callback
|
|
11
|
+
* has the outer query's main alias but an empty alias list: the aliases, joins included, are on its parent. A
|
|
12
|
+
* subquery sees the aliases of the outer query too.
|
|
13
|
+
*/
|
|
14
|
+
export declare function listQueryAliases(builder: WhereExpressionBuilder | QueryBuilder<ObjectLiteral>): Alias[];
|
|
15
|
+
/** Replaces placeholders of `deferColumnKey` in SQL built by `builder`, through the aliases it has by then. */
|
|
16
|
+
export declare function resolveDeferredKeys(builder: WhereExpressionBuilder, statement: string): string;
|
|
5
17
|
/**
|
|
6
18
|
* Database name of an entity property's column (`@Column({ name })`), looked up in the metadata of
|
|
7
19
|
* a query alias (the main alias when `aliasName` is undefined). `undefined` when the alias has no
|
|
@@ -29,6 +41,11 @@ export declare function findFieldColumn(builder: WhereExpressionBuilder, field:
|
|
|
29
41
|
* `stringToSQLIdentifier` does, in the driver's quotes.
|
|
30
42
|
*/
|
|
31
43
|
export declare function toFieldSql(builder: WhereExpressionBuilder, field: string): string;
|
|
44
|
+
/** The alias and property of the `@CalculatedColumn` a typed key picks; undefined for any other key. */
|
|
45
|
+
export declare function findTypedCalculatedProperty(builder: WhereExpressionBuilder, keyHolder: KeyHolder): {
|
|
46
|
+
aliasName: string | undefined;
|
|
47
|
+
propertyPath: string;
|
|
48
|
+
} | undefined;
|
|
32
49
|
/**
|
|
33
50
|
* SQL key for a typed callback on `builder`: `"alias"."column"`, or `"column"` on UPDATE / DELETE.
|
|
34
51
|
*
|
|
@@ -47,10 +64,32 @@ export declare function isTypedJsonPath<Type extends ObjectLiteral>(builder: Whe
|
|
|
47
64
|
*/
|
|
48
65
|
export declare function getTypedSingleColumnKey<Type extends ObjectLiteral>(builder: WhereExpressionBuilder, callback: KeyProxyCallback<Type>, methodName: string, jsonOptions?: JsonPathSqlOptions): string;
|
|
49
66
|
/**
|
|
50
|
-
*
|
|
67
|
+
* The alias and the entity property a typed callback picks, for methods that take a property rather than a column
|
|
68
|
+
* (a `@CalculatedColumn`): `u => u.imagesCount` is on the main alias, `q => q.owner.imagesCount` on `owner`.
|
|
69
|
+
*/
|
|
70
|
+
export declare function resolveTypedProperty<Type extends ObjectLiteral>(builder: WhereExpressionBuilder, callback: KeyProxyCallback<Type>, methodName: string): {
|
|
71
|
+
aliasName: string | undefined;
|
|
72
|
+
propertyPath: string;
|
|
73
|
+
};
|
|
74
|
+
/**
|
|
75
|
+
* Key for typed select / order / distinct / group by on a SelectQueryBuilder.
|
|
51
76
|
*
|
|
52
77
|
* Without quotes it is `alias.propertyPath` (`user.name`, `images.url`, `p.address.city`),
|
|
53
78
|
* which TypeORM maps to the column itself. With `useQuotes` it is the quoted database column
|
|
54
|
-
* (`"t"."ticket_status"`), since TypeORM doesn't map quoted keys.
|
|
79
|
+
* (`"t"."ticket_status"`), since TypeORM doesn't map quoted keys. An alias of the query without
|
|
80
|
+
* metadata (a subquery or a CTE in FROM or a join), or one the query still doesn't have when the SQL
|
|
81
|
+
* is built, is quoted unless `useQuotes` is `false`: TypeORM leaves its keys as written, and
|
|
82
|
+
* PostgreSQL folds an unquoted `cte.firstName` to `firstname`.
|
|
83
|
+
* Strings are kept as is.
|
|
84
|
+
*/
|
|
85
|
+
export declare function getTypedSelectionKey<Type extends ObjectLiteral>(builder: WhereExpressionBuilder, selection: KeyProxyCallback<Type> | KeyHolder | string, useQuotes?: boolean, columnsFor?: string): string | string[];
|
|
86
|
+
/**
|
|
87
|
+
* The ORDER BY a query is built with, in the order it was applied. `allOrderBys`, not `orderBys`: it is what the SQL
|
|
88
|
+
* is built from, so without an explicit order it falls back to the `orderBy` of @Entity, and respects the
|
|
89
|
+
* `disable-global-order` option.
|
|
55
90
|
*/
|
|
56
|
-
export declare function
|
|
91
|
+
export declare function getAppliedOrderBy<Entity extends ObjectLiteral>(builder: QueryBuilder<Entity>): OrderType[];
|
|
92
|
+
/** The query without paging: no ORDER BY (nor the entity's default one), LIMIT, OFFSET, take or skip. */
|
|
93
|
+
export declare function withoutPaging<Entity extends ObjectLiteral>(query: SelectQueryBuilder<Entity>): SelectQueryBuilder<Entity>;
|
|
94
|
+
/** The query runner a builder was created with, from a transactional manager; `undefined` for one from the pool. */
|
|
95
|
+
export declare function getQueryRunner<Entity extends ObjectLiteral>(builder: QueryBuilder<Entity>): QueryRunner | undefined;
|