okmodel 0.6.0 → 0.8.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 (267) hide show
  1. package/README.md +100 -1131
  2. package/dist/adapters/capabilities.d.ts +35 -0
  3. package/dist/adapters/failure.d.ts +13 -2
  4. package/dist/adapters/lazy-errors.d.ts +22 -0
  5. package/dist/adapters/pg/bun-sql.d.ts +53 -0
  6. package/dist/adapters/pg/bunsql-extra.d.ts +54 -3
  7. package/dist/adapters/pg/bunsql.d.ts +15 -2
  8. package/dist/adapters/pg/cursor.d.ts +17 -0
  9. package/dist/adapters/pg/neon-extra.d.ts +18 -0
  10. package/dist/adapters/pg/neon.d.ts +104 -0
  11. package/dist/adapters/pg/no-inflight-timeout.d.ts +11 -8
  12. package/dist/adapters/pg/nodepostgres-extra.d.ts +22 -1
  13. package/dist/adapters/pg/nodepostgres.d.ts +12 -0
  14. package/dist/adapters/pg/pglite-wire.d.ts +24 -0
  15. package/dist/adapters/pg/pglite.d.ts +10 -0
  16. package/dist/adapters/pg/postgres-extra.d.ts +27 -11
  17. package/dist/adapters/pg/reserved.d.ts +42 -0
  18. package/dist/adapters/pg/session.d.ts +0 -18
  19. package/dist/contracts/connection.d.ts +7 -6
  20. package/dist/contracts/error.d.ts +1 -1
  21. package/dist/dialects/pg/floor.d.ts +68 -0
  22. package/dist/dialects/pg/fn/index.d.ts +39 -1
  23. package/dist/dialects/pg/fn/index.js +118 -26
  24. package/dist/dialects/pg/index.d.ts +8 -1
  25. package/dist/dialects/pg/index.js +435 -170
  26. package/dist/dialects/pg/introspect.d.ts +11 -0
  27. package/dist/dialects/pg/keys.d.ts +11 -8
  28. package/dist/dialects/pg/model.d.ts +40 -0
  29. package/dist/dialects/pg/morph.d.ts +43 -0
  30. package/dist/dialects/pg/operator-fit.d.ts +2 -2
  31. package/dist/dialects/pg/operators.d.ts +14 -7
  32. package/dist/dialects/pg/ops/bucket.d.ts +65 -0
  33. package/dist/dialects/pg/ops/fragment.d.ts +119 -0
  34. package/dist/dialects/pg/ops/inc.d.ts +2 -2
  35. package/dist/dialects/pg/ops/lane.d.ts +49 -0
  36. package/dist/dialects/pg/ops/matches.d.ts +9 -12
  37. package/dist/dialects/pg/ops/relevance.d.ts +13 -0
  38. package/dist/dialects/pg/ops/search-query.d.ts +22 -0
  39. package/dist/dialects/pg/ops/window.d.ts +103 -0
  40. package/dist/dialects/pg/preset.d.ts +1 -1
  41. package/dist/dialects/pg/relations.d.ts +100 -3
  42. package/dist/dialects/pg/schema.d.ts +31 -3
  43. package/dist/dialects/pg/view/client.d.ts +14 -6
  44. package/dist/dialects/pg/view/index.d.ts +73 -1
  45. package/dist/dialects/pg/view/index.js +156 -5
  46. package/dist/dialects/pg/view/scratch.d.ts +8 -5
  47. package/dist/runtime/aggregate.d.ts +8 -2
  48. package/dist/runtime/bucket-group.d.ts +70 -0
  49. package/dist/runtime/conflict.d.ts +22 -4
  50. package/dist/runtime/include.d.ts +0 -8
  51. package/dist/runtime/inflight.d.ts +1 -1
  52. package/dist/runtime/otel.d.ts +105 -0
  53. package/dist/runtime/otel.js +97 -0
  54. package/dist/runtime/page.d.ts +4 -1
  55. package/dist/runtime/pg/bun.js +12 -6
  56. package/dist/runtime/pg/neon.d.ts +38 -0
  57. package/dist/runtime/pg/neon.js +64 -0
  58. package/dist/runtime/pg/pg.js +5 -5
  59. package/dist/runtime/pg/pglite.d.ts +1 -0
  60. package/dist/runtime/pg/pglite.js +9 -9
  61. package/dist/runtime/pg/postgresjs.js +5 -5
  62. package/dist/runtime/plan.d.ts +95 -5
  63. package/dist/runtime/read-stream.d.ts +13 -16
  64. package/dist/runtime/result-name.d.ts +17 -0
  65. package/dist/runtime/server-check.d.ts +3 -3
  66. package/dist/runtime/sort-bind.d.ts +21 -0
  67. package/dist/runtime/sort.d.ts +56 -0
  68. package/dist/runtime/sql-fragment.d.ts +43 -0
  69. package/dist/runtime/sync.d.ts +70 -0
  70. package/dist/runtime/tenancy/index.js +15 -13
  71. package/dist/runtime/text-search.d.ts +20 -0
  72. package/dist/runtime/topology.d.ts +1 -1
  73. package/dist/runtime/traits/index.d.ts +80 -0
  74. package/dist/runtime/traits/index.js +184 -21
  75. package/dist/runtime/tree.d.ts +38 -0
  76. package/dist/runtime/types.d.ts +232 -22
  77. package/dist/runtime/validate/index.js +4 -4
  78. package/dist/runtime/version.d.ts +39 -0
  79. package/dist/runtime/window.d.ts +21 -0
  80. package/dist/runtime/write.d.ts +54 -2
  81. package/dist/shared/{929h19xp.js → 0wrea3jq.js} +141 -13
  82. package/dist/shared/{qq3899ht.js → 12z7aznj.js} +243 -14
  83. package/dist/shared/{1z04fa85.js → 14x60fbf.js} +12 -57
  84. package/dist/shared/{ek2wt2dz.js → 16kvjebh.js} +4 -4
  85. package/dist/shared/{wynzeggs.js → 195pzzzz.js} +8 -8
  86. package/dist/shared/1d9q9cv2.js +312 -0
  87. package/dist/shared/2c13q96h.js +18 -0
  88. package/dist/shared/{b4v57v3x.js → 2d3xq4ps.js} +2 -2
  89. package/dist/shared/{1f0xa3cb.js → 3449rcae.js} +5 -5
  90. package/dist/shared/{wkme6tep.js → 35q0n9tz.js} +8 -16
  91. package/dist/shared/3bb7wsqt.js +99 -0
  92. package/dist/shared/3t6kw83m.js +249 -0
  93. package/dist/shared/{5j36z8dn.js → 4m6hskg8.js} +39 -70
  94. package/dist/shared/{n076ydsc.js → 4vbf83xx.js} +69 -28
  95. package/dist/shared/{vmfkhszw.js → 63f4ksbz.js} +33 -26
  96. package/dist/shared/{c58secgj.js → 63qtkrca.js} +38 -4
  97. package/dist/shared/6m78c8ss.js +6 -0
  98. package/dist/shared/{x3jc53kg.js → 760ppr76.js} +15 -7
  99. package/dist/shared/7ghwamrf.js +40 -0
  100. package/dist/shared/7kms6fvj.js +20 -0
  101. package/dist/shared/7n7ddwt4.js +6 -0
  102. package/dist/shared/9a4ae4p8.js +31 -0
  103. package/dist/shared/{hazqqecq.js → 9dr2qnx7.js} +63 -34
  104. package/dist/shared/{h15jx9bc.js → 9dvh1dr6.js} +1 -1
  105. package/dist/shared/a62rb2da.js +13 -0
  106. package/dist/shared/{cgbamx3e.js → ae4j5f42.js} +23 -4
  107. package/dist/shared/agsfb86s.js +233 -0
  108. package/dist/shared/{8x72s86k.js → b6d6p0zc.js} +13 -7
  109. package/dist/shared/{ag4c7516.js → b76b8d95.js} +2 -2
  110. package/dist/shared/{j60w0dvr.js → bah9nbg3.js} +58 -38
  111. package/dist/shared/bnby0esn.js +10 -0
  112. package/dist/shared/bsek72fg.js +225 -0
  113. package/dist/shared/{2cg3wnxc.js → bxas03mq.js} +608 -141
  114. package/dist/shared/{31vm914h.js → cm3w0ywp.js} +15 -16
  115. package/dist/shared/{gwn6v667.js → cnkky55j.js} +25 -14
  116. package/dist/shared/{dk8v79p3.js → d5nmj7vv.js} +1 -1
  117. package/dist/shared/{ttmg09vd.js → dpc2r7rb.js} +8 -8
  118. package/dist/shared/dzj09cye.js +10 -0
  119. package/dist/shared/{sbdme3vy.js → e8zyaqvj.js} +60 -10
  120. package/dist/shared/{2jd1sn0e.js → ecn8mfdq.js} +6 -6
  121. package/dist/shared/exn3sd90.js +359 -0
  122. package/dist/shared/{t3g0k88x.js → f4jy1j7x.js} +39 -22
  123. package/dist/shared/{y2t3jktd.js → fjpnhqan.js} +20 -13
  124. package/dist/shared/g5yc06ka.js +272 -0
  125. package/dist/shared/ga9j92qj.js +25 -0
  126. package/dist/shared/{3fqwmr09.js → hfqmpasr.js} +6 -6
  127. package/dist/shared/{wt5rzv1h.js → hm5f8jby.js} +7 -7
  128. package/dist/shared/{ys0xzyaj.js → hqpxf4a4.js} +224 -19
  129. package/dist/shared/jebgrkeq.js +179 -0
  130. package/dist/shared/{09p049xa.js → jp36k7dp.js} +44 -16
  131. package/dist/shared/jx2m62cs.js +96 -0
  132. package/dist/shared/{r11n8grd.js → k86n8vq3.js} +7 -4
  133. package/dist/shared/{2z7wv5tj.js → kgwp4jdd.js} +56 -35
  134. package/dist/shared/{knmes2kh.js → kj9d8maq.js} +1 -1
  135. package/dist/shared/{g90m9b0g.js → m4xff2a6.js} +6 -5
  136. package/dist/shared/{r6nwkxnt.js → m7n9h2a5.js} +4 -4
  137. package/dist/shared/mfedzr74.js +145 -0
  138. package/dist/shared/{f0f1n281.js → mkrn359n.js} +60 -11
  139. package/dist/shared/{p248q79y.js → mnvjvqyp.js} +10 -10
  140. package/dist/shared/{672t5vym.js → mss6ctgv.js} +2 -2
  141. package/dist/shared/{4az561fn.js → mtw6jz76.js} +8 -23
  142. package/dist/shared/n05z9nwz.js +313 -0
  143. package/dist/shared/{pjr6xrm5.js → n0jmpgj1.js} +20 -17
  144. package/dist/shared/{p6bjzq9q.js → n41w4fbz.js} +14 -6
  145. package/dist/shared/{b3awxn7h.js → n454kcnw.js} +1 -1
  146. package/dist/shared/n7kg8mmx.js +61 -0
  147. package/dist/shared/nbw1z4yd.js +18 -0
  148. package/dist/shared/needfe47.js +66 -0
  149. package/dist/shared/{1nw1f3vs.js → njga14v4.js} +9 -9
  150. package/dist/shared/{5yv4k6a6.js → nmnsgj7x.js} +145 -3
  151. package/dist/shared/{vjpnzwjz.js → p3xbdcvt.js} +14 -18
  152. package/dist/shared/p5nh3r8q.js +622 -0
  153. package/dist/shared/{nx9hh281.js → pan0370z.js} +13 -12
  154. package/dist/shared/q0cqt2sp.js +12 -0
  155. package/dist/shared/qd9hhd8f.js +37 -0
  156. package/dist/shared/{mb2ycs1p.js → qfw14tna.js} +15 -15
  157. package/dist/shared/{9s0ypp87.js → sjk86yrx.js} +1 -1
  158. package/dist/shared/th3be82n.js +208 -0
  159. package/dist/shared/{ed0b8k4s.js → typ3vy7t.js} +1 -1
  160. package/dist/shared/{5d8t84hg.js → v1wad97q.js} +14 -14
  161. package/dist/shared/{x72jb7ad.js → v8g1vgv8.js} +1 -1
  162. package/dist/shared/{9628a9xt.js → vk7rag46.js} +1 -1
  163. package/dist/shared/{ze4hxsmy.js → w9ejzaqf.js} +1 -1
  164. package/dist/shared/{q3j1tq7a.js → wcrheftc.js} +148 -23
  165. package/dist/shared/wvdjznah.js +213 -0
  166. package/dist/shared/wz2a78mp.js +8 -0
  167. package/dist/shared/xfhe73sb.js +436 -0
  168. package/dist/shared/{r1fdd0f6.js → z581d7ny.js} +5 -2
  169. package/dist/shared/{8etn7d8w.js → z7s6fpxv.js} +1 -1
  170. package/dist/shared/{32cnm7kn.js → zbqbmmrp.js} +76 -40
  171. package/dist/shared/{n7mcc1gk.js → zchaghkf.js} +4 -3
  172. package/dist/shared/{xq0mvhts.js → zgex00fd.js} +6 -6
  173. package/dist/shared/{nsva2a6b.js → znm0bpp5.js} +3 -0
  174. package/dist/shared/zq1he88x.js +155 -0
  175. package/dist/tooling/cli.js +26 -13
  176. package/dist/tooling/driver-run.js +4971 -0
  177. package/dist/tooling/driver-test.d.ts +36 -0
  178. package/dist/tooling/migrate/commands.d.ts +2 -2
  179. package/dist/tooling/migrate/engine.d.ts +3 -2
  180. package/dist/tooling/migrate/index.js +9 -9
  181. package/dist/tooling/migrate/project.d.ts +3 -0
  182. package/dist/tooling/shared/03k6res6.js +210 -0
  183. package/dist/tooling/shared/08kemxjd.js +10 -0
  184. package/dist/tooling/shared/2revefqt.js +209 -0
  185. package/dist/tooling/shared/2wtvc7rw.js +1425 -0
  186. package/dist/tooling/shared/345tbc2k.js +16 -0
  187. package/dist/tooling/shared/3m1hkg7z.js +344 -0
  188. package/dist/tooling/shared/3rrw5w8f.js +81 -0
  189. package/dist/tooling/shared/3tq8pnb8.js +131 -0
  190. package/dist/tooling/shared/417zdsk7.js +194 -0
  191. package/dist/tooling/shared/4d2w25vw.js +40 -0
  192. package/dist/tooling/shared/54tqkxja.js +51 -0
  193. package/dist/tooling/shared/5bvw2nev.js +12 -0
  194. package/dist/tooling/shared/6nyfyw70.js +231 -0
  195. package/dist/tooling/shared/72fyg4zv.js +160 -0
  196. package/dist/tooling/shared/733a1tq3.js +38 -0
  197. package/dist/tooling/shared/7ae7rjmn.js +20 -0
  198. package/dist/tooling/shared/7kms6fvj.js +20 -0
  199. package/dist/tooling/shared/8sqrsw3s.js +49 -0
  200. package/dist/tooling/shared/96ps4g1z.js +32 -0
  201. package/dist/tooling/shared/9kazs5p6.js +195 -0
  202. package/dist/tooling/shared/9xzm7hjg.js +38 -0
  203. package/dist/tooling/shared/a6pp9d12.js +49 -0
  204. package/dist/tooling/shared/a7q7t4n3.js +22 -0
  205. package/dist/tooling/shared/aftb2mwr.js +18 -0
  206. package/dist/tooling/shared/bz2dqhab.js +311 -0
  207. package/dist/tooling/shared/cmptmb4f.js +12 -0
  208. package/dist/tooling/shared/ddjtfgnx.js +177 -0
  209. package/dist/tooling/shared/djydjpqt.js +261 -0
  210. package/dist/tooling/shared/dw08f3m8.js +9 -0
  211. package/dist/tooling/shared/dy672fz6.js +16 -0
  212. package/dist/tooling/shared/dzx85q70.js +66 -0
  213. package/dist/tooling/shared/ec71zqgt.js +270 -0
  214. package/dist/{shared/d5azex6s.js → tooling/shared/ep8zh3bk.js} +1 -1
  215. package/dist/tooling/shared/f9mphxej.js +3789 -0
  216. package/dist/tooling/shared/fb9k2qwd.js +89 -0
  217. package/dist/tooling/shared/g9ad4n80.js +211 -0
  218. package/dist/tooling/shared/gfvtj6d0.js +94 -0
  219. package/dist/tooling/shared/gmcf9cxf.js +294 -0
  220. package/dist/tooling/shared/htnaj77v.js +17 -0
  221. package/dist/tooling/shared/j9t5s12a.js +7 -0
  222. package/dist/tooling/shared/jne7b93p.js +42 -0
  223. package/dist/tooling/shared/ma2340rx.js +118 -0
  224. package/dist/tooling/shared/mtrqn2hn.js +505 -0
  225. package/dist/tooling/shared/n4jqhpqz.js +27 -0
  226. package/dist/tooling/shared/nf7jmhfa.js +20 -0
  227. package/dist/tooling/shared/p7f08ktn.js +332 -0
  228. package/dist/tooling/shared/ppnnnvj8.js +13 -0
  229. package/dist/tooling/shared/pqy21k24.js +312 -0
  230. package/dist/tooling/shared/pw8fgahx.js +69 -0
  231. package/dist/tooling/shared/pwsytxm5.js +17 -0
  232. package/dist/tooling/shared/rf83gr2d.js +94 -0
  233. package/dist/tooling/shared/rq5kk8j6.js +401 -0
  234. package/dist/tooling/shared/rs1jb051.js +12 -0
  235. package/dist/tooling/shared/smn6kz1p.js +157 -0
  236. package/dist/tooling/shared/spk1jg3r.js +1696 -0
  237. package/dist/tooling/shared/tn8gay14.js +143 -0
  238. package/dist/tooling/shared/vraj6d74.js +42 -0
  239. package/dist/tooling/shared/vs0t6qt8.js +64 -0
  240. package/dist/tooling/shared/vx86qjv8.js +150 -0
  241. package/dist/tooling/shared/w7qe8sj1.js +140 -0
  242. package/dist/tooling/shared/wt7j7nf6.js +15 -0
  243. package/dist/tooling/shared/wwnekq5n.js +6 -0
  244. package/dist/tooling/shared/xhrnjch9.js +185 -0
  245. package/dist/tooling/shared/xjs6zqtc.js +190 -0
  246. package/dist/tooling/shared/y031jct9.js +16 -0
  247. package/dist/tooling/shared/y5656f0e.js +233 -0
  248. package/dist/tooling/shared/yfr8hzhm.js +604 -0
  249. package/dist/tooling/shared/yk9mp7vb.js +250 -0
  250. package/dist/tooling/shared/yw30vnq2.js +139 -0
  251. package/dist/tooling/shared/z8d7ptht.js +618 -0
  252. package/dist/tooling/shared/zhwnfyb2.js +9 -0
  253. package/dist/tooling/shared/zvnhh1n0.js +198 -0
  254. package/dist/tooling/testing/index.js +3 -3
  255. package/package.json +17 -3
  256. package/dist/shared/3qnhc7w5.js +0 -38
  257. package/dist/shared/7m88x3e9.js +0 -45
  258. package/dist/shared/8dqhth8c.js +0 -12
  259. package/dist/shared/j3rkk835.js +0 -99
  260. package/dist/shared/k68eedmy.js +0 -85
  261. package/dist/shared/venqrjna.js +0 -216
  262. package/dist/shared/wxr8cwns.js +0 -6
  263. package/dist/shared/y34a8714.js +0 -150
  264. package/dist/shared/zm0mafk4.js +0 -92
  265. package/dist/shared/zy8r7qvz.js +0 -116
  266. package/dist/shared/{ywr8hmey.js → 606g0nbf.js} +3 -3
  267. package/dist/shared/{rpycarcr.js → gcefca6p.js} +4 -4
