okmodel 0.8.0 → 0.9.1

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 (237) hide show
  1. package/README.md +23 -1
  2. package/dist/adapters/pg/bunsql-extra.d.ts +5 -5
  3. package/dist/adapters/pg/bunsql.d.ts +6 -2
  4. package/dist/adapters/pg/nodepostgres.d.ts +16 -1
  5. package/dist/adapters/pg/postgres-extra.d.ts +3 -17
  6. package/dist/adapters/pg/postgresjs.d.ts +2 -1
  7. package/dist/contracts/driver.d.ts +3 -2
  8. package/dist/contracts/error.d.ts +1 -1
  9. package/dist/dialects/pg/errors.d.ts +2 -0
  10. package/dist/dialects/pg/ext/btree-gin.d.ts +26 -0
  11. package/dist/dialects/pg/ext/btree-gin.js +20 -0
  12. package/dist/dialects/pg/ext/btree-gist.d.ts +26 -0
  13. package/dist/dialects/pg/ext/btree-gist.js +20 -0
  14. package/dist/dialects/pg/ext/call.d.ts +53 -0
  15. package/dist/dialects/pg/ext/citext.js +1 -1
  16. package/dist/dialects/pg/ext/feature.d.ts +26 -0
  17. package/dist/dialects/pg/ext/fuzzystrmatch.d.ts +34 -0
  18. package/dist/dialects/pg/ext/fuzzystrmatch.js +33 -0
  19. package/dist/dialects/pg/ext/hstore.d.ts +41 -0
  20. package/dist/dialects/pg/ext/hstore.js +29 -0
  21. package/dist/dialects/pg/ext/index.d.ts +56 -0
  22. package/dist/dialects/pg/ext/index.js +1 -1
  23. package/dist/dialects/pg/ext/ltree.d.ts +41 -0
  24. package/dist/dialects/pg/ext/ltree.js +29 -0
  25. package/dist/dialects/pg/ext/pg-trgm.js +4 -13
  26. package/dist/dialects/pg/ext/pgcrypto.d.ts +33 -0
  27. package/dist/dialects/pg/ext/pgcrypto.js +33 -0
  28. package/dist/dialects/pg/ext/unaccent.d.ts +26 -0
  29. package/dist/dialects/pg/ext/unaccent.js +21 -0
  30. package/dist/dialects/pg/ext/using.d.ts +23 -0
  31. package/dist/dialects/pg/ext/versions.d.ts +36 -0
  32. package/dist/dialects/pg/external.d.ts +19 -0
  33. package/dist/dialects/pg/filters.d.ts +2 -2
  34. package/dist/dialects/pg/fn/index.js +5 -5
  35. package/dist/dialects/pg/index.d.ts +1 -0
  36. package/dist/dialects/pg/index.js +19 -14
  37. package/dist/dialects/pg/introspect.d.ts +12 -0
  38. package/dist/dialects/pg/view/index.js +7 -7
  39. package/dist/dialects/pg/view/scratch.d.ts +4 -1
  40. package/dist/runtime/artifact-file.d.ts +22 -0
  41. package/dist/runtime/client.d.ts +10 -0
  42. package/dist/runtime/drift-detail.d.ts +2 -1
  43. package/dist/runtime/drift.d.ts +3 -10
  44. package/dist/runtime/param-limit.d.ts +20 -0
  45. package/dist/runtime/pg/bun.js +4 -4
  46. package/dist/runtime/pg/neon.js +4 -4
  47. package/dist/runtime/pg/pg.js +4 -4
  48. package/dist/runtime/pg/pglite.js +4 -4
  49. package/dist/runtime/pg/postgresjs.js +11 -11
  50. package/dist/runtime/server-check.d.ts +36 -6
  51. package/dist/runtime/tenancy/index.js +1 -1
  52. package/dist/runtime/traits/index.js +6 -6
  53. package/dist/runtime/validate/index.js +2 -2
  54. package/dist/runtime/write.d.ts +1 -1
  55. package/dist/shared/{4m6hskg8.js → 0j6qe91y.js} +4 -4
  56. package/dist/shared/{6m78c8ss.js → 1h5h1rf5.js} +1 -1
  57. package/dist/shared/{4vbf83xx.js → 2vcnpf0n.js} +1 -1
  58. package/dist/shared/{qd9hhd8f.js → 3ap5hxvj.js} +2 -1
  59. package/dist/shared/{v1wad97q.js → 3d7a80fq.js} +1 -1
  60. package/dist/shared/{wcrheftc.js → 3dr444ny.js} +58 -79
  61. package/dist/shared/{hm5f8jby.js → 3vvpcphd.js} +8 -7
  62. package/dist/shared/{760ppr76.js → 4a3mmhhe.js} +2 -2
  63. package/dist/shared/{mkrn359n.js → 4pkz5nvw.js} +222 -39
  64. package/dist/shared/{agsfb86s.js → 4te76xc5.js} +4 -4
  65. package/dist/shared/{63f4ksbz.js → 60y4ahmw.js} +1 -1
  66. package/dist/shared/61bmrmhr.js +35 -0
  67. package/dist/shared/{bxas03mq.js → 63qjmhnp.js} +100 -17
  68. package/dist/shared/{g5yc06ka.js → 67w3kn71.js} +1 -1
  69. package/dist/shared/{jgqj11w4.js → 6f0z3hzh.js} +4 -0
  70. package/dist/shared/{njga14v4.js → 6vfvsdkt.js} +10 -8
  71. package/dist/shared/{kj9d8maq.js → 6xqvesa5.js} +1 -1
  72. package/dist/shared/8gdbty5v.js +665 -0
  73. package/dist/shared/{pan0370z.js → 8ma6drzr.js} +211 -30
  74. package/dist/shared/{mnvjvqyp.js → 8p2bgye0.js} +124 -32
  75. package/dist/shared/{mfedzr74.js → 8qwqrxed.js} +14 -6
  76. package/dist/shared/{hfqmpasr.js → 8v7vzpgt.js} +11 -8
  77. package/dist/shared/{7ghwamrf.js → 99qp9vtg.js} +1 -1
  78. package/dist/shared/{zgex00fd.js → ak61ye1f.js} +5 -5
  79. package/dist/shared/{dpc2r7rb.js → bdekbvmt.js} +218 -95
  80. package/dist/shared/{jebgrkeq.js → bxjq6xqv.js} +2 -2
  81. package/dist/shared/c7dqd3gk.js +1806 -0
  82. package/dist/shared/ddh72ym5.js +20 -0
  83. package/dist/shared/e1c55v04.js +10 -0
  84. package/dist/shared/{mtw6jz76.js → e275q7sd.js} +1 -1
  85. package/dist/shared/{k86n8vq3.js → ekhq3ytz.js} +1 -1
  86. package/dist/shared/esy4dyxe.js +17 -0
  87. package/dist/shared/{gcefca6p.js → f9t9g54z.js} +22 -9
  88. package/dist/shared/{sjk86yrx.js → fk9vef30.js} +84 -73
  89. package/dist/shared/fkjne6gx.js +8 -0
  90. package/dist/shared/{e8zyaqvj.js → fne90dvz.js} +4 -1
  91. package/dist/shared/{needfe47.js → g89fmz5s.js} +1 -1
  92. package/dist/shared/{m4xff2a6.js → ghqzdp94.js} +2 -2
  93. package/dist/shared/{n0jmpgj1.js → gr9sn4za.js} +1 -1
  94. package/dist/shared/{5mtf6cj3.js → gzgfsspx.js} +5 -2
  95. package/dist/shared/h9811jjm.js +17 -0
  96. package/dist/shared/{z581d7ny.js → hgt69zjf.js} +2 -2
  97. package/dist/shared/{35q0n9tz.js → jvxcp1qk.js} +71 -87
  98. package/dist/shared/k73e8n9d.js +136 -0
  99. package/dist/shared/{195pzzzz.js → kzgrcy8s.js} +12 -8
  100. package/dist/shared/kzgrnckd.js +29 -0
  101. package/dist/shared/{p3xbdcvt.js → mz48rs74.js} +68 -8
  102. package/dist/shared/{zbqbmmrp.js → n6je5b28.js} +13 -26
  103. package/dist/shared/{b6d6p0zc.js → ns35jqz0.js} +75 -49
  104. package/dist/shared/{n05z9nwz.js → nstwgzn8.js} +1 -1
  105. package/dist/{tooling/shared/08kemxjd.js → shared/pgsak1yw.js} +1 -1
  106. package/dist/shared/py2zrrm6.js +451 -0
  107. package/dist/shared/{9dr2qnx7.js → qqm3ze6q.js} +1 -1
  108. package/dist/shared/{wvdjznah.js → rcjm0yn7.js} +31 -38
  109. package/dist/shared/rged92v6.js +17 -0
  110. package/dist/shared/{jp36k7dp.js → rw4tpcd0.js} +81 -51
  111. package/dist/shared/{bsek72fg.js → s5qe47a6.js} +3 -0
  112. package/dist/shared/{1d9q9cv2.js → smxzjz60.js} +2 -2
  113. package/dist/shared/{wz2a78mp.js → th5rnaxw.js} +1 -1
  114. package/dist/{tooling/shared/rs1jb051.js → shared/tr64w5p0.js} +1 -1
  115. package/dist/shared/{14x60fbf.js → tyqapcgk.js} +73 -10
  116. package/dist/shared/vsna85qf.js +8 -0
  117. package/dist/shared/{63qtkrca.js → vy47ryqa.js} +55 -5
  118. package/dist/shared/{jx2m62cs.js → wbdh9qbg.js} +7 -5
  119. package/dist/shared/{f4jy1j7x.js → wp7y8q3y.js} +946 -105
  120. package/dist/shared/{16kvjebh.js → xbd9xs6p.js} +7 -26
  121. package/dist/shared/{bah9nbg3.js → xbvz446k.js} +18 -23
  122. package/dist/shared/{p5nh3r8q.js → y6tfjk9q.js} +2 -2
  123. package/dist/shared/{3bb7wsqt.js → ycnft340.js} +1 -1
  124. package/dist/shared/{z7s6fpxv.js → ymenf259.js} +1 -1
  125. package/dist/shared/{0wrea3jq.js → ysdw2fg3.js} +10 -2
  126. package/dist/shared/zecrwdk9.js +61 -0
  127. package/dist/shared/{3t6kw83m.js → zm2rzqba.js} +2 -1
  128. package/dist/tooling/cli.js +200 -50
  129. package/dist/tooling/driver-run.js +109 -343
  130. package/dist/tooling/github/comment.d.ts +56 -0
  131. package/dist/tooling/github/post-comment.d.ts +17 -0
  132. package/dist/tooling/migrate/apply.d.ts +17 -2
  133. package/dist/tooling/migrate/commands.d.ts +2 -1
  134. package/dist/tooling/migrate/config.d.ts +13 -0
  135. package/dist/tooling/migrate/drift.d.ts +12 -0
  136. package/dist/tooling/migrate/driver-url.d.ts +17 -0
  137. package/dist/tooling/migrate/export.d.ts +165 -0
  138. package/dist/tooling/migrate/ext-surface.d.ts +80 -0
  139. package/dist/tooling/migrate/ext.d.ts +31 -4
  140. package/dist/tooling/migrate/import-drizzle.d.ts +40 -0
  141. package/dist/tooling/migrate/index.d.ts +3 -0
  142. package/dist/tooling/migrate/index.js +57 -10
  143. package/dist/tooling/migrate/lint-rules.d.ts +18 -1
  144. package/dist/tooling/migrate/lint.d.ts +14 -1
  145. package/dist/tooling/migrate/place.d.ts +18 -0
  146. package/dist/tooling/migrate/plan-json.d.ts +65 -0
  147. package/dist/tooling/migrate/policy.d.ts +17 -5
  148. package/dist/tooling/migrate/pooler-probe.d.ts +23 -0
  149. package/dist/tooling/migrate/project.d.ts +10 -1
  150. package/dist/tooling/migrate/pull-emit.d.ts +98 -0
  151. package/dist/tooling/migrate/pull-routines.d.ts +126 -0
  152. package/dist/tooling/migrate/pull-verify.d.ts +26 -0
  153. package/dist/tooling/migrate/pull.d.ts +65 -0
  154. package/dist/tooling/migrate/reprint.d.ts +32 -0
  155. package/dist/tooling/migrate/runner.d.ts +24 -1
  156. package/dist/tooling/migrate/sandbox.d.ts +8 -2
  157. package/dist/tooling/migrate/schema-api.d.ts +43 -0
  158. package/dist/tooling/migrate/sql-lex.d.ts +18 -0
  159. package/dist/tooling/shared/{ppnnnvj8.js → 09a6vsys.js} +1 -1
  160. package/dist/tooling/shared/{7ae7rjmn.js → 0v9ptnxp.js} +8 -8
  161. package/dist/tooling/shared/{fb9k2qwd.js → 0wtzps9p.js} +11 -30
  162. package/dist/tooling/shared/{a6pp9d12.js → 0yhf1db4.js} +6 -6
  163. package/dist/tooling/shared/{dy672fz6.js → 19msgrsc.js} +2 -2
  164. package/dist/{shared/q0cqt2sp.js → tooling/shared/1fwfm5m3.js} +1 -1
  165. package/dist/tooling/shared/{f9mphxej.js → 2jdn09e2.js} +401 -24
  166. package/dist/tooling/shared/{jne7b93p.js → 2qrte2ct.js} +5 -5
  167. package/dist/tooling/shared/{5bvw2nev.js → 2v4nwnkb.js} +1 -1
  168. package/dist/tooling/shared/{spk1jg3r.js → 33z39trp.js} +106 -23
  169. package/dist/tooling/shared/{z8d7ptht.js → 353vnw9z.js} +5 -5
  170. package/dist/tooling/shared/{dw08f3m8.js → 390kry9g.js} +2 -2
  171. package/dist/tooling/shared/{xjs6zqtc.js → 3f6etb9z.js} +18 -31
  172. package/dist/{shared/bnby0esn.js → tooling/shared/3t2cqmsx.js} +1 -1
  173. package/dist/tooling/shared/{wwnekq5n.js → 4dzvjtpy.js} +1 -1
  174. package/dist/tooling/shared/{y5656f0e.js → 4ec0nxvw.js} +10 -10
  175. package/dist/tooling/shared/{3m1hkg7z.js → 4tg2bn41.js} +59 -78
  176. package/dist/tooling/shared/{zvnhh1n0.js → 5rah55z0.js} +2 -2
  177. package/dist/tooling/shared/{pqy21k24.js → 804w1t69.js} +4 -4
  178. package/dist/tooling/shared/8g0m0rvd.js +134 -0
  179. package/dist/tooling/shared/8msbtw5s.js +8 -0
  180. package/dist/tooling/shared/{4d2w25vw.js → 8t22h3h7.js} +2 -2
  181. package/dist/tooling/shared/{smn6kz1p.js → 91c59b7b.js} +2 -2
  182. package/dist/tooling/shared/{aftb2mwr.js → adk9k6va.js} +1 -1
  183. package/dist/tooling/shared/{j9t5s12a.js → ajjd5cwz.js} +2 -2
  184. package/dist/tooling/shared/{cmptmb4f.js → angjck01.js} +1 -1
  185. package/dist/tooling/shared/{yw30vnq2.js → asnnc3v5.js} +1 -1
  186. package/dist/tooling/shared/{ma2340rx.js → bj1kyqc8.js} +2 -2
  187. package/dist/tooling/shared/{2wtvc7rw.js → bt3tjemb.js} +11 -3
  188. package/dist/tooling/shared/{ec71zqgt.js → chk2bh4f.js} +2 -2
  189. package/dist/tooling/shared/{gmcf9cxf.js → ckq4z5ax.js} +5 -2
  190. package/dist/tooling/shared/{w7qe8sj1.js → d3rhb24q.js} +1 -1
  191. package/dist/tooling/shared/{y031jct9.js → d8q00vxg.js} +4 -4
  192. package/dist/tooling/shared/{vs0t6qt8.js → dx188rxs.js} +2 -2
  193. package/dist/tooling/shared/{g9ad4n80.js → efq6p9df.js} +35 -42
  194. package/dist/tooling/shared/{ddjtfgnx.js → en6rwzq0.js} +3 -3
  195. package/dist/tooling/shared/{6nyfyw70.js → f2r5g0fs.js} +2 -2
  196. package/dist/tooling/shared/{03k6res6.js → f4gep0nk.js} +1 -1
  197. package/dist/tooling/shared/{gfvtj6d0.js → f8a010fm.js} +13 -11
  198. package/dist/tooling/shared/{3tq8pnb8.js → fdsek6pa.js} +1 -1
  199. package/dist/tooling/shared/fvmrxsd1.js +8 -0
  200. package/dist/tooling/shared/{733a1tq3.js → g3xybeqf.js} +4 -3
  201. package/dist/tooling/shared/{pwsytxm5.js → gefmpwsa.js} +1 -1
  202. package/dist/tooling/shared/{mtrqn2hn.js → gjj71hfh.js} +25 -30
  203. package/dist/tooling/shared/{8sqrsw3s.js → jgzt69pa.js} +5 -5
  204. package/dist/tooling/shared/{nf7jmhfa.js → jm30k2ca.js} +10 -8
  205. package/dist/tooling/shared/{vx86qjv8.js → kayqzpbk.js} +6 -3
  206. package/dist/tooling/shared/{zhwnfyb2.js → kvw1672d.js} +1 -1
  207. package/dist/tooling/shared/{rq5kk8j6.js → mr1kcgpw.js} +3 -3
  208. package/dist/tooling/shared/{72fyg4zv.js → mwbdf409.js} +1 -1
  209. package/dist/tooling/shared/{wt7j7nf6.js → ns9207v3.js} +1 -1
  210. package/dist/tooling/shared/{9xzm7hjg.js → p6tjv97k.js} +3 -3
  211. package/dist/tooling/shared/{yfr8hzhm.js → p73evwf0.js} +1 -1
  212. package/dist/tooling/shared/{dzx85q70.js → phc1nc4g.js} +1 -1
  213. package/dist/tooling/shared/{417zdsk7.js → ppybjw50.js} +79 -16
  214. package/dist/tooling/shared/{yk9mp7vb.js → qdrn8ghn.js} +5 -4
  215. package/dist/tooling/shared/rd8h01ta.js +20 -0
  216. package/dist/tooling/shared/{bz2dqhab.js → rwg8y90m.js} +3 -3
  217. package/dist/tooling/shared/{xhrnjch9.js → ry2f3w8p.js} +3 -3
  218. package/dist/tooling/shared/{a7q7t4n3.js → ryc5sa58.js} +8 -8
  219. package/dist/tooling/shared/{2revefqt.js → ss87qxwv.js} +2 -2
  220. package/dist/tooling/shared/{rf83gr2d.js → vg68k11z.js} +7 -3
  221. package/dist/tooling/shared/{p7f08ktn.js → vms9dta5.js} +73 -89
  222. package/dist/tooling/shared/{3rrw5w8f.js → xchpnbdv.js} +1 -1
  223. package/dist/tooling/shared/{djydjpqt.js → xn6p01fh.js} +5 -5
  224. package/dist/tooling/shared/{9kazs5p6.js → xwr6q618.js} +3 -3
  225. package/dist/tooling/shared/{ep8zh3bk.js → xx3gmq94.js} +1 -1
  226. package/dist/tooling/shared/{tn8gay14.js → y2bd7yfx.js} +21 -13
  227. package/dist/tooling/shared/{vraj6d74.js → y4gq9rbe.js} +11 -11
  228. package/dist/tooling/shared/y4vwft92.js +9 -0
  229. package/dist/tooling/shared/{345tbc2k.js → yz68xcmc.js} +1 -1
  230. package/dist/tooling/testing/factories.d.ts +1 -3
  231. package/dist/tooling/testing/index.js +2 -2
  232. package/package.json +39 -9
  233. package/dist/shared/3449rcae.js +0 -14
  234. package/dist/shared/fjpnhqan.js +0 -71
  235. package/dist/shared/n41w4fbz.js +0 -113
  236. package/dist/tooling/shared/pw8fgahx.js +0 -69
  237. /package/dist/shared/{ae4j5f42.js → mfvx6kjx.js} +0 -0
