query-builder-prisma 0.0.0-stage → 0.2.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.
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/index.ts","../src/core/conditions.ts","../src/core/pagination.ts","../src/dialects/capabilities.ts","../src/dialects/detect.ts","../src/dialects/registry.ts","../src/core/query-builder.ts"],"sourcesContent":["/**\n * query-builder-prisma\n *\n * Zero-coupling, fluent, fully type-safe query builder for any Prisma model\n * delegate. Works with every Prisma version (5/6/7/8 tested; future versions by\n * design) and every database Prisma supports. See ARCHITECTURE.md for the\n * architecture and AGENTS.md for the working rules.\n */\n\n// Core\nexport { QueryBuilder, NoResultError } from './core/query-builder';\nexport type { QueryBuilderOptions } from './core/query-builder';\n\n// Dialects\nexport {\n configQueryBuilder,\n registerDialect,\n resolveDialect,\n resetDialectConfig,\n setDialectDetector,\n} from './dialects/registry';\nexport { DIALECT_CAPABILITIES } from './dialects/capabilities';\nexport { detectDialect } from './dialects/detect';\nexport type { Dialect, DialectCapabilities } from './dialects/capabilities';\nexport type { ResolvedDialect } from './dialects/registry';\n\n// Structural types (for advanced wiring by consumers)\nexport type {\n FindManyArgsOf,\n IncludeOf,\n OrderByOf,\n OrderKeyOf,\n PrismaModelDelegate,\n RowElementOf,\n RowsOf,\n SelectOf,\n WhereKeyOf,\n WhereOf,\n} from './types/delegate';\nexport type {\n ApplyInclude,\n ApplyProjection,\n ApplySelect,\n FindResultOf,\n} from './types/projection';\n\n// Public option/meta types\nexport type {\n CursorDirection,\n CursorMeta,\n FilterInput,\n PaginationMeta,\n PaginationMetaNoTotal,\n RangeBound,\n RangeInput,\n SortOrder,\n} from './types/public';\n","/** Build-time condition assembly helpers used by the QueryBuilder core. */\n\n/**\n * Keys we refuse to write into objects we build: computed-key assignment on\n * `'__proto__'` would set a local prototype instead of an own property\n * (audit F16 — reachable via JSON-parsed request bodies).\n */\nconst DANGEROUS_KEYS: ReadonlySet<string> = new Set(['__proto__', 'constructor', 'prototype']);\n\nfunction isSafeKey(key: string): boolean {\n return !DANGEROUS_KEYS.has(key);\n}\n\n/** Strip `undefined` values so optional query params can be passed directly. */\nexport function stripUndefined(obj: Record<string, unknown>): Record<string, unknown> {\n const result: Record<string, unknown> = {};\n for (const [key, value] of Object.entries(obj)) {\n if (value !== undefined && isSafeKey(key)) {\n result[key] = value;\n }\n }\n return result;\n}\n\n/**\n * Recursive {@link stripUndefined}: rebuilds plain objects and arrays of plain\n * objects without `undefined` values at any depth. Values that are not plain\n * objects (Date, BigInt, class instances like Decimal) pass through untouched\n * and the input is never mutated. Used by `.custom()` so a later\n * `custom({ key: undefined })` cannot overwrite an earlier value (audit F15).\n */\nexport function deepStripUndefined(obj: Record<string, unknown>): Record<string, unknown> {\n const result: Record<string, unknown> = {};\n for (const [key, value] of Object.entries(obj)) {\n if (value === undefined || !isSafeKey(key)) {\n continue;\n }\n result[key] = isDeepStrippable(value)\n ? deepStripUndefined(value)\n : Array.isArray(value)\n ? value.map((item) => (isDeepStrippable(item) ? deepStripUndefined(item) : item))\n : value;\n }\n return result;\n}\n\n/** True for objects we may rebuild when deep-stripping (prototype-owned only). */\nfunction isDeepStrippable(value: unknown): value is Record<string, unknown> {\n if (typeof value !== 'object' || value === null || Array.isArray(value)) {\n return false;\n }\n const proto: unknown = Object.getPrototypeOf(value);\n return proto === Object.prototype || proto === null;\n}\n\n/** True for plain objects (not arrays, not null). */\nexport function isPlainObject(value: unknown): value is Record<string, unknown> {\n return typeof value === 'object' && value !== null && !Array.isArray(value);\n}\n\n/**\n * Expand `'avatar.size'` + a leaf value into `{ avatar: { size: leaf } }`.\n * Empty segments are skipped; a path containing a `__proto__`/`constructor`/\n * `prototype` segment expands to `{}` — refused, never written (audit F16).\n */\nexport function expandDotPath(path: string, leaf: unknown): Record<string, unknown> {\n const keys = path.split('.').filter((key) => key.length > 0);\n if (keys.length === 0 || keys.some((key) => !isSafeKey(key))) {\n return {};\n }\n let current: unknown = leaf;\n for (let i = keys.length - 1; i >= 0; i--) {\n const key = keys[i];\n if (key === undefined) {\n continue;\n }\n current = { [key]: current };\n }\n return current as Record<string, unknown>;\n}\n\n/**\n * AND-combine accumulated conditions with an optional seeded `where`.\n * A single condition is returned unwrapped (semantically identical to an\n * `AND` of one); zero conditions yields `undefined` (no `where` at all).\n */\nexport function combineAnd(\n conditions: readonly object[],\n customWhere?: unknown,\n): object | undefined {\n const all: object[] = isPlainObject(customWhere) ? [customWhere, ...conditions] : [...conditions];\n if (all.length === 0) {\n return undefined;\n }\n if (all.length === 1) {\n return all[0];\n }\n return { AND: all };\n}\n","/**\n * Offset (\"skip/take\") and cursor (\"seek\") pagination math — pure functions,\n * fully unit-testable without any database.\n */\nimport type { CursorDirection, CursorMeta, PaginationMeta } from '../types/public';\n\nexport const DEFAULT_PAGE_SIZE = 10;\nexport const MAX_PAGE_SIZE = 1000;\n/** Upper bound for offset `skip` so deep pages cannot hit the DB unbounded (audit F18). */\nexport const MAX_SKIP = 100_000;\n\n/** Clamp a page size to `[1, MAX_PAGE_SIZE]`; non-finite input gets the default. */\nexport function clampLimit(limit: number): number {\n if (!Number.isFinite(limit)) {\n return DEFAULT_PAGE_SIZE;\n }\n return Math.min(Math.max(1, Math.floor(limit)), MAX_PAGE_SIZE);\n}\n\n/** Clamp a 1-based page number; `0`, negatives and NaN all become page 1. */\nexport function clampPage(page: number): number {\n if (!Number.isFinite(page)) {\n return 1;\n }\n return Math.max(1, Math.floor(page));\n}\n\n/** `skip`/`take` for a 1-based page + page size (both clamped, `skip` capped). */\nexport function toOffsetArgs(\n page: number,\n limit: number,\n): { take: number; skip: number; page: number; limit: number } {\n const safePage = clampPage(page);\n const safeLimit = clampLimit(limit);\n const skip = Math.min((safePage - 1) * safeLimit, MAX_SKIP);\n return { take: safeLimit, skip, page: safePage, limit: safeLimit };\n}\n\n/** Offset pagination metadata for a known `total`. */\nexport function buildPaginationMeta(total: number, page: number, limit: number): PaginationMeta {\n const safeLimit = clampLimit(limit);\n const safePage = clampPage(page);\n return {\n page: safePage,\n limit: safeLimit,\n total,\n totalPage: Math.ceil(total / safeLimit),\n };\n}\n\n/**\n * Serialize one cursor value. Dates become ISO-8601 strings so cursors are\n * round-trippable and locale/TZ-independent (audit F4); everything else uses\n * plain string coercion.\n */\nexport function serializeCursorValue(value: unknown): string {\n return value instanceof Date ? value.toISOString() : String(value);\n}\n\n/** Everything needed to turn cursor options into `findMany` args. */\nexport interface CursorPlan {\n cursor?: string | number | Date | undefined;\n limit?: number | undefined;\n direction?: CursorDirection;\n cursorField: string;\n}\n\n/**\n * `take`/`cursor`/`skip` for seek pagination:\n * - over-fetches one row (`±(limit + 1)`) to detect the next/previous page,\n * - negative `take` walks backwards,\n * - `skip: 1` excludes the cursor row itself.\n * The cursor value is passed through raw — Prisma accepts strings, numbers\n * and Dates for the cursor field.\n */\nexport function toCursorArgs(plan: CursorPlan): {\n take: number;\n cursor?: Record<string, unknown>;\n skip?: number;\n} {\n const sign = plan.direction === 'backward' ? -1 : 1;\n const take = sign * (clampLimit(plan.limit ?? DEFAULT_PAGE_SIZE) + 1);\n if (plan.cursor === undefined) {\n return { take };\n }\n return {\n take,\n cursor: { [plan.cursorField]: plan.cursor },\n skip: 1,\n };\n}\n\n/** Exact edge flags from a strict-mode probe query (audit F10). */\nexport interface ExactCursorFlags {\n hasNextPage?: boolean | undefined;\n hasPrevPage?: boolean | undefined;\n}\n\n/** Inputs for interpreting an over-fetched cursor page. */\nexport interface CursorPageInfo {\n limit: number;\n direction: CursorDirection;\n cursorField: string;\n /** Whether a cursor was supplied (i.e. this is not the first page). */\n hadCursor: boolean;\n /**\n * Probe-derived flags (strict mode); each entry replaces the optimistic\n * approximation for that edge (audit F10 / G9).\n */\n exactFlags?: ExactCursorFlags | undefined;\n}\n\n/**\n * Slice an over-fetched result set into the page + cursor metadata. Rows are\n * always returned in the configured sort order regardless of `direction`.\n */\nexport function buildCursorPage<T extends Record<string, unknown>>(\n rows: T[],\n info: CursorPageInfo,\n): { data: T[]; meta: CursorMeta } {\n const { limit, direction, cursorField, hadCursor, exactFlags } = info;\n const safeLimit = clampLimit(limit);\n\n const hasExtra = rows.length > safeLimit;\n const pageRows = hasExtra ? rows.slice(0, safeLimit) : rows;\n const ordered = direction === 'backward' ? [...pageRows].reverse() : pageRows;\n\n const hasRows = rows.length > 0;\n const hasNextPage =\n exactFlags?.hasNextPage ?? (direction === 'forward' ? hasExtra : hadCursor && hasRows);\n const hasPrevPage =\n exactFlags?.hasPrevPage ?? (direction === 'backward' ? hasExtra : hadCursor && hasRows);\n\n const first = ordered[0];\n const last = ordered[ordered.length - 1];\n\n return {\n data: ordered,\n meta: {\n limit: safeLimit,\n nextCursor:\n hasNextPage && last !== undefined ? serializeCursorValue(last[cursorField]) : null,\n prevCursor:\n hasPrevPage && first !== undefined ? serializeCursorValue(first[cursorField]) : null,\n hasNextPage,\n hasPrevPage,\n },\n };\n}\n","/**\n * Per-database capability sets (ARCHITECTURE.md, invariant 4).\n *\n * Prisma-supported databases disagree on filter operators — most importantly,\n * `mode: 'insensitive'` is only accepted on PostgreSQL, CockroachDB and MongoDB,\n * and *throws* on MySQL, MariaDB, SQLite and SQL Server. Capability records let\n * every builder method ask \"what is allowed here?\" instead of hardcoding\n * database names.\n */\nexport interface DialectCapabilities {\n /**\n * Prisma accepts `mode: 'insensitive'` on string filters for this dialect\n * (postgresql, cockroachdb, mongodb).\n */\n caseInsensitiveMode: boolean;\n /**\n * The database's default collation makes `contains` case-insensitive without\n * any extra argument (mysql, mariadb, sqlserver). For sqlite this is `false`:\n * ASCII `LIKE` is case-sensitive there, and Prisma offers no `mode`.\n */\n caseInsensitiveCollation: boolean;\n}\n\n/** Built-in capability sets, one per database Prisma supports (plus universal). */\nexport const DIALECT_CAPABILITIES = {\n postgresql: { caseInsensitiveMode: true, caseInsensitiveCollation: false },\n cockroachdb: { caseInsensitiveMode: true, caseInsensitiveCollation: false },\n mysql: { caseInsensitiveMode: false, caseInsensitiveCollation: true },\n mariadb: { caseInsensitiveMode: false, caseInsensitiveCollation: true },\n sqlite: { caseInsensitiveMode: false, caseInsensitiveCollation: false },\n sqlserver: { caseInsensitiveMode: false, caseInsensitiveCollation: true },\n mongodb: { caseInsensitiveMode: true, caseInsensitiveCollation: false },\n /**\n * Fallback used when no dialect is configured/detected. Only emits arguments\n * that are valid on EVERY Prisma-supported database.\n */\n universal: { caseInsensitiveMode: false, caseInsensitiveCollation: false },\n} satisfies Record<string, DialectCapabilities>;\n\n/** Names of the built-in dialects. */\nexport type Dialect = keyof typeof DIALECT_CAPABILITIES;\n","import type { Dialect } from './capabilities';\n\n/**\n * Best-effort dialect auto-detection (M2 scope).\n *\n * v0 intentionally detects nothing and returns `undefined` → callers fall\n * through to `'universal'`, which never emits an invalid argument on any\n * database. Future heuristics (guarded property sniffing of the Prisma client)\n * must keep the same contract: NEVER throw, NEVER guess wrong loudly — an\n * unknown dialect must degrade to `'universal'`, not to a wrong guess.\n *\n * Users who know their database should prefer explicit configuration:\n * configQueryBuilder({ dialect: 'postgresql' })\n * or per builder:\n * new QueryBuilder(prisma.user, { dialect: 'mongodb' })\n */\nexport function detectDialect(): Dialect | undefined {\n return undefined;\n}\n","import { DIALECT_CAPABILITIES } from './capabilities';\nimport type { DialectCapabilities } from './capabilities';\nimport { detectDialect } from './detect';\n\n/*\n * Dialect registry (ARCHITECTURE.md, invariant 4).\n *\n * Resolution order (fails soft to 'universal', which is always valid):\n * 1. explicit per-builder override new QueryBuilder(prisma.user, { dialect: 'mysql' })\n * 2. global config configQueryBuilder({ dialect: 'postgresql' })\n * 3. registered auto-detector setDialectDetector(fn)\n * 4. built-in detector detectDialect() (no-op in v0 — audit G2)\n * 5. 'universal'\n */\n\n/** Mutable dialect state, shared via `globalThis` (audit F7). */\ninterface DialectState {\n registry: Map<string, DialectCapabilities>;\n globalDialect: string | undefined;\n detector: (() => string | undefined) | undefined;\n}\n\n/**\n * The state lives on `globalThis` under a registered symbol so ESM and CJS\n * copies of this package converge on ONE config — a bundler loading both\n * variants can no longer split the global dialect config (dual-package hazard,\n * audit F7). This is the only mutable module-adjacent state in the package;\n * prefer the per-builder `dialect` option anyway.\n */\nconst STATE_KEY = Symbol.for('query-builder-prisma.dialect-state');\n\nfunction state(): DialectState {\n const host = globalThis as typeof globalThis & { [STATE_KEY]?: DialectState };\n return (host[STATE_KEY] ??= {\n registry: new Map(Object.entries(DIALECT_CAPABILITIES) as [string, DialectCapabilities][]),\n globalDialect: undefined,\n detector: undefined,\n });\n}\n\n/**\n * Register capabilities for a database - including ones Prisma adds in the\n * future. No core code changes are ever required to support a new dialect.\n */\nexport function registerDialect(name: string, capabilities: DialectCapabilities): void {\n state().registry.set(name, capabilities);\n}\n\n/** Set the global default dialect for all builders that do not override it. */\nexport function configQueryBuilder(options: { dialect?: string | undefined }): void {\n state().globalDialect = options.dialect;\n}\n\n/**\n * Plug in an auto-detector (best-effort). It must never throw; an undefined\n * result simply falls through to the built-in detector and then 'universal'.\n */\nexport function setDialectDetector(detector: () => string | undefined): void {\n state().detector = detector;\n}\n\n/** A dialect name plus the capabilities resolved for it. */\nexport interface ResolvedDialect {\n name: string;\n capabilities: DialectCapabilities;\n}\n\n/**\n * Resolve the active dialect per the documented precedence. An unregistered\n * name resolves to `'universal'` — the reported name never lies about the\n * capabilities actually applied (audit G8).\n */\nexport function resolveDialect(explicit?: string | undefined): ResolvedDialect {\n const s = state();\n const requested = explicit ?? s.globalDialect ?? s.detector?.() ?? detectDialect() ?? 'universal';\n const capabilities = s.registry.get(requested);\n return capabilities\n ? { name: requested, capabilities }\n : { name: 'universal', capabilities: DIALECT_CAPABILITIES.universal };\n}\n\n/** Test helper: reset global configuration (registry entries are kept). */\nexport function resetDialectConfig(): void {\n const s = state();\n s.globalDialect = undefined;\n s.detector = undefined;\n}\n","import type {\n FindManyArgsOf,\n IncludeOf,\n OrderByOf,\n OrderKeyOf,\n PrismaModelDelegate,\n RowElementOf,\n SelectOf,\n WhereKeyOf,\n WhereOf,\n} from '../types/delegate';\nimport type { ApplyProjection, FindResultOf } from '../types/projection';\nimport type {\n CursorDirection,\n CursorMeta,\n FilterInput,\n PaginationMeta,\n PaginationMetaNoTotal,\n RangeBound,\n RangeInput,\n SortOrder,\n} from '../types/public';\nimport {\n combineAnd,\n deepStripUndefined,\n expandDotPath,\n isPlainObject,\n stripUndefined,\n} from './conditions';\nimport {\n buildCursorPage,\n buildPaginationMeta,\n clampLimit,\n clampPage,\n toCursorArgs,\n toOffsetArgs,\n DEFAULT_PAGE_SIZE,\n MAX_PAGE_SIZE,\n MAX_SKIP,\n} from './pagination';\nimport type { ExactCursorFlags } from './pagination';\nimport { resolveDialect } from '../dialects/registry';\nimport type { Dialect } from '../dialects/capabilities';\n\n/** Options accepted by the {@link QueryBuilder} constructor. */\nexport interface QueryBuilderOptions<D extends PrismaModelDelegate> {\n /** Seed `findMany` args, e.g. `{ where: { deletedAt: null } }` (prepended to every `where`). */\n initialArgs?: FindManyArgsOf<D> | undefined;\n /**\n * Per-builder dialect override. When omitted: global `configQueryBuilder()`\n * config → registered auto-detector → `'universal'` (always-valid args).\n */\n dialect?: Dialect | undefined;\n /**\n * Throw on out-of-range pagination input instead of clamping silently:\n * limits outside `[1, 1000]`, pages below 1, or a computed `skip` beyond\n * `MAX_SKIP` (audits F12 / F18). Defaults to clamping.\n */\n strictNumbers?: boolean | undefined;\n}\n\n/** Meta type of {@link QueryBuilder.executeWithMeta} for the given options. */\ntype MetaOf<O extends { includeTotal?: boolean }> = O['includeTotal'] extends false\n ? PaginationMetaNoTotal\n : PaginationMeta;\n\n/** Thrown by {@link QueryBuilder.firstOrThrow} when no row matched. */\nexport class NoResultError extends Error {\n constructor() {\n super('Query returned no rows');\n this.name = 'NoResultError';\n }\n}\n\n/**\n * Generic, reusable and fully type-safe query builder for any Prisma model\n * delegate, on every Prisma version (see ARCHITECTURE.md).\n *\n * All option types (`where`, `select`, `include`, `orderBy`, ...) are inferred\n * structurally from the delegate passed to the constructor — nothing is imported\n * from Prisma, so no Prisma upgrade can ever break this class.\n *\n * The result type of `execute()` is narrowed by `.select()` / `.include()` via a\n * structural projection engine, mirroring Prisma's own behaviour.\n *\n * @typeParam D - The Prisma model delegate, e.g. `typeof prisma.user`.\n * @typeParam TArgs - Accumulated `findMany` args. Defaults to no projection.\n *\n * @example\n * const result = await new QueryBuilder(prisma.user)\n * .search({ searchText, fields: ['email', 'username'] })\n * .filter({ role, status })\n * .range({ createdAt: { from, to }, 'avatar.size': { from: min, to: max } })\n * .sortBy({ sortBy: 'createdAt', sortOrder: 'desc' })\n * .paginate({ page: 1, limit: 10 })\n * .select({ id: true, email: true })\n * .execute();\n */\nexport class QueryBuilder<D extends PrismaModelDelegate, TArgs = object> {\n private readonly delegate: D;\n private readonly dialect: Dialect | undefined;\n private readonly strictNumbers: boolean;\n private readonly andConditions: object[] = [];\n private customArgs: Record<string, unknown> = {};\n /**\n * The `initialArgs` seed `where` plus every `.custom({ where })`, AND-merged.\n * Kept out of `customArgs` so a later `.custom({ where })` merges with the\n * seed instead of replacing it (audit F2 — the seed carries safety filters).\n */\n private customWhere: unknown;\n private orderByArg: object | undefined;\n private selectArg: object | undefined;\n private includeArg: object | undefined;\n private page: number | undefined;\n private limit: number | undefined;\n private cursorActive = false;\n private cursor: string | number | Date | undefined;\n private cursorLimit: number | undefined;\n private cursorDirection: CursorDirection = 'forward';\n private cursorField: string = 'id';\n private cursorStrict = false;\n\n /**\n * @param delegate - The Prisma delegate to query (e.g. `prisma.user`).\n * @param options - Optional seed args, a dialect override, or `strictNumbers`.\n */\n constructor(delegate: D, options?: QueryBuilderOptions<D>) {\n this.delegate = delegate;\n this.dialect = options?.dialect;\n this.strictNumbers = options?.strictNumbers ?? false;\n if (options?.initialArgs) {\n const { where, ...rest } = options.initialArgs as Record<string, unknown>;\n this.customArgs = { ...rest };\n this.customWhere = where;\n }\n }\n\n /**\n * Case-insensitive `contains` across the provided string fields. No condition\n * is added when `searchText` is empty or whitespace-only (audit G7).\n *\n * Dialect-aware: adds `mode: 'insensitive'` only where Prisma accepts it (see\n * `caseInsensitiveMode` in `src/dialects/capabilities.ts`); everywhere else\n * the bare `contains` relies on the database's collation, and where that is\n * ASCII-only matching stays case-sensitive — Prisma offers no alternative\n * there.\n */\n search(params: { searchText?: string | undefined; fields: WhereKeyOf<D>[] }): this {\n const text = params.searchText?.trim();\n const fields = params.fields;\n if (text && fields.length > 0) {\n const { capabilities } = resolveDialect(this.dialect);\n this.andConditions.push({\n OR: fields.map((field) => {\n // One match object per arm — never a shared reference (audit F13).\n const match: Record<string, unknown> = { contains: text };\n if (capabilities.caseInsensitiveMode) {\n match.mode = 'insensitive';\n }\n return { [field]: match };\n }),\n });\n }\n return this;\n }\n\n /**\n * Adds an equality/operator filter. Accepts a partial Prisma `where` object;\n * `undefined` values are ignored so optional query params are safe to pass.\n */\n filter(filters: FilterInput<D>): this {\n const cleaned = stripUndefined(filters);\n if (Object.keys(cleaned).length > 0) {\n this.andConditions.push(cleaned);\n }\n return this;\n }\n\n /**\n * Adds `gte`/`lte` range conditions. Keys may be dot-paths to reach relations\n * or nested objects (e.g. `'avatar.size'`). Bounds left `undefined` are\n * skipped; a field is only added when at least one bound is present.\n */\n range(ranges: Record<string, RangeInput>): this {\n for (const [path, bound] of Object.entries(ranges)) {\n const condition: Record<string, RangeBound> = {};\n if (bound.from !== undefined) {\n condition.gte = bound.from;\n }\n if (bound.to !== undefined) {\n condition.lte = bound.to;\n }\n if (Object.keys(condition).length > 0) {\n const expanded = expandDotPath(path, condition);\n if (Object.keys(expanded).length > 0) {\n this.andConditions.push(expanded);\n }\n }\n }\n return this;\n }\n\n /** Adds an arbitrary, fully-typed Prisma `where` condition. */\n where(condition: WhereOf<D>): this {\n const cleaned = stripUndefined(condition as Record<string, unknown>);\n if (Object.keys(cleaned).length > 0) {\n this.andConditions.push(cleaned);\n }\n return this;\n }\n\n /**\n * Sets `orderBy` from a single key. No-op when `sortBy` is not provided.\n * Dot paths expand like `.range()` (`'avatar.size'` → `{ avatar: { size } }`,\n * audit F6). For multi-key or nested relation sorts use {@link orderBy}.\n */\n sortBy(params: { sortBy?: OrderKeyOf<D> | (string & {}); sortOrder?: SortOrder }): this {\n const { sortBy, sortOrder = 'desc' } = params;\n if (sortBy) {\n const expanded = expandDotPath(sortBy, sortOrder);\n if (Object.keys(expanded).length > 0) {\n this.orderByArg = expanded;\n }\n }\n return this;\n }\n\n /**\n * Sets `orderBy` verbatim from the full Prisma shape: arrays for multi-key\n * sorts, nested relation order objects. `.sortBy()` remains the single-key\n * convenience — the latest of the two calls wins (audit G1).\n */\n orderBy(order: OrderByOf<D>): this {\n this.orderByArg = order as object;\n return this;\n }\n\n /** Configures `skip`/`take` from a 1-based page number and page size. */\n paginate(params: { page?: number; limit?: number }): this {\n this.assertPage(params.page);\n this.assertLimit(params.limit);\n this.page = params.page ?? 1;\n this.limit = params.limit ?? DEFAULT_PAGE_SIZE;\n return this;\n }\n\n /**\n * Configures cursor-based (\"seek\") pagination. Use {@link executeWithCursor}\n * to run the query and obtain `next`/`prev` cursors.\n *\n * - `cursor` is the value of `cursorField` from the edge row of the previous\n * page (omit it for the first page). Strings, numbers and Dates are\n * accepted; Dates serialize to ISO-8601 in the returned cursors (audit F4).\n * - `direction` walks `'forward'` (next) or `'backward'` (previous).\n * - `cursorField` is the unique, sequential column to seek on (default `id`).\n * Pair it with a matching {@link sortBy} for stable ordering.\n * - `strict` spends one extra 1-row probe query to make `hasNextPage` /\n * `hasPrevPage` exact instead of optimistic (audit F10).\n *\n * Takes precedence over {@link paginate} when both are set.\n */\n cursorPaginate(params: {\n cursor?: string | number | Date | undefined;\n limit?: number;\n direction?: CursorDirection;\n cursorField?: OrderKeyOf<D> | (string & {});\n strict?: boolean;\n }): this {\n this.assertLimit(params.limit);\n this.cursorActive = true;\n this.cursor = params.cursor;\n this.cursorLimit = params.limit;\n this.cursorDirection = params.direction ?? 'forward';\n this.cursorField = params.cursorField ?? 'id';\n this.cursorStrict = params.strict ?? false;\n return this;\n }\n\n /**\n * Projects fields with Prisma `select`. The result type of `execute()` is\n * narrowed to exactly the selected shape. Clears any active `.include()`.\n */\n select<TSelect extends SelectOf<D>>(\n select: TSelect,\n ): QueryBuilder<D, Omit<TArgs, 'select' | 'include'> & { select: TSelect }> {\n this.selectArg = select;\n this.includeArg = undefined;\n return this as unknown as QueryBuilder<\n D,\n Omit<TArgs, 'select' | 'include'> & { select: TSelect }\n >;\n }\n\n /**\n * Eager-loads relations with Prisma `include`. The result type of `execute()`\n * is widened with the included relations. Clears any active `.select()`.\n */\n include<TInclude extends IncludeOf<D>>(\n include: TInclude,\n ): QueryBuilder<D, Omit<TArgs, 'select' | 'include'> & { include: TInclude }> {\n this.includeArg = include;\n this.selectArg = undefined;\n return this as unknown as QueryBuilder<\n D,\n Omit<TArgs, 'select' | 'include'> & { include: TInclude }\n >;\n }\n\n /**\n * Merges raw `findMany` args, e.g. `cursor`, `distinct` or a custom `where`.\n * Values that are `undefined` are stripped at any depth, so\n * `custom({ distinct: undefined })` cannot overwrite an earlier value\n * (audit F15). A custom `where` is AND-ed with the `initialArgs` seed and any\n * previous custom `where` — it never replaces them (audit F2). Successive\n * custom `where`s may nest `{ AND: [...] }` groups; Prisma treats that\n * identically.\n */\n custom(args: FindManyArgsOf<D>): this {\n const { where, ...rest } = args as Record<string, unknown>;\n this.customArgs = { ...this.customArgs, ...deepStripUndefined(rest) };\n if (where !== undefined) {\n const cleaned = isPlainObject(where) ? deepStripUndefined(where) : where;\n const hasKeys = !isPlainObject(cleaned) || Object.keys(cleaned).length > 0;\n if (hasKeys) {\n this.customWhere = combineAnd([cleaned as object], this.customWhere);\n }\n }\n return this;\n }\n\n /** The fully assembled `findMany` args. Useful for debugging or reuse. */\n buildArgs(): FindManyArgsOf<D> {\n const args: Record<string, unknown> = { ...this.customArgs };\n\n const where = this.buildWhere();\n if (where) {\n args.where = where;\n }\n if (this.orderByArg) {\n args.orderBy = this.orderByArg;\n }\n if (this.selectArg) {\n args.select = this.selectArg;\n }\n if (this.includeArg) {\n args.include = this.includeArg;\n }\n\n if (this.cursorActive) {\n const cursorArgs = toCursorArgs({\n cursor: this.cursor,\n limit: this.cursorLimit,\n direction: this.cursorDirection,\n cursorField: this.cursorField,\n });\n args.take = cursorArgs.take;\n if (cursorArgs.cursor) {\n args.cursor = cursorArgs.cursor;\n }\n if (cursorArgs.skip !== undefined) {\n args.skip = cursorArgs.skip;\n }\n } else if (this.limit !== undefined) {\n const page = this.page ?? 1;\n this.assertSkipCap(page, this.limit);\n const offset = toOffsetArgs(page, this.limit);\n args.take = offset.take;\n args.skip = offset.skip;\n }\n\n return args as FindManyArgsOf<D>;\n }\n\n /**\n * Executes the query and returns the rows, typed from `.select()`/`.include()`.\n *\n * Tip: for 100% Prisma-native inference you can always run the passthrough\n * `prisma.user.findMany(qb.buildArgs())` — same args, Prisma's own overloads.\n */\n async execute(): Promise<FindResultOf<D, TArgs>> {\n const findMany = this.delegate.findMany.bind(this.delegate) as unknown as (\n args: object,\n ) => Promise<unknown>;\n const data = await findMany(this.buildArgs());\n return data as FindResultOf<D, TArgs>;\n }\n\n /** Executes the query and returns the first row, or `null` when none matched. */\n async first(): Promise<ApplyProjection<RowElementOf<D>, TArgs> | null> {\n const args = { ...(this.buildArgs() as object) } as Record<string, unknown>;\n args.take = 1;\n delete args.skip;\n delete args.cursor;\n const findMany = this.delegate.findMany.bind(this.delegate) as unknown as (\n args: object,\n ) => Promise<unknown>;\n const rows = (await findMany(args)) as unknown[];\n const row = rows[0];\n return (row ?? null) as ApplyProjection<RowElementOf<D>, TArgs> | null;\n }\n\n /** Like {@link first}, but throws {@link NoResultError} when nothing matched. */\n async firstOrThrow(): Promise<ApplyProjection<RowElementOf<D>, TArgs>> {\n const row = await this.first();\n if (row === null) {\n throw new NoResultError();\n }\n return row;\n }\n\n /** Counts rows matching the current filters (ignores pagination/projection). */\n async count(): Promise<number> {\n const where = this.buildWhere();\n const countFn = this.delegate.count.bind(this.delegate) as unknown as (\n args: object,\n ) => Promise<number>;\n return countFn(where ? { where } : {});\n }\n\n /**\n * Executes the query and returns the rows plus offset pagination metadata.\n * When no pagination was configured, defaults to page 1, limit 10 so `meta`\n * always describes the data actually returned. `count` and `findMany` run in\n * parallel.\n *\n * Pass `{ includeTotal: false }` to skip the `COUNT` query entirely — `meta`\n * then carries `total: null` / `totalPage: null` (audit G3).\n *\n * Throws when cursor pagination is configured — offset meta cannot describe a\n * seek query, and the cursor over-fetch row would leak into `data` (audit F1).\n * Use {@link executeWithCursor} instead.\n */\n async executeWithMeta<O extends { includeTotal?: boolean } = { includeTotal?: boolean }>(\n opts?: O,\n ): Promise<{ meta: MetaOf<O>; data: FindResultOf<D, TArgs> }> {\n if (this.cursorActive) {\n throw new Error(\n 'executeWithMeta() is offset-mode only: this builder has cursor pagination ' +\n 'configured via cursorPaginate(). Use executeWithCursor() instead.',\n );\n }\n if (this.limit === undefined) {\n this.paginate({ page: 1, limit: DEFAULT_PAGE_SIZE });\n }\n // Fail before the COUNT goes out (strictNumbers + skip cap, audit F18).\n this.assertSkipCap(this.page ?? 1, this.limit ?? DEFAULT_PAGE_SIZE);\n const offset = toOffsetArgs(this.page ?? 1, this.limit ?? DEFAULT_PAGE_SIZE);\n\n if (opts?.includeTotal === false) {\n const data = await this.execute();\n return {\n meta: { page: offset.page, limit: offset.limit, total: null, totalPage: null },\n data,\n } as { meta: MetaOf<O>; data: FindResultOf<D, TArgs> };\n }\n\n const [total, data] = await Promise.all([this.count(), this.execute()]);\n\n return {\n meta: buildPaginationMeta(total, offset.page, offset.limit),\n data,\n } as { meta: MetaOf<O>; data: FindResultOf<D, TArgs> };\n }\n\n /**\n * Executes a cursor-paginated query (see {@link cursorPaginate}) and returns\n * the page rows plus `next`/`prev` cursors. Rows are always returned in the\n * configured sort order, regardless of pagination `direction`.\n *\n * Throws when a `.select()` projection drops `cursorField` — the page cursors\n * are derived from that field and would come out as `undefined` (audit F5).\n */\n async executeWithCursor(): Promise<{ meta: CursorMeta; data: FindResultOf<D, TArgs> }> {\n if (!this.cursorActive) {\n this.cursorPaginate({});\n }\n this.assertCursorFieldProjected();\n const limit = this.cursorLimit ?? DEFAULT_PAGE_SIZE;\n const hadCursor = this.cursor !== undefined;\n\n const findMany = this.delegate.findMany.bind(this.delegate) as unknown as (\n args: object,\n ) => Promise<Record<string, unknown>[]>;\n const rows = await findMany(this.buildArgs());\n\n // Strict mode spends one extra 1-row probe query to make the optimistic\n // opposite edge exact (audit F10 / G9): forward pages probe the row before\n // the cursor, backward pages the row after it. The probe mirrors the main\n // query's `where`/`orderBy` — Prisma positions the cursor within the\n // query's own sort order and filters.\n let exactFlags: ExactCursorFlags | undefined;\n if (this.cursorStrict && hadCursor) {\n const probeArgs: Record<string, unknown> = {\n take: this.cursorDirection === 'forward' ? -1 : 1,\n cursor: { [this.cursorField]: this.cursor },\n skip: 1,\n };\n const where = this.buildWhere();\n if (where) {\n probeArgs.where = where;\n }\n if (this.orderByArg) {\n probeArgs.orderBy = this.orderByArg;\n }\n const probe = await findMany(probeArgs);\n const hasEdgeRow = probe.length > 0;\n exactFlags =\n this.cursorDirection === 'forward'\n ? { hasPrevPage: hasEdgeRow }\n : { hasNextPage: hasEdgeRow };\n }\n\n const { data, meta } = buildCursorPage(rows, {\n limit,\n direction: this.cursorDirection,\n cursorField: this.cursorField,\n hadCursor,\n exactFlags,\n });\n\n return { meta, data: data as unknown as FindResultOf<D, TArgs> };\n }\n\n /** strictNumbers: out-of-range limits throw instead of clamping (audit F12). */\n private assertLimit(limit: number | undefined): void {\n if (!this.strictNumbers || limit === undefined) {\n return;\n }\n if (!Number.isFinite(limit) || limit < 1 || limit > MAX_PAGE_SIZE) {\n throw new Error(`strictNumbers: limit ${String(limit)} is outside [1, ${MAX_PAGE_SIZE}].`);\n }\n }\n\n private assertPage(page: number | undefined): void {\n if (!this.strictNumbers || page === undefined) {\n return;\n }\n if (!Number.isFinite(page) || page < 1) {\n throw new Error(`strictNumbers: page ${String(page)} must be a finite number >= 1.`);\n }\n }\n\n /** strictNumbers: a computed skip beyond MAX_SKIP throws (audit F18). */\n private assertSkipCap(page: number, limit: number): void {\n if (!this.strictNumbers) {\n return;\n }\n const skip = (clampPage(page) - 1) * clampLimit(limit);\n if (skip > MAX_SKIP) {\n throw new Error(\n `strictNumbers: computed skip ${String(skip)} exceeds the ${String(MAX_SKIP)} cap — ` +\n 'use cursor pagination for deep pages.',\n );\n }\n }\n\n /** A projection without the cursor field would derive cursors from `undefined` (audit F5). */\n private assertCursorFieldProjected(): void {\n // `.custom({ select })` also feeds args.select when no `.select()` ran.\n const select = (this.selectArg ?? this.customArgs.select) as\n Record<string, unknown> | undefined;\n if (select && !select[this.cursorField]) {\n throw new Error(\n `executeWithCursor(): the projection drops cursorField \"${this.cursorField}\", so page ` +\n 'cursors would be built from undefined. Keep the field in .select() or remove the projection.',\n );\n }\n }\n\n private buildWhere(): object | undefined {\n return combineAnd(this.andConditions, this.customWhere);\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACOA,IAAM,iBAAsC,oBAAI,IAAI,CAAC,aAAa,eAAe,WAAW,CAAC;AAE7F,SAAS,UAAU,KAAsB;AACvC,SAAO,CAAC,eAAe,IAAI,GAAG;AAChC;AAGO,SAAS,eAAe,KAAuD;AACpF,QAAM,SAAkC,CAAC;AACzC,aAAW,CAAC,KAAK,KAAK,KAAK,OAAO,QAAQ,GAAG,GAAG;AAC9C,QAAI,UAAU,UAAa,UAAU,GAAG,GAAG;AACzC,aAAO,GAAG,IAAI;AAAA,IAChB;AAAA,EACF;AACA,SAAO;AACT;AASO,SAAS,mBAAmB,KAAuD;AACxF,QAAM,SAAkC,CAAC;AACzC,aAAW,CAAC,KAAK,KAAK,KAAK,OAAO,QAAQ,GAAG,GAAG;AAC9C,QAAI,UAAU,UAAa,CAAC,UAAU,GAAG,GAAG;AAC1C;AAAA,IACF;AACA,WAAO,G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AAgB,OAAO,QAAQ,CAAC;AAAA,MAE9E;AAAA,IACF;AAAA,EACF;AAAA;AAAA,EAGQ,6BAAmC;AAEzC,UAAM,SAAU,KAAK,aAAa,KAAK,WAAW;AAElD,QAAI,UAAU,CAAC,OAAO,KAAK,WAAW,GAAG;AACvC,YAAM,IAAI;AAAA,QACR,0DAA0D,KAAK,WAAW;AAAA,MAE5E;AAAA,IACF;AAAA,EACF;AAAA,EAEQ,aAAiC;AACvC,WAAO,WAAW,KAAK,eAAe,KAAK,WAAW;AAAA,EACxD;AACF;","names":["data"]}
@@ -0,0 +1,481 @@
1
+ /**
2
+ * Structural contracts — the ONLY knowledge this package has about Prisma.
3
+ *
4
+ * Nothing here imports Prisma. Any object exposing `findMany` + `count` with the
5
+ * standard Prisma delegate call shape satisfies these contracts — Prisma 5, 6, 7,
6
+ * 8, and (per ARCHITECTURE.md, invariant 2) any future version that keeps its
7
+ * public API.
8
+ */
9
+ /**
10
+ * Minimal structural contract every Prisma model delegate (e.g. `prisma.user`)
11
+ * already satisfies. Used only as an upper bound so the concrete delegate type is
12
+ * preserved at call sites while keeping our classes generic.
13
+ */
14
+ interface PrismaModelDelegate {
15
+ findMany: (...args: never[]) => unknown;
16
+ count: (...args: never[]) => unknown;
17
+ }
18
+ /** `findMany` arguments for the given delegate, derived from the delegate itself. */
19
+ type FindManyArgsOf<D extends PrismaModelDelegate> = NonNullable<Parameters<D['findMany']>[0]>;
20
+ /** `where` input of the model, derived from the delegate. */
21
+ type WhereOf<D extends PrismaModelDelegate> = NonNullable<FindManyArgsOf<D>['where']>;
22
+ /** `select` input of the model, derived from the delegate. */
23
+ type SelectOf<D extends PrismaModelDelegate> = NonNullable<FindManyArgsOf<D>['select']>;
24
+ /** `include` input of the model, derived from the delegate. */
25
+ type IncludeOf<D extends PrismaModelDelegate> = NonNullable<FindManyArgsOf<D>['include']>;
26
+ /** Scalar/relation keys that can be referenced from a model's `where` input. */
27
+ type WhereKeyOf<D extends PrismaModelDelegate> = keyof WhereOf<D> & string;
28
+ /** `orderBy` input of the model, derived from the delegate. */
29
+ type OrderByOf<D extends PrismaModelDelegate> = NonNullable<FindManyArgsOf<D>['orderBy']>;
30
+ /** Keys that can be used to order a model's results. */
31
+ type OrderKeyOf<D extends PrismaModelDelegate> = OrderByOf<D> extends infer O ? O extends readonly unknown[] ? keyof O[number] & string : keyof O & string : never;
32
+ /** The rows array `findMany` resolves to, derived from the delegate. */
33
+ type RowsOf<D extends PrismaModelDelegate> = Awaited<ReturnType<D['findMany']>>;
34
+ /** A single row of the model, derived from the delegate. */
35
+ type RowElementOf<D extends PrismaModelDelegate> = RowsOf<D> extends readonly (infer E)[] ? E : never;
36
+
37
+ /**
38
+ * Structural projection engine (ARCHITECTURE.md, invariant 3).
39
+ *
40
+ * Narrows the output type of `findMany` according to the accumulated
41
+ * `select`/`include` arguments — without importing a single Prisma type.
42
+ * Everything is derived from the model's own row type, which already encodes
43
+ * relation shapes, so this works on every Prisma version.
44
+ *
45
+ * Degradation rule: when Prisma's exact semantics can't be mirrored, the result
46
+ * is the *wider but correct* type — never a wrong one.
47
+ */
48
+
49
+ /** Keys of a select/include spec that are "on" (`true` or a nested spec). */
50
+ type TruthyKeys<S> = {
51
+ [K in keyof S]-?: NonNullable<S[K]> extends false ? never : K;
52
+ }[keyof S];
53
+ /**
54
+ * Apply a `select` spec to a row: only selected fields remain, nested selects
55
+ * recurse into relation element types.
56
+ */
57
+ type ApplySelect<Row, S> = {
58
+ [K in TruthyKeys<S> & keyof Row]: ProjectField<Row[K], S[K]>;
59
+ };
60
+ /**
61
+ * Apply an `include` spec to a row: all base fields stay, included relations are
62
+ * projected (recursively when the include carries a nested `select`), and a
63
+ * truthy `_count` widens in as `Record<string, number>` (audit F9 — the engine
64
+ * cannot know the selected relation keys, so it degrades wide, never wrong).
65
+ */
66
+ type ApplyInclude<Row, I> = Row & {
67
+ [K in TruthyKeys<I> & (keyof Row | '_count')]: K extends '_count' ? Record<string, number> : ProjectField<Row[K & keyof Row], I[K]>;
68
+ };
69
+ /** Project one field (`Field`) according to its select/include `Spec`. */
70
+ type ProjectField<Field, Spec> = Spec extends true ? Field : Spec extends {
71
+ select: infer Sub;
72
+ } ? ProjectNested<Field, Sub> : Spec extends {
73
+ include: infer Sub;
74
+ } ? ProjectNestedInclude<Field, Sub> : Field;
75
+ /**
76
+ * Project a relation field through a `select`. Only the selected keys remain.
77
+ * Lists map over their element; optionality (`| null | undefined`) is preserved
78
+ * exactly.
79
+ */
80
+ type ProjectNested<Field, Sub> = Field extends readonly (infer E)[] ? ApplySelect<E, Sub>[] : ApplySelect<NonNullable<Field>, Sub> | (undefined extends Field ? undefined : never) | (null extends Field ? null : never);
81
+ /**
82
+ * Project a relation field through an `include`. Unlike select, include keeps
83
+ * the relation's own fields — the element is intersected with its projection
84
+ * via `ApplyInclude` (audit F3). Lists map over their element; optionality is
85
+ * preserved exactly.
86
+ */
87
+ type ProjectNestedInclude<Field, Sub> = Field extends readonly (infer E)[] ? ApplyInclude<E, Sub>[] : ApplyInclude<NonNullable<Field>, Sub> | (undefined extends Field ? undefined : never) | (null extends Field ? null : never);
88
+ /**
89
+ * The row shape produced by a `findMany` call with the given accumulated args.
90
+ * With no `select`/`include`, this is the full model row (identity).
91
+ */
92
+ type ApplyProjection<Row, TArgs> = TArgs extends {
93
+ select: infer S;
94
+ } ? ApplySelect<Row, S> : TArgs extends {
95
+ include: infer I;
96
+ } ? ApplyInclude<Row, I> : Row;
97
+ /** The array a builder's `execute()` resolves to for the given delegate + args. */
98
+ type FindResultOf<D extends PrismaModelDelegate, TArgs> = ApplyProjection<RowElementOf<D>, TArgs>[];
99
+
100
+ /** Sort direction accepted by Prisma's `orderBy`. */
101
+ type SortOrder = 'asc' | 'desc';
102
+ /** Direction to walk through a cursor-paginated result set. */
103
+ type CursorDirection = 'forward' | 'backward';
104
+ /** A single numeric/date/string bound used by `QueryBuilder.range()`. */
105
+ type RangeBound = string | number | Date;
106
+ /** Open/closed bounds for one field path. Omitted bounds are skipped. */
107
+ interface RangeInput {
108
+ from?: RangeBound | undefined;
109
+ to?: RangeBound | undefined;
110
+ }
111
+ /** Offset pagination metadata returned by `executeWithMeta()`. */
112
+ interface PaginationMeta {
113
+ page: number;
114
+ limit: number;
115
+ total: number;
116
+ totalPage: number;
117
+ }
118
+ /**
119
+ * Metadata shape when `executeWithMeta({ includeTotal: false })` skips the
120
+ * `COUNT` query — the totals are unknown, not zero (audit G3).
121
+ */
122
+ interface PaginationMetaNoTotal {
123
+ page: number;
124
+ limit: number;
125
+ total: null;
126
+ totalPage: null;
127
+ }
128
+ /** Cursor pagination metadata returned by `executeWithCursor()`. */
129
+ interface CursorMeta {
130
+ limit: number;
131
+ /** Cursor to pass as `cursor` to fetch the next page (`null` if none). */
132
+ nextCursor: string | null;
133
+ /** Cursor to pass as `cursor` (with `direction: 'backward'`) for the previous page. */
134
+ prevCursor: string | null;
135
+ hasNextPage: boolean;
136
+ hasPrevPage: boolean;
137
+ }
138
+ /**
139
+ * A partial `where` whose values may also be `undefined`, so optional query
140
+ * params can be forwarded directly (they are stripped out at build time).
141
+ */
142
+ type FilterInput<D extends PrismaModelDelegate> = {
143
+ [K in WhereKeyOf<D>]?: WhereOf<D>[K] | undefined;
144
+ };
145
+
146
+ /**
147
+ * Per-database capability sets (ARCHITECTURE.md, invariant 4).
148
+ *
149
+ * Prisma-supported databases disagree on filter operators — most importantly,
150
+ * `mode: 'insensitive'` is only accepted on PostgreSQL, CockroachDB and MongoDB,
151
+ * and *throws* on MySQL, MariaDB, SQLite and SQL Server. Capability records let
152
+ * every builder method ask "what is allowed here?" instead of hardcoding
153
+ * database names.
154
+ */
155
+ interface DialectCapabilities {
156
+ /**
157
+ * Prisma accepts `mode: 'insensitive'` on string filters for this dialect
158
+ * (postgresql, cockroachdb, mongodb).
159
+ */
160
+ caseInsensitiveMode: boolean;
161
+ /**
162
+ * The database's default collation makes `contains` case-insensitive without
163
+ * any extra argument (mysql, mariadb, sqlserver). For sqlite this is `false`:
164
+ * ASCII `LIKE` is case-sensitive there, and Prisma offers no `mode`.
165
+ */
166
+ caseInsensitiveCollation: boolean;
167
+ }
168
+ /** Built-in capability sets, one per database Prisma supports (plus universal). */
169
+ declare const DIALECT_CAPABILITIES: {
170
+ postgresql: {
171
+ caseInsensitiveMode: true;
172
+ caseInsensitiveCollation: false;
173
+ };
174
+ cockroachdb: {
175
+ caseInsensitiveMode: true;
176
+ caseInsensitiveCollation: false;
177
+ };
178
+ mysql: {
179
+ caseInsensitiveMode: false;
180
+ caseInsensitiveCollation: true;
181
+ };
182
+ mariadb: {
183
+ caseInsensitiveMode: false;
184
+ caseInsensitiveCollation: true;
185
+ };
186
+ sqlite: {
187
+ caseInsensitiveMode: false;
188
+ caseInsensitiveCollation: false;
189
+ };
190
+ sqlserver: {
191
+ caseInsensitiveMode: false;
192
+ caseInsensitiveCollation: true;
193
+ };
194
+ mongodb: {
195
+ caseInsensitiveMode: true;
196
+ caseInsensitiveCollation: false;
197
+ };
198
+ /**
199
+ * Fallback used when no dialect is configured/detected. Only emits arguments
200
+ * that are valid on EVERY Prisma-supported database.
201
+ */
202
+ universal: {
203
+ caseInsensitiveMode: false;
204
+ caseInsensitiveCollation: false;
205
+ };
206
+ };
207
+ /** Names of the built-in dialects. */
208
+ type Dialect = keyof typeof DIALECT_CAPABILITIES;
209
+
210
+ /** Options accepted by the {@link QueryBuilder} constructor. */
211
+ interface QueryBuilderOptions<D extends PrismaModelDelegate> {
212
+ /** Seed `findMany` args, e.g. `{ where: { deletedAt: null } }` (prepended to every `where`). */
213
+ initialArgs?: FindManyArgsOf<D> | undefined;
214
+ /**
215
+ * Per-builder dialect override. When omitted: global `configQueryBuilder()`
216
+ * config → registered auto-detector → `'universal'` (always-valid args).
217
+ */
218
+ dialect?: Dialect | undefined;
219
+ /**
220
+ * Throw on out-of-range pagination input instead of clamping silently:
221
+ * limits outside `[1, 1000]`, pages below 1, or a computed `skip` beyond
222
+ * `MAX_SKIP` (audits F12 / F18). Defaults to clamping.
223
+ */
224
+ strictNumbers?: boolean | undefined;
225
+ }
226
+ /** Meta type of {@link QueryBuilder.executeWithMeta} for the given options. */
227
+ type MetaOf<O extends {
228
+ includeTotal?: boolean;
229
+ }> = O['includeTotal'] extends false ? PaginationMetaNoTotal : PaginationMeta;
230
+ /** Thrown by {@link QueryBuilder.firstOrThrow} when no row matched. */
231
+ declare class NoResultError extends Error {
232
+ constructor();
233
+ }
234
+ /**
235
+ * Generic, reusable and fully type-safe query builder for any Prisma model
236
+ * delegate, on every Prisma version (see ARCHITECTURE.md).
237
+ *
238
+ * All option types (`where`, `select`, `include`, `orderBy`, ...) are inferred
239
+ * structurally from the delegate passed to the constructor — nothing is imported
240
+ * from Prisma, so no Prisma upgrade can ever break this class.
241
+ *
242
+ * The result type of `execute()` is narrowed by `.select()` / `.include()` via a
243
+ * structural projection engine, mirroring Prisma's own behaviour.
244
+ *
245
+ * @typeParam D - The Prisma model delegate, e.g. `typeof prisma.user`.
246
+ * @typeParam TArgs - Accumulated `findMany` args. Defaults to no projection.
247
+ *
248
+ * @example
249
+ * const result = await new QueryBuilder(prisma.user)
250
+ * .search({ searchText, fields: ['email', 'username'] })
251
+ * .filter({ role, status })
252
+ * .range({ createdAt: { from, to }, 'avatar.size': { from: min, to: max } })
253
+ * .sortBy({ sortBy: 'createdAt', sortOrder: 'desc' })
254
+ * .paginate({ page: 1, limit: 10 })
255
+ * .select({ id: true, email: true })
256
+ * .execute();
257
+ */
258
+ declare class QueryBuilder<D extends PrismaModelDelegate, TArgs = object> {
259
+ private readonly delegate;
260
+ private readonly dialect;
261
+ private readonly strictNumbers;
262
+ private readonly andConditions;
263
+ private customArgs;
264
+ /**
265
+ * The `initialArgs` seed `where` plus every `.custom({ where })`, AND-merged.
266
+ * Kept out of `customArgs` so a later `.custom({ where })` merges with the
267
+ * seed instead of replacing it (audit F2 — the seed carries safety filters).
268
+ */
269
+ private customWhere;
270
+ private orderByArg;
271
+ private selectArg;
272
+ private includeArg;
273
+ private page;
274
+ private limit;
275
+ private cursorActive;
276
+ private cursor;
277
+ private cursorLimit;
278
+ private cursorDirection;
279
+ private cursorField;
280
+ private cursorStrict;
281
+ /**
282
+ * @param delegate - The Prisma delegate to query (e.g. `prisma.user`).
283
+ * @param options - Optional seed args, a dialect override, or `strictNumbers`.
284
+ */
285
+ constructor(delegate: D, options?: QueryBuilderOptions<D>);
286
+ /**
287
+ * Case-insensitive `contains` across the provided string fields. No condition
288
+ * is added when `searchText` is empty or whitespace-only (audit G7).
289
+ *
290
+ * Dialect-aware: adds `mode: 'insensitive'` only where Prisma accepts it (see
291
+ * `caseInsensitiveMode` in `src/dialects/capabilities.ts`); everywhere else
292
+ * the bare `contains` relies on the database's collation, and where that is
293
+ * ASCII-only matching stays case-sensitive — Prisma offers no alternative
294
+ * there.
295
+ */
296
+ search(params: {
297
+ searchText?: string | undefined;
298
+ fields: WhereKeyOf<D>[];
299
+ }): this;
300
+ /**
301
+ * Adds an equality/operator filter. Accepts a partial Prisma `where` object;
302
+ * `undefined` values are ignored so optional query params are safe to pass.
303
+ */
304
+ filter(filters: FilterInput<D>): this;
305
+ /**
306
+ * Adds `gte`/`lte` range conditions. Keys may be dot-paths to reach relations
307
+ * or nested objects (e.g. `'avatar.size'`). Bounds left `undefined` are
308
+ * skipped; a field is only added when at least one bound is present.
309
+ */
310
+ range(ranges: Record<string, RangeInput>): this;
311
+ /** Adds an arbitrary, fully-typed Prisma `where` condition. */
312
+ where(condition: WhereOf<D>): this;
313
+ /**
314
+ * Sets `orderBy` from a single key. No-op when `sortBy` is not provided.
315
+ * Dot paths expand like `.range()` (`'avatar.size'` → `{ avatar: { size } }`,
316
+ * audit F6). For multi-key or nested relation sorts use {@link orderBy}.
317
+ */
318
+ sortBy(params: {
319
+ sortBy?: OrderKeyOf<D> | (string & {});
320
+ sortOrder?: SortOrder;
321
+ }): this;
322
+ /**
323
+ * Sets `orderBy` verbatim from the full Prisma shape: arrays for multi-key
324
+ * sorts, nested relation order objects. `.sortBy()` remains the single-key
325
+ * convenience — the latest of the two calls wins (audit G1).
326
+ */
327
+ orderBy(order: OrderByOf<D>): this;
328
+ /** Configures `skip`/`take` from a 1-based page number and page size. */
329
+ paginate(params: {
330
+ page?: number;
331
+ limit?: number;
332
+ }): this;
333
+ /**
334
+ * Configures cursor-based ("seek") pagination. Use {@link executeWithCursor}
335
+ * to run the query and obtain `next`/`prev` cursors.
336
+ *
337
+ * - `cursor` is the value of `cursorField` from the edge row of the previous
338
+ * page (omit it for the first page). Strings, numbers and Dates are
339
+ * accepted; Dates serialize to ISO-8601 in the returned cursors (audit F4).
340
+ * - `direction` walks `'forward'` (next) or `'backward'` (previous).
341
+ * - `cursorField` is the unique, sequential column to seek on (default `id`).
342
+ * Pair it with a matching {@link sortBy} for stable ordering.
343
+ * - `strict` spends one extra 1-row probe query to make `hasNextPage` /
344
+ * `hasPrevPage` exact instead of optimistic (audit F10).
345
+ *
346
+ * Takes precedence over {@link paginate} when both are set.
347
+ */
348
+ cursorPaginate(params: {
349
+ cursor?: string | number | Date | undefined;
350
+ limit?: number;
351
+ direction?: CursorDirection;
352
+ cursorField?: OrderKeyOf<D> | (string & {});
353
+ strict?: boolean;
354
+ }): this;
355
+ /**
356
+ * Projects fields with Prisma `select`. The result type of `execute()` is
357
+ * narrowed to exactly the selected shape. Clears any active `.include()`.
358
+ */
359
+ select<TSelect extends SelectOf<D>>(select: TSelect): QueryBuilder<D, Omit<TArgs, 'select' | 'include'> & {
360
+ select: TSelect;
361
+ }>;
362
+ /**
363
+ * Eager-loads relations with Prisma `include`. The result type of `execute()`
364
+ * is widened with the included relations. Clears any active `.select()`.
365
+ */
366
+ include<TInclude extends IncludeOf<D>>(include: TInclude): QueryBuilder<D, Omit<TArgs, 'select' | 'include'> & {
367
+ include: TInclude;
368
+ }>;
369
+ /**
370
+ * Merges raw `findMany` args, e.g. `cursor`, `distinct` or a custom `where`.
371
+ * Values that are `undefined` are stripped at any depth, so
372
+ * `custom({ distinct: undefined })` cannot overwrite an earlier value
373
+ * (audit F15). A custom `where` is AND-ed with the `initialArgs` seed and any
374
+ * previous custom `where` — it never replaces them (audit F2). Successive
375
+ * custom `where`s may nest `{ AND: [...] }` groups; Prisma treats that
376
+ * identically.
377
+ */
378
+ custom(args: FindManyArgsOf<D>): this;
379
+ /** The fully assembled `findMany` args. Useful for debugging or reuse. */
380
+ buildArgs(): FindManyArgsOf<D>;
381
+ /**
382
+ * Executes the query and returns the rows, typed from `.select()`/`.include()`.
383
+ *
384
+ * Tip: for 100% Prisma-native inference you can always run the passthrough
385
+ * `prisma.user.findMany(qb.buildArgs())` — same args, Prisma's own overloads.
386
+ */
387
+ execute(): Promise<FindResultOf<D, TArgs>>;
388
+ /** Executes the query and returns the first row, or `null` when none matched. */
389
+ first(): Promise<ApplyProjection<RowElementOf<D>, TArgs> | null>;
390
+ /** Like {@link first}, but throws {@link NoResultError} when nothing matched. */
391
+ firstOrThrow(): Promise<ApplyProjection<RowElementOf<D>, TArgs>>;
392
+ /** Counts rows matching the current filters (ignores pagination/projection). */
393
+ count(): Promise<number>;
394
+ /**
395
+ * Executes the query and returns the rows plus offset pagination metadata.
396
+ * When no pagination was configured, defaults to page 1, limit 10 so `meta`
397
+ * always describes the data actually returned. `count` and `findMany` run in
398
+ * parallel.
399
+ *
400
+ * Pass `{ includeTotal: false }` to skip the `COUNT` query entirely — `meta`
401
+ * then carries `total: null` / `totalPage: null` (audit G3).
402
+ *
403
+ * Throws when cursor pagination is configured — offset meta cannot describe a
404
+ * seek query, and the cursor over-fetch row would leak into `data` (audit F1).
405
+ * Use {@link executeWithCursor} instead.
406
+ */
407
+ executeWithMeta<O extends {
408
+ includeTotal?: boolean;
409
+ } = {
410
+ includeTotal?: boolean;
411
+ }>(opts?: O): Promise<{
412
+ meta: MetaOf<O>;
413
+ data: FindResultOf<D, TArgs>;
414
+ }>;
415
+ /**
416
+ * Executes a cursor-paginated query (see {@link cursorPaginate}) and returns
417
+ * the page rows plus `next`/`prev` cursors. Rows are always returned in the
418
+ * configured sort order, regardless of pagination `direction`.
419
+ *
420
+ * Throws when a `.select()` projection drops `cursorField` — the page cursors
421
+ * are derived from that field and would come out as `undefined` (audit F5).
422
+ */
423
+ executeWithCursor(): Promise<{
424
+ meta: CursorMeta;
425
+ data: FindResultOf<D, TArgs>;
426
+ }>;
427
+ /** strictNumbers: out-of-range limits throw instead of clamping (audit F12). */
428
+ private assertLimit;
429
+ private assertPage;
430
+ /** strictNumbers: a computed skip beyond MAX_SKIP throws (audit F18). */
431
+ private assertSkipCap;
432
+ /** A projection without the cursor field would derive cursors from `undefined` (audit F5). */
433
+ private assertCursorFieldProjected;
434
+ private buildWhere;
435
+ }
436
+
437
+ /**
438
+ * Register capabilities for a database - including ones Prisma adds in the
439
+ * future. No core code changes are ever required to support a new dialect.
440
+ */
441
+ declare function registerDialect(name: string, capabilities: DialectCapabilities): void;
442
+ /** Set the global default dialect for all builders that do not override it. */
443
+ declare function configQueryBuilder(options: {
444
+ dialect?: string | undefined;
445
+ }): void;
446
+ /**
447
+ * Plug in an auto-detector (best-effort). It must never throw; an undefined
448
+ * result simply falls through to the built-in detector and then 'universal'.
449
+ */
450
+ declare function setDialectDetector(detector: () => string | undefined): void;
451
+ /** A dialect name plus the capabilities resolved for it. */
452
+ interface ResolvedDialect {
453
+ name: string;
454
+ capabilities: DialectCapabilities;
455
+ }
456
+ /**
457
+ * Resolve the active dialect per the documented precedence. An unregistered
458
+ * name resolves to `'universal'` — the reported name never lies about the
459
+ * capabilities actually applied (audit G8).
460
+ */
461
+ declare function resolveDialect(explicit?: string | undefined): ResolvedDialect;
462
+ /** Test helper: reset global configuration (registry entries are kept). */
463
+ declare function resetDialectConfig(): void;
464
+
465
+ /**
466
+ * Best-effort dialect auto-detection (M2 scope).
467
+ *
468
+ * v0 intentionally detects nothing and returns `undefined` → callers fall
469
+ * through to `'universal'`, which never emits an invalid argument on any
470
+ * database. Future heuristics (guarded property sniffing of the Prisma client)
471
+ * must keep the same contract: NEVER throw, NEVER guess wrong loudly — an
472
+ * unknown dialect must degrade to `'universal'`, not to a wrong guess.
473
+ *
474
+ * Users who know their database should prefer explicit configuration:
475
+ * configQueryBuilder({ dialect: 'postgresql' })
476
+ * or per builder:
477
+ * new QueryBuilder(prisma.user, { dialect: 'mongodb' })
478
+ */
479
+ declare function detectDialect(): Dialect | undefined;
480
+
481
+ export { type ApplyInclude, type ApplyProjection, type ApplySelect, type CursorDirection, type CursorMeta, DIALECT_CAPABILITIES, type Dialect, type DialectCapabilities, type FilterInput, type FindManyArgsOf, type FindResultOf, type IncludeOf, NoResultError, type OrderByOf, type OrderKeyOf, type PaginationMeta, type PaginationMetaNoTotal, type PrismaModelDelegate, QueryBuilder, type QueryBuilderOptions, type RangeBound, type RangeInput, type ResolvedDialect, type RowElementOf, type RowsOf, type SelectOf, type SortOrder, type WhereKeyOf, type WhereOf, configQueryBuilder, detectDialect, registerDialect, resetDialectConfig, resolveDialect, setDialectDetector };