@@ -0,0 +1,312 @@
1
+ import {
2
+ emitSqlSelect,
3
+ decodeSqlNumber
4
+ } from "./3bb7wsqt.js";
5
+ import {
6
+ refusePrototypeKey
7
+ } from "./a62rb2da.js";
8
+ import {
9
+ isWindow
10
+ } from "./9a4ae4p8.js";
11
+ import {
12
+ readSelectFragment
13
+ } from "./bsek72fg.js";
14
+ import {
15
+ emitWhere,
16
+ emitOrder,
17
+ refuseHidden,
18
+ emitLimit,
19
+ parseOrder,
20
+ projectExpr,
21
+ indexes,
22
+ quote,
23
+ list,
24
+ isRecord,
25
+ fail2
26
+ } from "./kgwp4jdd.js";
27
+ import {
28
+ throwNamed2
29
+ } from "./52szzakm.js";
30
+
31
+ // src/runtime/window.ts
32
+ var AS_NUMBER = (wire) => Number(wire);
33
+ var AS_TEXT = (wire) => wire;
34
+ var NUMERIC = /^(smallint|integer|bigint|real|double precision|numeric|decimal)\b/;
35
+ var OPTION_KEYS = ["as", "orderBy", "partitionBy"];
36
+ function attach(schema, call) {
37
+ const table = indexesOf(schema, call.table);
38
+ return { ...call, build: statement(readSpec(table, call.select)) };
39
+ }
40
+ function statement(spec) {
41
+ return (schema, table, sink, outputs, call, hooks) => {
42
+ sink.mark(`${call.op}|${table.model.name}|`);
43
+ if (call.include !== undefined && hooks === undefined) {
44
+ fail2("OKM1120", "An include needs the include planner.");
45
+ }
46
+ const includes = hooks === undefined || call.include === undefined ? [] : hooks.read(schema, table, call.include, call.all);
47
+ sink.text("select ");
48
+ let column = 0;
49
+ for (const item of spec.items) {
50
+ if (column > 0)
51
+ sink.text(", ");
52
+ if (item.kind === "column") {
53
+ sink.text(projectExpr(`t.${quote(item.column.sql)}`, item.column.dataType));
54
+ sink.mark(`s:${item.column.field}`);
55
+ outputs?.fields.push({ key: item.column.field, at: column, decode: item.column.decode });
56
+ } else if (item.kind === "sql") {
57
+ emitSqlSelect(table, item.parts, sink, "t");
58
+ sink.text("::text");
59
+ sink.mark(`s:${item.as}`);
60
+ outputs?.fields.push({
61
+ key: item.as,
62
+ at: column,
63
+ decode: item.textual === true ? AS_TEXT : decodeSqlNumber
64
+ });
65
+ } else {
66
+ emitWindow(table, item.window, sink);
67
+ sink.text("::text");
68
+ outputs?.fields.push({ key: item.window.as, at: column, decode: item.window.decode });
69
+ }
70
+ column += 1;
71
+ }
72
+ if (spec.items.length === 0 && includes.length === 0)
73
+ sink.text("1");
74
+ for (let index = 0;index < includes.length; index += 1) {
75
+ const include = includes[index];
76
+ if (include === undefined || hooks === undefined)
77
+ continue;
78
+ column = hooks.select(include, `i${String(index)}`, sink, outputs, column);
79
+ }
80
+ sink.text(" from ");
81
+ sink.text(quote(table.model.sql));
82
+ sink.text(" t");
83
+ for (let index = 0;index < includes.length; index += 1) {
84
+ const include = includes[index];
85
+ if (include === undefined || hooks === undefined)
86
+ continue;
87
+ hooks.join(schema, include, sink, "t", `i${String(index)}`, 0);
88
+ }
89
+ emitWhere(schema, table, call.where, sink, "t", 0, false, call.after);
90
+ emitResultOrder(table, call.orderBy, sink, spec.ordinals);
91
+ emitLimit(call, sink);
92
+ call.tail?.(sink);
93
+ };
94
+ }
95
+ function emitResultOrder(table, orderBy, sink, ordinals) {
96
+ if (!isRecord(orderBy) || !mentionsOrdinal(orderBy, ordinals)) {
97
+ emitOrder(table, orderBy, sink, "t");
98
+ return;
99
+ }
100
+ const keys = Object.keys(orderBy);
101
+ sink.text(" order by ");
102
+ for (let index = 0;index < keys.length; index += 1) {
103
+ const key = keys[index];
104
+ if (key === undefined)
105
+ continue;
106
+ const parsed = parseOrder(key, orderBy[key]);
107
+ if (index > 0)
108
+ sink.text(", ");
109
+ const ordinal = ordinals.get(key);
110
+ if (ordinal !== undefined) {
111
+ sink.text(ordinal);
112
+ } else {
113
+ const column = table.columns.get(key);
114
+ if (column === undefined) {
115
+ throwNamed2("OKM1120", key, table.names, `Field ${key} is not on ${table.model.name}. Accepted names: ${list(table.names)}.`);
116
+ }
117
+ refuseHidden(column);
118
+ sink.text("t.");
119
+ sink.text(quote(column.sql));
120
+ }
121
+ sink.text(parsed.dir === "asc" ? " asc" : " desc");
122
+ sink.text(parsed.nulls === "first" ? " nulls first" : " nulls last");
123
+ sink.mark(`o:${key}:${parsed.dir}:${parsed.nulls}`);
124
+ }
125
+ }
126
+ function mentionsOrdinal(orderBy, ordinals) {
127
+ if (ordinals.size === 0)
128
+ return false;
129
+ for (const key of Object.keys(orderBy)) {
130
+ if (ordinals.has(key))
131
+ return true;
132
+ }
133
+ return false;
134
+ }
135
+ function emitWindow(table, win, sink) {
136
+ sink.mark(`w:${win.fn}:${win.as}:p:${win.partition.map((column) => column.field).join("+")}`);
137
+ if (win.fn === "sum") {
138
+ const column = win.column;
139
+ if (column === undefined)
140
+ fail2("OKM1120", "runningTotal needs a column.");
141
+ sink.text("sum(t.");
142
+ sink.text(quote(column.sql));
143
+ sink.text(")");
144
+ } else {
145
+ sink.text(win.fn);
146
+ sink.text("()");
147
+ }
148
+ sink.text(" over (");
149
+ if (win.partition.length > 0) {
150
+ sink.text("partition by ");
151
+ for (let index = 0;index < win.partition.length; index += 1) {
152
+ const column = win.partition[index];
153
+ if (column === undefined)
154
+ continue;
155
+ if (index > 0)
156
+ sink.text(", ");
157
+ sink.text("t.");
158
+ sink.text(quote(column.sql));
159
+ }
160
+ }
161
+ emitOrder(table, win.orderBy, sink, "t");
162
+ if (win.tieBreak) {
163
+ const named = isRecord(win.orderBy) ? Object.keys(win.orderBy) : [];
164
+ for (const field of table.model.primary) {
165
+ if (named.includes(field))
166
+ continue;
167
+ const column = table.columns.get(field);
168
+ if (column === undefined)
169
+ continue;
170
+ sink.text(", t.");
171
+ sink.text(quote(column.sql));
172
+ sink.text(" asc");
173
+ }
174
+ }
175
+ sink.text(")");
176
+ }
177
+ function readSpec(table, select) {
178
+ if (!Array.isArray(select))
179
+ fail2("OKM1120", "select must be a list of field names.");
180
+ const items = [];
181
+ const ordinals = new Map;
182
+ const names = new Set;
183
+ for (const entry of select) {
184
+ if (typeof entry === "string") {
185
+ const column = columnOn(table, entry, "select");
186
+ names.add(column.field);
187
+ items.push({ kind: "column", column });
188
+ continue;
189
+ }
190
+ const sql = readSelectFragment(entry);
191
+ if (sql !== undefined) {
192
+ const as = readAs(sql.as, "fragment");
193
+ if (names.has(as) || table.columns.has(as)) {
194
+ fail2("OKM1120", `fragment as ${as} clashes with a column of ${table.model.name}.`, "Pick an as name that is not a column.");
195
+ }
196
+ names.add(as);
197
+ ordinals.set(as, String(items.length + 1));
198
+ items.push(sql.textual === true ? { kind: "sql", as, parts: sql.parts, textual: true } : { kind: "sql", as, parts: sql.parts });
199
+ continue;
200
+ }
201
+ if (!isWindow(entry)) {
202
+ fail2("OKM1120", "select takes field names or a window helper. A plain object is not a window.", "Pass rowNumber, rank, denseRank, or runningTotal.");
203
+ }
204
+ const win = readWindow(table, entry, names);
205
+ names.add(win.as);
206
+ ordinals.set(win.as, String(items.length + 1));
207
+ items.push({ kind: "window", window: win });
208
+ }
209
+ return { items, ordinals };
210
+ }
211
+ function readWindow(table, call, taken) {
212
+ if (!isRecord(call))
213
+ fail2("OKM1120", "A window helper was not created by its function.");
214
+ for (const key of Object.keys(call)) {
215
+ if (key === "label" || key === "fn" || key === "column")
216
+ continue;
217
+ if (OPTION_KEYS.includes(key))
218
+ continue;
219
+ fail2("OKM1120", `${call.label} does not take ${key}. Accepted: partitionBy, orderBy, as.`, "Pass partitionBy, orderBy, and as.");
220
+ }
221
+ const as = readAs(call.as, call.label);
222
+ if (taken.has(as) || table.columns.has(as)) {
223
+ fail2("OKM1120", `${call.label} as ${as} clashes with a column of ${table.model.name}.`, "Pick an as name that is not a column.");
224
+ }
225
+ const partition = readPartition(table, call.partitionBy, call.label);
226
+ if (!isRecord(call.orderBy) || Object.keys(call.orderBy).length === 0) {
227
+ fail2("OKM1120", `${call.label} needs orderBy, the order inside the group.`, 'Pass orderBy: { field: "desc" }.');
228
+ }
229
+ for (const field of Object.keys(call.orderBy))
230
+ columnOn(table, field, `${call.label} orderBy`);
231
+ let column;
232
+ let decode = AS_NUMBER;
233
+ if (call.fn === "sum") {
234
+ if (typeof call.column !== "string") {
235
+ fail2("OKM1120", "runningTotal needs the column to total.");
236
+ }
237
+ column = columnOn(table, call.column, "runningTotal");
238
+ if (!NUMERIC.test(column.dataType)) {
239
+ fail2("OKM1124", `runningTotal does not apply to ${column.dataType} column ${column.field}. It takes integer, real, and numeric columns.`);
240
+ }
241
+ decode = totalDecode(column);
242
+ }
243
+ return {
244
+ fn: call.fn,
245
+ label: call.label,
246
+ column,
247
+ partition,
248
+ orderBy: call.orderBy,
249
+ as,
250
+ decode,
251
+ tieBreak: call.fn === "row_number" || call.fn === "sum"
252
+ };
253
+ }
254
+ function readPartition(table, value, label) {
255
+ if (value === undefined)
256
+ return [];
257
+ if (!Array.isArray(value) || value.length === 0) {
258
+ fail2("OKM1120", `${label} partitionBy needs the fields that form the group.`, 'Pass partitionBy: ["status"], or leave it out to use the whole result.');
259
+ }
260
+ const columns = [];
261
+ const seen = new Set;
262
+ for (const name of value) {
263
+ if (typeof name !== "string") {
264
+ fail2("OKM1120", `${label} partitionBy takes field names.`);
265
+ }
266
+ const column = columnOn(table, name, `${label} partitionBy`);
267
+ if (seen.has(column.field)) {
268
+ fail2("OKM1120", `${label} partitionBy lists ${column.field} twice.`);
269
+ }
270
+ seen.add(column.field);
271
+ columns.push(column);
272
+ }
273
+ return columns;
274
+ }
275
+ function readAs(value, label) {
276
+ if (typeof value !== "string" || value.length === 0) {
277
+ fail2("OKM1120", `${label} needs as, the name of the result key.`, "Set as to a name, such as n.");
278
+ }
279
+ for (let index = 0;index < value.length; index += 1) {
280
+ if ((value.charCodeAt(index) ?? 0) < 32) {
281
+ fail2("OKM1120", `${label} as has a control character.`);
282
+ }
283
+ }
284
+ refusePrototypeKey(value, `${label} as`);
285
+ return value;
286
+ }
287
+ function totalDecode(column) {
288
+ const kind = typeof (column.decode?.("0") ?? "");
289
+ if (kind === "string")
290
+ return AS_TEXT;
291
+ if (kind === "number")
292
+ return AS_NUMBER;
293
+ return fail2("OKM1124", `runningTotal needs a column whose value is a number or a string. ${column.field} reads as ${kind}.`);
294
+ }
295
+ function columnOn(table, name, where) {
296
+ const column = table.columns.get(name);
297
+ if (column === undefined) {
298
+ throwNamed2("OKM1120", name, table.names, `Field ${name} is not on ${table.model.name}. ${where} accepts: ${list(table.names)}.`);
299
+ }
300
+ if (where !== "select")
301
+ refuseHidden(column);
302
+ return column;
303
+ }
304
+ function indexesOf(schema, name) {
305
+ const table = indexes(schema).get(name);
306
+ if (table === undefined)
307
+ fail2("OKM1120", `Table ${name} is not in the schema.`);
308
+ return table;
309
+ }
310
+ export {
311
+ attach
312
+ };
@@ -0,0 +1,18 @@
1
+ import {
2
+ DriverError2
3
+ } from "./cm3w0ywp.js";
4
+ import {
5
+ OkmError2
6
+ } from "./52szzakm.js";
7
+
8
+ // src/adapters/lazy-errors.ts
9
+ function refused() {
10
+ return Promise.reject(new OkmError2("OKM1120", "timeout"));
11
+ }
12
+ function closed() {
13
+ return Promise.reject(new DriverError2("The pool is closed.", { sqlstate: "08006" }));
14
+ }
15
+ export {
16
+ closed,
17
+ refused
18
+ };
@@ -2,8 +2,8 @@
2
2
  async function refuseUncancellableTimeout(pool, timeout) {
3
3
  if (pool.capabilities.cancel === true || timeout === undefined || !(timeout > 0))
4
4
  return;
5
- const { noTimeout } = await import("./wxr8cwns.js");
6
- noTimeout({ timeout });
5
+ const { refused } = await import("./2c13q96h.js");
6
+ await refused();
7
7
  }
