turbine-orm 0.81.0 → 0.90.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 (295) hide show
  1. package/README.md +26 -25
  2. package/dist/checkout.d.ts +27 -2
  3. package/dist/checkout.js +75 -4
  4. package/dist/cjs/checkout.d.ts +27 -2
  5. package/dist/cjs/checkout.js +76 -3
  6. package/dist/cjs/cli/code-first-tags.d.ts +62 -0
  7. package/dist/cjs/cli/code-first-tags.js +124 -0
  8. package/dist/cjs/cli/compile-query.js +9 -0
  9. package/dist/cjs/cli/config.d.ts +35 -6
  10. package/dist/cjs/cli/config.js +17 -1
  11. package/dist/cjs/cli/destructive.d.ts +7 -4
  12. package/dist/cjs/cli/destructive.js +224 -20
  13. package/dist/cjs/cli/error-catalog.js +36 -0
  14. package/dist/cjs/cli/error-text.d.ts +15 -0
  15. package/dist/cjs/cli/error-text.js +40 -0
  16. package/dist/cjs/cli/index.d.ts +62 -4
  17. package/dist/cjs/cli/index.js +568 -108
  18. package/dist/cjs/cli/local-server-guard.d.ts +53 -0
  19. package/dist/cjs/cli/local-server-guard.js +119 -0
  20. package/dist/cjs/cli/local-server-output.d.ts +41 -0
  21. package/dist/cjs/cli/local-server-output.js +103 -0
  22. package/dist/cjs/cli/mcp.d.ts +8 -0
  23. package/dist/cjs/cli/mcp.js +121 -32
  24. package/dist/cjs/cli/migrate.d.ts +113 -5
  25. package/dist/cjs/cli/migrate.js +270 -21
  26. package/dist/cjs/cli/observe.d.ts +6 -1
  27. package/dist/cjs/cli/observe.js +85 -55
  28. package/dist/cjs/cli/pii-predicate-guard.d.ts +43 -23
  29. package/dist/cjs/cli/pii-predicate-guard.js +98 -37
  30. package/dist/cjs/cli/prisma-resolve.js +17 -13
  31. package/dist/cjs/cli/prisma-schema.js +12 -4
  32. package/dist/cjs/cli/studio-ui.generated.js +1 -1
  33. package/dist/cjs/cli/studio.d.ts +14 -2
  34. package/dist/cjs/cli/studio.js +244 -69
  35. package/dist/cjs/cli/ui.d.ts +1 -1
  36. package/dist/cjs/client.d.ts +558 -85
  37. package/dist/cjs/client.js +1270 -395
  38. package/dist/cjs/connection-guard.d.ts +13 -0
  39. package/dist/cjs/connection-guard.js +28 -0
  40. package/dist/cjs/connection-url.d.ts +51 -16
  41. package/dist/cjs/connection-url.js +67 -34
  42. package/dist/cjs/diagnostics.d.ts +81 -0
  43. package/dist/cjs/diagnostics.js +147 -0
  44. package/dist/cjs/dialect.d.ts +449 -20
  45. package/dist/cjs/dialect.js +117 -76
  46. package/dist/cjs/engine-config.d.ts +7 -6
  47. package/dist/cjs/errors.d.ts +126 -6
  48. package/dist/cjs/errors.js +256 -13
  49. package/dist/cjs/generate.d.ts +57 -7
  50. package/dist/cjs/generate.js +635 -279
  51. package/dist/cjs/global-filters-config.d.ts +59 -0
  52. package/dist/cjs/global-filters-config.js +367 -0
  53. package/dist/cjs/index.d.ts +9 -4
  54. package/dist/cjs/index.js +10 -2
  55. package/dist/cjs/introspect.d.ts +31 -6
  56. package/dist/cjs/introspect.js +108 -50
  57. package/dist/cjs/log-codes.d.ts +12 -0
  58. package/dist/cjs/log-codes.js +77 -0
  59. package/dist/cjs/logger.d.ts +87 -0
  60. package/dist/cjs/logger.js +98 -0
  61. package/dist/cjs/mssql.d.ts +8 -5
  62. package/dist/cjs/mssql.js +352 -65
  63. package/dist/cjs/mysql.d.ts +3 -5
  64. package/dist/cjs/mysql.js +420 -70
  65. package/dist/cjs/nested-write.d.ts +3 -0
  66. package/dist/cjs/nested-write.js +179 -114
  67. package/dist/cjs/pipeline-submittable.d.ts +12 -0
  68. package/dist/cjs/pipeline-submittable.js +118 -44
  69. package/dist/cjs/pipeline.js +21 -26
  70. package/dist/cjs/powdb-introspect.d.ts +5 -2
  71. package/dist/cjs/powdb-introspect.js +20 -15
  72. package/dist/cjs/powdb-shared.d.ts +36 -5
  73. package/dist/cjs/powdb-shared.js +67 -8
  74. package/dist/cjs/powdb.d.ts +4 -0
  75. package/dist/cjs/powdb.js +183 -51
  76. package/dist/cjs/powql.d.ts +394 -51
  77. package/dist/cjs/powql.js +1829 -284
  78. package/dist/cjs/prisma-compat.d.ts +23 -15
  79. package/dist/cjs/prisma-compat.js +507 -372
  80. package/dist/cjs/query/aggregates.d.ts +17 -1
  81. package/dist/cjs/query/aggregates.js +261 -29
  82. package/dist/cjs/query/batched-loader.d.ts +25 -6
  83. package/dist/cjs/query/batched-loader.js +103 -20
  84. package/dist/cjs/query/builder.d.ts +325 -184
  85. package/dist/cjs/query/builder.js +1452 -490
  86. package/dist/cjs/query/column-ref.d.ts +61 -0
  87. package/dist/cjs/query/column-ref.js +73 -0
  88. package/dist/cjs/query/compound-unique.d.ts +21 -0
  89. package/dist/cjs/query/compound-unique.js +98 -18
  90. package/dist/cjs/query/deferred.d.ts +53 -16
  91. package/dist/cjs/query/expr.d.ts +217 -0
  92. package/dist/cjs/query/expr.js +859 -0
  93. package/dist/cjs/query/filters.d.ts +155 -53
  94. package/dist/cjs/query/filters.js +613 -76
  95. package/dist/cjs/query/index.d.ts +2 -0
  96. package/dist/cjs/query/index.js +7 -1
  97. package/dist/cjs/query/json-value.d.ts +43 -0
  98. package/dist/cjs/query/json-value.js +59 -0
  99. package/dist/cjs/query/normalize-args.d.ts +87 -0
  100. package/dist/cjs/query/normalize-args.js +527 -0
  101. package/dist/cjs/query/option-surface.d.ts +16 -4
  102. package/dist/cjs/query/option-surface.js +57 -14
  103. package/dist/cjs/query/relation-names.d.ts +14 -0
  104. package/dist/cjs/query/relation-names.js +77 -18
  105. package/dist/cjs/query/relations.d.ts +30 -3
  106. package/dist/cjs/query/relations.js +219 -63
  107. package/dist/cjs/query/row-lock.d.ts +49 -0
  108. package/dist/cjs/query/row-lock.js +138 -0
  109. package/dist/cjs/query/sql-comment.d.ts +161 -0
  110. package/dist/cjs/query/sql-comment.js +381 -0
  111. package/dist/cjs/query/stream-idle.d.ts +132 -0
  112. package/dist/cjs/query/stream-idle.js +212 -0
  113. package/dist/cjs/query/table-client.d.ts +101 -0
  114. package/dist/cjs/query/table-client.js +74 -0
  115. package/dist/cjs/query/types.d.ts +677 -298
  116. package/dist/cjs/query/utils.d.ts +105 -6
  117. package/dist/cjs/query/utils.js +426 -19
  118. package/dist/cjs/query/warn-registry.d.ts +18 -0
  119. package/dist/cjs/query/warn-registry.js +18 -0
  120. package/dist/cjs/query/where-compile.d.ts +138 -14
  121. package/dist/cjs/query/where-compile.js +513 -29
  122. package/dist/cjs/query/where.d.ts +159 -59
  123. package/dist/cjs/query/where.js +716 -246
  124. package/dist/cjs/query/writes.d.ts +112 -50
  125. package/dist/cjs/query/writes.js +1498 -200
  126. package/dist/cjs/query-events.d.ts +4 -2
  127. package/dist/cjs/query-events.js +3 -1
  128. package/dist/cjs/realtime.d.ts +7 -3
  129. package/dist/cjs/realtime.js +13 -2
  130. package/dist/cjs/schema-builder.d.ts +55 -4
  131. package/dist/cjs/schema-builder.js +382 -18
  132. package/dist/cjs/schema-metadata.d.ts +21 -1
  133. package/dist/cjs/schema-metadata.js +29 -7
  134. package/dist/cjs/schema-sql.d.ts +75 -5
  135. package/dist/cjs/schema-sql.js +497 -45
  136. package/dist/cjs/schema.d.ts +26 -5
  137. package/dist/cjs/schema.js +110 -13
  138. package/dist/cjs/sql-placeholders.d.ts +56 -0
  139. package/dist/cjs/sql-placeholders.js +204 -0
  140. package/dist/cjs/sqlite.d.ts +75 -20
  141. package/dist/cjs/sqlite.js +593 -95
  142. package/dist/cjs/supplied-pool-types.d.ts +48 -0
  143. package/dist/cjs/supplied-pool-types.js +256 -0
  144. package/dist/cjs/transaction-control.d.ts +51 -0
  145. package/dist/cjs/transaction-control.js +316 -0
  146. package/dist/cjs/transaction-state.d.ts +342 -0
  147. package/dist/cjs/transaction-state.js +707 -0
  148. package/dist/cjs/typed-sql.d.ts +37 -3
  149. package/dist/cjs/typed-sql.js +102 -8
  150. package/dist/cli/code-first-tags.d.ts +62 -0
  151. package/dist/cli/code-first-tags.js +120 -0
  152. package/dist/cli/compile-query.js +9 -0
  153. package/dist/cli/config.d.ts +35 -6
  154. package/dist/cli/config.js +16 -1
  155. package/dist/cli/destructive.d.ts +7 -4
  156. package/dist/cli/destructive.js +224 -20
  157. package/dist/cli/error-catalog.js +36 -0
  158. package/dist/cli/error-text.d.ts +15 -0
  159. package/dist/cli/error-text.js +37 -0
  160. package/dist/cli/index.d.ts +62 -4
  161. package/dist/cli/index.js +569 -112
  162. package/dist/cli/local-server-guard.d.ts +53 -0
  163. package/dist/cli/local-server-guard.js +113 -0
  164. package/dist/cli/local-server-output.d.ts +41 -0
  165. package/dist/cli/local-server-output.js +98 -0
  166. package/dist/cli/mcp.d.ts +8 -0
  167. package/dist/cli/mcp.js +121 -34
  168. package/dist/cli/migrate.d.ts +113 -5
  169. package/dist/cli/migrate.js +261 -21
  170. package/dist/cli/observe.d.ts +6 -1
  171. package/dist/cli/observe.js +84 -54
  172. package/dist/cli/pii-predicate-guard.d.ts +43 -23
  173. package/dist/cli/pii-predicate-guard.js +100 -35
  174. package/dist/cli/prisma-resolve.js +15 -11
  175. package/dist/cli/prisma-schema.js +12 -4
  176. package/dist/cli/studio-ui.generated.js +1 -1
  177. package/dist/cli/studio.d.ts +14 -2
  178. package/dist/cli/studio.js +246 -71
  179. package/dist/cli/ui.d.ts +1 -1
  180. package/dist/client.d.ts +558 -85
  181. package/dist/client.js +1275 -400
  182. package/dist/connection-guard.d.ts +13 -0
  183. package/dist/connection-guard.js +27 -0
  184. package/dist/connection-url.d.ts +51 -16
  185. package/dist/connection-url.js +63 -34
  186. package/dist/diagnostics.d.ts +81 -0
  187. package/dist/diagnostics.js +144 -0
  188. package/dist/dialect.d.ts +449 -20
  189. package/dist/dialect.js +115 -43
  190. package/dist/engine-config.d.ts +7 -6
  191. package/dist/errors.d.ts +126 -6
  192. package/dist/errors.js +252 -12
  193. package/dist/generate.d.ts +57 -7
  194. package/dist/generate.js +635 -281
  195. package/dist/global-filters-config.d.ts +59 -0
  196. package/dist/global-filters-config.js +361 -0
  197. package/dist/index.d.ts +9 -4
  198. package/dist/index.js +4 -2
  199. package/dist/introspect.d.ts +31 -6
  200. package/dist/introspect.js +106 -50
  201. package/dist/log-codes.d.ts +12 -0
  202. package/dist/log-codes.js +74 -0
  203. package/dist/logger.d.ts +87 -0
  204. package/dist/logger.js +93 -0
  205. package/dist/mssql.d.ts +8 -5
  206. package/dist/mssql.js +354 -67
  207. package/dist/mysql.d.ts +3 -5
  208. package/dist/mysql.js +423 -73
  209. package/dist/nested-write.d.ts +3 -0
  210. package/dist/nested-write.js +177 -112
  211. package/dist/pipeline-submittable.d.ts +12 -0
  212. package/dist/pipeline-submittable.js +117 -44
  213. package/dist/pipeline.js +21 -26
  214. package/dist/powdb-introspect.d.ts +5 -2
  215. package/dist/powdb-introspect.js +21 -16
  216. package/dist/powdb-shared.d.ts +36 -5
  217. package/dist/powdb-shared.js +65 -8
  218. package/dist/powdb.d.ts +4 -0
  219. package/dist/powdb.js +183 -51
  220. package/dist/powql.d.ts +394 -51
  221. package/dist/powql.js +1836 -291
  222. package/dist/prisma-compat.d.ts +23 -15
  223. package/dist/prisma-compat.js +508 -373
  224. package/dist/query/aggregates.d.ts +17 -1
  225. package/dist/query/aggregates.js +263 -32
  226. package/dist/query/batched-loader.d.ts +25 -6
  227. package/dist/query/batched-loader.js +101 -21
  228. package/dist/query/builder.d.ts +325 -184
  229. package/dist/query/builder.js +1458 -495
  230. package/dist/query/column-ref.d.ts +61 -0
  231. package/dist/query/column-ref.js +66 -0
  232. package/dist/query/compound-unique.d.ts +21 -0
  233. package/dist/query/compound-unique.js +97 -19
  234. package/dist/query/deferred.d.ts +53 -16
  235. package/dist/query/expr.d.ts +217 -0
  236. package/dist/query/expr.js +848 -0
  237. package/dist/query/filters.d.ts +155 -53
  238. package/dist/query/filters.js +597 -72
  239. package/dist/query/index.d.ts +2 -0
  240. package/dist/query/index.js +4 -0
  241. package/dist/query/json-value.d.ts +43 -0
  242. package/dist/query/json-value.js +54 -0
  243. package/dist/query/normalize-args.d.ts +87 -0
  244. package/dist/query/normalize-args.js +517 -0
  245. package/dist/query/option-surface.d.ts +16 -4
  246. package/dist/query/option-surface.js +56 -13
  247. package/dist/query/relation-names.d.ts +14 -0
  248. package/dist/query/relation-names.js +77 -19
  249. package/dist/query/relations.d.ts +30 -3
  250. package/dist/query/relations.js +220 -67
  251. package/dist/query/row-lock.d.ts +49 -0
  252. package/dist/query/row-lock.js +131 -0
  253. package/dist/query/sql-comment.d.ts +161 -0
  254. package/dist/query/sql-comment.js +374 -0
  255. package/dist/query/stream-idle.d.ts +132 -0
  256. package/dist/query/stream-idle.js +203 -0
  257. package/dist/query/table-client.d.ts +101 -0
  258. package/dist/query/table-client.js +70 -0
  259. package/dist/query/types.d.ts +677 -298
  260. package/dist/query/utils.d.ts +105 -6
  261. package/dist/query/utils.js +414 -18
  262. package/dist/query/warn-registry.d.ts +18 -0
  263. package/dist/query/warn-registry.js +18 -0
  264. package/dist/query/where-compile.d.ts +138 -14
  265. package/dist/query/where-compile.js +508 -31
  266. package/dist/query/where.d.ts +159 -59
  267. package/dist/query/where.js +711 -248
  268. package/dist/query/writes.d.ts +112 -50
  269. package/dist/query/writes.js +1496 -202
  270. package/dist/query-events.d.ts +4 -2
  271. package/dist/query-events.js +3 -1
  272. package/dist/realtime.d.ts +7 -3
  273. package/dist/realtime.js +13 -2
  274. package/dist/schema-builder.d.ts +55 -4
  275. package/dist/schema-builder.js +381 -18
  276. package/dist/schema-metadata.d.ts +21 -1
  277. package/dist/schema-metadata.js +28 -7
  278. package/dist/schema-sql.d.ts +75 -5
  279. package/dist/schema-sql.js +494 -44
  280. package/dist/schema.d.ts +26 -5
  281. package/dist/schema.js +109 -13
  282. package/dist/sql-placeholders.d.ts +56 -0
  283. package/dist/sql-placeholders.js +200 -0
  284. package/dist/sqlite.d.ts +75 -20
  285. package/dist/sqlite.js +597 -99
  286. package/dist/supplied-pool-types.d.ts +48 -0
  287. package/dist/supplied-pool-types.js +247 -0
  288. package/dist/transaction-control.d.ts +51 -0
  289. package/dist/transaction-control.js +311 -0
  290. package/dist/transaction-state.d.ts +342 -0
  291. package/dist/transaction-state.js +696 -0
  292. package/dist/typed-sql.d.ts +37 -3
  293. package/dist/typed-sql.js +100 -8
  294. package/package.json +7 -4
  295. package/skills/turbine-orm/SKILL.md +56 -6
