turbine-orm 0.49.0 → 0.50.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.
Files changed (157) hide show
  1. package/README.md +122 -39
  2. package/dist/cjs/adapters/cockroachdb.d.ts +39 -0
  3. package/dist/cjs/adapters/index.d.ts +110 -0
  4. package/dist/cjs/adapters/yugabytedb.d.ts +51 -0
  5. package/dist/cjs/cli/config.d.ts +181 -0
  6. package/dist/cjs/cli/config.js +32 -6
  7. package/dist/cjs/cli/destructive.d.ts +38 -0
  8. package/dist/cjs/cli/index.d.ts +359 -0
  9. package/dist/cjs/cli/index.js +228 -56
  10. package/dist/cjs/cli/loader.d.ts +61 -0
  11. package/dist/cjs/cli/mcp.d.ts +42 -0
  12. package/dist/cjs/cli/migrate.d.ts +356 -0
  13. package/dist/cjs/cli/migrate.js +131 -40
  14. package/dist/cjs/cli/observe-ui.d.ts +1 -0
  15. package/dist/cjs/cli/observe-ui.js +14 -5
  16. package/dist/cjs/cli/observe.d.ts +25 -0
  17. package/dist/cjs/cli/observe.js +49 -12
  18. package/dist/cjs/cli/pii-tags.d.ts +53 -0
  19. package/dist/cjs/cli/prisma-report.d.ts +33 -0
  20. package/dist/cjs/cli/prisma-report.js +73 -0
  21. package/dist/cjs/cli/prisma-resolve.d.ts +106 -0
  22. package/dist/cjs/cli/prisma-resolve.js +1 -0
  23. package/dist/cjs/cli/prisma-schema.d.ts +176 -0
  24. package/dist/cjs/cli/prisma-schema.js +82 -4
  25. package/dist/cjs/cli/rate-limit.d.ts +32 -0
  26. package/dist/cjs/cli/rate-limit.js +45 -0
  27. package/dist/cjs/cli/studio-demo.d.ts +43 -0
  28. package/dist/cjs/cli/studio-ui.generated.d.ts +1 -0
  29. package/dist/cjs/cli/studio.d.ts +207 -0
  30. package/dist/cjs/cli/studio.js +136 -71
  31. package/dist/cjs/cli/ui.d.ts +73 -0
  32. package/dist/cjs/cli/ui.js +51 -9
  33. package/dist/cjs/client.d.ts +837 -0
  34. package/dist/cjs/client.js +3 -0
  35. package/dist/cjs/dialect.d.ts +516 -0
  36. package/dist/cjs/dialect.js +37 -12
  37. package/dist/cjs/errors.d.ts +370 -0
  38. package/dist/cjs/generate.d.ts +137 -0
  39. package/dist/cjs/generate.js +39 -6
  40. package/dist/cjs/index-advisor.d.ts +153 -0
  41. package/dist/cjs/index-stats.d.ts +384 -0
  42. package/dist/cjs/index.d.ts +55 -0
  43. package/dist/cjs/index.js +7 -2
  44. package/dist/cjs/introspect.d.ts +269 -0
  45. package/dist/cjs/mssql.d.ts +232 -0
  46. package/dist/cjs/mssql.js +6 -0
  47. package/dist/cjs/mysql.d.ts +173 -0
  48. package/dist/cjs/mysql.js +16 -0
  49. package/dist/cjs/nested-write.d.ts +96 -0
  50. package/dist/cjs/nested-write.js +414 -24
  51. package/dist/cjs/observe.d.ts +115 -0
  52. package/dist/cjs/optional-peer-import.d.cts +72 -0
  53. package/dist/cjs/pipeline-submittable.d.ts +93 -0
  54. package/dist/cjs/pipeline.d.ts +71 -0
  55. package/dist/cjs/powdb-introspect.d.ts +84 -0
  56. package/dist/cjs/powdb.d.ts +931 -0
  57. package/dist/cjs/powdb.js +106 -21
  58. package/dist/cjs/powql.d.ts +592 -0
  59. package/dist/cjs/powql.js +42 -6
  60. package/dist/cjs/prisma-compat.d.ts +283 -0
  61. package/dist/cjs/prisma-compat.js +167 -9
  62. package/dist/cjs/query/aggregates.d.ts +92 -0
  63. package/dist/cjs/query/aggregates.js +7 -3
  64. package/dist/cjs/query/batched-loader.d.ts +193 -0
  65. package/dist/cjs/query/builder.d.ts +849 -0
  66. package/dist/cjs/query/builder.js +571 -65
  67. package/dist/cjs/query/compound-unique.d.ts +51 -0
  68. package/dist/cjs/query/deferred.d.ts +223 -0
  69. package/dist/cjs/query/filters.d.ts +201 -0
  70. package/dist/cjs/query/index.d.ts +14 -0
  71. package/dist/cjs/query/index.js +6 -1
  72. package/dist/cjs/query/relations.d.ts +609 -0
  73. package/dist/cjs/query/relations.js +693 -46
  74. package/dist/cjs/query/types.d.ts +1300 -0
  75. package/dist/cjs/query/utils.d.ts +209 -0
  76. package/dist/cjs/query/utils.js +208 -1
  77. package/dist/cjs/query/warn-registry.d.ts +68 -0
  78. package/dist/cjs/query/warn-registry.js +9 -0
  79. package/dist/cjs/query/where-compile.d.ts +139 -0
  80. package/dist/cjs/query/where.d.ts +548 -0
  81. package/dist/cjs/query/where.js +58 -22
  82. package/dist/cjs/query/writes.d.ts +172 -0
  83. package/dist/cjs/query/writes.js +105 -12
  84. package/dist/cjs/realtime.d.ts +70 -0
  85. package/dist/cjs/schema-builder.d.ts +354 -0
  86. package/dist/cjs/schema-metadata.d.ts +83 -0
  87. package/dist/cjs/schema-sql.d.ts +217 -0
  88. package/dist/cjs/schema-sql.js +23 -5
  89. package/dist/cjs/schema.d.ts +356 -0
  90. package/dist/cjs/schema.js +125 -0
  91. package/dist/cjs/seed.d.ts +15 -0
  92. package/dist/cjs/serverless.d.ts +142 -0
  93. package/dist/cjs/sqlite.d.ts +143 -0
  94. package/dist/cjs/sqlite.js +4 -0
  95. package/dist/cjs/typed-sql.d.ts +102 -0
  96. package/dist/cli/config.d.ts +18 -4
  97. package/dist/cli/config.js +31 -6
  98. package/dist/cli/index.d.ts +123 -0
  99. package/dist/cli/index.js +223 -58
  100. package/dist/cli/migrate.d.ts +59 -10
  101. package/dist/cli/migrate.js +128 -41
  102. package/dist/cli/observe-ui.d.ts +1 -1
  103. package/dist/cli/observe-ui.js +14 -5
  104. package/dist/cli/observe.d.ts +7 -1
  105. package/dist/cli/observe.js +48 -12
  106. package/dist/cli/prisma-report.d.ts +14 -0
  107. package/dist/cli/prisma-report.js +72 -0
  108. package/dist/cli/prisma-resolve.d.ts +6 -0
  109. package/dist/cli/prisma-resolve.js +1 -0
  110. package/dist/cli/prisma-schema.d.ts +62 -2
  111. package/dist/cli/prisma-schema.js +81 -4
  112. package/dist/cli/rate-limit.d.ts +32 -0
  113. package/dist/cli/rate-limit.js +40 -0
  114. package/dist/cli/studio.d.ts +5 -5
  115. package/dist/cli/studio.js +135 -70
  116. package/dist/cli/ui.d.ts +1 -1
  117. package/dist/cli/ui.js +51 -9
  118. package/dist/client.d.ts +40 -0
  119. package/dist/client.js +3 -0
  120. package/dist/dialect.d.ts +17 -1
  121. package/dist/dialect.js +37 -12
  122. package/dist/generate.js +40 -7
  123. package/dist/index.d.ts +1 -1
  124. package/dist/index.js +1 -1
  125. package/dist/mssql.js +6 -0
  126. package/dist/mysql.js +16 -0
  127. package/dist/nested-write.d.ts +2 -0
  128. package/dist/nested-write.js +415 -25
  129. package/dist/powdb.d.ts +4 -2
  130. package/dist/powdb.js +106 -21
  131. package/dist/powql.d.ts +5 -0
  132. package/dist/powql.js +42 -6
  133. package/dist/prisma-compat.d.ts +2 -0
  134. package/dist/prisma-compat.js +166 -8
  135. package/dist/query/aggregates.js +7 -3
  136. package/dist/query/builder.d.ts +292 -21
  137. package/dist/query/builder.js +570 -64
  138. package/dist/query/deferred.d.ts +39 -0
  139. package/dist/query/index.d.ts +1 -1
  140. package/dist/query/index.js +1 -1
  141. package/dist/query/relations.d.ts +173 -5
  142. package/dist/query/relations.js +688 -47
  143. package/dist/query/types.d.ts +123 -39
  144. package/dist/query/utils.d.ts +116 -0
  145. package/dist/query/utils.js +198 -0
  146. package/dist/query/warn-registry.d.ts +9 -0
  147. package/dist/query/warn-registry.js +9 -0
  148. package/dist/query/where.d.ts +38 -1
  149. package/dist/query/where.js +58 -23
  150. package/dist/query/writes.d.ts +42 -1
  151. package/dist/query/writes.js +104 -13
  152. package/dist/schema-sql.d.ts +14 -0
  153. package/dist/schema-sql.js +23 -5
  154. package/dist/schema.d.ts +38 -0
  155. package/dist/schema.js +123 -0
  156. package/dist/sqlite.js +4 -0
  157. package/package.json +77 -28
