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
@@ -24,8 +24,10 @@ export declare function isConnectionErrno(code: string): boolean;
24
24
  /**
25
25
  * Reports whether `error` is a dropped or refused connection.
26
26
  *
27
- * Constraint failures are not connection failures. `23505` stays a unique
28
- * violation even when it is raised at commit.
27
+ * The decision is a driver `code` ({@link isConnectionErrno}, including
28
+ * `CONNECT_TIMEOUT`, or `ERR_POSTGRES_CONNECTION_CLOSED`) or a SQLSTATE in
29
+ * class `08` or `57P01`–`57P03`. A server SQLSTATE outside that set is never
30
+ * a lost connection. Message text is not read.
29
31
  *
30
32
  * @param error - Caught value
31
33
  * @returns `true` when no session remains
@@ -35,10 +37,9 @@ export declare function isConnectionFailure(error: unknown): boolean;
35
37
  * Reports whether the connection is gone after `error`, or the outcome of a
36
38
  * statement on it is unknown (`outcome_unknown`).
37
39
  *
38
- * It reads what {@link isConnectionFailure} reads, plus the messages node-postgres
39
- * ("Connection terminated unexpectedly") and Bun.sql (`ERR_POSTGRES_CONNECTION_CLOSED`)
40
- * give, and the error's `cause`. Nothing more should be sent to such a connection:
41
- * not a rollback, not a reset. Loaded with the code that reserves a connection.
40
+ * It reads what {@link isConnectionFailure} reads, and the error's `cause`.
41
+ * Nothing more should be sent to such a connection: not a rollback, not a
42
+ * reset. Loaded with the code that reserves a connection.
42
43
  *
43
44
  * @param error - Caught value
44
45
  * @returns `true` when the session cannot be used again
@@ -31,7 +31,7 @@ export type ColumnCode = (typeof COLUMN_CODES)[number];
31
31
  * These are spec §21 codes. They are a type only, so the runtime entry does
32
32
  * not gain a second registry.
33
33
  */
34
- export type QueryCode = "OKM1101" | "OKM1102" | "OKM1104" | "OKM1105" | "OKM1111" | "OKM1120" | "OKM1121" | "OKM1124" | "OKM1130" | "OKM1190" | "OKM1701" | "OKM1704" | "OKM1801" | "OKM1802" | "OKM1803" | "OKM1843";
34
+ export type QueryCode = "OKM1101" | "OKM1102" | "OKM1104" | "OKM1105" | "OKM1111" | "OKM1120" | "OKM1121" | "OKM1124" | "OKM1125" | "OKM1130" | "OKM1190" | "OKM1701" | "OKM1704" | "OKM1801" | "OKM1802" | "OKM1803" | "OKM1843";
35
35
  /** Kinds from spec §14, in category order. */
36
36
  export declare const ERROR_KINDS: readonly ["invalid", "not_null", "check", "foreign_key", "unique", "exclusion", "conflict", "not_found", "not_unique", "forbidden", "serialization", "deadlock", "lock_timeout", "timeout", "cancelled", "unavailable", "schema_drift", "driver", "read_only", "outcome_unknown"];
37
37
  /** One spec §14 kind. */
@@ -0,0 +1,68 @@
1
+ /**
2
+ * Postgres majors a schema may name, and the features that read them.
3
+ *
4
+ * 15–18 are the majors okmodel runs. A major outside that range is refused
5
+ * when `schema()` runs. Messages read these numbers. They do not repeat them.
6
+ */
7
+ /** Majors `minPostgres` and `requires.postgres` accept, oldest first. */
8
+ export declare const POSTGRES_MAJORS: readonly [15, 16, 17, 18];
9
+ /** A major {@link POSTGRES_MAJORS} allows. */
10
+ export type PostgresMajor = (typeof POSTGRES_MAJORS)[number];
11
+ /**
12
+ * Oldest major connect accepts when the schema names no floor.
13
+ *
14
+ * A server below this is OKM1803.
15
+ */
16
+ export declare const POSTGRES_FLOOR = 15;
17
+ /**
18
+ * `uuidv7()` database default.
19
+ *
20
+ * Add the next feature constant beside this one, and name it on the minPostgres page.
21
+ */
22
+ export declare const UUIDV7_POSTGRES = 18;
23
+ /**
24
+ * Accepts a major from {@link POSTGRES_MAJORS}.
25
+ *
26
+ * @param value - Candidate from schema input
27
+ * @returns Whether `value` is 15, 16, 17, or 18
28
+ */
29
+ export declare function isPostgresMajor(value: unknown): value is PostgresMajor;
30
+ /**
31
+ * Reads a stored `>=N` floor.
32
+ *
33
+ * `readFloor`, `refuseUuidV7`, and `acceptServer` share this parse.
34
+ *
35
+ * @param postgres - Stored or input range
36
+ * @returns The major, or `NaN` when the text is not `>=` plus digits
37
+ */
38
+ export declare function parsePostgresFloor(postgres: string | undefined): number;
39
+ /**
40
+ * Stores a major as `>=N`.
41
+ *
42
+ * @param major - Allowed major
43
+ * @returns The stored floor text
44
+ */
45
+ export declare function formatPostgresFloor(major: number): string;
46
+ /**
47
+ * Definition error for a floor outside 15–18.
48
+ *
49
+ * @returns OKM1060 message
50
+ */
51
+ export declare function minPostgresDefinition(): string;
52
+ /**
53
+ * Sentence for a `uuidv7()` default the declared floor does not allow.
54
+ *
55
+ * @returns The OKM1812 message
56
+ */
57
+ export declare function uuidv7NeedsPostgres(): string;
58
+ /**
59
+ * Connect refusal when the server is below the schema floor.
60
+ *
61
+ * OKM1802 and OKM1803 share this sentence. OKM1803 passes {@link POSTGRES_FLOOR}.
62
+ * Loaded with the connect check, not with `schema()`.
63
+ *
64
+ * @param server - Major the server reported
65
+ * @param need - Major the schema requires
66
+ * @returns The message
67
+ */
68
+ export declare function serverNeedsPostgres(server: number, need: number): string;
@@ -5,12 +5,46 @@
5
5
  * records. `schema()` only asks each declared object for those records.