@@ -3,7 +3,7 @@ import {
3
3
  catalogHash2,
4
4
  loadTrustedCatalog2,
5
5
  catalogFileText2
6
- } from "./f9mphxej.js";
6
+ } from "./2jdn09e2.js";
7
7
  export {
8
8
  catalogFileText2 as catalogFileText,
9
9
  catalogHash2 as catalogHash,
@@ -1,11 +1,14 @@
1
+ import {
2
+ assertParamCount2
3
+ } from "./rd8h01ta.js";
1
4
  import {
2
5
  stack2
3
- } from "./cmptmb4f.js";
6
+ } from "./angjck01.js";
4
7
  import {
5
8
  assertOperatorFits,
6
9
  textArray,
7
10
  arrayElementType
8
- } from "./3tq8pnb8.js";
11
+ } from "./fdsek6pa.js";
9
12
  import {
10
13
  runWrite
11
14
  } from "./n4jqhpqz.js";
@@ -30,11 +33,12 @@ import {
30
33
  decodeRow,
31
34
  indexes,
32
35
  quote,
36
+ list,
33
37
  isRecord,
34
38
  orFail,
35
39
  registerFailFix,
36
40
  fail2
37
- } from "./f9mphxej.js";
41
+ } from "./2jdn09e2.js";
38
42
 