@@ -10,15 +10,30 @@
10
10
  * stay class-resident, reached through the ctx. See builder.ts for the thin
11
11
  * delegating methods and the async execute wrappers.
12
12
  */
13
- import type { ReturningSelection } from '../dialect.js';
13
+ import { type ReturningSelection } from '../dialect.js';
14
14
  import type { TableMetadata } from '../schema.js';
15
15
  import type { DeferredQuery } from './deferred.js';
16
16
  import type { CreateArgs, CreateManyArgs, DeleteArgs, DeleteManyArgs, UpdateArgs, UpdateManyArgs, UpsertArgs } from './types.js';
17
17
  import type { BuilderCtx } from './where.js';
18
18
  /**
19
- * Normalize one `data` value before it is bound as a write param.
19
+ * Normalize one `data` value before it is bound as a write param. This is THE
20
+ * write bind seam: create, createMany, update, updateMany, both halves of
21
+ * upsert, the cache-hit param collectors and (through those public methods)
22
+ * the nested-write engine all bind through it.
20
23
  *
21
- * Two value shapes need rewriting, both a JS `Date` on a temporal column:
24
+ * JSON columns (json / jsonb):
25
+ *
26
+ * - A JS array is serialized with `JSON.stringify`. The drivers' default
27
+ * array serialization is a Postgres ARRAY literal, so `[]` was stored as the
28
+ * object `{}`, `["a"]` failed with 22P02, and `createMany`'s UNNEST
29
+ * transpose flattened `[1, 2, 3]` into three rows.
30
+ * - A {@link jsonValue} wrapper is serialized with `JSON.stringify`, which is
31
+ * how a JSON string or a JSON `null` is written.
32
+ * - A JS string is RAW JSON TEXT and passes through untouched, so
33
+ * `JSON.stringify(value)` callers keep storing the parsed value. A plain
34
+ * object passes through too: every driver already serializes it as JSON.
35
+ *
36
+ * Temporal columns, a JS `Date`:
22
37
  *
23
38
  * 1. A time-of-day column (`time` / `timetz`), the driver serializes a `Date`
24
39
  * as a full ISO timestamp with the process offset and Postgres answers
@@ -28,14 +43,22 @@ import type { BuilderCtx } from './where.js';
28
43
  * non-UTC process the stored value is wrong and (because the read path
29
44
  * interprets an offset-less value as UTC) does not round-trip. Rewritten to
30
45
  * the UTC components, mirroring `parseDbDate`. See `toLocalDateTimeLiteral`
31
- * in query/utils.ts.
46
+ * in query/utils.ts. `timestamptz` is deliberately untouched: it stores a
47
+ * real instant and the driver's local-offset string is already correct.
32
48
  *
33
- * `timestamptz` is deliberately untouched: it stores a real instant and the
34
- * driver's local-offset string is already correct for it.
49
+ * A plain object or an array bound to a known scalar column (text, int, uuid,
50
+ * ...) is refused with E003, and so is a `Map` or `Set` anywhere; see
51
+ * {@link assertScalarBindable} and {@link assertNotCollection}.
35
52
  *
36
- * Every other value, including a string that is already a valid literal, is
37
- * returned by identity, so this is a byte-for-byte no-op for every non-temporal
38
- * column.
53
+ * Expressions (`expr.*`, `col()`) never bind as a value: the update paths
54
+ * compile them before reaching here, so one that arrives is in a position that
55
+ * takes values only (create data, `{ set }`) and is refused. An unbranded
56
+ * object shaped like one is refused on a non-JSON column on every engine.
57
+ *
58
+ * Every other value is returned by identity, so a primitive costs one check
59
+ * and no lookup. The exception is a string on an engine that defines the
60
+ * dialect's `checkTextWrite` (SQLite), which is checked against its column's
61
+ * type first; see {@link checkTextWrite}.
39
62
  */