6
6
  */
7
7
  import type { CatalogObject, FunctionLanguage, FunctionSecurity, FunctionVolatility, TriggerEvent, TriggerLevel, TriggerTiming } from "../../../contracts/catalog/types.js";
8
+ import { type FragmentIdent } from "../ops/fragment.js";
9
+ import { type Eq } from "../operators.js";
10
+ import type { Window } from "../ops/window.js";
8
11
  import type { AnyTable, SqlText } from "../table.js";
9
12
  /** One argument of {@link fn}. */
10
13
  export type FunctionArgumentInput = {
11
14
  readonly name: string;
12
15
  readonly type: string;
13
16
  };
17
+ /** Postgres types that bind as a number. Anything else binds as text. */
18
+ type NumericReturn = "smallint" | "integer" | "bigint" | "int2" | "int4" | "int8" | "real" | "double precision" | "float4" | "float8" | "numeric";
19
+ /** A select name for {@link FnCall.as}. Numeric returns are numbers. Text stays text. */
20
+ type CallAs<R extends string, A extends string> = R extends NumericReturn | `numeric${string}` ? Window<A, number> : Window<A, string>;
21
+ /**
22
+ * A typed call.
23
+ *
24
+ * It is a `sql` fragment, so `where` accepts it as {@link Eq}. `.as(name)` is
25
+ * the `select` form. `orderBy` does not: adding the call to that union is one
26
+ * composite type over the ceiling.
27
+ *
28
+ * @typeParam R - Declared return type
29
+ */
30
+ export type FnCall<R extends string = string> = Eq<never> & {
31
+ /**
32
+ * Names the select result.
33
+ *
34
+ * @typeParam A - Result key
35
+ * @param name - Result key. Not a column name
36
+ * @returns A select entry
37
+ */
38
+ as<const A extends string>(name: A): CallAs<R, A>;
39
+ };
40
+ /** One argument value. `ident` names a field. Null is SQL null. */
41
+ type CallValue<T extends string> = T extends "boolean" | "bool" ? boolean | FragmentIdent | null : T extends NumericReturn | `numeric${string}` ? number | FragmentIdent | null : string | FragmentIdent | null;
42
+ /** Argument list of a call, in declaration order. */
43
+ type CallArgs<A extends readonly FunctionArgumentInput[]> = {
44
+ [I in keyof A]: A[I] extends FunctionArgumentInput ? CallValue<A[I]["type"]> : never;
45
+ };
46
+ /** `fn.slugify(col)`. The value is {@link FnCall}. */
47
+ type FnCaller<A extends readonly FunctionArgumentInput[], R extends string> = (...args: CallArgs<A>) => FnCall<R>;
14
48
  /**
15
49
  * A table, or one column of a table.
16
50
  *
@@ -96,7 +130,10 @@ export type TriggerDeclaration = {
96
130
  * @param options - Signature, language, body, and dependencies
97
131
  * @returns The definition object `schema({ functions })` stores
98
132
  */
