import { EntityMetadata, FindOperator, FindOptionsRelations, ObjectLiteral, Repository, SelectQueryBuilder } from 'typeorm'; import { ColumnMetadata } from 'typeorm/metadata/ColumnMetadata'; import { EmbeddedMetadata } from 'typeorm/metadata/EmbeddedMetadata'; /** * Joins 2 keys as `K`, `K.P`, `K.(P` or `K.P)` * The parenthesis notation is included for embedded columns */ type Join = K extends string ? P extends string ? `${K}${'' extends P ? '' : '.'}${P | `(${P}` | `${P})`}` : never : never; /** * Get the previous number between 0 and 10. Examples: * Prev[3] = 2 * Prev[0] = never. * Prev[20] = 0 */ type Prev = [never, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, ...0[]]; /** * Unwrap Promise to T */ type UnwrapPromise = T extends Promise ? UnwrapPromise : T; /** * Unwrap Array to T */ type UnwrapArray = T extends Array ? UnwrapArray : T; /** * Find all the dotted path properties for a given column. * * T: The column * D: max depth */ export type Column = [D] extends [never] ? never : T extends Record ? { [K in keyof T]-?: K extends string ? T[K] extends string | number ? `${K}` : T[K] extends Date ? `${K}` : T[K] extends Array ? // yes, unwrap it, and recurse deeper `${K}` | Join, Prev[D]>> : T[K] extends Promise ? U extends Array ? `${K}` | Join, Prev[D]>> : `${K}` | Join, Prev[D]>> : // no, we have no more special cases, so treat it as an `${K}` | Join> : never; }[keyof T] : ''; export type RelationColumn = Extract, { [K in Column]: K extends `${infer R}.${string}` ? R : never; }[Column]>; export type Order = [Column | Column[], 'ASC' | 'DESC']; export type SortBy = Order[]; export type MappedColumns = { [key in Column | (string & {})]: S; }; export type JoinMethod = 'leftJoinAndSelect' | 'innerJoinAndSelect'; export type RelationSchemaInput = FindOptionsRelations | RelationColumn[]; export type RelationSchema = { [relation in Column | (string & {})]: true; }; export declare function isEntityKey(entityColumns: (Column | (string & {}))[], column: string): column is Column; export declare const positiveNumberOrDefault: (value: number | undefined, defaultValue: number, minValue?: 0 | 1) => number; export type ColumnProperties = { propertyPath?: string; propertyName: string; isNested: boolean; column: string; }; export declare function getPropertiesByColumnName(column: string): ColumnProperties; export declare function extractVirtualProperty(qb: SelectQueryBuilder, columnProperties: ColumnProperties): Partial; export declare function includesAllPrimaryKeyColumns(qb: SelectQueryBuilder, propertyPath: string[]): boolean; export declare function getPrimaryKeyColumns(qb: SelectQueryBuilder, entityName?: string): string[]; export declare function getMissingPrimaryKeyColumns(qb: SelectQueryBuilder, transformedCols: string[]): string[]; export declare function hasColumnWithPropertyPath(qb: SelectQueryBuilder, columnProperties: ColumnProperties): boolean; export declare function checkIsRelation(qb: SelectQueryBuilder, propertyPath: string): boolean; /** * Whether a dot-path terminates on a relation rather than a column, e.g. `home` or `home.pillows` * (as opposed to `home.street`). Such a column names the relation itself, so it carries no value to * compare — it can only be tested for presence (`$any`) or absence (`$none`). * * Walks relations into their inverse entity and embeddeds into their own metadata, so it resolves * nested paths of any depth. */ export declare function isRelationPath(qb: SelectQueryBuilder, column: string): boolean; export declare function checkIsNestedRelation(qb: SelectQueryBuilder, propertyPath: string): boolean; export declare function checkIsOneOfNestedPrimaryColumns(qb: SelectQueryBuilder, propertyPath: string): boolean; export declare function checkIsEmbedded(qb: SelectQueryBuilder, propertyPath: string): boolean; export declare function checkIsArray(qb: SelectQueryBuilder, propertyName: string): boolean; export declare function checkIsJsonb(qb: SelectQueryBuilder, propertyName: string): boolean; /** * Describes how a dot-separated filter path maps to a JSONB column. * * Given a path like `detail.referrer.source.platform`: * - relationPath: ['detail'] — segments that are TypeORM relations (require JOIN) * - jsonbColumn: 'referrer' — the JSONB column on the final relation entity * - jsonPath: ['source', 'platform'] — the key path inside the JSON value */ export interface JsonbPathResolution { isJsonb: boolean; /** Relation segments leading up to the entity that owns the JSONB column */ relationPath: string[]; /** Name of the JSONB column on that entity */ jsonbColumn: string; /** Key path inside the JSON value (may be empty for a top-level JSONB filter) */ jsonPath: string[]; } /** * Column data types treated as JSON. Both `jsonb` and plain `json` are supported: * `#>>` path extraction works on both, and TypeORM's `JsonContains` ($eq/$in/$contains) * emits ` ::jsonb @> :value`, which casts a `json` column to `jsonb` for free. */ export declare const JSON_COLUMN_TYPES: string[]; /** * Whether a dot-path resolves to a real column, relation or embedded on the entity. * * Follows relations into their inverse entity and embeddeds into their own metadata; a JSON(B) * column terminates the walk, since its trailing segments are a JSON key path rather than * relations. A polymorphic `~` group resolves when every alternative does. */ export declare function resolvesToColumn(metadata: EntityMetadata | EmbeddedMetadata, column: string): boolean; /** * Walks the dot-separated `column` path through TypeORM entity metadata to determine * whether the path terminates in a JSONB column and, if so, where the relation chain * ends and the JSON key path begins. * * Algorithm: * For each segment, check whether the current entity metadata has a relation * with that name. If yes, follow the relation and continue. If no, check * whether it is a JSONB column on the current entity. If yes, all remaining * segments are JSON key path. Otherwise, the path is not JSONB. */ export declare function resolveJsonbPath(qb: SelectQueryBuilder, column: string): JsonbPathResolution; export declare function fixColumnAlias(properties: ColumnProperties, alias: string, isRelation?: boolean, isVirtualProperty?: boolean, isEmbedded?: boolean, query?: ColumnMetadata['query'], qb?: SelectQueryBuilder): string; export declare function getQueryUrlComponents(path: string): { queryOrigin: string; queryPath: string; }; export declare function isISODate(str: string): boolean; /** True for a date-only string (`YYYY-MM-DD`), used to coerce filters on `date` columns whose * values carry no time component and therefore never match {@link isISODate}. */ export declare function isISODateOnly(str: string): boolean; /** Whether a filter value on a column of this type should be coerced to a JS number. */ export declare function isNumberColumnType(type: unknown): boolean; /** Whether a filter value on a column of this type should be coerced to a JS boolean. */ export declare function isBooleanColumnType(type: unknown): boolean; /** * Date-only column type (`@Column('date')`), kept separate from {@link isDateColumnType}. Cursor * pagination relies on `isDateColumnType` and calls `Date.getTime()` on the loaded value; a * `date` column may surface as a plain string there, so it is only treated as temporal for filter * value coercion, not for cursor generation. */ export declare function isDateOnlyColumnType(type: unknown): boolean; /** * True only for strings that represent a finite JS number. Rejects empty/whitespace-only input * (which `Number('')` would turn into `0`) and anything non-numeric, so a value is never coerced * to a number by accident. */ export declare function isFiniteNumericString(value: string): boolean; /** * Parses the closed set of boolean tokens (`true`/`false`/`1`/`0`, case-insensitive). Returns * `undefined` for anything else so a value that does not clearly denote a boolean is left as-is. */ export declare function parseBooleanToken(value: string): boolean | undefined; /** * Resolves the TypeORM column type for a (possibly nested) filter path, so a filter value can be * coerced to the matching JavaScript type. Handles: * - root columns (`age`), * - embedded columns (`size.height`) via TypeORM's dotted property-path lookup, and * - relation columns, including nested chains (`toys.name`, `home.pillows.color`), by walking * the relation chain hop by hop to the leaf column. * * Returns `undefined` when the path cannot be resolved to a concrete column (e.g. a virtual/ * computed column with no backing column, or an unknown segment); callers then leave the value * as a string. */ export declare function resolveColumnType(qb: SelectQueryBuilder, column: string): unknown; export declare function isRepository(repo: unknown | Repository): repo is Repository; export declare function isFindOperator(value: unknown | FindOperator): value is FindOperator; export declare function createRelationSchema(configurationRelations: RelationSchemaInput): RelationSchema; export declare function mergeRelationSchema(...schemas: RelationSchema[]): any; export declare function getPaddedExpr(valueExpr: string, length: number, dbType: string): string; export declare function isDateColumnType(type: any): boolean; export declare function quoteColumn(columnName: string, isMySqlOrMariaDb: boolean): string; export declare function isNil(v: unknown): boolean; export declare function isNotNil(v: unknown): boolean; export declare function andWhereNoneExist(qb: SelectQueryBuilder, existsQb: SelectQueryBuilder): SelectQueryBuilder; /** * Adds a condition to the query builder that ensures all related entities match the given filter criteria. * * This method combines two conditions: * 1. EXISTS(X) - There must be at least one related entity matching the criteria * 2. NOT EXISTS(NOT X) - There must not be any related entities that don't match the criteria * * Together, these conditions ensure that all related entities match the filter criteria X. * For example, when filtering pillows in a cat home, this could find homes where ALL pillows are red. * * If you need to include cases where there are either 0 or all entities match, use $none:$not:X instead. * * @param {SelectQueryBuilder} qb The main query builder instance to add the condition to. * @param {SelectQueryBuilder} existsQb The subquery builder containing the filter criteria. * @return {SelectQueryBuilder} The modified query builder with the combined EXISTS conditions. */ export declare function andWhereAllExist(qb: SelectQueryBuilder, existsQb: SelectQueryBuilder): SelectQueryBuilder; /** * Strips the parts of a fully-built paginate query that do not affect how many root * entities match, so the count query stays cheap even when many relations are joined * for hydration. * * Pruning rules: * - INNER joins are always kept: they restrict the result set even when unreferenced. * - LEFT joins are kept only when the WHERE clause references their alias. * - Parent joins of any kept join are kept, so nested relation chains stay intact. * - ORDER BY is cleared, since ordering does not change the count. * * Used by `paginate` when `PaginateConfig.optimizedCount` is enabled. It can also be * composed inside a custom `PaginateConfig.buildCountQuery`. * * @param {SelectQueryBuilder} qb A clone of the fully-built query builder. * @return {SelectQueryBuilder} The same builder with count-irrelevant joins removed. */ export declare function buildOptimizedCountQuery(qb: SelectQueryBuilder): SelectQueryBuilder; /** * Whether a row can be ordered by `column` — whether it names one value. * * A path that ends on a relation names no value of its own, and TypeORM compiles it to an ORDER BY * over a column its paginated DISTINCT subquery never selects (`column distinctAlias.__root_ * does not exist`). Ordering *through* a to-many (`toys.id`) does name a value and stays allowed, * as does a `json` column, which is ordered as `jsonb` (see orderableColumnExpression). */ export declare function isOrderableColumn(metadata: EntityMetadata, column: string): boolean; /** * Whether ordering by `column` needs it cast. Postgres `json` has no ordering operators, `jsonb` * has a total order, and the cast between them is exact — so a `json` column is ordered as `jsonb` * rather than refused, and sorts like the `jsonb` column beside it. */ export declare function needsJsonbSortCast(qb: SelectQueryBuilder, column: string): boolean; /** * Whether `column` names a Postgres `json` column itself rather than a key path into one. Such a * column has no equality or comparison operators — there is no `json = unknown` — so a value filter * on it cannot be compiled at all. A key path (`col.key`) is read out as text and is fine, as is * `$null`. `jsonb`, which does have those operators, is unaffected. */ export declare function isBareJsonColumn(metadata: EntityMetadata, column: string): boolean; export {};