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
@@ -1,12 +1,32 @@
1
+ import"../../shared/12z7aznj.js";
1
2
  import {
2
3
  jsonReplacer2,
3
4
  json2,
4
5
  jsonb2
5
- } from "../../shared/9628a9xt.js";
6
+ } from "../../shared/vk7rag46.js";
7
+ import {
8
+ searchValue
9
+ } from "../../shared/dzj09cye.js";
10
+ import {
11
+ rowNumber2,
12
+ rank2,
13
+ denseRank2,
14
+ runningTotal2
15
+ } from "../../shared/9a4ae4p8.js";
16
+ import {
17
+ bucket2
18
+ } from "../../shared/nbw1z4yd.js";
6
19
  import {
7
20
  withOwner2
8
21
  } from "../../shared/xqve9598.js";
9
22
  import {
23
+ smallint2,
24
+ integer2,
25
+ bigint2,
26
+ identity2,
27
+ encodeBigintString,
28
+ decodeBigintString,
29
+ integerToken,
10
30
  encodeInstant,
11
31
  decodeInstant,
12
32
  encodeDate,
@@ -17,22 +37,22 @@ import {
17
37
  time2,
18
38
  timetz2,
19
39
  interval2
20
- } from "../../shared/5yv4k6a6.js";
40
+ } from "../../shared/nmnsgj7x.js";
21
41
  import {
22
- schema2
23
- } from "../../shared/hazqqecq.js";
42
+ id2,
43
+ uuid2
44
+ } from "../../shared/ecn8mfdq.js";
24
45
  import {
25
- domainType
26
- } from "../../shared/ywspezzx.js";
46
+ schema2
47
+ } from "../../shared/9dr2qnx7.js";
27
48
  import {
28
49
  one2,
29
50
  many2,
30
- manyThrough2
31
- } from "../../shared/k68eedmy.js";
32
- import {
33
- id2,
34
- uuid2
35
- } from "../../shared/2jd1sn0e.js";
51
+ manyThrough2,
52
+ morph2,
53
+ morphMany2,
54
+ morphTo2
55
+ } from "../../shared/exn3sd90.js";
36
56
  import {
37
57
  text2,
38
58
  varchar2,
@@ -40,18 +60,28 @@ import {
40
60
  citext2,
41
61
  encodeText,
42
62
  decodeText
43
- } from "../../shared/ed0b8k4s.js";
63
+ } from "../../shared/typ3vy7t.js";
44
64
  import {
45
65
  table2,
46
66
  index2,
47
67
  sql2
48
- } from "../../shared/rpycarcr.js";
68
+ } from "../../shared/gcefca6p.js";
49
69
  import {
50
70
  ColumnBuilder2,
51
71
  required,
52
- openColumn,
53
72
  formatType
54
- } from "../../shared/ywr8hmey.js";
73
+ } from "../../shared/606g0nbf.js";
74
+ import {
75
+ isFragmentParts,
76
+ fragment2,
77
+ ident2
78
+ } from "../../shared/bsek72fg.js";
79
+ import {
80
+ quoteIdent
81
+ } from "../../shared/sjk86yrx.js";
82
+ import {
83
+ domainType
84
+ } from "../../shared/ywspezzx.js";
55
85
  import {
56
86
  definition,
57
87
  rejected
@@ -61,11 +91,15 @@ import {
61
91
  compareText
62
92
  } from "../../shared/358zsv4r.js";
63
93
  import {
94
+ isOperator,
95
+ operatorName,
96
+ operatorValue,
64
97
  tag
65
98
  } from "../../shared/cn0n68ft.js";
66
99
  import {
67
100
  OkmError2,
68
- catalogError2
101
+ catalogError2,
102
+ throwNamed2
69
103
  } from "../../shared/52szzakm.js";
70
104
  var __defProp = Object.defineProperty;
71
105
  var __returnValue = (v) => v;
@@ -95,146 +129,6 @@ function custom(spec) {
95
129
  ...spec.extension !== undefined ? { extension: spec.extension } : {}
96
130
  });
97
131
  }