99
- export declare function fn(name: string, options: FunctionOptions): Routine;
133
+ export declare function fn<const A extends readonly FunctionArgumentInput[] = readonly [], const R extends string = string>(name: string, options: FunctionOptions & {
134
+ readonly arguments?: A;
135
+ readonly returns: R;
136
+ }): Routine & FnCaller<A, R>;
100
137
  /**
101
138
  * Declares a trigger.
102
139
  *
@@ -105,3 +142,4 @@ export declare function fn(name: string, options: FunctionOptions): Routine;
105
142
  * @returns The definition object `schema({ triggers })` stores
106
143
  */
107
144
  export declare function trigger(name: string, options: TriggerOptions): TriggerDeclaration;
145
+ export {};
@@ -1,10 +1,23 @@
1
1
  import {
2
2
  functionObject,
3
3
  triggerObject
4
- } from "../../../shared/y34a8714.js";
4
+ } from "../../../shared/12z7aznj.js";
5
+ import {
6
+ isFragmentParts,
7
+ sqlExpression,
8
+ identName
9
+ } from "../../../shared/bsek72fg.js";
10
+ import {
11
+ quoteIdent
12
+ } from "../../../shared/sjk86yrx.js";
5
13
  import {
6
14
  staticNamespace2
7
15
  } from "../../../shared/358zsv4r.js";
16
+ import {
17
+ isOperator,
18
+ operatorName,
19
+ operatorValue
20
+ } from "../../../shared/cn0n68ft.js";
8
21
  import {
9
22
  assertIdentifier2
10
23
  } from "../../../shared/nfzc5z0w.js";
@@ -36,32 +49,111 @@ function fn(name, options) {
36
49
  }
37
50
  const argTypes = (options.arguments ?? []).map((argument) => argument.type);
38
51
  const schema = options.schema ?? "public";
39
- return {
40
- name,
41
- schema,
42
- argTypes,
43
- contribute(peers, built) {
44
- assertPeers(peers, "functions");
45
- const namespace = staticNamespace2(schema);
46
- const provenance = { origin: "file", name };
47
- return [
48
- functionObject({
49
- namespace,
50
- name,
51
- ...options.arguments !== undefined ? { arguments: options.arguments } : {},
52
- returns: options.returns,
53
- language,
54
- ...options.volatility !== undefined ? { volatility: options.volatility } : {},
55
- ...options.security !== undefined ? { security: options.security } : {},
56
- ...options.searchPath !== undefined ? { searchPath: options.searchPath } : {},
57
- body,
58
- ...atomic ? { atomic: true } : {},
59
- provenance,
60
- dependencies: dependencyEdges(options.dependsOn, built)
61
- })
62
- ];
63
- }
52
+ const declared = options.arguments ?? [];
53
+ const contribute = (peers, built) => {
54
+ assertPeers(peers, "functions");
55
+ const namespace = staticNamespace2(schema);
56
+ const provenance = { origin: "file", name };
57
+ return [
58
+ functionObject({
59
+ namespace,
60
+ name,
61
+ ...options.arguments !== undefined ? { arguments: options.arguments } : {},
62
+ returns: options.returns,
63
+ language,
64
+ ...options.volatility !== undefined ? { volatility: options.volatility } : {},
65
+ ...options.security !== undefined ? { security: options.security } : {},
66
+ ...options.searchPath !== undefined ? { searchPath: options.searchPath } : {},
67
+ body,
68
+ ...atomic ? { atomic: true } : {},
69
+ provenance,
70
+ dependencies: dependencyEdges(options.dependsOn, built)
71
+ })
72
+ ];
64
73
  };
74
+ const call = (...args) => invoke(schema, name, declared, options.returns, args);
75
+ define(call, "name", name);
76
+ define(call, "schema", schema);
77
+ define(call, "argTypes", argTypes);
78
+ define(call, "contribute", contribute);
79
+ return call;
80
+ }
81
+ function define(target, key, value) {
82
+ Object.defineProperty(target, key, {
83
+ value,
84
+ enumerable: true,
85
+ writable: true,
86
+ configurable: true
87
+ });
88
+ }
89
+ var NUMERIC_RETURNS = new Set([
90
+ "smallint",
91
+ "integer",
92
+ "bigint",
93
+ "int2",
94
+ "int4",
95
+ "int8",
96
+ "real",
97
+ "double precision",
98
+ "float4",
99
+ "float8",
100
+ "numeric"
101
+ ]);
102
+ function invoke(schemaName, name, declared, returns, args) {
103
+ if (args.length !== declared.length) {
104
+ throw new OkmError2("OKM1120", `Function ${name} expects ${String(declared.length)} arguments.`, { fix: { summary: "Pass one value for each declared argument, in order." } });
105
+ }
106
+ const parts = [{ k: "t", s: `${quoteIdent(schemaName)}.${quoteIdent(name)}(` }];
107
+ for (let index = 0;index < args.length; index += 1) {
108
+ if (index > 0)
109
+ parts.push({ k: "t", s: ", " });
110
+ appendArg(parts, args[index], name);
111
+ }
112
+ parts.push({ k: "t", s: ")" });
113
+ const textual = !(NUMERIC_RETURNS.has(returns) || returns.startsWith("numeric("));
114
+ return sqlExpression(parts, textual);
115
+ }
116
+ function appendArg(parts, value, name) {
117
+ if (value === null) {
118
+ parts.push({ k: "n" });
119
+ return;
120
+ }
121
+ if (typeof value === "string" || typeof value === "boolean") {
122
+ parts.push({ k: "p", v: String(value) });
123
+ return;
124
+ }
125
+ if (typeof value === "number") {
126
+ if (!Number.isFinite(value)) {
127
+ throw new OkmError2("OKM1120", `Function ${name} needs a finite number.`, {
128
+ fix: { summary: "Pass a finite number, or leave it out." }
129
+ });
130
+ }
131
+ parts.push({ k: "p", v: String(value) });
132
+ return;
133
+ }
134
+ const field = identName(value);
135
+ if (field !== undefined) {
136
+ parts.push({ k: "i", n: field });
137
+ return;
138
+ }
139
+ if (isOperator(value) && operatorName(value) === "sql") {
140
+ const stored = operatorValue(value);
141
+ if (isFragmentParts(stored)) {
142
+ parts.push({ k: "f", parts: stored });
143
+ return;
144
+ }
145
+ }
146
+ if (isHandle(value)) {
147
+ assertIdentifier2(value.name, `function ${name}`);
148
+ parts.push({ k: "i", n: value.name });
149
+ return;
150
+ }
151
+ throw new OkmError2("OKM1121", `Function ${name} received a value it cannot bind.`, {
152
+ fix: { summary: "Pass a string, number, boolean, null, or ident(field)." }
153
+ });
154
+ }
155
+ function isHandle(value) {
156
+ return typeof value === "object" && value !== null && "name" in value && typeof value.name === "string" && value.name.length > 0 && !isOperator(value);
65
157
  }