40
63
  export declare function coerceWriteValue(qi: BuilderCtx, key: string, value: unknown): unknown;
41
64
  /**
@@ -44,21 +67,60 @@ export declare function coerceWriteValue(qi: BuilderCtx, key: string, value: unk
44
67
  * return rows from non-RETURNING engines. Reuses the same parameterized WHERE
45
68
  * builder as reads, so no user value is interpolated.
46
69
  */
47
- export declare function buildReselectByWhere(qi: BuilderCtx, whereObj: Record<string, unknown>, projection?: WriteProjection): {
70
+ export declare function buildReselectByWhere(qi: BuilderCtx, whereObj: Record<string, unknown>, projection?: WriteProjection, lockRows?: boolean): {
48
71
  sql: string;
49
72
  params: unknown[];
50
73
  };
51
74
  export declare function buildCreate<T extends object>(qi: BuilderCtx, args: CreateArgs<T>, projection?: WriteProjection): DeferredQuery<T>;
52
75
  /**
53
- * Build the `'reselect'` plan for {@link buildCreate}: run the INSERT, then
54
- * `SELECT * WHERE pk = ?`. Returns `undefined` (skipped) unless the active
55
- * dialect's result strategy is `'reselect'`, so the PostgreSQL/RETURNING path
56
- * pays nothing. Not yet wired to a real non-RETURNING engine.
76
+ * Build the `'reselect'` plan for {@link buildCreate} (MySQL): run the INSERT,
77
+ * then `SELECT ... WHERE <key> = ?` by a key whose value is known exactly
78
+ * (see {@link createReselectKey}). Returns `undefined` unless the dialect's
79
+ * result strategy is `'reselect'`, so the RETURNING engines pay nothing.
57
80
  */
58
81
  export declare function makeCreateReselect<T extends object>(qi: BuilderCtx, insertSql: string, insertParams: unknown[], data: Record<string, unknown>, projection?: WriteProjection): DeferredQuery<T>['reselect'];
59
- export declare function buildCreateMany<T extends object>(qi: BuilderCtx, args: CreateManyArgs<T>): DeferredQuery<T[]>;
82
+ export declare function buildCreateMany<T extends object>(qi: BuilderCtx, args: CreateManyArgs<T>, overBindLimit?: 'refuse' | 'allow', projection?: WriteProjection): DeferredQuery<T[]>;
83
+ /**
84
+ * `createMany()` as the statements it runs: one when the rows fit one
85
+ * statement, else consecutive chunks that each do. The whole call is validated
86
+ * once, before any chunk is built, so a refusal (a duplicate conflict key in
87
+ * the last chunk included) sends nothing, and the chunks are sized before any
88
+ * statement is built, so no engine's own per-statement check refuses one.
89
+ *
90
+ * Built eagerly and synchronously: the chunks read state the call set on the
91
+ * builder (`skipGlobalFilters`), which a concurrent call could change across
92
+ * an await.
93
+ */
94
+ export declare function planCreateMany<T extends object>(qi: BuilderCtx, args: CreateManyArgs<T>, projection?: WriteProjection): {
95
+ chunks: DeferredQuery<T[]>[];
96
+ rowsPerChunk: number;
97
+ };
98
+ /**
99
+ * `err` from running a `createMany({ onConflict })`, with the engine's
100
+ * "one statement touched one row twice" errors (PostgreSQL 21000, SQL Server
101
+ * 8672) turned into the E003 that names the cause. Anything else is returned
102
+ * as it was.
103
+ */
104
+ export declare function explainConflictKeyCollision(qi: BuilderCtx, args: {
105
+ readonly onConflict?: unknown;
106
+ }, err: unknown): unknown;
60
107
  export declare function buildUpdate<T extends object>(qi: BuilderCtx, args: UpdateArgs<T>, projection?: WriteProjection): DeferredQuery<T>;
61
108
  export declare function buildDelete<T extends object>(qi: BuilderCtx, args: DeleteArgs<T>, projection?: WriteProjection): DeferredQuery<T>;
109
+ /**
110
+ * Refuse `limit` / `take` / `offset` / `skip` on `updateMany` / `deleteMany`.
111
+ * No engine applies them to a bulk write here, so `deleteMany({ where, limit:
112
+ * 1000 })` used to touch every matching row. Shared with the PowDB engine.
113
+ */
114
+ export declare function assertNoBulkWritePaging(table: string, operation: 'updateMany' | 'deleteMany', args: object): void;
115
+ /**
116
+ * Refuse `optimisticLock` on a write that does not implement it. It is an
117
+ * `update` option; on a sibling method it used to be ignored, so a stale
118
+ * write went through with no error, which is the one outcome the option
119
+ * exists to prevent. The message names the equivalent for each method.
120
+ */
121
+ export declare function assertNoOptimisticLock(qi: BuilderCtx, args: object, operation: OptimisticLockRefusal): void;
122
+ /** The equivalent of a version check for each write that refuses `optimisticLock`. */
123
+ type OptimisticLockRefusal = 'upsert' | 'updateMany' | 'delete' | 'deleteMany';
62
124
  /**
63
125
  * Why an `upsert` cannot run as this engine's single conflict statement, or
64
126
  * `null` when it can. The one authority for that decision: `upsert()` asks it
@@ -72,6 +134,11 @@ export declare function buildDelete<T extends object>(qi: BuilderCtx, args: Dele
72
134
  * - `empty-update`: an `update` with no fields has no `DO UPDATE SET` to emit;
73
135
  * every engine rejected the statement as a syntax error. Prisma reads it as
74
136
  * "create it if it is missing", which the lookup answers.
137
+ * - `other-unique-key` (MySQL): `ON DUPLICATE KEY UPDATE` has no conflict
138
+ * target and updates whichever row a unique key collides on first, so when
139
+ * `create` could also collide on a unique key `where` does not pin (the
140
+ * primary key included), it could update a row `where` does not name
141
+ * (otherCollidingUniqueKey).
75
142
  * - `global-filter`: MySQL's `ON DUPLICATE KEY UPDATE` has no predicate slot
76
143
  * and SQL Server's MERGE cannot take the builder's column references there,
77
144
  * so the table's global filter cannot guard the conflict update. The lookup
@@ -80,7 +147,7 @@ export declare function buildDelete<T extends object>(qi: BuilderCtx, args: Dele
80
147
  *
81
148
  * Reads `currentSkip`, so it resolves `skipGlobalFilters` itself first.
82
149
  */
83
- export type UpsertLookupReason = 'where-differs' | 'empty-update' | 'global-filter';
150
+ export type UpsertLookupReason = 'where-differs' | 'empty-update' | 'other-unique-key' | 'global-filter';
84
151
  export declare function upsertLookupReason<T extends object>(qi: BuilderCtx, args: UpsertArgs<T>): UpsertLookupReason | null;
85
152
  export declare function buildUpsert<T extends object>(qi: BuilderCtx, args: UpsertArgs<T>, projection?: WriteProjection): DeferredQuery<T>;
86
153
  export declare function buildUpdateMany<T extends object>(qi: BuilderCtx, args: UpdateManyArgs<T>): DeferredQuery<{
@@ -92,8 +159,8 @@ export declare function buildDeleteMany<T extends object>(qi: BuilderCtx, args:
92
159
  /**
93
160
  * The snake_case names of a table's PII-tagged (`defineSchema` `pii: true`)
94
161
  * columns. PII columns are excluded from default projections (findMany /
95
- * findUnique / relation subqueries / batched loads) unless the query opts in
96
- * via `includePii` or names the column explicitly in `select`. Returns an
162
+ * findUnique / relation subqueries / batched loads) unless a read passes
163
+ * `includePii: UNSAFE`; naming one in `select` without it is E003. Returns an
97
164
  * empty set for any table with no PII column, so untagged schemas keep their
98
165
  * byte-identical SQL.
99
166
  */
@@ -102,8 +169,8 @@ export declare function piiColumns(_qi: BuilderCtx, meta: TableMetadata): Set<st
102
169
  * The camelCase field names of a table's PII-tagged columns: the read-side
103
170
  * counterpart of {@link piiColumns} applied to already-parsed entities.
104
171
  * Used to strip PII from a write's RETURNING/reselect row (writes accept no
105
- * `includePii`/`select`, so their returned row always applies the default
106
- * exclusion; you may still write PII fields freely).
172
+ * `includePii`, and a PII column named in a write's `select` is E003, so their
173
+ * returned row never carries one; you may still write PII fields freely).
107
174
  */
108
175
  export declare function piiFields(_qi: BuilderCtx, meta: TableMetadata): string[];
109
176
  /**
@@ -114,9 +181,10 @@ export declare function piiFields(_qi: BuilderCtx, meta: TableMetadata): string[
114
181
  * resolve to a column or the call throws E003, a relation name gets its own
115
182
  * message, `select` must name something, `select` and `omit` are exclusive, the
116
183
  * list is in TABLE order (a caller's key order must not mint distinct
117
- * statements), and an explicit `select` of a PII column is the opt-in that
118
- * returns it while `omit` leaves PII excluded. (builder.ts rather than this
119
- * module because relations.ts already imports this one.)
184
+ * statements), and PII is never returned: a write takes no `includePii`, so a
185
+ * PII column named in `select` is E003 and `omit` leaves PII excluded.
186
+ * (builder.ts rather than this module because relations.ts already imports
187
+ * this one.)
120
188
  *
121
189
  * The point is bytes: `RETURNING *` sends back every column, a large JSON
122
190
  * payload included, on every insert. Measured with a 3.1 KB jsonb column at
@@ -143,8 +211,9 @@ export declare function writeProjectionCacheSegment(projection: WriteProjection
143
211
  * column so the PII values never leave the database on a write. A PII-tagged
144
212
  * PRIMARY KEY column is kept in the projection regardless (the returned row
145
213
  * must stay addressable): tag sensitive data, not keys, a PII PK is
146
- * documented out of scope for stripping. Writes accept no `select`/`includePii`
147
- * (unlike reads), so this is the whole write-return policy at the SQL level;
214
+ * documented out of scope for stripping. Writes accept no `includePii` and
215
+ * their `select` cannot name a PII column, so this is the whole write-return
216
+ * policy at the SQL level;
148
217
  * {@link parseWriteRow} remains as a defense-in-depth strip (a no-op once the
149
218
  * SQL already excludes the columns). Derived purely from static per-table
150
219
  * schema metadata, so the write SQL cache needs no extra key segment.
@@ -204,32 +273,22 @@ export declare function assertWritable(qi: BuilderCtx, operation: string): void;
204
273
  */
205
274
  export declare function assertNoGeneratedColumns(qi: BuilderCtx, data: Record<string, unknown>, operation: string): void;
206
275
  /**
207
- * Build a single SET clause entry for update/updateMany.
208
- *
209
- * Supports plain values and atomic operator objects ({ set, increment,
210
- * decrement, multiply, divide }). An operator object is detected ONLY when
211
- * it has EXACTLY one key that is one of the 5 operator keys, this avoids
212
- * misinterpreting JSON column values like `{ set: 'x' }` as operators
213
- * (real operator objects always have exactly one key, and a plain JSON
214
- * payload that happens to have a single `set` key is extremely unusual).
215
- * Multi-key objects are always treated as plain (JSON) values.
216
- *
217
- * Returns the SQL fragment (e.g., `"view_count" = "view_count" + $3`) and
218
- * pushes any required params onto the shared params array so that WHERE
219
- * clause numbering continues correctly afterward.
276
+ * The atomic operator a SET value names, or `null` when it is a plain value.
277
+ * THE one rule, read by the SET build, its fingerprint and its cache-hit param
278
+ * collector, so the three cannot disagree about whether a value is an
279
+ * operator.
220
280
  *
221
- * `refQualifier` prefixes the column REFERENCE an arithmetic operator reads
222
- * from (`"view_count" = <qualifier>"view_count" + $n`). A plain `UPDATE` has
223
- * one table in scope and passes nothing; `upsert` passes the table name,
224
- * because inside `ON CONFLICT ... DO UPDATE SET` the target table and
225
- * `excluded` are BOTH in scope and a bare reference is 42702 on PostgreSQL.
226
- * The assignment target on the left stays bare on every engine (it can only
227
- * ever be the target table's column), and `set` / literal values reference no
228
- * column at all, so their SQL is byte-identical with or without a qualifier.
281
+ * A branded expression or `col()` reference is checked FIRST and answers
282
+ * `'expr'`: it is a frozen plain object too, and must never reach the
283
+ * operator test below. An operator is a plain object with EXACTLY one key from
284
+ * {@link UPDATE_OPERATOR_KEYS}. On a json/jsonb column only `set` is an
285
+ * operator: an object there IS the JSON value, so `{ increment: 1 }` is the
286
+ * document `{"increment":1}`, and `{ set: doc }` is the way to write a
287
+ * document that is itself shaped like `{ set: ... }`.
229
288
  */
230
- export declare function buildSetClause(qi: BuilderCtx, key: string, value: unknown, params: unknown[], refQualifier?: string): string;
289
+ export declare function setOperatorOf(qi: BuilderCtx, key: string, value: unknown): string | null;
231
290
  /**
232
- * Reject a `data` value that reached {@link buildSetClause}'s plain-value
291
+ * Reject a `data` value that reached {@link buildSetClauses}'s plain-value
233
292
  * fallthrough as a plain object with exactly ONE key that is not a known
234
293
  * atomic operator. On a scalar column that shape can only be a misspelled
235
294
  * operator (`{ incremnt: 1 }`, `{ bogus: 'x' }`); binding it plainly writes the
@@ -248,10 +307,13 @@ export declare function buildSetClause(qi: BuilderCtx, key: string, value: unkno
248
307
  export declare function assertBindableSetValue(qi: BuilderCtx, key: string, value: unknown): void;
249
308
  /**
250
309
  * Fingerprint SET clauses for update/updateMany.
251
- * Captures key names + operator types (set/increment/etc) but not values.
310
+ * Captures key names + operator types (set/increment/etc) but not values. An
311
+ * expression contributes `k:expr(<shape>)` from the same walk that compiles
312
+ * it, so a statement without one keeps its key byte-identical.
252
313
  */
253
314
  export declare function fingerprintSet(qi: BuilderCtx, data: Record<string, unknown>): string;
254
315
  /**
255
- * Collect SET params for update/updateMany. Mirrors buildSetClause param order.
316
+ * Collect SET params for update/updateMany. Mirrors buildSetClauses param order.
256
317
  */
257
318
  export declare function collectSetParams(qi: BuilderCtx, data: Record<string, unknown>, params: unknown[]): void;
319
+ export {};