okmodel 0.8.0 → 0.9.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (237) hide show
  1. package/README.md +23 -1
  2. package/dist/adapters/pg/bunsql-extra.d.ts +5 -5
  3. package/dist/adapters/pg/bunsql.d.ts +6 -2
  4. package/dist/adapters/pg/nodepostgres.d.ts +16 -1
  5. package/dist/adapters/pg/postgres-extra.d.ts +3 -17
  6. package/dist/adapters/pg/postgresjs.d.ts +2 -1
  7. package/dist/contracts/driver.d.ts +3 -2
  8. package/dist/contracts/error.d.ts +1 -1
  9. package/dist/dialects/pg/errors.d.ts +2 -0
  10. package/dist/dialects/pg/ext/btree-gin.d.ts +26 -0
  11. package/dist/dialects/pg/ext/btree-gin.js +20 -0
  12. package/dist/dialects/pg/ext/btree-gist.d.ts +26 -0
  13. package/dist/dialects/pg/ext/btree-gist.js +20 -0
  14. package/dist/dialects/pg/ext/call.d.ts +53 -0
  15. package/dist/dialects/pg/ext/citext.js +1 -1
  16. package/dist/dialects/pg/ext/feature.d.ts +26 -0
  17. package/dist/dialects/pg/ext/fuzzystrmatch.d.ts +34 -0
  18. package/dist/dialects/pg/ext/fuzzystrmatch.js +33 -0
  19. package/dist/dialects/pg/ext/hstore.d.ts +41 -0
  20. package/dist/dialects/pg/ext/hstore.js +29 -0
  21. package/dist/dialects/pg/ext/index.d.ts +56 -0
  22. package/dist/dialects/pg/ext/index.js +1 -1
  23. package/dist/dialects/pg/ext/ltree.d.ts +41 -0
  24. package/dist/dialects/pg/ext/ltree.js +29 -0
  25. package/dist/dialects/pg/ext/pg-trgm.js +4 -13
  26. package/dist/dialects/pg/ext/pgcrypto.d.ts +33 -0
  27. package/dist/dialects/pg/ext/pgcrypto.js +33 -0
  28. package/dist/dialects/pg/ext/unaccent.d.ts +26 -0
  29. package/dist/dialects/pg/ext/unaccent.js +21 -0
  30. package/dist/dialects/pg/ext/using.d.ts +23 -0
  31. package/dist/dialects/pg/ext/versions.d.ts +36 -0
  32. package/dist/dialects/pg/external.d.ts +19 -0
  33. package/dist/dialects/pg/filters.d.ts +2 -2
  34. package/dist/dialects/pg/fn/index.js +5 -5
  35. package/dist/dialects/pg/index.d.ts +1 -0
  36. package/dist/dialects/pg/index.js +19 -14
  37. package/dist/dialects/pg/introspect.d.ts +12 -0
  38. package/dist/dialects/pg/view/index.js +7 -7
  39. package/dist/dialects/pg/view/scratch.d.ts +4 -1
  40. package/dist/runtime/artifact-file.d.ts +22 -0
  41. package/dist/runtime/client.d.ts +10 -0
  42. package/dist/runtime/drift-detail.d.ts +2 -1
  43. package/dist/runtime/drift.d.ts +3 -10
  44. package/dist/runtime/param-limit.d.ts +20 -0
  45. package/dist/runtime/pg/bun.js +4 -4
  46. package/dist/runtime/pg/neon.js +4 -4
  47. package/dist/runtime/pg/pg.js +4 -4
  48. package/dist/runtime/pg/pglite.js +4 -4
  49. package/dist/runtime/pg/postgresjs.js +11 -11
  50. package/dist/runtime/server-check.d.ts +36 -6
  51. package/dist/runtime/tenancy/index.js +1 -1
  52. package/dist/runtime/traits/index.js +6 -6
  53. package/dist/runtime/validate/index.js +2 -2
  54. package/dist/runtime/write.d.ts +1 -1
  55. package/dist/shared/{4m6hskg8.js → 0j6qe91y.js} +4 -4
  56. package/dist/shared/{6m78c8ss.js → 1h5h1rf5.js} +1 -1
  57. package/dist/shared/{4vbf83xx.js → 2vcnpf0n.js} +1 -1
  58. package/dist/shared/{qd9hhd8f.js → 3ap5hxvj.js} +2 -1
  59. package/dist/shared/{v1wad97q.js → 3d7a80fq.js} +1 -1
  60. package/dist/shared/{wcrheftc.js → 3dr444ny.js} +58 -79
  61. package/dist/shared/{hm5f8jby.js → 3vvpcphd.js} +8 -7
  62. package/dist/shared/{760ppr76.js → 4a3mmhhe.js} +2 -2
  63. package/dist/shared/{mkrn359n.js → 4pkz5nvw.js} +222 -39
  64. package/dist/shared/{agsfb86s.js → 4te76xc5.js} +4 -4
  65. package/dist/shared/{63f4ksbz.js → 60y4ahmw.js} +1 -1
  66. package/dist/shared/61bmrmhr.js +35 -0
  67. package/dist/shared/{bxas03mq.js → 63qjmhnp.js} +100 -17
  68. package/dist/shared/{g5yc06ka.js → 67w3kn71.js} +1 -1
  69. package/dist/shared/{jgqj11w4.js → 6f0z3hzh.js} +4 -0
  70. package/dist/shared/{njga14v4.js → 6vfvsdkt.js} +10 -8
  71. package/dist/shared/{kj9d8maq.js → 6xqvesa5.js} +1 -1
  72. package/dist/shared/8gdbty5v.js +665 -0
  73. package/dist/shared/{pan0370z.js → 8ma6drzr.js} +211 -30
  74. package/dist/shared/{mnvjvqyp.js → 8p2bgye0.js} +124 -32
  75. package/dist/shared/{mfedzr74.js → 8qwqrxed.js} +14 -6
  76. package/dist/shared/{hfqmpasr.js → 8v7vzpgt.js} +11 -8
  77. package/dist/shared/{7ghwamrf.js → 99qp9vtg.js} +1 -1
  78. package/dist/shared/{zgex00fd.js → ak61ye1f.js} +5 -5
  79. package/dist/shared/{dpc2r7rb.js → bdekbvmt.js} +218 -95
  80. package/dist/shared/{jebgrkeq.js → bxjq6xqv.js} +2 -2
  81. package/dist/shared/c7dqd3gk.js +1806 -0
  82. package/dist/shared/ddh72ym5.js +20 -0
  83. package/dist/shared/e1c55v04.js +10 -0
  84. package/dist/shared/{mtw6jz76.js → e275q7sd.js} +1 -1
  85. package/dist/shared/{k86n8vq3.js → ekhq3ytz.js} +1 -1
  86. package/dist/shared/esy4dyxe.js +17 -0
  87. package/dist/shared/{gcefca6p.js → f9t9g54z.js} +22 -9
  88. package/dist/shared/{sjk86yrx.js → fk9vef30.js} +84 -73
  89. package/dist/shared/fkjne6gx.js +8 -0
  90. package/dist/shared/{e8zyaqvj.js → fne90dvz.js} +4 -1
  91. package/dist/shared/{needfe47.js → g89fmz5s.js} +1 -1
  92. package/dist/shared/{m4xff2a6.js → ghqzdp94.js} +2 -2
  93. package/dist/shared/{n0jmpgj1.js → gr9sn4za.js} +1 -1
  94. package/dist/shared/{5mtf6cj3.js → gzgfsspx.js} +5 -2
  95. package/dist/shared/h9811jjm.js +17 -0
  96. package/dist/shared/{z581d7ny.js → hgt69zjf.js} +2 -2
  97. package/dist/shared/{35q0n9tz.js → jvxcp1qk.js} +71 -87
  98. package/dist/shared/k73e8n9d.js +136 -0
  99. package/dist/shared/{195pzzzz.js → kzgrcy8s.js} +12 -8
  100. package/dist/shared/kzgrnckd.js +29 -0
  101. package/dist/shared/{p3xbdcvt.js → mz48rs74.js} +68 -8
  102. package/dist/shared/{zbqbmmrp.js → n6je5b28.js} +13 -26
  103. package/dist/shared/{b6d6p0zc.js → ns35jqz0.js} +75 -49
  104. package/dist/shared/{n05z9nwz.js → nstwgzn8.js} +1 -1
  105. package/dist/{tooling/shared/08kemxjd.js → shared/pgsak1yw.js} +1 -1
  106. package/dist/shared/py2zrrm6.js +451 -0
  107. package/dist/shared/{9dr2qnx7.js → qqm3ze6q.js} +1 -1
  108. package/dist/shared/{wvdjznah.js → rcjm0yn7.js} +31 -38
  109. package/dist/shared/rged92v6.js +17 -0
  110. package/dist/shared/{jp36k7dp.js → rw4tpcd0.js} +81 -51
  111. package/dist/shared/{bsek72fg.js → s5qe47a6.js} +3 -0
  112. package/dist/shared/{1d9q9cv2.js → smxzjz60.js} +2 -2
  113. package/dist/shared/{wz2a78mp.js → th5rnaxw.js} +1 -1
  114. package/dist/{tooling/shared/rs1jb051.js → shared/tr64w5p0.js} +1 -1
  115. package/dist/shared/{14x60fbf.js → tyqapcgk.js} +73 -10
  116. package/dist/shared/vsna85qf.js +8 -0
  117. package/dist/shared/{63qtkrca.js → vy47ryqa.js} +55 -5
  118. package/dist/shared/{jx2m62cs.js → wbdh9qbg.js} +7 -5
  119. package/dist/shared/{f4jy1j7x.js → wp7y8q3y.js} +946 -105
  120. package/dist/shared/{16kvjebh.js → xbd9xs6p.js} +7 -26
  121. package/dist/shared/{bah9nbg3.js → xbvz446k.js} +18 -23
  122. package/dist/shared/{p5nh3r8q.js → y6tfjk9q.js} +2 -2
  123. package/dist/shared/{3bb7wsqt.js → ycnft340.js} +1 -1
  124. package/dist/shared/{z7s6fpxv.js → ymenf259.js} +1 -1
  125. package/dist/shared/{0wrea3jq.js → ysdw2fg3.js} +10 -2
  126. package/dist/shared/zecrwdk9.js +61 -0
  127. package/dist/shared/{3t6kw83m.js → zm2rzqba.js} +2 -1
  128. package/dist/tooling/cli.js +200 -50
  129. package/dist/tooling/driver-run.js +109 -343
  130. package/dist/tooling/github/comment.d.ts +56 -0
  131. package/dist/tooling/github/post-comment.d.ts +17 -0
  132. package/dist/tooling/migrate/apply.d.ts +17 -2
  133. package/dist/tooling/migrate/commands.d.ts +2 -1
  134. package/dist/tooling/migrate/config.d.ts +13 -0
  135. package/dist/tooling/migrate/drift.d.ts +12 -0
  136. package/dist/tooling/migrate/driver-url.d.ts +17 -0
  137. package/dist/tooling/migrate/export.d.ts +165 -0
  138. package/dist/tooling/migrate/ext-surface.d.ts +80 -0
  139. package/dist/tooling/migrate/ext.d.ts +31 -4
  140. package/dist/tooling/migrate/import-drizzle.d.ts +40 -0
  141. package/dist/tooling/migrate/index.d.ts +3 -0
  142. package/dist/tooling/migrate/index.js +57 -10
  143. package/dist/tooling/migrate/lint-rules.d.ts +18 -1
  144. package/dist/tooling/migrate/lint.d.ts +14 -1
  145. package/dist/tooling/migrate/place.d.ts +18 -0
  146. package/dist/tooling/migrate/plan-json.d.ts +65 -0
  147. package/dist/tooling/migrate/policy.d.ts +17 -5
  148. package/dist/tooling/migrate/pooler-probe.d.ts +23 -0
  149. package/dist/tooling/migrate/project.d.ts +10 -1
  150. package/dist/tooling/migrate/pull-emit.d.ts +98 -0
  151. package/dist/tooling/migrate/pull-routines.d.ts +126 -0
  152. package/dist/tooling/migrate/pull-verify.d.ts +26 -0
  153. package/dist/tooling/migrate/pull.d.ts +65 -0
  154. package/dist/tooling/migrate/reprint.d.ts +32 -0
  155. package/dist/tooling/migrate/runner.d.ts +24 -1
  156. package/dist/tooling/migrate/sandbox.d.ts +8 -2
  157. package/dist/tooling/migrate/schema-api.d.ts +43 -0
  158. package/dist/tooling/migrate/sql-lex.d.ts +18 -0
  159. package/dist/tooling/shared/{ppnnnvj8.js → 09a6vsys.js} +1 -1
  160. package/dist/tooling/shared/{7ae7rjmn.js → 0v9ptnxp.js} +8 -8
  161. package/dist/tooling/shared/{fb9k2qwd.js → 0wtzps9p.js} +11 -30
  162. package/dist/tooling/shared/{a6pp9d12.js → 0yhf1db4.js} +6 -6
  163. package/dist/tooling/shared/{dy672fz6.js → 19msgrsc.js} +2 -2
  164. package/dist/{shared/q0cqt2sp.js → tooling/shared/1fwfm5m3.js} +1 -1
  165. package/dist/tooling/shared/{f9mphxej.js → 2jdn09e2.js} +401 -24
  166. package/dist/tooling/shared/{jne7b93p.js → 2qrte2ct.js} +5 -5
  167. package/dist/tooling/shared/{5bvw2nev.js → 2v4nwnkb.js} +1 -1
  168. package/dist/tooling/shared/{spk1jg3r.js → 33z39trp.js} +106 -23
  169. package/dist/tooling/shared/{z8d7ptht.js → 353vnw9z.js} +5 -5
  170. package/dist/tooling/shared/{dw08f3m8.js → 390kry9g.js} +2 -2
  171. package/dist/tooling/shared/{xjs6zqtc.js → 3f6etb9z.js} +18 -31
  172. package/dist/{shared/bnby0esn.js → tooling/shared/3t2cqmsx.js} +1 -1
  173. package/dist/tooling/shared/{wwnekq5n.js → 4dzvjtpy.js} +1 -1
  174. package/dist/tooling/shared/{y5656f0e.js → 4ec0nxvw.js} +10 -10
  175. package/dist/tooling/shared/{3m1hkg7z.js → 4tg2bn41.js} +59 -78
  176. package/dist/tooling/shared/{zvnhh1n0.js → 5rah55z0.js} +2 -2
  177. package/dist/tooling/shared/{pqy21k24.js → 804w1t69.js} +4 -4
  178. package/dist/tooling/shared/8g0m0rvd.js +134 -0
  179. package/dist/tooling/shared/8msbtw5s.js +8 -0
  180. package/dist/tooling/shared/{4d2w25vw.js → 8t22h3h7.js} +2 -2
  181. package/dist/tooling/shared/{smn6kz1p.js → 91c59b7b.js} +2 -2
  182. package/dist/tooling/shared/{aftb2mwr.js → adk9k6va.js} +1 -1
  183. package/dist/tooling/shared/{j9t5s12a.js → ajjd5cwz.js} +2 -2
  184. package/dist/tooling/shared/{cmptmb4f.js → angjck01.js} +1 -1
  185. package/dist/tooling/shared/{yw30vnq2.js → asnnc3v5.js} +1 -1
  186. package/dist/tooling/shared/{ma2340rx.js → bj1kyqc8.js} +2 -2
  187. package/dist/tooling/shared/{2wtvc7rw.js → bt3tjemb.js} +11 -3
  188. package/dist/tooling/shared/{ec71zqgt.js → chk2bh4f.js} +2 -2
  189. package/dist/tooling/shared/{gmcf9cxf.js → ckq4z5ax.js} +5 -2
  190. package/dist/tooling/shared/{w7qe8sj1.js → d3rhb24q.js} +1 -1
  191. package/dist/tooling/shared/{y031jct9.js → d8q00vxg.js} +4 -4
  192. package/dist/tooling/shared/{vs0t6qt8.js → dx188rxs.js} +2 -2
  193. package/dist/tooling/shared/{g9ad4n80.js → efq6p9df.js} +35 -42
  194. package/dist/tooling/shared/{ddjtfgnx.js → en6rwzq0.js} +3 -3
  195. package/dist/tooling/shared/{6nyfyw70.js → f2r5g0fs.js} +2 -2
  196. package/dist/tooling/shared/{03k6res6.js → f4gep0nk.js} +1 -1
  197. package/dist/tooling/shared/{gfvtj6d0.js → f8a010fm.js} +13 -11
  198. package/dist/tooling/shared/{3tq8pnb8.js → fdsek6pa.js} +1 -1
  199. package/dist/tooling/shared/fvmrxsd1.js +8 -0
  200. package/dist/tooling/shared/{733a1tq3.js → g3xybeqf.js} +4 -3
  201. package/dist/tooling/shared/{pwsytxm5.js → gefmpwsa.js} +1 -1
  202. package/dist/tooling/shared/{mtrqn2hn.js → gjj71hfh.js} +25 -30
  203. package/dist/tooling/shared/{8sqrsw3s.js → jgzt69pa.js} +5 -5
  204. package/dist/tooling/shared/{nf7jmhfa.js → jm30k2ca.js} +10 -8
  205. package/dist/tooling/shared/{vx86qjv8.js → kayqzpbk.js} +6 -3
  206. package/dist/tooling/shared/{zhwnfyb2.js → kvw1672d.js} +1 -1
  207. package/dist/tooling/shared/{rq5kk8j6.js → mr1kcgpw.js} +3 -3
  208. package/dist/tooling/shared/{72fyg4zv.js → mwbdf409.js} +1 -1
  209. package/dist/tooling/shared/{wt7j7nf6.js → ns9207v3.js} +1 -1
  210. package/dist/tooling/shared/{9xzm7hjg.js → p6tjv97k.js} +3 -3
  211. package/dist/tooling/shared/{yfr8hzhm.js → p73evwf0.js} +1 -1
  212. package/dist/tooling/shared/{dzx85q70.js → phc1nc4g.js} +1 -1
  213. package/dist/tooling/shared/{417zdsk7.js → ppybjw50.js} +79 -16
  214. package/dist/tooling/shared/{yk9mp7vb.js → qdrn8ghn.js} +5 -4
  215. package/dist/tooling/shared/rd8h01ta.js +20 -0
  216. package/dist/tooling/shared/{bz2dqhab.js → rwg8y90m.js} +3 -3
  217. package/dist/tooling/shared/{xhrnjch9.js → ry2f3w8p.js} +3 -3
  218. package/dist/tooling/shared/{a7q7t4n3.js → ryc5sa58.js} +8 -8
  219. package/dist/tooling/shared/{2revefqt.js → ss87qxwv.js} +2 -2
  220. package/dist/tooling/shared/{rf83gr2d.js → vg68k11z.js} +7 -3
  221. package/dist/tooling/shared/{p7f08ktn.js → vms9dta5.js} +73 -89
  222. package/dist/tooling/shared/{3rrw5w8f.js → xchpnbdv.js} +1 -1
  223. package/dist/tooling/shared/{djydjpqt.js → xn6p01fh.js} +5 -5
  224. package/dist/tooling/shared/{9kazs5p6.js → xwr6q618.js} +3 -3
  225. package/dist/tooling/shared/{ep8zh3bk.js → xx3gmq94.js} +1 -1
  226. package/dist/tooling/shared/{tn8gay14.js → y2bd7yfx.js} +21 -13
  227. package/dist/tooling/shared/{vraj6d74.js → y4gq9rbe.js} +11 -11
  228. package/dist/tooling/shared/y4vwft92.js +9 -0
  229. package/dist/tooling/shared/{345tbc2k.js → yz68xcmc.js} +1 -1
  230. package/dist/tooling/testing/factories.d.ts +1 -3
  231. package/dist/tooling/testing/index.js +2 -2
  232. package/package.json +39 -9
  233. package/dist/shared/3449rcae.js +0 -14
  234. package/dist/shared/fjpnhqan.js +0 -71
  235. package/dist/shared/n41w4fbz.js +0 -113
  236. package/dist/tooling/shared/pw8fgahx.js +0 -69
  237. /package/dist/shared/{ae4j5f42.js → mfvx6kjx.js} +0 -0