@@ -0,0 +1,548 @@
1
+ /**
2
+ * turbine-orm: WHERE-clause compilation (extracted from builder.ts)
3
+ *
4
+ * The whole WHERE web: the top-level build/collect/fingerprint trio, the
5
+ * table-scoped trio for relation-filter EXISTS sub-wheres and relation
6
+ * `with`-clause wheres, the leaf JSON/array/vector/text-search clause builders,
7
+ * operator-clause + column-reference compilation, and the client-level
8
+ * global-filter helpers. All functions take a {@link BuilderCtx} as their first
9
+ * argument: the privacy-preserving view of the owning {@link QueryInterface}
10
+ * instance (built once in its constructor) exposing exactly the class-resident
11
+ * primitives this module needs. See builder.ts for the thin delegating methods.
12
+ */
13
+ import type pg from 'pg';
14
+ import type { Dialect } from '../dialect.js';
15
+ import { ValidationError } from '../errors.js';
16
+ import type { RelationDef, SchemaMetadata, TableMetadata } from '../schema.js';
17
+ import type { ArrayFilter, ColumnRef, GlobalFilters, JsonFilter, JsonPathOrderBy, SkipGlobalFilters, TextSearchFilter, VectorFilter, WhereClause, WhereOperator } from './types.js';
18
+ import { type SqlCacheEntry } from './utils.js';
19
+ import { type WhereHost, type WhereRecord } from './where-compile.js';
20
+ /**
21
+ * The privacy-preserving view of a {@link QueryInterface} instance passed as the
22
+ * first argument to every function in this module. Built once as an object
23
+ * literal in the QueryInterface constructor (mirroring the `whereHost`
24
+ * precedent). Data fields are live references to the instance's own state;
25
+ * `currentSkip` is a live getter (it is reassigned per `build*` call). The
26
+ * method members are the class-resident primitives these functions still need.
27
+ */
28
+ export interface BuilderCtx {
29
+ readonly dialect: Dialect;
30
+ readonly table: string;
31
+ readonly schema: SchemaMetadata;
32
+ readonly tableMeta: TableMetadata;
33
+ readonly whereHost: WhereHost;
34
+ readonly globalFilters?: GlobalFilters;
35
+ readonly scopedHostCache: Map<string, WhereHost>;
36
+ readonly columnPgTypeMap: Map<string, string>;
37
+ readonly columnArrayTypeMap: Map<string, string>;
38
+ /**
39
+ * The client's `utcTimestamps` setting, when the owning QueryInterface
40
+ * supplies it. Optional so an older ctx literal (and every test that builds
41
+ * one by hand) keeps the default. `false` opts out of BOTH the UTC read
42
+ * parsing and the symmetric UTC bind rewriting for zone-less `date` /
43
+ * `timestamp` columns (see `coerceWriteValue` in writes.ts).
44
+ */
45
+ readonly utcTimestamps?: boolean;
46
+ readonly crossSchemaTypeColumns: Set<string>;
47
+ /**
48
+ * The active query's `skipGlobalFilters` opt-out. A live getter/setter over
49
+ * the owning instance's field: `build*` methods set it at their top, and the
50
+ * synchronous SQL-build + param-collect tree reads it deep inside
51
+ * `resolveGlobalFilter`.
52
+ */
53
+ currentSkip: SkipGlobalFilters | undefined;
54
+ q(name: string): string;
55
+ p(index: number): string;
56
+ inParam(values: unknown): unknown;
57
+ inClause(expr: string, paramRef: string, negated: boolean): string;
58
+ toColumn(field: string): string;
59
+ castAgg(expr: string, target: 'int' | 'float'): string;
60
+ parseRow(row: Record<string, unknown>, table: string): Record<string, unknown>;
61
+ nullsSuffix(nulls: 'first' | 'last' | undefined): string;
62
+ isRelationOrderByValue(value: unknown): boolean;
63
+ resolveOrderByColumn(table: string, meta: TableMetadata, key: string): string;
64
+ buildJsonPathOrderEntry(table: string, meta: TableMetadata, field: string, spec: JsonPathOrderBy, prefix: string, params?: unknown[]): string;
65
+ toSqlColumn(field: string): string;
66
+ mutationInsertId(result: pg.QueryResult): unknown;
67
+ acquireSql(cacheKey: string, build: (params: unknown[]) => string): SqlCacheEntry;
68
+ crossCheckCache(op: string, cacheKey: string, entry: SqlCacheEntry, build: (params: unknown[]) => string, collectedParams: unknown[]): void;
69
+ readonly jsonEncoding: 'object' | 'positional';
70
+ readonly camelDateFieldCache: Map<string, Set<string>>;
71
+ limitOneClause(): string;
72
+ buildPagination(limitPh: string | undefined, offsetPh: string | undefined, hasOrderBy: boolean): string;
73
+ paginationRef(value: unknown, params: unknown[], arg?: string): string;
74
+ /**
75
+ * Coerce + validate a LIMIT/OFFSET argument (non-negative safe integer).
76
+ * The cache-hit param-collect paths call it directly, so a warmed template
77
+ * can never bind an unvalidated NaN (which Postgres reads as "no limit").
78
+ */
79
+ paginationValue(value: unknown, arg?: string): number;
80
+ }
81
+ /**
82
+ * Column-reference resolution context threaded into
83
+ * {@link QueryInterface.buildOperatorClauses} / `collectOperatorParams`: the
84
+ * table whose fields a `{ col }` reference may name, plus the SQL prefix
85
+ * (`''` top-level, `"table".` in relation-filter subqueries, `t0.` against a
86
+ * relation alias) the compiled identifier must carry so it resolves in the
87
+ * same scope as the operator's own column.
88
+ */
89
+ interface ColumnRefContext {
90
+ meta: TableMetadata;
91
+ table: string;
92
+ prefix: string;
93
+ /**
94
+ * The operator's own RAW (unquoted) column name. The `column` argument the
95
+ * operator builders receive is already quoted on the build side and raw on
96
+ * the collect side, so the temporal bind rewrite resolves the column's type
97
+ * from here instead — the one value both sides pass identically.
98
+ */
99
+ rawColumn: string;
100
+ }
101
+ /**
102
+ * A table-scoped WHERE compilation context for a sub-where that is NOT the
103
+ * top-level `this.tableMeta` clause. Both relation-filter `EXISTS` sub-wheres
104
+ * (correlated against the bare target table, `"target".col`) and relation
105
+ * `with`-clause `where` filters (against a per-subquery alias, `t0.col`) compile
106
+ * an arbitrary target table's where against a column qualifier. They differ ONLY
107
+ * in that qualifier, the correlation parent handed to `buildRelationFilter`, and
108
+ * the unknown-column error wording — so a single scoped build/collect/fingerprint
109
+ * trio, driven by the SAME canonical {@link walkWhere} the top level uses, serves
110
+ * both. See `buildScopedWhere` / `collectScopedWhereParams` / `fingerprintScopedWhere`.
111
+ */
112
+ interface WhereScope {
113
+ /** The target table's metadata (column map, relations, types). */
114
+ meta: TableMetadata;
115
+ /** The target table name (used for host binding + error messages). */
116
+ table: string;
117
+ /** SQL prefix before `q(col)` — `"target".` for EXISTS sub-wheres, `t0.` for aliases. */
118
+ qualifier: string;
119
+ /** The `parentTable` correlation argument for nested `buildRelationFilter` calls. */
120
+ relationParent: string;
121
+ /** {@link WhereHost} bound to `meta`, so {@link walkWhere} enumerates this scope's keys. */
122
+ host: WhereHost;
123
+ /** Typed error for an unknown column reference (wording differs per scope). */
124
+ unknownColumn: (field: string) => ValidationError;
125
+ }
126
+ /**
127
+ * Produce a value-invariant fingerprint of a where clause.
128
+ * Same keys + same operator shapes + same combinator structure => same string.
129
+ * Different values (e.g. id=1 vs id=999) => identical fingerprint.
130
+ *
131
+ * @internal Exposed as package-private for testing via class access.
132
+ */
133
+ export declare function fingerprintWhere(qi: BuilderCtx, where: Record<string, unknown>): string;
134
+ /**
135
+ * Fingerprint the present branches of a normalized relation filter, in the
136
+ * fixed order some→every→none→is→isNot. A `null` branch tokenizes as
137
+ * `<branch>(null)`; a present branch recurses through
138
+ * {@link fingerprintRelFilter} so the FULL inner shape is captured (two
139
+ * different sub-wheres must never collide on one cached SQL text).
140
+ */
141
+ export declare function fingerprintRelationParts(qi: BuilderCtx, relDef: RelationDef, filterObj: WhereRecord): string[];
142
+ /**
143
+ * Fingerprint a relation filter sub-where for some/every/none. Thin wrapper
144
+ * over the unified {@link fingerprintScopedWhere}. When the target table is
145
+ * unknown, an empty-relations host makes every key scalar (matching the old
146
+ * `meta?.relations` short-circuit).
147
+ */
148
+ export declare function fingerprintRelFilter(qi: BuilderCtx, targetTable: string, subWhere: Record<string, unknown>): string;
149
+ /**
150
+ * Walk a where clause and push ONLY values into `params`, in the EXACT same
151
+ * order that `buildWhereClause` pushes them. Used on cache hit to fill params
152
+ * without rebuilding SQL.
153
+ *
154
+ * @internal Exposed as package-private for testing.
155
+ */
156
+ export declare function collectWhereParams(qi: BuilderCtx, where: Record<string, unknown>, params: unknown[]): void;
157
+ /**
158
+ * Push a scalar WHERE value's params, mirroring {@link buildScalarClause}'s
159
+ * emissions exactly. Both resolve the value's shape via the shared
160
+ * {@link classifyScalarForSql}, so a cache HIT binds each `$N` to the value
161
+ * the cached SQL expects. A JSON/array-shaped value on a non-JSON/array column
162
+ * (`jsonThrow`/`arrayThrow`) falls through to the equality path here, the
163
+ * same fall-through the collect path has always taken (the build path's typed
164
+ * error there is only reachable on a MISS, before anything is cached).
165
+ */
166
+ export declare function collectScalarParams(qi: BuilderCtx, key: string, value: unknown, params: unknown[]): void;
167
+ /**
168
+ * Param-collect mirror of {@link buildRelationFilter} for one relation-filter
169
+ * object (`{ some/every/none/is/isNot }`, already normalized). Pushes, per
170
+ * present branch and in the canonical order some→none→every→is→isNot, the
171
+ * branch's sub-where params THEN the target table's global-filter params —
172
+ * exactly the order buildRelationFilter emits. When no global filter applies
173
+ * the gf calls are no-ops, so this stays byte-identical to the pre-0.28 path.
174
+ * Shared by every collect site that mirrors buildRelationFilter
175
+ * (collectWhereParams, collectRelFilterParams, collectAliasWhereParams).
176
+ */
177
+ export declare function collectRelationFilterParams(qi: BuilderCtx, relDef: RelationDef, filterObj: Record<string, unknown>, params: unknown[]): void;
178
+ export declare function collectRelFilterParams(qi: BuilderCtx, targetTable: string, subWhere: Record<string, unknown>, params: unknown[]): void;
179
+ /**
180
+ * Collect params from operator clauses. Mirrors buildOperatorClauses:
181
+ * {@link ColumnRef} values compile into the SQL text, so they push NOTHING -
182
+ * but they re-run the same validation (unknown ref / insensitive mode) so a
183
+ * warmed cache can never skip a check the build path enforces.
184
+ */
185
+ export declare function collectOperatorParams(qi: BuilderCtx, column: string, op: WhereOperator, params: unknown[], refCtx?: ColumnRefContext): void;
186
+ /**
187
+ * Collect params from JSON filter. Mirrors buildJsonFilterClauses exactly:
188
+ * the `path` is bound at most once (its placeholder is shared by every
189
+ * extraction clause), then equals/contains/hasKey values, then the range
190
+ * comparison values in {@link JSON_RANGE_OPERATORS} order.
191
+ */
192
+ export declare function collectJsonFilterParams(qi: BuilderCtx, filter: JsonFilter, params: unknown[], column: string): void;
193
+ /** Collect params from array filter. Mirrors buildArrayFilterClauses. */
194
+ export declare function collectArrayFilterParams(qi: BuilderCtx, filter: ArrayFilter, params: unknown[]): void;
195
+ /**
196
+ * Collect params for a vector distance WHERE filter. Mirrors
197
+ * {@link buildVectorFilterClauses}: the `$n::vector` query vector first, then
198
+ * the comparison threshold(s).
199
+ */
200
+ export declare function collectVectorFilterParams(qi: BuilderCtx, field: string, rawColumn: string, filter: VectorFilter, params: unknown[]): void;
201
+ /** Build WHERE clause from a where object (supports operators, NULL, OR) */
202
+ export declare function buildWhere<T extends object>(qi: BuilderCtx, where: WhereClause<T>): {
203
+ sql: string;
204
+ params: unknown[];
205
+ };
206
+ /**
207
+ * Resolve the configured global filter for `table`, evaluating a function
208
+ * filter, honoring the active query's `skipGlobalFilters`. Returns `null` when
209
+ * no filter applies, the query opted out, or the filter is empty.
210
+ */
211
+ export declare function resolveGlobalFilter(qi: BuilderCtx, table: string, skip?: SkipGlobalFilters | undefined): Record<string, unknown> | null;
212
+ /**
213
+ * AND-merge this table's resolved global filter into a user `where`. Either
214
+ * side may be absent. When no filter applies the user where is returned by
215
+ * reference, so fingerprints/SQL stay byte-identical to the pre-0.28 path.
216
+ */
217
+ export declare function mergeGlobalFilter(qi: BuilderCtx, userWhere: Record<string, unknown> | undefined): Record<string, unknown> | undefined;
218
+ /**
219
+ * SQL clause for `targetTable`'s global filter rendered against `alias`
220
+ * (relation subqueries, `_count`, relation `orderBy`). Pushes its params to
221
+ * `params`; returns `''` when no filter applies. Mirror:
222
+ * {@link collectTargetGlobalFilterAlias}.
223
+ */
224
+ export declare function targetGlobalFilterAlias(qi: BuilderCtx, targetTable: string, alias: string, params: unknown[]): string;
225
+ /** Param-collect mirror of {@link targetGlobalFilterAlias}. */
226
+ export declare function collectTargetGlobalFilterAlias(qi: BuilderCtx, targetTable: string, params: unknown[]): void;
227
+ /**
228
+ * SQL clause for `targetTable`'s global filter rendered against the bare
229
+ * (unaliased) table name — the form used inside relation-filter `EXISTS`
230
+ * subqueries. Pushes its params; `''` when none. Mirror:
231
+ * {@link collectTargetGlobalFilterExists}.
232
+ */
233
+ export declare function targetGlobalFilterExists(qi: BuilderCtx, targetTable: string, params: unknown[]): string;
234
+ /** Param-collect mirror of {@link targetGlobalFilterExists}. */
235
+ export declare function collectTargetGlobalFilterExists(qi: BuilderCtx, targetTable: string, params: unknown[]): void;
236
+ /**
237
+ * Value-invariant SQL-cache-key segment for the active global-filter
238
+ * environment. Relation-subquery / relation-filter / `_count` / relation-
239
+ * `orderBy` global filters are rendered at build time but their SHAPE is not
240
+ * otherwise in the where/with fingerprint, so this segment guards the cache:
241
+ * two different filter shapes never collide on one cached SQL text, while two
242
+ * function-filter results of the SAME shape (differing only in values) share
243
+ * the entry and bind their own params. Empty (`''`) when no filter applies, so
244
+ * cache keys stay byte-identical when the feature is unused.
245
+ */
246
+ export declare function globalFilterCacheSegment(qi: BuilderCtx): string;
247
+ /**
248
+ * True when the USER-supplied `where` compiles to no predicate (`{}`,
249
+ * `{ id: undefined }`, `{ OR: [{ a: undefined }] }`, …). This is the exact
250
+ * signal the empty-`where` guard needs — the compiled emptiness, NOT the
251
+ * fingerprint (which is non-empty for an all-undefined `OR`/`AND`). It ignores
252
+ * any configured global filter, so a global filter never lets an unguarded
253
+ * mass mutation through.
254
+ */
255
+ export declare function userPredicateIsEmpty(qi: BuilderCtx, userWhere: Record<string, unknown>): boolean;
256
+ export declare function assertMutationHasPredicate(qi: BuilderCtx, operation: 'update' | 'updateMany' | 'delete' | 'deleteMany', whereSql: string, allowFullTableScan: boolean | undefined): void;
257
+ /**
258
+ * Build the inner WHERE expression (without the WHERE keyword).
259
+ * Returns null if no conditions exist.
260
+ * Supports: equality, operators, NULL, OR, AND, NOT, relation filters (some/every/none).
261
+ */
262
+ export declare function buildWhereClause(qi: BuilderCtx, where: Record<string, unknown>, params: unknown[]): string | null;
263
+ /**
264
+ * Emit the SQL clause(s) for one scalar WHERE key onto `andClauses`, pushing
265
+ * any params. The shape decision comes from the shared
266
+ * {@link classifyScalarForSql} so {@link collectScalarParams} pushes an
267
+ * identical param list on a cache hit. The `*Throw` branches preserve the
268
+ * strict-validation errors for a JSON/array operator on the wrong column type.
269
+ */
270
+ export declare function buildScalarClause(qi: BuilderCtx, key: string, value: unknown, params: unknown[], andClauses: string[]): void;
271
+ /**
272
+ * A {@link WhereHost} with no relations — used to fingerprint a sub-where
273
+ * whose target table is unknown (`schema.tables[t]` miss). `walkWhere` reads
274
+ * only `tableMeta.relations`, so every key falls to the scalar path, matching
275
+ * the pre-unification `meta?.relations` short-circuit.
276
+ */
277
+ export declare function emptyRelationsHost(qi: BuilderCtx, table: string): WhereHost;
278
+ export declare function scopedWhereHost(qi: BuilderCtx, meta: TableMetadata): WhereHost;
279
+ /** Build the scope for a relation-filter EXISTS sub-where over the bare target table. */
280
+ export declare function relationWhereScope(qi: BuilderCtx, targetTable: string, meta: TableMetadata): WhereScope;
281
+ /** Build the scope for a relation `with`-clause `where` compiled against `alias`. */
282
+ export declare function aliasWhereScope(qi: BuilderCtx, targetTable: string, meta: TableMetadata, alias: string): WhereScope;
283
+ /**
284
+ * Compile a scoped sub-where to SQL. Serves BOTH the relation-filter EXISTS
285
+ * body ({@link buildSubWhereForRelation}) and the relation `with`-clause
286
+ * `where` ({@link buildAliasWhere}) — the emitted SQL is byte-identical to the
287
+ * former hand-mirrored walkers, since it renders the same clauses in the same
288
+ * ({@link walkWhere}-canonical) key order.
289
+ */
290
+ export declare function buildScopedWhere(qi: BuilderCtx, scope: WhereScope, where: Record<string, unknown>, params: unknown[]): string | null;
291
+ /**
292
+ * Emit the SQL clause(s) for one scalar key of a scoped sub-where. Reproduces
293
+ * the null / JSON / array / operator / equality fall-through both former
294
+ * walkers shared (relation sub-wheres and alias wheres carry no vector or
295
+ * text-search scalar surface, so — unlike the top-level {@link buildScalarClause}
296
+ * — those shapes are not special-cased here and keep their historical
297
+ * equality-guard behavior).
298
+ */
299
+ export declare function buildScopedScalarClause(qi: BuilderCtx, scope: WhereScope, field: string, value: unknown, params: unknown[], clauses: string[]): void;
300
+ /**
301
+ * Cache-hit param-collect mirror of {@link buildScopedWhere}: pushes the exact
302
+ * same params in the exact same order (driven by the same {@link walkWhere}),
303
+ * without rebuilding SQL. Serves both {@link collectRelFilterParams} and
304
+ * {@link collectAliasWhereParams}.
305
+ */
306
+ export declare function collectScopedWhereParams(qi: BuilderCtx, scope: WhereScope, where: Record<string, unknown>, params: unknown[]): void;
307
+ /** Param-collect mirror of {@link buildScopedScalarClause}. */
308
+ export declare function collectScopedScalarParams(qi: BuilderCtx, scope: WhereScope, field: string, value: unknown, params: unknown[]): void;
309
+ /**
310
+ * Value-invariant fingerprint of a scoped sub-where. Same canonical
311
+ * {@link walkWhere} as {@link fingerprintWhere}, so two shapes that compile to
312
+ * different SQL never collide on one cached SQL string. Serves both
313
+ * {@link fingerprintRelFilter} and {@link fingerprintAliasWhere}. Fingerprint
314
+ * bytes are process-local cache keys (never persisted), so their exact text
315
+ * may differ from the pre-unification walkers as long as collisions stay
316
+ * impossible.
317
+ */
318
+ export declare function fingerprintScopedWhere(qi: BuilderCtx, host: WhereHost, where: Record<string, unknown>): string;
319
+ /**
320
+ * Build relation filter SQL: WHERE EXISTS / NOT EXISTS subquery
321
+ * Supports: some (EXISTS), every (NOT EXISTS ... NOT), none (NOT EXISTS)
322
+ */
323
+ export declare function buildRelationFilter(qi: BuilderCtx, _relName: string, relDef: RelationDef, filterObj: Record<string, unknown>, params: unknown[], parentTable?: string): string | null;
324
+ /**
325
+ * Build WHERE clause conditions for a relation filter subquery.
326
+ * Uses the target table's column mapping to resolve field names.
327
+ */
328
+ export declare function buildSubWhereForRelation(qi: BuilderCtx, targetTable: string, subWhere: Record<string, unknown>, params: unknown[]): string | null;
329
+ /**
330
+ * Resolve a column's Postgres type from an arbitrary table's metadata
331
+ * (relation targets, not just `qi.table`).
332
+ */
333
+ export declare function pgTypeForColumn(_qi: BuilderCtx, meta: TableMetadata, column: string): string;
334
+ /**
335
+ * Rewrite a WHERE operand bound against `column` the same way the write path
336
+ * rewrites a `data` value ({@link coerceTemporalValue}): a JS `Date` on a
337
+ * `time` / `timetz` column becomes a time-of-day literal (Postgres otherwise
338
+ * answers `22007 invalid input syntax for type time` for the ISO timestamp the
339
+ * driver would send), and on a zone-less `date` / `timestamp` column it becomes
340
+ * the UTC-component literal, so a predicate matches the value a write of the
341
+ * same `Date` stored.
342
+ *
343
+ * This is a VALUE transform only — it never changes the emitted SQL — so the
344
+ * SQL-template cache is unaffected, and it is applied on the cache-hit
345
+ * param-collect path as well as the build path.
346
+ *
347
+ * `timestamptz` and every non-temporal column are returned by identity.
348
+ */
349
+ export declare function coerceWhereOperand(qi: BuilderCtx, meta: TableMetadata, column: string, value: unknown): unknown;
350
+ /**
351
+ * The Postgres enum type name for a column, when the schema knows one.
352
+ *
353
+ * Introspection stores each column's `udt_name` in `pgTypes` and every
354
+ * database enum in `schema.enums` (typname → labels); a column whose type
355
+ * matches an enum key needs an explicit `::"EnumName"` cast on its write
356
+ * binds — bulk-insert forms like `UNNEST($1::text[])` otherwise type the
357
+ * value as text and Postgres refuses the implicit text→enum coercion
358
+ * ("column X is of type Y but expression is of type text").
359
+ *
360
+ * Postgres-only by construction: gated on the active dialect being
361
+ * `postgresql` AND on `schema.enums` having entries (only PG introspection
362
+ * produces them — `defineSchema` and the other engines leave it empty), so
363
+ * SQLite/MySQL/MSSQL/PowDB output is byte-identical.
364
+ */
365
+ export declare function enumTypeForColumn(qi: BuilderCtx, column: string): string | null;
366
+ /**
367
+ * `::"EnumName"` cast suffix for a write-bind placeholder on an enum
368
+ * column; `''` for every other column, so non-enum SQL stays byte-identical.
369
+ * The type name is an introspected identifier and is quoted via the dialect.
370
+ */
371
+ export declare function enumCastSuffix(qi: BuilderCtx, column: string): string;
372
+ /**
373
+ * Equality-fallthrough guard shared by every SQL-build path AND every
374
+ * cache-hit param-collect path. A plain object literal that matched no known
375
+ * filter shape on a non-JSON column is almost always a misspelled operator
376
+ * (`startWith` for `startsWith`); binding it as `col = $1` silently returns
377
+ * wrong rows. Class instances (Buffer for bytea, Decimal wrappers, ...) are
378
+ * legitimate bind values and pass through, as do objects on json/jsonb
379
+ * columns (object equality).
380
+ */
381
+ export declare function assertBindableEqualityValue(qi: BuilderCtx, rawColumn: string, value: unknown, columnPgType: string, table: string): void;
382
+ /**
383
+ * Build the user-supplied `where` filter of a relation `with` clause against
384
+ * the relation's table alias. Supports the same scalar surface as the
385
+ * top-level WHERE builder — equality, IS NULL, operator objects (incl.
386
+ * `mode: 'insensitive'`), and OR/AND/NOT combinators. Unknown operator
387
+ * objects throw via {@link assertBindableEqualityValue}.
388
+ *
389
+ * Param push order MUST mirror {@link collectAliasWhereParams} exactly, or
390
+ * cache hits and pipeline batching will desync.
391
+ */
392
+ export declare function buildAliasWhere(qi: BuilderCtx, targetTable: string, targetMeta: TableMetadata, alias: string, where: Record<string, unknown>, params: unknown[]): string | null;
393
+ /** Mirrors {@link buildAliasWhere} param-push order for the cache-hit collect path. */
394
+ export declare function collectAliasWhereParams(qi: BuilderCtx, targetTable: string, targetMeta: TableMetadata, where: Record<string, unknown>, params: unknown[]): void;
395
+ /**
396
+ * Value-invariant, shape-aware fingerprint for a relation `with` clause's
397
+ * `where` filter. Must distinguish every SQL shape {@link buildAliasWhere}
398
+ * can emit — equality vs null vs operator sets vs combinators — or two
399
+ * differently-shaped wheres would share one cached SQL string.
400
+ */
401
+ export declare function fingerprintAliasWhere(qi: BuilderCtx, where: Record<string, unknown>, targetTable?: string): string;
402
+ /**
403
+ * Validate a `{ col }` column reference against its table and return the
404
+ * resolved snake_case column name. Shared by the SQL-build path
405
+ * ({@link buildOperatorClauses}) and the cache-hit param-collect path
406
+ * (`collectOperatorParams`) so both always throw identically: a warmed
407
+ * cache can never skip the check.
408
+ */
409
+ export declare function resolveColumnRef(_qi: BuilderCtx, ref: ColumnRef, ctx: ColumnRefContext, mode?: 'default' | 'insensitive'): string;
410
+ /**
411
+ * Compile a `{ col }` reference to its quoted, prefix-matched SQL identifier.
412
+ * NO param is bound: the referenced column is part of the SQL text (and of
413
+ * the where fingerprint, via `fingerprintOperatorShape` in `filters.ts`).
414
+ */
415
+ export declare function columnRefSql(qi: BuilderCtx, ref: ColumnRef, ctx: ColumnRefContext | undefined, mode?: 'default' | 'insensitive'): string;
416
+ /**
417
+ * Build SQL clauses for a single operator object on a column.
418
+ * Each operator key becomes its own clause, all ANDed together.
419
+ *
420
+ * `equals`/`not`/`gt`/`gte`/`lt`/`lte` also accept a {@link ColumnRef}
421
+ * (`{ col: 'otherField' }`) which compiles to a column-to-column comparison
422
+ * against `refCtx`: no param bound, so `collectOperatorParams` mirrors by
423
+ * pushing nothing and the referenced name lives in the fingerprint.
424
+ */
425
+ export declare function buildOperatorClauses(qi: BuilderCtx, column: string, op: WhereOperator, params: unknown[], refCtx?: ColumnRefContext): string[];
426
+ /**
427
+ * Gate the full-text `search` filter on {@link Dialect.supportsFullTextSearch}.
428
+ * The clause it guards is `to_tsvector(...) @@ to_tsquery(...)`, which only
429
+ * PostgreSQL parses, so every other engine gets a typed
430
+ * {@link UnsupportedFeatureError} (E017) instead of a raw driver syntax error.
431
+ * Called from BOTH the build and the param-collect side (mirroring the vector
432
+ * gate) so the two paths can never diverge.
433
+ */
434
+ export declare function requireFullTextSearch(qi: BuilderCtx): void;
435
+ /**
436
+ * Gate the array filter operators (`has` / `hasEvery` / `hasSome` / `isEmpty`)
437
+ * on {@link Dialect.supportsArrayColumns}. They compile to PostgreSQL array
438
+ * operators (`= ANY(col)`, `@>`, `&&`, `cardinality(col)`) over a native array
439
+ * column, which no other supported engine has. Called from BOTH the build and
440
+ * the param-collect side.
441
+ */
442
+ export declare function requireArrayColumns(qi: BuilderCtx): void;
443
+ /**
444
+ * Resolve a {@link VectorMetric} to its pgvector distance operator from a
445
+ * fixed allow-list, validating the target column is actually a `vector`
446
+ * column. Throws {@link ValidationError} for an unknown metric or a
447
+ * non-vector column — a user-supplied string can never become a SQL operator.
448
+ */
449
+ export declare function vectorOperator(qi: BuilderCtx, field: string, rawColumn: string, metric: string): string;
450
+ /**
451
+ * Validate and bind a query vector as a single `$n::vector` parameter.
452
+ * Every element must be a finite number (no NaN / Infinity / strings) so a
453
+ * malformed array can never produce a broken `::vector` literal, and the array
454
+ * is NEVER string-interpolated into the SQL text. Returns the `$n::vector`
455
+ * placeholder string.
456
+ */
457
+ export declare function pushVectorParam(qi: BuilderCtx, field: string, _rawColumn: string, to: unknown, params: unknown[]): string;
458
+ /**
459
+ * Prisma-compat: a plain object on a to-one relation key —
460
+ * `where: { vendor: { name: { contains: 'x' } } }` — is an implicit `is`
461
+ * filter. Normalize it to `{ is: obj }` so all downstream handling (SQL,
462
+ * params, fingerprint) sees one canonical shape. To-many relations still
463
+ * require an explicit `some`/`every`/`none` (a bare object there is
464
+ * ambiguous and was never valid in Prisma either).
465
+ */
466
+ export declare function normalizeRelationFilter(_qi: BuilderCtx, relDef: RelationDef, filterObj: Record<string, unknown>): Record<string, unknown>;
467
+ /**
468
+ * Case-insensitive json/jsonb column-type check. Postgres reports lowercase
469
+ * udt_names, but SQLite/MySQL introspection surfaces the DECLARED type
470
+ * (e.g. `JSON`), so every JSON-feature gate compares through this predicate
471
+ * — build and collect sides alike, keeping the SQL-cache lockstep.
472
+ */
473
+ export declare function isJsonColumnType(_qi: BuilderCtx, colType: string): boolean;
474
+ export declare function getColumnPgType(qi: BuilderCtx, column: string): string;
475
+ /**
476
+ * Get the Postgres base element type for an array column.
477
+ * E.g. '_text' → 'text', '_int4' → 'integer'
478
+ */
479
+ export declare function getArrayElementType(_qi: BuilderCtx, pgType: string): string;
480
+ /**
481
+ * Validate and enumerate the range comparisons (`gt`/`gte`/`lt`/`lte`) on a
482
+ * JSON filter, in the fixed {@link JSON_RANGE_OPERATORS} order. Shared by
483
+ * the SQL-build path ({@link buildJsonFilterClauses}) and the cache-hit
484
+ * param-collect path ({@link collectJsonFilterParams}) so both always agree
485
+ * on which params are pushed — and both throw identically for invalid
486
+ * shapes, so a warmed cache can never skip validation.
487
+ */
488
+ export declare function jsonRangeEntries(_qi: BuilderCtx, filter: JsonFilter, column: string): {
489
+ sqlOp: string;
490
+ value: number | string;
491
+ }[];
492
+ /**
493
+ * Build SQL clauses for JSONB filter operators on a column.
494
+ * Supports: path, equals, contains, hasKey, gt, gte, lt, lte.
495
+ *
496
+ * The `path` param is bound at most once and its placeholder is shared by
497
+ * every clause that extracts it (equals + range ops), so the param list
498
+ * stays byte-identical to {@link collectJsonFilterParams}.
499
+ */
500
+ export declare function buildJsonFilterClauses(qi: BuilderCtx, column: string, filter: JsonFilter, params: unknown[]): string[];
501
+ /**
502
+ * Bind value for a JSON path parameter, encoded per dialect. PostgreSQL's
503
+ * `#>>` takes a `text[]` (the segments as strings — or `nativeForm` when the
504
+ * caller has a specific native binding, e.g. JsonFilter's raw path array).
505
+ * Every other engine's JSON function (`json_extract` / `JSON_EXTRACT` /
506
+ * `JSON_VALUE`) takes a `'$'`-rooted JSONPath STRING: binding the raw array
507
+ * would arrive as `'["a"]'` (the driver shims JSON.stringify non-primitive
508
+ * params) and fail at runtime with the engine's bad-JSON-path error. The
509
+ * encoded path stays a bound parameter — never spliced into SQL text — so
510
+ * the build/collect param mirrors stay in lockstep and injection-safe.
511
+ */
512
+ export declare function jsonPathParam(qi: BuilderCtx, path: readonly (string | number)[], nativeForm?: unknown): unknown;
513
+ /**
514
+ * Cast an extracted JSON path text value to a numeric type for range
515
+ * comparison. PostgreSQL uses `(expr)::numeric` (exact — the right way to
516
+ * compare JSON numbers, and `::float` would lose precision on big ints);
517
+ * other dialects route through {@link Dialect.castAggregate} (SQLite/MySQL/
518
+ * SQL Server have no `::` operator) as a float cast.
519
+ */
520
+ export declare function castJsonNumeric(qi: BuilderCtx, extract: string): string;
521
+ /**
522
+ * Build SQL clauses for Array filter operators on a column.
523
+ * Supports: has, hasEvery, hasSome, isEmpty.
524
+ */
525
+ export declare function buildArrayFilterClauses(qi: BuilderCtx, column: string, filter: ArrayFilter, params: unknown[], pgType: string): string[];
526
+ /**
527
+ * Build SQL clauses for a pgvector distance WHERE filter:
528
+ *
529
+ * `"embedding" <-> $1::vector < $2`
530
+ *
531
+ * The query vector is bound as a `$n::vector` param (never interpolated), the
532
+ * metric maps to an operator via a fixed allow-list, and each comparison
533
+ * threshold (`lt`/`lte`/`gt`/`gte`) is its own bound param. Emits one clause
534
+ * per supplied comparator (all ANDed). Param push order matches
535
+ * {@link collectVectorFilterParams}.
536
+ */
537
+ export declare function buildVectorFilterClauses(qi: BuilderCtx, field: string, rawColumn: string, filter: VectorFilter, params: unknown[]): string[];
538
+ /**
539
+ * Build SQL clause for full-text search using to_tsvector @@ to_tsquery.
540
+ * The config name is validated to prevent injection (only alphanumeric + underscore).
541
+ */
542
+ export declare function buildTextSearchClause(qi: BuilderCtx, column: string, filter: TextSearchFilter, params: unknown[]): string;
543
+ /**
544
+ * Get the Postgres array type for a column (used by UNNEST in createMany).
545
+ * Uses pre-computed Map for O(1) lookup instead of linear scan.
546
+ */
547
+ export declare function getColumnArrayType(qi: BuilderCtx, column: string): string;
548
+ export {};