8
8
 
9
9
  export { refuseUncancellableTimeout };
@@ -2,11 +2,11 @@ import {
2
2
  assertAuthorDrift2,
3
3
  catalogQuery2,
4
4
  managedRoleOptions2
5
- } from "./f0f1n281.js";
6
- import"./vjpnzwjz.js";
7
- import"./ttmg09vd.js";
8
- import"./9s0ypp87.js";
9
- import"./qq3899ht.js";
5
+ } from "./mkrn359n.js";
6
+ import"./p3xbdcvt.js";
7
+ import"./dpc2r7rb.js";
8
+ import"./sjk86yrx.js";
9
+ import"./12z7aznj.js";
10
10
  export {
11
11
  assertAuthorDrift2 as assertAuthorDrift,
12
12
  catalogQuery2 as catalogQuery,
@@ -6,7 +6,7 @@ import {
6
6
  runCall,
7
7
  EMPTY_NOTICES,
8
8
  resultFrom
9
- } from "./cgbamx3e.js";
9
+ } from "./ae4j5f42.js";
10
10
 
11
11
  // src/adapters/pg/postgresjs.ts
12
12
  import net from "node:net";
@@ -117,26 +117,18 @@ function open2(config) {
117
117
  execute(text, params, options) {
118
118
  return sockets.occupy(() => runCall(closed, options, (watch) => root.query(text, params, watch)));
119
119
  },
120
- async batch(statements, options) {
121
- return sockets.occupy(async () => {
122
- const { checkout } = await import("./r1fdd0f6.js");
123
- const connection = await checkout(held);
124
- try {
125
- return await connection.batch(statements, options);
126
- } finally {
127
- await connection.release();
128
- }
129
- });
120
+ batch(statements, options) {
121
+ return sockets.occupy(() => import("./z581d7ny.js").then((mod) => mod.runBatch(held, statements, options)));
130
122
  },
131
123
  reserve() {
132
124
  const gate = sockets.busyGate();
133
125
  gate.enter();
134
- return import("./r1fdd0f6.js").then((mod) => mod.holdCheckout(gate, () => mod.checkout(held)), (error) => {
126
+ return import("./z581d7ny.js").then((mod) => mod.holdCheckout(gate, () => mod.checkout(held)), (error) => {
135
127
  gate.leave();
136
128
  throw error;
137
129
  });
138
130
  },
139
- describe: (text, params) => sockets.occupy(() => import("./r1fdd0f6.js").then((mod) => mod.describe(sql, text, params))),
131
+ describe: (text, params) => sockets.occupy(() => import("./z581d7ny.js").then((mod) => mod.describe(sql, text, params))),
140
132
  stream(text, params) {
141
133
  const gate = sockets.busyGate();
142
134
  return async function* () {
@@ -151,7 +143,7 @@ function open2(config) {
151
143
  listen(channel, onNotify) {
152
144
  const gate = sockets.listenerGate();
153
145
  gate.enter();
154
- return import("./r1fdd0f6.js").then((mod) => mod.holdListener(gate, async () => {
146
+ return import("./z581d7ny.js").then((mod) => mod.holdListener(gate, async () => {
155
147
  const listening = await sql.listen(channel, onNotify);
156
148
  return async () => {
157
149
  await listening.unlisten();
@@ -221,7 +213,7 @@ class PgSession {
221
213
  onAbort();
222
214
  else
223
215
  watch.signal.addEventListener("abort", onAbort, { once: true });
224
- return import("./r1fdd0f6.js").then((mod) => mod.watchQuery(pending, watch, onAbort, {
216
+ return import("./z581d7ny.js").then((mod) => mod.watchQuery(pending, watch, onAbort, {
225
217
  start,
226
218
  text,
227
219
  notices: this.notices,
@@ -273,7 +265,7 @@ class PgSession {
273
265
  }
274
266
  }
275
267
  async function* loadStream(sql, text, params) {
276
- const { stream } = await import("./r1fdd0f6.js");
268
+ const { stream } = await import("./z581d7ny.js");
277
269
  yield* stream(sql, text, params);
278
270
  }
279
271
  function send(sql, text, params, named) {
@@ -0,0 +1,99 @@
1
+ import {
2
+ isFragmentParts
3
+ } from "./bsek72fg.js";
4
+ import {
5
+ refuseHidden,
6
+ quote,
7
+ list,
8
+ fail2
9
+ } from "./kgwp4jdd.js";
10
+ import {
11
+ OkmError2,
12
+ throwNamed2
13
+ } from "./52szzakm.js";
14
+
15
+ // src/runtime/sql-fragment.ts
16
+ function emitSqlValue(table, ref, value, sink) {
17
+ const dot = ref.indexOf(".");
18
+ const alias = dot < 0 ? ref : ref.slice(0, dot);
19
+ writeFragment(requireParts(value), sink, alias, ref, table, "where");
20
+ }
21
+ function emitSqlSelect(table, parts, sink, alias) {
22
+ writeFragment(parts, sink, alias, undefined, table, "select");
23
+ }
24
+ function decodeSqlNumber(wire) {
25
+ const parsed = Number(wire);
26
+ if (!Number.isFinite(parsed)) {
27
+ throw new OkmError2("OKM1125", "A select fragment must be a number.", {
28
+ fix: { summary: "Use a numeric expression, such as length(title). Text stays in where." }
29
+ });
30
+ }
31
+ return parsed;
32
+ }
33
+ function requireParts(value) {
34
+ if (!isFragmentParts(value)) {
35
+ throw new OkmError2("OKM1125", "A fragment was not created by fragment``.", {
36
+ fix: { summary: "Call fragment`...`." }
37
+ });
38
+ }
39
+ return value;
40
+ }
41
+ function writeFragment(parts, sink, alias, ref, table, place) {
42
+ sink.mark(":g");
43
+ sink.text("(");
44
+ for (const part of parts)
45
+ writePart(part, sink, alias, ref, table, place);
46
+ sink.mark(":g");
47
+ sink.text(")");
48
+ }
49
+ function writePart(part, sink, alias, ref, table, place) {
50
+ if (part.k === "t") {
51
+ sink.mark(`:t:${String(part.s.length)}:${part.s}`);
52
+ sink.text(part.s);
53
+ return;
54
+ }
55
+ if (part.k === "p") {
56
+ sink.mark(":p");
57
+ sink.param(part.v);
58
+ return;
59
+ }
60
+ if (part.k === "n") {
61
+ sink.mark(":n");
62
+ sink.text("null");
63
+ return;
64
+ }
65
+ if (part.k === "i") {
66
+ writeIdent(part.n, table, sink, alias, place);
67
+ return;
68
+ }
69
+ if (part.k === "c") {
70
+ if (ref === undefined) {
71
+ throw new OkmError2("OKM1125", "fragment.column belongs on a where field.", {
72
+ fix: { summary: "Use ident(name) in select, or put fragment.column on a where field." }
73
+ });
74
+ }
75
+ sink.mark(":c");
76
+ sink.text(ref);
77
+ return;
78
+ }
79
+ writeFragment(part.parts, sink, alias, ref, table, place);
80
+ }
81
+ function writeIdent(name, table, sink, alias, place) {
82
+ const column = table.columns.get(name);
83
+ if (column === undefined) {
84
+ throwNamed2("OKM1120", name, table.names, `Field ${name} is not on ${table.model.name}. Accepted names: ${list(table.names)}.`);
85
+ }
86
+ if (place === "select") {
87
+ if (column.hidden) {
88
+ fail2("OKM1120", `Field ${column.field} is hidden.`, "A select fragment cannot name a hidden field.");
89
+ }
90
+ } else {
91
+ refuseHidden(column);
92
+ }
93
+ sink.mark(`:i:${String(column.field.length)}:${column.field}`);
94
+ sink.text(alias);
95
+ sink.text(".");
96
+ sink.text(quote(column.sql));
97
+ }
98
+
99
+ export { emitSqlValue, emitSqlSelect, decodeSqlNumber };