import { EntityMetadata, Repository, SelectQueryBuilder } from 'typeorm'; import { Sorting, ListParam } from '../service/common-types/list-param.js'; import { Domain } from '../service/domain/domain.js'; /** * `search` 연산자의 매칭 방식. * - contains(기본): `%v%` — 어디든 포함(유연하나 인덱스 미활용). * - startsWith: `v%` — 접두 일치(인덱스 활용 가능 → 대용량에서 빠름). * - exact: `v` — 정확 일치(대소문자 무시). */ export type SearchMode = 'contains' | 'startsWith' | 'exact'; /** * Builds a TypeORM SelectQueryBuilder from a generic ListParam (filters, search, sortings, * pagination) plus optional multi-tenant domain scoping. Returns the builder so callers can * further chain joins/select/where before executing (e.g. getMany / getManyAndCount). * * Supported filter operators (`Filter.operator`): * eq, noteq, like, nlike, i_like, i_nlike, search, lt, gt, lte, gte, * in, notin, notin_with_null, between, * is_null, is_not_null, is_true, is_false, is_not_true, is_not_false, * is_present, is_blank, is_empty_num_id. * An unknown operator throws a clear, actionable error. * * Behavior notes: * - `search` uses case-insensitive substring match (`LOWER(col) LIKE %v%`) and requires the column * to be listed in `searchables`. * - `like`/`i_like` filters are IGNORED (with a console.warn) unless the column is in `searchables`, * to avoid unindexed full-table scans. * - Boolean operators are emitted as parameter-bound comparisons (portable across all supported DBs). * - Domain scoping is applied only when `domain` is provided, honoring `params.inherited` * (None = own domain, Include = own + parent, Only = parent). * - Pagination uses skip/take; with joins this triggers TypeORM's two-query strategy for correctness. * - Unknown filter columns / operators / relations throw a clear, actionable error (fail-fast). * * @param options.repository TypeORM repository (or a tx-scoped repository) to build from. * @param options.params ListParam: `{ filters, sortings, pagination, inherited }`. * @param [options.domain] Optional current domain `{ id, parentId }` for tenant scoping. * @param [options.alias] Optional entity alias (defaults to the entity name). * @param [options.searchables] Columns eligible for `search`/`like` filtering. * @param [options.filtersMap] Maps a filter/sort name to a column or relation column, e.g. * `{ ownerName: { columnName: 'name', relationColumn: 'owner' } }`. * @param [options.searchMode] `search` matching mode: 'contains'(default) / 'startsWith' / 'exact'. * 'startsWith' emits `v%` (prefix) which can use an index on large tables. * @returns {SelectQueryBuilder} The constructed SelectQueryBuilder (not yet executed). */ export declare function getQueryBuilderFromListParams(options: { repository: Repository; params: ListParam; domain?: Domain; alias?: string; searchables?: string[]; filtersMap?: { [name: string]: { columnName: string; relationColumn?: string; }; }; /** Trusted server-defined joined column expressions. Never populate this from request input. */ columnExpressions?: Record; searchMode?: SearchMode; /** * 페이지 크기를 안 준 호출에 씌울 기본 상한. * * 지정하지 않으면 **예전과 똑같이 무제한**이다(하위호환). 다만 무제한으로 나가는 질의는 경고를 남긴다 — * 표가 작을 때는 아무 문제가 없다가 데이터가 늘면 조용히 무너지는 종류의 결함이라, 늘기 전에 보여야 한다. */ defaultLimit?: number; /** 호출자가 요구한 페이지 크기의 상한. 넘겨도 여기서 잘린다(서버 보호). */ maxLimit?: number; /** * 정렬 허용 컬럼. 주면 목록에 없는 정렬은 **명시 실패**한다. * * `searchables` 로 인덱스 없는 LIKE 는 막으면서 정렬은 아무 컬럼이나 받던 비대칭을 메운다 — * 인덱스 없는 컬럼 정렬은 큰 표에서 전체 정렬 스캔을 부른다. */ sortables?: string[]; /** * 거르기 허용 컬럼. 주면 목록에 없는 칸의 거르기(검색 연산 포함)는 **명시 실패**한다. * * 고르기 문(`<개념>Choices`, ADR-0139)이 쓴다. 고르기 문은 가리키는 칸만 내는데, 숨긴 칸으로 거를 수 * 있으면 결과에 끼는지 아닌지로 그 칸의 내용을 맞혀 볼 수 있다. 내는 칸만 거를 수 있게 한다. */ filterables?: string[]; /** * 커서 페이징의 타이브레이커 컬럼. 기본은 엔티티 PK. * * 마지막 정렬 축은 반드시 **유일**해야 한다 — 같은 값이 여러 행에 있으면 페이지 경계에서 * 행이 건너뛰어지거나 반복된다. */ cursorTiebreak?: string; /** * The order this list has when the reader sorts by nothing - and, after the reader's columns, the order that * settles their ties. Left out, the newest row comes first (`createdAt`, when the entity has it): the latest on top * is the rule for every list (the user, 2026-11-02). The primary key closes it, so a page boundary never repeats or * drops a row. Keyset paging keeps its own axes (`cursorSortings`) and is not touched. */ defaultSortings?: Sorting[]; }): SelectQueryBuilder; /** * The reader's columns, then the list's own order (`defaultSortings`, or the newest first by `createdAt`), then the * primary key - each column once, the reader's way kept where they named it. */ export declare function settledSortings(sortings: Sorting[] | undefined, defaultSortings: Sorting[] | undefined, metadata: EntityMetadata, tiebreak: string | undefined): Sorting[]; /** * How many rows of a list hold each value of one field - the numbers beside a list's filter chips (an opportunity's * stages, a request's statuses). Counted by the database, grouped by the field, under the list's own conditions: * the same options as the list (domain, filters, search, searchables ...), less the conditions on `field` itself, so * each chip says how many it would show whichever chips are pressed. The list's pagination and sorting play no part; * the grouped rows are left unsorted (the builder sorts a list newest first, which a GROUP BY cannot carry). * * `field` is a plain column of the entity. A value no row holds is absent from the map - a caller lists its own values, * each as a `ListValueCount`. */ export declare function countListByField(options: Parameters>[0] & { field: string; /** The conditions a list door adds of its own after the builder (the caller's own rows, say) - added here alike. */ narrow?: (builder: SelectQueryBuilder) => void; }): Promise>;