66
158
  function trigger(name, options) {
67
159
  return {
@@ -4,6 +4,7 @@
4
4
  * Column types, codecs, picklists, `table()`, and `schema()`.
5
5
  * Each builder is a separate export so a bundle can keep only the ones it calls.
6
6
  */
7
+ export { type PostgresMajor } from "./floor.js";
7
8
  export { schema, type BuiltSchema, type SchemaCodecs, type SchemaInput, type SchemaRequires, } from "./schema.js";
8
9
  export { withOwner, type DeclaredOwner } from "./owner.js";
9
10
  export { index, sql, table, type AnyTable, type ColumnHandle, type IndexCall, type SqlText, type SqlValue, type FilterOperator, type Table, type TableOptions, } from "./table.js";
@@ -27,6 +28,8 @@ export { domain, enumColumn as enum } from "./enum.js";
27
28
  export { t } from "./namespace.js";
28
29
  export * as arr from "./ops/arr-ns.js";
29
30
  export * as json from "./ops/json-ns.js";
31
+ export { bucket, type Bucket, type BucketUnit, type WeekStart } from "./ops/bucket.js";
32
+ export { denseRank, rank, rowNumber, runningTotal, type Window, type WindowOrder, } from "./ops/window.js";
30
33
  export { between } from "./ops/between.js";
31
34
  export { containedBy } from "./ops/containedBy.js";
32
35
  export { contains } from "./ops/contains.js";
@@ -43,6 +46,8 @@ export { ilike } from "./ops/ilike.js";
43
46
  export { inList } from "./ops/inList.js";
44
47
  export { like } from "./ops/like.js";
45
48
  export { matches } from "./ops/matches.js";
49
+ export { relevance } from "./ops/relevance.js";
50
+ export type { SearchMatch } from "./operators.js";
46
51
  export { lt } from "./ops/lt.js";
47
52
  export { lte } from "./ops/lte.js";
48
53
  export { none } from "./ops/none.js";
@@ -52,4 +57,6 @@ export { or } from "./ops/or.js";
52
57
  export { overlaps } from "./ops/overlaps.js";
53
58
  export { path } from "./ops/path.js";
54
59
  export { startsWith } from "./ops/startsWith.js";
55
- export { many, manyThrough, one, type ManyRelation, type ManyThroughRelation, type OneRelation, type RelationCall, } from "./relations.js";
60
+ export { fragment, ident, type Fragment } from "./ops/fragment.js";
61
+ export { explain, raw, type ExplainResult } from "./ops/lane.js";
62
+ export { many, manyThrough, morph, morphMany, morphTo, one, type ManyRelation, type ManyThroughRelation, type MorphManyRelation, type MorphRelation, type OneRelation, type RelationCall, } from "./relations.js";