@@ -0,0 +1,451 @@
1
+ import {
2
+ open2
3
+ } from "./jvxcp1qk.js";
4
+ import"./12z7aznj.js";
5
+ import"./n442h54c.js";
6
+ import"./fk9vef30.js";
7
+ import {
8
+ openProject
9
+ } from "./wp7y8q3y.js";
10
+ import {
11
+ driverUrl,
12
+ sessionFailure,
13
+ finishQuiet,
14
+ assertTargetPolicy,
15
+ selectTarget
16
+ } from "./bdekbvmt.js";
17
+ import {
18
+ isExactVersion,
19
+ compareExtensionVersions
20
+ } from "./r3j8s5y0.js";
21
+ import {
22
+ OkmError2
23
+ } from "./52szzakm.js";
24
+
25
+ // src/tooling/migrate/ext.ts
26
+ import { existsSync, writeFileSync } from "node:fs";
27
+ import { isAbsolute, join } from "node:path";
28
+ import { pathToFileURL } from "node:url";
29
+
30
+ // src/tooling/migrate/ext-surface.ts
31
+ var INSTALLED = `
32
+ select e.extversion, n.nspname, e.extrelocatable::text, current_setting('server_version_num')
33
+ from pg_extension e
34
+ join pg_namespace n on n.oid = e.extnamespace
35
+ where e.extname = $1
36
+ `;
37
+ var TYPES = `
38
+ select t.typname
39
+ from pg_depend d
40
+ join pg_extension e on e.oid = d.refobjid
41
+ join pg_type t on t.oid = d.objid
42
+ where e.extname = $1
43
+ and d.deptype = 'e'
44
+ and d.classid = 'pg_type'::regclass
45
+ and t.typtype in ('b', 'e', 'd', 'c')
46
+ order by t.typname
47
+ `;
48
+ var FUNCTIONS = `
49
+ select p.proname,
50
+ pg_get_function_identity_arguments(p.oid),
51
+ pg_get_function_result(p.oid)
52
+ from pg_depend d
53
+ join pg_extension e on e.oid = d.refobjid
54
+ join pg_proc p on p.oid = d.objid
55
+ where e.extname = $1
56
+ and d.deptype = 'e'
57
+ and d.classid = 'pg_proc'::regclass
58
+ order by p.proname, pg_get_function_identity_arguments(p.oid)
59
+ `;
60
+ var OPERATORS = `
61
+ select o.oprname,
62
+ coalesce(l.typname, ''),
63
+ coalesce(r.typname, ''),
64
+ res.typname
65
+ from pg_depend d
66
+ join pg_extension e on e.oid = d.refobjid
67
+ join pg_operator o on o.oid = d.objid
68
+ left join pg_type l on l.oid = o.oprleft
69
+ left join pg_type r on r.oid = o.oprright
70
+ join pg_type res on res.oid = o.oprresult
71
+ where e.extname = $1
72
+ and d.deptype = 'e'
73
+ and d.classid = 'pg_operator'::regclass
74
+ order by o.oprname, l.typname, r.typname
75
+ `;
76
+ var OPCLASSES = `
77
+ select am.amname, oc.opcname
78
+ from pg_depend d
79
+ join pg_extension e on e.oid = d.refobjid
80
+ join pg_opclass oc on oc.oid = d.objid
81
+ join pg_am am on am.oid = oc.opcmethod
82
+ where e.extname = $1
83
+ and d.deptype = 'e'
84
+ and d.classid = 'pg_opclass'::regclass
85
+ order by am.amname, oc.opcname
86
+ `;
87
+ var SETTINGS = `
88
+ select name from pg_settings where name like $1 order by name
89
+ `;
90
+ async function readSurface(pool, name) {
91
+ const installed = await pool.execute(INSTALLED, [name]);
92
+ const row = installed.rows[0];
93
+ if (row === undefined) {
94
+ throw new OkmError2("OKM1811", `Extension ${name} is not installed on the server.`, {
95
+ fix: { summary: "Install the extension, then run okm ext scaffold again." }
96
+ });
97
+ }
98
+ const version = text(row[0]);
99
+ const schema = text(row[1]);
100
+ const relocatable = row[2] === "t" || row[2] === "true";
101
+ const serverMajor = majorOf(text(row[3]));
102
+ const [types, functions, operators, methods, settings] = await Promise.all([
103
+ pool.execute(TYPES, [name]),
104
+ pool.execute(FUNCTIONS, [name]),
105
+ pool.execute(OPERATORS, [name]),
106
+ pool.execute(OPCLASSES, [name]),
107
+ pool.execute(SETTINGS, [`${name}.%`])
108
+ ]);
109
+ return {
110
+ name,
111
+ version,
112
+ schema,
113
+ relocatable,
114
+ serverMajor,
115
+ types: types.rows.map((item) => ({ name: text(item[0]) })),
116
+ functions: functions.rows.flatMap((item) => callable(item)),
117
+ operators: operators.rows.flatMap((item) => visibleOperator(item)),
118
+ indexMethods: methods.rows.map((item) => ({
119
+ name: text(item[0]),
120
+ opclass: text(item[1])
121
+ })),
122
+ settings: settings.rows.map((item) => text(item[0]))
123
+ };
124
+ }
125
+ function renderScaffold(surface) {
126
+ const exportName = `${camel(surface.name)}Ext`;
127
+ const settings = surface.settings.length === 0 ? "none" : surface.settings.join(", ");
128
+ const body = {
129
+ schema: surface.schema,
130
+ relocatable: surface.relocatable,
131
+ requires: {
132
+ postgres: ">=15",
133
+ version: `>=${surface.version}`
134
+ },
135
+ provides: {
136
+ types: surface.types,
137
+ operators: surface.operators,
138
+ functions: surface.functions,
139
+ indexMethods: surface.indexMethods
140
+ }
141
+ };
142
+ return [
143
+ 'import { extension } from "okmodel/ext";',
144
+ "",
145
+ "/**",
146
+ ` * Starting definition for ${surface.name} ${surface.version} in schema ${surface.schema}.`,
147
+ " * Edit this file. okm ext test checks it against the connected server.",
148
+ ` * Settings: ${settings}.`,
149
+ " */",
150
+ `export const ${exportName} = extension(${JSON.stringify(surface.name)}, ${JSON.stringify(body, null, 2)});`,
151
+ ""
152
+ ].join(`
153
+ `);
154
+ }
155
+ function surfaceMismatches(declared, server) {
156
+ const lines = [];
157
+ lines.push(...versionMismatches(declared, server));
158
+ const provides = declared.provides;
159
+ if (provides === undefined)
160
+ return lines;
161
+ for (const type of provides.types ?? []) {
162
+ if (!server.types.some((item) => item.name === type.name)) {
163
+ lines.push(`type ${type.name} is not in ${declared.name}`);
164
+ }
165
+ }
166
+ for (const operator of provides.operators ?? []) {
167
+ if (!operatorMatches(operator, server.operators)) {
168
+ lines.push(operatorLine(operator));
169
+ }
170
+ }
171
+ for (const fn of provides.functions ?? []) {
172
+ if (!functionMatches(fn, server.functions)) {
173
+ lines.push(`function ${fn.name}(${fn.args.join(", ")}) -> ${fn.returns}`);
174
+ }
175
+ }
176
+ for (const method of provides.indexMethods ?? []) {
177
+ if (!methodMatches(method, server.indexMethods)) {
178
+ const opclass = method.opclass === undefined ? "" : ` ${method.opclass}`;
179
+ lines.push(`index method ${method.name}${opclass}`);
180
+ }
181
+ }
182
+ return lines;
183
+ }
184
+ function refuseMismatches(name, mismatches) {
185
+ if (mismatches.length === 0)
186
+ return;
187
+ const version = mismatches.some((line) => line.startsWith("version ") || line.startsWith("postgres "));
188
+ const code = version ? "OKM1812" : "invalid";
189
+ throw new OkmError2(code, `Extension ${name} does not match the server.
190
+ ${mismatches.join(`
191
+ `)}`, {
192
+ fix: {
193
+ summary: "Edit the definition so each signature matches the server, or install the version requires names."
194
+ }
195
+ });
196
+ }
197
+ function versionMismatches(declared, server) {
198
+ const lines = [];
199
+ const requires = {
200
+ ...declared.requires,
201
+ ...declared.version !== undefined ? { version: declared.version } : {}
202
+ };
203
+ const postgres = requires.postgres;
204
+ if (postgres !== undefined && !majorAllows(postgres, server.serverMajor)) {
205
+ lines.push(`postgres ${postgres} is not met. The server is PostgreSQL ${String(server.serverMajor)}. minPostgres: ${floorText(postgres)}.`);
206
+ }
207
+ const version = requires.version;
208
+ if (version !== undefined && !versionAllows(version, server.version)) {
209
+ lines.push(`version ${version} is not met. The server has ${server.version}.`);
210
+ }
211
+ return lines;
212
+ }
213
+ function majorAllows(declared, server) {
214
+ const floor = /^>=(\d+)$/.exec(declared);
215
+ const exact = floor?.[1] ?? (/^\d+$/.test(declared) ? declared : undefined);
216
+ if (exact === undefined)
217
+ return false;
218
+ return server >= Number(exact);
219
+ }
220
+ function versionAllows(declared, installed) {
221
+ const floor = /^>=(\d+(?:\.\d+)*)$/.exec(declared);
222
+ const pinned = floor?.[1] ?? declared;
223
+ if (!isExactVersion(pinned) || !isExactVersion(installed))
224
+ return declared === installed;
225
+ return compareExtensionVersions(installed, pinned) >= 0;
226
+ }
227
+ function floorText(declared) {
228
+ return declared.startsWith(">=") ? declared.slice(2) : declared;
229
+ }
230
+ function operatorMatches(declared, server) {
231
+ return server.some((item) => item.name === declared.name && (declared.left === undefined || item.left === declared.left) && (declared.right === undefined || item.right === declared.right) && item.result === declared.result);
232
+ }
233
+ function functionMatches(declared, server) {
234
+ const args = declared.args.join(", ");
235
+ return server.some((item) => item.name === declared.name && item.args.join(", ") === args && item.returns === declared.returns);
236
+ }
237
+ function methodMatches(declared, server) {
238
+ return server.some((item) => item.name === declared.name && (declared.opclass === undefined || item.opclass === declared.opclass));
239
+ }
240
+ function operatorLine(operator) {
241
+ const left = operator.left ?? "";
242
+ const right = operator.right ?? "";
243
+ return `operator ${left} ${operator.name} ${right} -> ${operator.result}`.replaceAll(/\s+/g, " ").trim();
244
+ }
245
+ function callable(row) {
246
+ const args = text(row[1]);
247
+ const returns = text(row[2]);
248
+ if (args.includes("internal") || returns.includes("internal"))
249
+ return [];
250
+ return [
251
+ {
252
+ name: text(row[0]),
253
+ args: args.length === 0 ? [] : args.split(", ").filter((part) => part.length > 0),
254
+ returns
255
+ }
256
+ ];
257
+ }
258
+ function visibleOperator(row) {
259
+ const left = text(row[1]);
260
+ const right = text(row[2]);
261
+ const result = text(row[3]);
262
+ if ([left, right, result].some((part) => part === "internal"))
263
+ return [];
264
+ return [
265
+ {
266
+ name: text(row[0]),
267
+ ...left.length > 0 ? { left } : {},
268
+ ...right.length > 0 ? { right } : {},
269
+ result
270
+ }
271
+ ];
272
+ }
273
+ function text(value) {
274
+ if (typeof value === "string")
275
+ return value;
276
+ if (typeof value === "number" || typeof value === "boolean")
277
+ return String(value);
278
+ return "";
279
+ }
280
+ function majorOf(versionNum) {
281
+ const parsed = Number(versionNum);
282
+ if (!Number.isFinite(parsed))
283
+ return 0;
284
+ return Math.floor(parsed / 1e4);
285
+ }
286
+ function camel(name) {
287
+ const parts = name.split(/[^A-Za-z0-9]+/).filter((part) => part.length > 0);
288
+ const [first, ...rest] = parts;
289
+ if (first === undefined)
290
+ return "extension";
291
+ return first.toLowerCase() + rest.map((part) => part.slice(0, 1).toUpperCase() + part.slice(1).toLowerCase()).join("");
292
+ }
293
+ function isExtension(value) {
294
+ if (typeof value !== "object" || value === null)
295
+ return false;
296
+ if (!("name" in value) || !("contribute" in value) || !("schema" in value))
297
+ return false;
298
+ return typeof value.name === "string" && typeof value.contribute === "function";
299
+ }
300
+ function extensionsFromModule(imported) {
301
+ if (typeof imported !== "object" || imported === null)
302
+ return [];
303
+ const found = [];
304
+ for (const value of Object.values(imported)) {
305
+ if (isExtension(value))
306
+ found.push(value);
307
+ }
308
+ return found;
309
+ }
310
+
311
+ // src/tooling/migrate/ext.ts
312
+ async function extProject(cwd, command, flags) {
313
+ const opened = await openProject(cwd);
314
+ const target = selectTarget(opened.config, flags.target);
315
+ assertTargetPolicy(target, "check", flags.allowProtected);
316
+ const pool = open2({ url: driverUrl(target.url), max: 1 });
317
+ try {
318
+ if (command === "list")
319
+ return formatList(await readExtensions(pool));
320
+ return formatCheck(opened.built.catalog.objects, await readExtensions(pool));
321
+ } catch (error) {
322
+ throw sessionFailure(error) ?? error;
323
+ } finally {
324
+ await finishQuiet(() => pool.close());
325
+ }
326
+ }
327
+ var LIST_SQL = `
328
+ select a.name, a.default_version, e.extversion, n.nspname
329
+ from pg_available_extensions a
330
+ left join pg_extension e on e.extname = a.name
331
+ left join pg_namespace n on n.oid = e.extnamespace
332
+ order by a.name
333
+ `;
334
+ async function readExtensions(pool) {
335
+ const result = await pool.execute(LIST_SQL);
336
+ return result.rows.map((row) => ({
337
+ name: cell(row[0]),
338
+ defaultVersion: cell(row[1]),
339
+ installedVersion: cell(row[2]),
340
+ schema: cell(row[3])
341
+ }));
342
+ }
343
+ function cell(value) {
344
+ return typeof value === "string" ? value : "";
345
+ }
346
+ function formatList(rows) {
347
+ const lines = ["name\tdefault\tinstalled\tschema"];
348
+ for (const row of rows) {
349
+ lines.push([row.name, row.defaultVersion, row.installedVersion, row.schema].join("\t"));
350
+ }
351
+ return `${lines.join(`
352
+ `)}
353
+ `;
354
+ }
355
+ function formatCheck(objects, server) {
356
+ const declared = objects.filter((object) => object.kind === "extension");
357
+ if (declared.length === 0)
358
+ return `no extensions
359
+ `;
360
+ const installed = new Map(server.map((row) => [row.name, row.installedVersion]));
361
+ const lines = ["name\tdeclared\tinstalled"];
362
+ for (const object of [...declared].sort((left, right) => left.identity.name < right.identity.name ? -1 : 1)) {
363
+ const name = object.identity.name;
364
+ const have = installed.get(name) ?? "";
365
+ if (have.length === 0) {
366
+ throw new OkmError2("OKM1811", `Extension ${name} is not installed on the server.`, {
367
+ fix: { summary: "Install the extension, or remove the declaration." }
368
+ });
369
+ }
370
+ const want = object.definition.version;
371
+ if (!versionAccepted(want, have)) {
372
+ throw new OkmError2("OKM1812", extensionNeeds(name, want ?? "", have), {
373
+ fix: { summary: "Install a version the declaration accepts, or change the pin." }
374
+ });
375
+ }
376
+ lines.push([name, want ?? "-", have].join("\t"));
377
+ }
378
+ return `${lines.join(`
379
+ `)}
380
+ `;
381
+ }
382
+ function extensionNeeds(name, want, have) {
383
+ const floor = /^>=(\d+(?:\.\d+)*)$/.exec(want);
384
+ const need = floor?.[1] ?? want;
385
+ const higher = floor === null ? "" : " or higher";
386
+ return `Extension ${name} needs ${need}${higher}. The server has ${have}. Install a version the declaration accepts, or change the pin.`;
387
+ }
388
+ async function extScaffold(cwd, name, flags, out) {
389
+ if (out !== undefined) {
390
+ const path = isAbsolute(out) ? out : join(cwd, out);
391
+ if (existsSync(path)) {
392
+ throw new OkmError2("invalid", `okm ext scaffold would overwrite ${path}. Nothing was written.`, { fix: { summary: "Pass a path that does not exist. The command never overwrites." } });
393
+ }
394
+ }
395
+ const text = await withServer(cwd, flags, async (pool) => renderScaffold(await readSurface(pool, name)));
396
+ if (out === undefined)
397
+ return text;
398
+ const path = isAbsolute(out) ? out : join(cwd, out);
399
+ writeFileSync(path, text);
400
+ return `wrote ${path}
401
+ `;
402
+ }
403
+ async function extTest(cwd, file, flags) {
404
+ const path = isAbsolute(file) ? file : join(cwd, file);
405
+ const imported = await import(pathToFileURL(path).href);
406
+ const declared = extensionsFromModule(imported);
407
+ if (declared.length === 0) {
408
+ throw new OkmError2("invalid", `okm ext test found no extension() in ${path}.`, {
409
+ fix: { summary: "Export the value extension() returns." }
410
+ });
411
+ }
412
+ return withServer(cwd, flags, async (pool) => {
413
+ const lines = [];
414
+ for (const extension of declared) {
415
+ const server = await readSurface(pool, extension.name);
416
+ refuseMismatches(extension.name, surfaceMismatches(extension, server));
417
+ lines.push(`ok ${extension.name}`);
418
+ }
419
+ return `${lines.join(`
420
+ `)}
421
+ `;
422
+ });
423
+ }
424
+ async function withServer(cwd, flags, body) {
425
+ const opened = await openProject(cwd);
426
+ const target = selectTarget(opened.config, flags.target);
427
+ assertTargetPolicy(target, "check", flags.allowProtected);
428
+ const pool = open2({ url: driverUrl(target.url), max: 1 });
429
+ try {
430
+ return await body(pool);
431
+ } catch (error) {
432
+ throw sessionFailure(error) ?? error;
433
+ } finally {
434
+ await finishQuiet(() => pool.close());
435
+ }
436
+ }
437
+ function versionAccepted(declared, installed) {
438
+ if (declared === undefined)
439
+ return true;
440
+ const floor = /^>=(\d+(?:\.\d+)*)$/.exec(declared);
441
+ const minimum = floor?.[1];
442
+ if (minimum !== undefined) {
443
+ return isExactVersion(installed) && compareExtensionVersions(installed, minimum) >= 0;
444
+ }
445
+ return declared === installed;
446
+ }
447
+ export {
448
+ extProject,
449
+ extScaffold,
450
+ extTest
451
+ };
@@ -17,7 +17,7 @@ import {
17
17
  snakeCase,
18
18
  emittedTypeName,
19
19
  rejectLater
20
- } from "./gcefca6p.js";
20
+ } from "./f9t9g54z.js";
21
21
  import {
22
22
  ColumnBuilder2,
23
23
  formatType
@@ -4,12 +4,12 @@ import {
4
4
  import {
5
5
  send2,
6
6
  reserve,
7
- park
8
- } from "./zbqbmmrp.js";
7
+ releaseReserved
8
+ } from "./n6je5b28.js";
9
9
  import {
10
10
  resetSession2,
11
11
  refuseWhenLost2
12
- } from "./7ghwamrf.js";
12
+ } from "./99qp9vtg.js";
13
13
  import {
14
14
  cursorStream
15
15
  } from "./7kms6fvj.js";