39
43
  // src/runtime/predicate.ts
40
44
  function effectivePredicate(where) {
@@ -199,7 +203,7 @@ async function requireValidationImport(schema, op, tableName, options) {
199
203
  const source = stored.tables?.find((item) => item.name === tableName);
200
204
  if (source === undefined || !writeWouldValidate(stored.validation, source, options))
201
205
  return;
202
- const { refuseMissingValidation } = await import("./wt7j7nf6.js");
206
+ const { refuseMissingValidation } = await import("./ns9207v3.js");
203
207
  refuseMissingValidation();
204
208
  }
205
209
  function validationRegistered(schema) {
@@ -244,7 +248,7 @@ async function prepareWrite(host, op, table, input, options, mods, scope) {
244
248
  return {
245
249
  statements: planned.statements,
246
250
  options: callOptions(options),
247
- ...planned.parentGuard === true ? { checked: "parent" } : planned.expect !== undefined ? { checked: "expect" } : {},
251
+ ...planned.parentGuard === true ? { checked: "parent" } : planned.treeGuard === true ? { checked: "tree" } : planned.expect !== undefined ? { checked: "expect" } : {},
248
252
  ...planned.recover === undefined ? {} : {
249
253
  follow: (results) => planned.recover?.(decodePlanned(withoutQuiet(results, planned.quiet), planned.outputs)) ?? []
250
254
  },
@@ -269,7 +273,7 @@ async function planWrite(schema, generators, op, tableName, input, options, mods
269
273
  fail2("OKM1120", `Table ${tableName} is not in the schema.`);
270
274
  }
271
275
  if (mods.uses !== undefined && op !== "insert") {
272
- const { resolve } = await import("./ma2340rx.js");
276
+ const { resolve } = await import("./bj1kyqc8.js");
273
277
  mods = { ...mods, presets: resolve(schema, tableName, mods.uses).wheres };
274
278
  }
275
279
  const record = isRecord(options) ? options : {};
@@ -279,7 +283,7 @@ async function planWrite(schema, generators, op, tableName, input, options, mods
279
283
  }
280
284
  if (op === "update") {
281
285
  if (traitNamed(table, "versioned")) {
282
- const { planVersioned } = await import("./yk9mp7vb.js");
286
+ const { planVersioned } = await import("./qdrn8ghn.js");
283
287
  return withRowFilters(scope, mods.archive, () => {
284
288
  noteArchive(table, mods.archive);
285
289
  const planned = planVersioned(schema, table, input, record, mods);
@@ -325,12 +329,12 @@ async function planInsert(table, input, options, mods, generators, scope, tenanc
325
329
  keyColumns: undefined
326
330
  };
327
331
  }
328
- const conflictMod = options.onConflict === undefined || options.onConflict === "error" ? undefined : await import("./6nyfyw70.js");
332
+ const conflictMod = options.onConflict === undefined || options.onConflict === "error" ? undefined : await import("./f2r5g0fs.js");
329
333
  const conflict = conflictMod?.readConflict(table, options.onConflict, allow, tenantKeyList(tenancy));
330
334
  if (conflict?.kind === "update" && traitNamed(table, "versioned")) {
331
335
  fail2("OKM1120", `onConflict update on ${table.model.name} does not check the version you read.`, "Read the row and update. ignore and return do not change the existing row.");
332
336
  }
333
- const sortMod = sorting ? await import("./w7qe8sj1.js") : undefined;
337
+ const sortMod = sorting ? await import("./d3rhb24q.js") : undefined;
334
338
  const chunks = chunkRows(rows.map((row) => cellsFor(columns, row)));
335
339
  const statements = [];
336
340
  const quiet = [];
@@ -389,7 +393,7 @@ function planUpdate(schema, table, input, options, mods, scope) {
389
393
  rejectDuplicateTargets2(table, rows);
390
394
  rejectMixedSets2(rows);
391
395
  for (const row of rows)
392
- refuseTreeCycle(table, row.where, row.set, schema.tenancy?.key);
396
+ refuseTreeCycle(table, row.where, row.set, tenantKeys(schema.tenancy));
393
397
  const moves = rows.some((row) => pathField(schema.tenancy, table.model.name, row.set) !== undefined);
394
398
  if (moves) {
395
399
  return {
@@ -419,7 +423,8 @@ function planUpdate(schema, table, input, options, mods, scope) {
419
423
  requireFilter2(table, input.where, mods, "update");
420
424
  if (Object.keys(set).length === 0)
421
425
  fail2("OKM1120", "update set is empty.");
422
- refuseTreeCycle(table, input.where, set, schema.tenancy?.key);
426
+ const keys = tenantKeys(schema.tenancy);
427
+ const cycle = refuseTreeCycle(table, input.where, set, keys);
423
428
  const where = stack2(input.where, mods.presets);
424
429
  const moved = pathAssignment(schema.tenancy, table.model.name, set, scope);
425
430
  if (moved !== undefined && claim !== undefined) {
@@ -446,6 +451,17 @@ function planUpdate(schema, table, input, options, mods, scope) {
446
451
  keyColumns: undefined
447
452
  };
448
453
  }
454
+ if (cycle !== undefined) {
455
+ return {
456
+ statements: [treeSetUpdate(schema, table, where, set, cycle, returning)],
457
+ outputs: parentOutputs(returning),
458
+ shape: returning === undefined ? "count" : "rows",
459
+ expect,
460
+ keys: undefined,
461
+ keyColumns: undefined,
462
+ treeGuard: true
463
+ };
464
+ }
449
465
  const sql = new Sql2;
450
466
  sql.text("update ");
451
467
  sql.text(quote(table.model.sql));
@@ -492,6 +508,8 @@ function finish(results, planned, table) {
492
508
  return finishVersioned(results, planned, table);
493
509
  if (planned.parentGuard === true)
494
510
  return finishParent(results, planned, table);
511
+ if (planned.treeGuard === true)
512
+ return finishTree(results, planned, table);
495
513
  if (planned.shape === "count") {
496
514
  let count = 0;
497
515
  for (const result of results)
@@ -520,6 +538,18 @@ function finishParent(results, planned, table) {
520
538
  fix: { summary: "Point the foreign key at a parent in this tenant." }
521
539
  });
522
540
  }
541
+ return finishGuarded(results, planned, table, updated);
542
+ }
543
+ function finishTree(results, planned, table) {
544
+ const row = results[0]?.rows[0];
545
+ const matched = countCell(row?.[0]);
546
+ const updated = countCell(row?.[1]);
547
+ if (updated < matched) {
548
+ fail2("OKM1120", `update on ${table} cannot point a tree row at itself or its descendant.`, "Set the parent to another row that is not under this one. A filter that is not the primary key is not checked.");
549
+ }
550
+ return finishGuarded(results, planned, table, updated);
551
+ }
552
+ function finishGuarded(results, planned, table, updated) {
523
553
  if (planned.shape === "count") {
524
554
  checkExpect(updated, planned.expect, table, "write");
525
555
  return { count: updated };
@@ -1155,6 +1185,7 @@ class Sql2 {
1155
1185
  };
1156
1186
  }
1157
1187
  statement() {
1188
+ assertParamCount2(this.params.length);
1158
1189
  return this.params.length === 0 ? { text: this.parts.join("") } : { text: this.parts.join(""), params: this.params };
1159
1190
  }
1160
1191
  }
@@ -1165,7 +1196,7 @@ function insertRow(table, value, allow, tenancy) {
1165
1196
  for (const key of Object.keys(value)) {
1166
1197
  const column = table.columns.get(key);
1167
1198
  if (column === undefined)
1168
- continue;
1199
+ refuseUnknownField(table, key);
1169
1200
  tenancy?.guard(table.model.name, key, "insert");
1170
1201
  if (!writable(table, column, allow, "insert"))
1171
1202
  refuse(table, column);
@@ -1175,6 +1206,9 @@ function insertRow(table, value, allow, tenancy) {
1175
1206
  refuseHalfMorph(table, row);
1176
1207
  return row;
1177
1208
  }
1209
+ function refuseUnknownField(table, key) {
1210
+ throwNamed("OKM1120", key, table.names, `Field ${key} is not on ${table.model.name}. Accepted names: ${list(table.names)}.`);
1211
+ }
1178
1212
  function cellsFor(columns, row) {
1179
1213
  return columns.map((column) => {
1180
1214
  if (!Object.hasOwn(row, column.field))
@@ -1281,10 +1315,10 @@ function writeSet2(table, value, allow, tenancy) {
1281
1315
  }
1282
1316
  const set = {};
1283
1317
  for (const key of Object.keys(value)) {
1284
- if (value[key] === undefined)
1285
- continue;
1286
1318
  const column = table.columns.get(key);
1287
1319
  if (column === undefined)
1320
+ refuseUnknownField(table, key);
1321
+ if (value[key] === undefined)
1288
1322
  continue;
1289
1323
  tenancy?.guard(table.model.name, key, "update");
1290
1324
  if (column.guardUpdate || !writable(table, column, allow, "update"))
@@ -1294,10 +1328,11 @@ function writeSet2(table, value, allow, tenancy) {
1294
1328
  refuseHalfMorph(table, set);
1295
1329
  return set;
1296
1330
  }
1297
- function refuseTreeCycle(table, where, set, scopeKey) {
1298
- const own = keyedId(table, where, scopeKey);
1299
- if (own === undefined)
1331
+ function refuseTreeCycle(table, where, set, scopeKeys) {
1332
+ const keyed = keyedId(table, where, scopeKeys);
1333
+ if (keyed === undefined)
1300
1334
  return;
1335
+ let found;
1301
1336
  for (const relation of table.model.relations) {
1302
1337
  if (relation.kind !== "many" || relation.through !== undefined || relation.morph !== undefined) {
1303
1338
  continue;
@@ -1312,17 +1347,20 @@ function refuseTreeCycle(table, where, set, scopeKey) {
1312
1347
  if (typeof value !== "string" && typeof value !== "number" && typeof value !== "bigint") {
1313
1348
  continue;
1314
1349
  }
1315
- if ((typeof value === "string" ? value : value.toString()) !== own)
1316
- continue;
1317
- fail2("OKM1120", `update on ${table.model.name}.${column.field} cannot point a tree row at itself.`, "Set the parent to another row. A filter that is not the primary key is not checked.");
1350
+ const parent = typeof value === "string" ? value : value.toString();
1351
+ if (parent === keyed.own) {
1352
+ fail2("OKM1120", `update on ${table.model.name}.${column.field} cannot point a tree row at itself.`, "Set the parent to another row. A filter that is not the primary key is not checked.");
1353
+ }
1354
+ found = { own: keyed.own, parent, column, identity: keyed.identity };
1318
1355
  }
1319
1356
  }
1357
+ return found;
1320
1358
  }
1321
- function keyedId(table, where, scopeKey) {
1359
+ function keyedId(table, where, scopeKeys) {
1322
1360
  if (!isRecord(where))
1323
1361
  return;
1324
1362
  const primary = table.model.primary;
1325
- const required = primary.filter((field) => field !== scopeKey);
1363
+ const required = primary.filter((field) => !scopeKeys.includes(field));
1326
1364
  const field = required.length === 1 ? required[0] : undefined;
1327
1365
  if (field === undefined || !Object.hasOwn(where, field))
1328
1366
  return;
@@ -1334,7 +1372,51 @@ function keyedId(table, where, scopeKey) {
1334
1372
  if (typeof value !== "string" && typeof value !== "number" && typeof value !== "bigint") {
1335
1373
  return;
1336
1374
  }
1337
- return String(value);
1375
+ const identity = table.columns.get(field);
1376
+ if (identity === undefined)
1377
+ return;
1378
+ return { own: String(value), identity };
1379
+ }
1380
+ function tenantKeys(tenancy) {
1381
+ if (tenancy === undefined)
1382
+ return [];
1383
+ if (tenancy.keys !== undefined && tenancy.keys.length > 0)
1384
+ return tenancy.keys;
1385
+ return [tenancy.key];
1386
+ }
1387
+ function treeSetUpdate(schema, table, where, set, cycle, returning) {
1388
+ const sql = new Sql2;
1389
+ sql.text("with matched as (select ");
1390
+ sql.text(rowId("t"));
1391
+ sql.text(" from ");
1392
+ sql.text(quote(table.model.sql));
1393
+ sql.text(" as t");
1394
+ emitFilter(schema, table, where, sql, "t");
1395
+ sql.text("), updated as (update ");
1396
+ sql.text(quote(table.model.sql));
1397
+ sql.text(" as t set ");
1398
+ emitSet2(sql, table, set, "t");
1399
+ sql.text(" where (");
1400
+ sql.text(rowId("t"));
1401
+ sql.text(") in (select tableoid, ctid from matched) and not exists (with recursive d as (select ");
1402
+ sql.text(quote(cycle.identity.sql));
1403
+ sql.text(" as k from ");
1404
+ sql.text(quote(table.model.sql));
1405
+ sql.text(" where ");
1406
+ sql.text(quote(cycle.column.sql));
1407
+ sql.text(" = ");
1408
+ sql.param(cycle.own, cycle.identity.dataType);
1409
+ sql.text(" union all select c.");
1410
+ sql.text(quote(cycle.identity.sql));
1411
+ sql.text(" from ");
1412
+ sql.text(quote(table.model.sql));
1413
+ sql.text(" c join d on c.");
1414
+ sql.text(quote(cycle.column.sql));
1415
+ sql.text(" = d.k) select 1 from d where d.k = ");
1416
+ sql.param(cycle.parent, cycle.identity.dataType);
1417
+ sql.text(")");
1418
+ endParent(sql, returning);
1419
+ return sql.statement();
1338
1420
  }
1339
1421
  function columnBySql(table, sql) {
1340
1422
  for (const column of table.model.columns) {
@@ -1443,6 +1525,7 @@ function chunkRows(rows) {
1443
1525
  function withParams(text, params) {
1444
1526
  if (params === undefined || params.length === 0)
1445
1527
  return { text };
1528
+ assertParamCount2(params.length);
1446
1529
  return { text, params };
1447
1530
  }
1448
1531
  function keyWire(columns, row) {
@@ -1,13 +1,13 @@
1
1
  import {
2
2
  identityColumn2
3
- } from "./ec71zqgt.js";
3
+ } from "./chk2bh4f.js";
4
4
  import {
5
5
  runWrite
6
6
  } from "./n4jqhpqz.js";
7
7
  import {
8
8
  queryHandle,
9
9
  settleCall
10
- } from "./mtrqn2hn.js";
10
+ } from "./gjj71hfh.js";
11
11
  import {
12
12
  OkmError,
13
13
  throwNamed,
@@ -22,7 +22,7 @@ import {
22
22
  list,
23
23
  isRecord,
24
24
  fail2
25
- } from "./f9mphxej.js";
25
+ } from "./2jdn09e2.js";
26
26
 
27
27
  // src/runtime/sync.ts
28
28
  var OPTIONS = ["expect", "signal", "timeout", "route"];
@@ -539,8 +539,8 @@ function callOf(options) {
539
539
  async function presetWhere(schema, table, uses) {
540
540
  if (uses === undefined)
541
541
  return;
542
- const { resolve } = await import("./ma2340rx.js");
543
- const { stack } = await import("./wwnekq5n.js");
542
+ const { resolve } = await import("./bj1kyqc8.js");
543
+ const { stack } = await import("./4dzvjtpy.js");
544
544
  return stack(undefined, resolve(schema, table, uses).wheres);
545
545
  }
546
546
  function noteSafety(session, table, view) {
@@ -1,8 +1,8 @@
1
1
  import {
2
2
  build2,
3
3
  identityColumn2
4
- } from "./ec71zqgt.js";
5
- import"./mtrqn2hn.js";
4
+ } from "./chk2bh4f.js";
5
+ import"./gjj71hfh.js";
6
6
  export {
7
7
  build2 as build,
8
8
  identityColumn2 as identityColumn
@@ -1,20 +1,20 @@
1
1
  import {
2
2
  DriverError2
3
- } from "./f9mphxej.js";
3
+ } from "./2jdn09e2.js";
4
4
  import {
5
5
  noticeBuffer,
6
6
  WireSession
7
- } from "./yw30vnq2.js";
7
+ } from "./asnnc3v5.js";
8
8
  import {
9
9
  noTimeout
10
- } from "./rs1jb051.js";
10
+ } from "./1fwfm5m3.js";
11
11
  import {
12
12
  BUNSQL_CAPABILITIES,
13
13
  driverErrors,
14
14
  rejectClosed,
15
15
  mapFailure,
16
16
  runCall
17
- } from "./xhrnjch9.js";
17
+ } from "./ry2f3w8p.js";
18
18
 
19
19
  // src/adapters/pg/bunsql.ts
20
20
  import { SQL as BunSQL } from "bun";
@@ -22,7 +22,7 @@ var clientPools = new WeakSet;
22
22
  function markClientPool2(pool) {
23
23
  clientPools.add(pool);
24
24
  }
25
- function open2(config) {
25
+ function open3(config) {
26
26
  const max = config.max ?? 10;
27
27
  const acquireMs = config.timeouts?.acquire;
28
28
  const counters = { reserved: 0, busy: 0, reservedBusy: 0, waiting: 0 };
@@ -30,7 +30,6 @@ function open2(config) {
30
30
  let closed = false;
31
31
  const isClosed = () => closed;
32
32
  const named = config.prepared === "named";
33
- const parked = [];
34
33
  let dropped = 0;
35
34
  let closures = 0;
36
35
  const sql = new BunSQL(config.url, {
@@ -50,14 +49,13 @@ function open2(config) {
50
49
  closures += 1;
51
50
  }
52
51
  });
53
- const root = new WireSession((text, params) => send2(sql, text, params), notices, isClosed, false, () => {
52
+ const root = new WireSession((text, params) => send3(sql, text, params), notices, isClosed, false, () => {
54
53
  counters.busy += 1;
55
54
  }, () => {
56
55
  counters.busy = Math.max(0, counters.busy - 1);
57
56
  });
58
57
  const held = {
59
58
  sql,
60
- parked,
61
59
  acquireMs,
62
60
  counters,
63
61
  notices,
@@ -66,26 +64,26 @@ function open2(config) {
66
64
  };
67
65
  const run = (text, params, watch) => {
68
66
  const sent = dropped;
69
- return root.query(text, params, watch).catch((error) => import("./g9ad4n80.js").then((mod) => mod.recover(sql, error, text, root.depth(), clientPools.has(pool), dropped > sent, () => root.query(text, params, watch))));
67
+ return root.query(text, params, watch).catch((error) => import("./efq6p9df.js").then((mod) => mod.recover(sql, error, text, root.depth(), clientPools.has(pool), dropped > sent, () => root.query(text, params, watch))));
70
68
  };
71
69
  const afterDrop = (text, params, watch) => {
72
70
  if (dropped === 0)
73
71
  return run(text, params, watch);
74
72
  const seen = dropped;
75
- return import("./g9ad4n80.js").then((mod) => mod.drainClosed(sql).then(() => {
73
+ return import("./efq6p9df.js").then((mod) => mod.drainClosed(sql).then(() => {
76
74
  if (dropped === seen)
77
75
  dropped = 0;
78
76
  return run(text, params, watch);
79
77
  }));
80
78
  };
81
- const checkout = () => closed ? rejectClosed() : import("./g9ad4n80.js").then((mod) => mod.checkout(held));
79
+ const checkout = () => closed ? rejectClosed() : import("./efq6p9df.js").then((mod) => mod.checkout(held));
82
80
  const pool = {
83
81
  capabilities: BUNSQL_CAPABILITIES,
84
82
  execute(text, params, options) {
85
83
  const refused = noTimeout(options);
86
84
  if (refused !== undefined)
87
85
  return refused;
88
- return runCall(closed, options, (watch) => releaseParked(parked).then(() => afterDrop(text, params, watch)));
86
+ return runCall(closed, options, (watch) => afterDrop(text, params, watch));
89
87
  },
90
88
  async batch(statements, options) {
91
89
  const refused = noTimeout(options);
@@ -101,23 +99,22 @@ function open2(config) {
101
99
  reserve: () => checkout(),
102
100
  stream(text, params) {
103
101
  return async function* () {
104
- const { streamRows } = await import("./g9ad4n80.js");
102
+ const { streamRows } = await import("./efq6p9df.js");
105
103
  yield* streamRows(checkout, text, params);
106
104
  }();
107
105
  },
108
106
  listen(channel, onNotify) {
109
- return import("./g9ad4n80.js").then((mod) => mod.listen(sql, parked, closed, channel, onNotify));
107
+ return import("./efq6p9df.js").then((mod) => mod.listen(sql, closed, channel, onNotify));
110
108
  },
111
109
  stats: () => statsOf(counters, max),
112
110
  async close() {
113
111
  closed = true;
114
- await releaseParked(parked);
115
112
  await sql.close();
116
113
  }
117
114
  };
118
115
  return pool;
119
116
  }
120
- function send2(sql, text, params) {
117
+ function send3(sql, text, params) {
121
118
  const refused = refuseInt8(params);
122
119
  if (refused !== undefined)
123
120
  return refused;
@@ -149,25 +146,15 @@ async function reserve2(sql, acquireMs, counters) {
149
146
  const errors = await driverErrors();
150
147
  throw errors.acquireTimeout();
151
148
  }
149
+ if (error instanceof Error && (error.message === "Connection closed" || error.message === "connection must be a PostgresSQLConnection")) {
150
+ throw new DriverError2(error.message, { cause: error, sqlstate: "08006" });
151
+ }
152
152
  throw await mapFailure(error);
153
153
  } finally {
154
154
  counters.waiting = Math.max(0, counters.waiting - 1);
155
155
  }
156
156
  }
157
- async function park2(parked, reserved) {
158
- parked.push(reserved);
159
- while (parked.length > 1) {
160
- const extra = parked.shift();
161
- if (extra !== undefined)
162
- await releaseReserved(extra);
163
- }
164
- }
165
- async function releaseParked(parked) {
166
- const pending = parked.splice(0);
167
- for (const reserved of pending)
168
- await releaseReserved(reserved);
169
- }
170
- function releaseReserved(reserved) {
157
+ function releaseReserved2(reserved) {
171
158
  const done = reserved.release();
172
159
  return done instanceof Promise ? done.then(() => {
173
160
  return;
@@ -187,4 +174,4 @@ function statsOf(counters, size) {
187
174
  };
188
175
  }
189
176
 
190
- export { markClientPool2, open2, send2, reserve2, park2 };
177
+ export { markClientPool2, open3, send3, reserve2, releaseReserved2 };
@@ -2,7 +2,7 @@ import {
2
2
  resetSession2,
3
3
  resetQueried2,
4
4
  refuseWhenLost2
5
- } from "./7ghwamrf.js";
5
+ } from "./8t22h3h7.js";
6
6
  export {
7
7
  refuseWhenLost2 as refuseWhenLost,
8
8
  resetQueried2 as resetQueried,
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  stack2
3
- } from "./cmptmb4f.js";
3
+ } from "./angjck01.js";
4
4
  export {
5
5
  stack2 as stack
6
6
  };
@@ -1,13 +1,13 @@
1
1
  import {
2
2
  outcomeUnknown2
3
- } from "./f9mphxej.js";
3
+ } from "./2jdn09e2.js";
4
4
  import {
5
5
  noticeBuffer,
6
6
  WireSession
7
- } from "./yw30vnq2.js";
7
+ } from "./asnnc3v5.js";
8
8
  import {
9
9
  noTimeout
10
- } from "./rs1jb051.js";
10
+ } from "./1fwfm5m3.js";
11
11
  import {
12
12
  NEON_WEBSOCKET_CAPABILITIES,
13
13
  NEON_HTTP_CAPABILITIES,
@@ -17,7 +17,7 @@ import {
17
17
  runCall,
18
18
  EMPTY_NOTICES,
19
19
  resultFrom
20
- } from "./xhrnjch9.js";
20
+ } from "./ry2f3w8p.js";
21
21
 
22
22
  // src/adapters/pg/neon.ts
23
23
  import {
@@ -32,12 +32,12 @@ var WIRE = {
32
32
  }
33
33
  };
34
34
  var names = new Map;
35
- async function open5(config) {
35
+ async function open2(config) {
36
36
  if (config.mode === "http")
37
37
  return openHttp(config);
38
38
  return openWebSocket(config);
39
39
  }
40
- function connectClient3(pool, acquireMs, counters) {
40
+ function connectClient2(pool, acquireMs, counters) {
41
41
  counters.waiting += 1;
42
42
  let settled = false;
43
43
  return new Promise((resolve, reject) => {
@@ -70,7 +70,7 @@ function connectClient3(pool, acquireMs, counters) {
70
70
  });
71
71
  });
72
72
  }
73
- function send4(runner, text, params, named) {
73
+ function send2(runner, text, params, named) {
74
74
  const query = {
75
75
  text,
76
76
  rowMode: "array",
@@ -111,13 +111,13 @@ async function openWebSocket(config) {
111
111
  });
112
112
  throw await mapFailure(error);
113
113
  }
114
- const root = new WireSession((text, params) => send4(pool, text, params, named), notices, isClosed, false, () => {
114
+ const root = new WireSession((text, params) => send2(pool, text, params, named), notices, isClosed, false, () => {
115
115
  counters.busy += 1;
116
116
  }, () => {
117
117
  counters.busy = Math.max(0, counters.busy - 1);
118
118
  });
119
119
  const held = { pool, acquireMs, counters, notices, named, isClosed };
120
- const checkout = () => closed ? rejectClosed() : import("./gfvtj6d0.js").then((mod) => mod.checkout(held));
120
+ const checkout = () => closed ? rejectClosed() : import("./f8a010fm.js").then((mod) => mod.checkout(held));
121
121
  return {
122
122
  capabilities: NEON_WEBSOCKET_CAPABILITIES,
123
123
  execute(text, params, options) {
@@ -230,4 +230,4 @@ function statsOf(counters, size) {
230
230
  };
231
231
  }
232
232
 
233
- export { open5, connectClient3, send4 };
233
+ export { open2, connectClient2, send2 };