98
- // src/dialects/pg/integer.ts
99
- function smallint() {
100
- return required({
101
- baseType: "smallint",
102
- encode: (value) => integerToken(value, -32768, 32767, "smallint"),
103
- decode: (wire) => decodeBounded(wire, -32768, 32767, "smallint"),
104
- sqlForm: "raw"
105
- });
106
- }
107
- function integer() {
108
- return required({
109
- baseType: "integer",
110
- encode: (value) => integerToken(value, -2147483648, 2147483647, "integer"),
111
- decode: (wire) => decodeBounded(wire, -2147483648, 2147483647, "integer"),
112
- sqlForm: "raw"
113
- });
114
- }
115
- function bigint(options) {
116
- const mode = options?.as ?? "string";
117
- if (mode === "number") {
118
- return required({
119
- baseType: "bigint",
120
- encode: encodeBigintNumber,
121
- decode: decodeBigintNumber,
122
- sqlForm: "raw",
123
- typeLabel: "number"
124
- });
125
- }
126
- if (mode === "bigint") {
127
- return required({
128
- baseType: "bigint",
129
- encode: encodeBigintValue,
130
- decode: decodeBigintValue,
131
- sqlForm: "raw",
132
- typeLabel: "bigint"
133
- });
134
- }
135
- if (mode !== "string") {
136
- definition(`bigint as ${String(mode)} must be string, number, or bigint.`);
137
- }
138
- return required({
139
- baseType: "bigint",
140
- encode: encodeBigintString,
141
- decode: decodeBigintString,
142
- sqlForm: "raw"
143
- });
144
- }
145
- function identity(options) {
146
- const mode = options?.as ?? "string";
147
- if (mode === "number") {
148
- return openColumn({
149
- ...identityFlags(),
150
- encode: encodeBigintNumber,
151
- decode: decodeBigintNumber,
152
- typeLabel: "number"
153
- });
154
- }
155
- if (mode === "bigint") {
156
- return openColumn({
157
- ...identityFlags(),
158
- encode: encodeBigintValue,
159
- decode: decodeBigintValue,
160
- typeLabel: "bigint"
161
- });
162
- }
163
- if (mode !== "string") {
164
- definition(`identity as ${String(mode)} must be string, number, or bigint.`);
165
- }
166
- return openColumn({
167
- ...identityFlags(),
168
- encode: encodeBigintString,
169
- decode: decodeBigintString
170
- });
171
- }
172
- function encodeBigintString(value) {
173
- parseBigint(value);
174
- return value;
175
- }
176
- function decodeBigintString(wire) {
177
- return encodeBigintString(wire);
178
- }
179
- function encodeBigintNumber(value) {
180
- if (!Number.isSafeInteger(value)) {
181
- rejected(`bigint number ${String(value)} must be an integer from ${String(Number.MIN_SAFE_INTEGER)} to ${String(Number.MAX_SAFE_INTEGER)}.`);
182
- }
183
- return String(value);
184
- }
185
- function decodeBigintNumber(wire) {
186
- const parsed = parseBigint(wire);
187
- const value = Number(parsed);
188
- if (!Number.isSafeInteger(value)) {
189
- rejected(`bigint ${wire} must be an integer from ${String(Number.MIN_SAFE_INTEGER)} to ${String(Number.MAX_SAFE_INTEGER)} when as is number.`);
190
- }
191
- return value;
192
- }
193
- function encodeBigintValue(value) {
194
- return value.toString();
195
- }
196
- function decodeBigintValue(wire) {
197
- return parseBigint(wire);
198
- }
199
- function integerToken(value, min, max, role) {
200
- if (!Number.isInteger(value) || value < min || value > max) {
201
- rejected(`${role} ${String(value)} must be an integer from ${String(min)} to ${String(max)}.`);
202
- }
203
- return String(value);
204
- }
205
- function decodeBounded(wire, min, max, role) {
206
- if (!integerText().test(wire)) {
207
- rejected(`${role} ${wire} must be an integer, for example 0 or -12.`);
208
- }
209
- const value = Number(wire);
210
- integerToken(value, min, max, role);
211
- return value;
212
- }
213
- function identityFlags() {
214
- return {
215
- baseType: "bigint",
216
- nullable: false,
217
- hasDefault: true,
218
- generated: false,
219
- guarded: false,
220
- hidden: false,
221
- omitWrite: true,
222
- sqlForm: "raw",
223
- identity: { always: true },
224
- primaryKey: true
225
- };
226
- }
227
- function parseBigint(wire) {
228
- if (!integerText().test(wire)) {
229
- rejected(`bigint ${wire} must be an integer with no leading zeros, for example 0 or -12.`);
230
- }
231
- return BigInt(wire);
232
- }
233
- function integerText() {
234
- integerPattern ??= /^-?(?:0|[1-9]\d*)$/;
235
- return integerPattern;
236
- }
237
- var integerPattern;
238
132
  // src/dialects/pg/finite.ts