@@ -18,14 +18,14 @@ import {
18
18
  } from "./cnkky55j.js";
19
19
  import {
20
20
  noTimeout
21
- } from "./q0cqt2sp.js";
21
+ } from "./tr64w5p0.js";
22
22
  import {
23
23
  WireSession
24
- } from "./mtw6jz76.js";
24
+ } from "./e275q7sd.js";
25
25
  import {
26
26
  rejectClosed,
27
27
  runCall
28
- } from "./ae4j5f42.js";
28
+ } from "./mfvx6kjx.js";
29
29
 
30
30
  // src/adapters/pg/bunsql-extra.ts
31
31
  async function recover(sql, error, text, depth, clientRead, closedDuring, again) {
@@ -62,19 +62,13 @@ function lostQuery(error) {
62
62
  function socketClosed(error) {
63
63
  if (!(error instanceof Error))
64
64
  return false;
65
- if (error.message === "Connection closed")
65
+ if (bunClosed(error.message))
66
66
  return true;
67
- return error.cause instanceof Error && error.cause.message === "Connection closed";
67
+ return error.cause instanceof Error && bunClosed(error.cause.message);
68
68
  }
69
- async function listen(sql, parked, closed, channel, onNotify) {
69
+ async function listen(sql, closed, channel, onNotify) {
70
70
  if (closed)
71
71
  return rejectClosed();
72
- const pending = parked.splice(0);
73
- for (const reserved of pending) {
74
- const done = reserved.release();
75
- if (done instanceof Promise)
76
- await done;
77
- }
78
72
  const subscription = await sql.listen(channel, onNotify);
79
73
  return async () => {
80
74
  await subscription.unlisten();
@@ -84,7 +78,7 @@ async function checkout(held) {
84
78
  const { counters, isClosed } = held;
85
79
  if (isClosed())
86
80
  return rejectClosed();
87
- const reserved = await takeOpen(held) ?? await reserve(held.sql, held.acquireMs, counters);
81
+ const reserved = await reserve(held.sql, held.acquireMs, counters);
88
82
  counters.reserved += 1;
89
83
  const session = new WireSession((text, params) => send2(reserved, text, params), held.notices, isClosed, false, () => {
90
84
  counters.reservedBusy += 1;
@@ -140,20 +134,33 @@ async function checkout(held) {
140
134
  try {
141
135
  if (!lost.on)
142
136
  await reset(session, reserved);
143
- } catch (error) {
144
- if (lostQuery(error) || reportsClosed(reserved))
145
- lost.on = true;
146
- else
147
- throw error;
137
+ else if (session.depth() > 0 && !reportsClosed(reserved)) {
138
+ await reserved.unsafe("ROLLBACK").catch(() => {
139
+ return;
140
+ });
141
+ session.abandon();
142
+ }
143
+ } catch {
144
+ lost.on = true;
148
145
  } finally {
149
146
  counters.reserved = Math.max(0, counters.reserved - 1);
150
147
  if (lost.on) {
151
148
  try {
152
149
  reserved.release();
153
150
  } catch {}
154
- await flushClosed(held.sql);
155
- } else
156
- await park(held.parked, reserved);
151
+ if (counters.reserved === 0)
152
+ await flushClosed(held.sql);
153
+ } else {
154
+ try {
155
+ await releaseReserved(reserved);
156
+ } catch {
157
+ try {
158
+ reserved.release();
159
+ } catch {}
160
+ if (counters.reserved === 0)
161
+ await flushClosed(held.sql);
162
+ }
163
+ }
157
164
  }
158
165
  }
159
166
  };
@@ -161,20 +168,6 @@ async function checkout(held) {
161
168
  function reportsClosed(reserved) {
162
169
  return Reflect.get(reserved, "closed") === true;
163
170
  }
164
- async function takeOpen(held) {
165
- while (held.parked.length > 0) {
166
- const next = held.parked.pop();
167
- if (next === undefined)
168
- return;
169
- if (!reportsClosed(next))
170
- return next;
171
- try {
172
- next.release();
173
- } catch {}
174
- await flushClosed(held.sql);
175
- }
176
- return;
177
- }
178
171
  async function flushClosed(sql) {
179
172
  for (let attempt = 0;attempt < 3; attempt += 1) {
180
173
  try {
@@ -0,0 +1,17 @@
1
+ import {
2
+ assertAuthorDrift2,
3
+ sealDomainChecks2,
4
+ catalogQuery2,
5
+ managedRoleOptions2
6
+ } from "./4pkz5nvw.js";
7
+ import"./e1c55v04.js";
8
+ import"./mz48rs74.js";
9
+ import"./bdekbvmt.js";
10
+ import"./fk9vef30.js";
11
+ import"./12z7aznj.js";
12
+ export {
13
+ assertAuthorDrift2 as assertAuthorDrift,
14
+ catalogQuery2 as catalogQuery,
15
+ managedRoleOptions2 as managedRoleOptions,
16
+ sealDomainChecks2 as sealDomainChecks
17
+ };