239
133
  function decimalText(value, role) {
240
134
  if (!Number.isFinite(value)) {
@@ -761,11 +655,11 @@ function canonicalScalar(typeName) {
761
655
  // src/dialects/pg/namespace.ts
762
656
  var t = {
763
657
  id: id2,
764
- identity,
658
+ identity: identity2,
765
659
  uuid: uuid2,
766
- smallint,
767
- integer,
768
- bigint,
660
+ smallint: smallint2,
661
+ integer: integer2,
662
+ bigint: bigint2,
769
663
  numeric,
770
664
  real,
771
665
  double,
@@ -887,11 +781,11 @@ function like(pattern) {
887
781
  }
888
782
  // src/dialects/pg/ops/matches.ts
889
783
  function matches(query, options) {
890
- return tag("matches", {
891
- query,
892
- mode: options?.mode ?? "websearch",
893
- config: options?.config
894
- });
784
+ return tag("matches", searchValue(query, options));
785
+ }
786
+ // src/dialects/pg/ops/relevance.ts
787
+ function relevance(query, options) {
788
+ return tag("relevance", searchValue(query, options));
895
789
  }
896
790
  // src/dialects/pg/ops/lt.ts
897
791
  function lt(value) {
@@ -934,12 +828,371 @@ function path(segments, op) {
934
828
  function startsWith(value) {
935
829
  return tag("startsWith", value);
936
830
  }
831
+ // src/dialects/pg/ops/lane.ts
832
+ var LANE = Symbol.for("okm.lane");
833
+ var READ = "read";
834
+ var WRITE = "write";
835
+ var BLOCKED = new Set(["__proto__", "constructor", "toString", "hasOwnProperty"]);
836
+ async function raw(handle, cls, statement, source) {
837
+ const lane = readLane(handle);
838
+ const kind = readClass(statement);
839
+ const indexed = openTable(lane);
840
+ const parts = readParts(source);
841
+ const compiled = compile(indexed, parts);
842
+ const word = verb(compiled.text);
843
+ if (kind === READ && word !== "select") {
844
+ bad("A raw read starts with select.", 'Pass "read" and a single select. A leading with is a write.');
845
+ }
846
+ if (kind === WRITE && word !== "insert" && word !== "update" && word !== "delete") {
847
+ bad("A raw write starts with insert, update, or delete.", 'Pass "write" and one insert, update, or delete.');
848
+ }
849
+ const tenancy = predicateOf(lane.session, indexed);
850
+ if (kind === WRITE && tenancy !== undefined) {
851
+ unverifiable("A raw write on a tenant table cannot keep the tenant predicate.", 'Use update or delete. unscoped("reason") is the reviewed hatch.');
852
+ }
853
+ const guard = kind === READ ? guardOf(indexed, tenancy, compiled.params.length) : undefined;
854
+ if (guard !== undefined)
855
+ requireKey(indexed, lane.session.schema.tenancy?.key, parts);
856
+ const text = guard === undefined ? compiled.text : wrap(indexed, lane.session.schema.tenancy?.key, compiled.text, guard.text);
857
+ const params = guard === undefined ? compiled.params : [...compiled.params, ...guard.params];
858
+ await lane.session.connected;
859
+ try {
860
+ const result = await lane.session.pool.execute(text, params, kind === WRITE ? { route: "primary" } : undefined);
861
+ return decodeRows(cls, result.rows, indexed);
862
+ } catch (error) {
863
+ return raise(lane, error);
864
+ }
865
+ }
866
+ async function explain(handle, query) {
867
+ const lane = readLane(handle);
868
+ const got = readPlanned(await readSql(query));
869
+ if (production())
870
+ return { text: got.text, params: [], plan: null };
871
+ await lane.session.connected;
872
+ let rows;
873
+ try {
874
+ const result = await lane.session.pool.execute(`explain ${got.text}`, got.params);
875
+ rows = result.rows;
876
+ } catch (error) {
877
+ return raise(lane, error);
878
+ }
879
+ const plan = [];
880
+ for (const row of rows) {
881
+ const line = row[0];
882
+ if (typeof line === "string")
883
+ plan.push(line);
884
+ }
885
+ return { text: got.text, params: got.params, plan };
886
+ }
887
+ async function raise(lane, error) {
888
+ const mapped = await lane.fail(lane.session, error);
889
+ lane.session.logger?.error?.({ code: mapped.code, summary: mapped.summary });
890
+ throw mapped;
891
+ }
892
+ function production() {
893
+ const proc = Reflect.get(globalThis, "process");
894
+ if (typeof proc !== "object" || proc === null)
895
+ return false;
896
+ const env = Reflect.get(proc, "env");
897
+ if (typeof env !== "object" || env === null)
898
+ return false;
899
+ return Reflect.get(env, "NODE_ENV") === "production";
900
+ }
901
+ function readLane(handle) {
902
+ const value = Reflect.get(handle, LANE);
903
+ if (!Array.isArray(value)) {
904
+ bad("Pass the table handle.", "raw and explain take the table, such as db.notes, including a table from for().");
905
+ }
906
+ const session = value[0];
907
+ const table = value[1];
908
+ const fail = value[2];
909
+ if (typeof table !== "string" || typeof fail !== "function" || !isSession(session)) {
910
+ bad("Pass the table handle.", "raw and explain take the table, such as db.notes, including a table from for().");
911
+ }
912
+ return { session, table, fail };
913
+ }
914
+ function isSession(value) {
915
+ if (typeof value !== "object" || value === null)
916
+ return false;
917
+ const schema = Reflect.get(value, "schema");
918
+ const connected = Reflect.get(value, "connected");
919
+ const pool = Reflect.get(value, "pool");
920
+ if (typeof schema !== "object" || schema === null)
921
+ return false;
922
+ if (typeof Reflect.get(schema, "model") !== "object")
923
+ return false;
924
+ if (typeof connected !== "object" || connected === null || typeof Reflect.get(connected, "then") !== "function") {
925
+ return false;
926
+ }
927
+ return typeof pool === "object" && pool !== null && typeof Reflect.get(pool, "execute") === "function";
928
+ }
929
+ function readSql(query) {
930
+ const sql = Reflect.get(query, "sql");
931
+ if (typeof sql !== "function") {
932
+ bad("Pass a query.", "explain takes the table and a query from that table, such as notes.find({ limit: 1 }).");
933
+ }
934
+ return sql.call(query);
935
+ }
936
+ function readPlanned(value) {
937
+ if (typeof value !== "object" || value === null) {
938
+ bad("The statement has no text.", "Call explain on a query.");
939
+ }
940
+ const text = Reflect.get(value, "text");
941
+ const params = Reflect.get(value, "params");
942
+ if (typeof text !== "string" || !Array.isArray(params)) {
943
+ bad("The statement has no text.", "Call explain on a query.");
944
+ }
945
+ const bound = [];
946
+ for (const param of params) {
947
+ if (typeof param !== "string" && param !== null) {
948
+ bad("A statement parameter was not text.", "Parameters are bound text.");
949
+ }
950
+ bound.push(param);
951
+ }
952
+ return { text, params: bound };
953
+ }
954
+ function openTable(lane) {
955
+ const model = lane.session.schema.model[lane.table];
956
+ if (model === undefined) {
957
+ bad(`Table ${lane.table} is not in the schema.`, "Call raw on a table this schema declares.");
958
+ }
959
+ const columns = new Map;
960
+ const names = [];
961
+ for (const column of model.columns) {
962
+ columns.set(column.field, column);
963
+ names.push(column.field);
964
+ }
965
+ names.sort();
966
+ return { model, columns, names };
967
+ }
968
+ function compile(table, parts) {
969
+ const params = [];
970
+ const chunks = [];
971
+ let count = 0;
972
+ const sink = {
973
+ text(value) {
974
+ chunks.push(value);
975
+ },
976
+ param(encoded) {
977
+ params.push(encoded);
978
+ count += 1;
979
+ chunks.push(`$${String(count)}`);
980
+ },
981
+ mark() {}
982
+ };
983
+ for (const part of parts)
984
+ writePart(part, sink, table);
985
+ return { text: chunks.join(""), params };
986
+ }
987
+ function writePart(part, sink, table) {
988
+ if (part.k === "t") {
989
+ sink.text(part.s);
990
+ return;
991
+ }
992
+ if (part.k === "p") {
993
+ sink.param(part.v);
994
+ return;
995
+ }
996
+ if (part.k === "n") {
997
+ sink.text("null");
998
+ return;
999
+ }
1000
+ if (part.k === "i") {
1001
+ writeIdent(part.n, sink, table);
1002
+ return;
1003
+ }
1004
+ if (part.k === "c") {
1005
+ throw new OkmError2("OKM1125", "fragment.column belongs on a where field.", {
1006
+ fix: { summary: "Use ident(name) in a raw statement." }
1007
+ });
1008
+ }
1009
+ sink.text("(");
1010
+ for (const nested of part.parts)
1011
+ writePart(nested, sink, table);
1012
+ sink.text(")");
1013
+ }
1014
+ function writeIdent(name, sink, table) {
1015
+ const column = table.columns.get(name);
1016
+ if (column === undefined) {
1017
+ throwNamed2("OKM1120", name, table.names, `Field ${name} is not on ${table.model.name}. Accepted names: ${table.names.join(", ")}.`);
1018
+ }
1019
+ if (column.hidden) {
1020
+ throw new OkmError2("OKM1120", `Field ${column.field} is hidden.`, {
1021
+ fix: { summary: "A raw statement cannot name a hidden field." }
1022
+ });
1023
+ }
1024
+ sink.text(quoteIdent(column.sql));
1025
+ }
1026
+ function readClass(statement) {
1027
+ if (statement === READ || statement === WRITE)
1028
+ return statement;
1029
+ bad('The statement class is "read" or "write".', 'Pass "read" or "write".');
1030
+ }
1031
+ function readParts(source) {
1032
+ if (typeof source !== "object" || source === null) {
1033
+ bad("Pass fragment`...`.", "Identifiers are ident(name). A string, number, boolean, or null is a parameter.");
1034
+ }
1035
+ if (typeof Reflect.get(source, "as") === "string") {
1036
+ bad("Pass the fragment, not .as(name).", "The class names the row. Drop .as().");
1037
+ }
1038
+ if (!isOperator(source) || operatorName(source) !== "sql") {
1039
+ bad("Pass fragment`...`.", "Identifiers are ident(name). A string, number, boolean, or null is a parameter.");
1040
+ }
1041
+ const stored = operatorValue(source);
1042
+ if (!isFragmentParts(stored)) {
1043
+ bad("Pass fragment`...`.", "Call fragment`...`. Do not build the parts yourself.");
1044
+ }
1045
+ return stored;
1046
+ }
1047
+ function verb(text) {
1048
+ return /^[a-z]+/i.exec(text.trimStart())?.[0]?.toLowerCase() ?? "";
1049
+ }
1050
+ function predicateOf(session, table) {
1051
+ const tenancy = session.schema.tenancy;
1052
+ if (tenancy === undefined)
1053
+ return;
1054
+ const chunks = [];
1055
+ const params = [];
1056
+ let count = 0;
1057
+ const wrote = tenancy.predicate({
1058
+ table: table.model.name,
1059
+ fieldSql: (field) => table.columns.get(field)?.sql,
1060
+ encode: table.columns.get(tenancy.key)?.encode,
1061
+ alias: "okm_tenant",
1062
+ appended: false,
1063
+ scope: session.scope,
1064
+ sink: {
1065
+ text(value) {
1066
+ chunks.push(value);
1067
+ },
1068
+ param(encoded) {
1069
+ params.push(encoded);
1070
+ count += 1;
1071
+ chunks.push(`$${String(count)}`);
1072
+ },
1073
+ mark() {}
1074
+ }
1075
+ });
1076
+ if (!wrote)
1077
+ return;
1078
+ return { text: chunks.join("").replace(/^\s*where\s+/i, ""), params };
1079
+ }
1080
+ function guardOf(table, tenancy, userCount) {
1081
+ const archive = table.model.archive?.at;
1082
+ if (tenancy === undefined && archive === undefined)
1083
+ return;
1084
+ const parts = [];
1085
+ if (tenancy !== undefined)
1086
+ parts.push(shift(tenancy.text, userCount));
1087
+ if (archive !== undefined)
1088
+ parts.push(`okm_tenant.${quoteIdent(archive)} is null`);
1089
+ return { text: parts.join(" and "), params: tenancy?.params ?? [] };
1090
+ }
1091
+ function requireKey(table, tenantKey, parts) {
1092
+ const key = rowKey(table, tenantKey);
1093
+ if (key === undefined) {
1094
+ unverifiable("A raw read needs one primary key column besides the tenant key.", "Declare one primary key. The tenant predicate binds that column.");
1095
+ }
1096
+ if (!namesIdent(parts, key)) {
1097
+ unverifiable(`A raw read must select ${key} with ident.`, `Put ident("${key}") in the select list. Do not alias it. The tenant predicate is added outside the statement.`);
1098
+ }
1099
+ }
1100
+ function rowKey(table, tenantKey) {
1101
+ const keys = table.model.primary.filter((field) => field !== tenantKey);
1102
+ return keys.length === 1 ? keys[0] : undefined;
1103
+ }
1104
+ function namesIdent(parts, name) {
1105
+ for (const part of parts) {
1106
+ if (part.k === "i" && part.n === name)
1107
+ return true;
1108
+ if (part.k === "f" && namesIdent(part.parts, name))
1109
+ return true;
1110
+ }
1111
+ return false;
1112
+ }
1113
+ function wrap(table, tenantKey, text, where) {
1114
+ const key = rowKey(table, tenantKey);
1115
+ const column = key === undefined ? undefined : table.columns.get(key);
1116
+ if (column === undefined) {
1117
+ unverifiable("A raw read needs one primary key column besides the tenant key.", "Declare one primary key. The tenant predicate binds that column.");
1118
+ }
1119
+ const quoted = quoteIdent(column.sql);
1120
+ return `select okm_raw.* from (${text}) as okm_raw where okm_raw.${quoted} in (select ${quoted} from ${quoteIdent(table.model.sql)} as okm_tenant where ${where})`;
1121
+ }
1122
+ function shift(text, by) {
1123
+ if (by === 0)
1124
+ return text;
1125
+ return text.replace(/\$(\d+)/g, (_match, digits) => `$${String(Number(digits) + by)}`);
1126
+ }
1127
+ function decodeRows(cls, rows, table) {
1128
+ const ctor = readClassCtor(cls);
1129
+ const sample = construct(ctor);
1130
+ const keys = Object.keys(sample);
1131
+ if (keys.length === 0) {
1132
+ bad("The class needs an initializer on every result column.", 'Write `id = ""` or `n = 0`. The initializer selects the decode, and the order is the select list.');
1133
+ }
1134
+ for (const key of keys) {
1135
+ if (BLOCKED.has(key))
1136
+ bad(`Field ${key} is reserved.`, "Rename the class field.");
1137
+ }
1138
+ return rows.map((wire) => {
1139
+ const row = construct(ctor);
1140
+ for (let index = 0;index < keys.length; index += 1) {
1141
+ const key = keys[index];
1142
+ if (key === undefined)
1143
+ continue;
1144
+ Reflect.set(row, key, decodeWire(wire[index], Reflect.get(sample, key), table.columns.get(key)));
1145
+ }
1146
+ return row;
1147
+ });
1148
+ }
1149
+ function readClassCtor(cls) {
1150
+ if (typeof cls !== "function") {
1151
+ bad("Pass a class.", "The result of raw is one instance of that class per row.");
1152
+ }
1153
+ return cls;
1154
+ }
1155
+ function construct(ctor) {
1156
+ try {
1157
+ return new ctor;
1158
+ } catch {
1159
+ bad("The class must construct with no arguments.", "Give each field an initializer and no constructor arguments.");
1160
+ }
1161
+ }
1162
+ function decodeWire(wire, sample, column) {
1163
+ if (wire === null || wire === undefined)
1164
+ return null;
1165
+ if (column !== undefined)
1166
+ return column.decode === undefined ? wire : column.decode(wire);
1167
+ if (typeof sample === "number") {
1168
+ const parsed = Number(wire);
1169
+ if (!Number.isFinite(parsed)) {
1170
+ bad("A class field initialized with a number received a non-numeric value.", "Use a numeric expression, or initialize the field with a string.");
1171
+ }
1172
+ return parsed;
1173
+ }
1174
+ if (typeof sample === "boolean") {
1175
+ if (wire === "t" || wire === "true" || wire === "1")
1176
+ return true;
1177
+ if (wire === "f" || wire === "false" || wire === "0")
1178
+ return false;
1179
+ bad("A class field initialized with a boolean received another value.", "Use a boolean expression, or initialize the field with a string.");
1180
+ }
1181
+ return wire;
1182
+ }
1183
+ function bad(message, fix) {
1184
+ throw new OkmError2("OKM1602", message, { fix: { summary: fix } });
1185
+ }
1186
+ function unverifiable(message, fix) {
1187
+ throw new OkmError2("OKM1702", message, { fix: { summary: fix } });
1188
+ }
937
1189
  export {
938
1190
  ColumnBuilder2 as ColumnBuilder,
939
1191
  exports_arr_ns as arr,
940
1192
  between,
941
- bigint,
1193
+ bigint2 as bigint,
942
1194
  boolean,
1195
+ bucket2 as bucket,
943
1196
  bytea,
944
1197
  char2 as char,
945
1198
  cidr,
@@ -949,19 +1202,23 @@ export {
949
1202
  custom,
950
1203
  date2 as date,
951
1204
  daterange,
1205
+ denseRank2 as denseRank,
952
1206
  domain,
953
1207
  double,
954
1208
  endsWith,
955
1209
  enumColumn as enum,
956
1210
  eq,
957
1211
  every,
1212
+ explain,
1213
+ fragment2 as fragment,
958
1214
  gt,
959
1215
  gte,
960
1216
  has,
961
1217
  hasAnyKey,
962
1218
  hasKey,
963
1219
  id2 as id,
964
- identity,
1220
+ ident2 as ident,
1221
+ identity2 as identity,
965
1222
  ilike,
966
1223
  inList,
967
1224
  inc,
@@ -969,7 +1226,7 @@ export {
969
1226
  inet,
970
1227
  int4range,
971
1228
  int8range,
972
- integer,
1229
+ integer2 as integer,
973
1230
  interval2 as interval,
974
1231
  exports_json_ns as json,
975
1232
  jsonReplacer2 as jsonReplacer,
@@ -984,6 +1241,9 @@ export {
984
1241
  many2 as many,
985
1242
  manyThrough2 as manyThrough,
986
1243
  matches,
1244
+ morph2 as morph,
1245
+ morphMany2 as morphMany,
1246
+ morphTo2 as morphTo,
987
1247
  none,
988
1248
  not,
989
1249
  notIn,
@@ -994,9 +1254,14 @@ export {
994
1254
  overlaps,
995
1255
  path,
996
1256
  point,
1257
+ rank2 as rank,
1258
+ raw,
997
1259
  real,
1260
+ relevance,
1261
+ rowNumber2 as rowNumber,
1262
+ runningTotal2 as runningTotal,
998
1263
  schema2 as schema,
999
- smallint,
1264
+ smallint2 as smallint,
1000
1265
  sql2 as sql,
1001
1266
  startsWith,
1002
1267
  t,