okmodel 0.8.0 → 0.9.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 (202) hide show
  1. package/README.md +14 -0
  2. package/dist/dialects/pg/ext/btree-gin.d.ts +26 -0
  3. package/dist/dialects/pg/ext/btree-gin.js +20 -0
  4. package/dist/dialects/pg/ext/btree-gist.d.ts +26 -0
  5. package/dist/dialects/pg/ext/btree-gist.js +20 -0
  6. package/dist/dialects/pg/ext/call.d.ts +53 -0
  7. package/dist/dialects/pg/ext/citext.js +1 -1
  8. package/dist/dialects/pg/ext/feature.d.ts +26 -0
  9. package/dist/dialects/pg/ext/fuzzystrmatch.d.ts +34 -0
  10. package/dist/dialects/pg/ext/fuzzystrmatch.js +33 -0
  11. package/dist/dialects/pg/ext/hstore.d.ts +41 -0
  12. package/dist/dialects/pg/ext/hstore.js +29 -0
  13. package/dist/dialects/pg/ext/index.d.ts +56 -0
  14. package/dist/dialects/pg/ext/index.js +1 -1
  15. package/dist/dialects/pg/ext/ltree.d.ts +41 -0
  16. package/dist/dialects/pg/ext/ltree.js +29 -0
  17. package/dist/dialects/pg/ext/pg-trgm.js +4 -13
  18. package/dist/dialects/pg/ext/pgcrypto.d.ts +33 -0
  19. package/dist/dialects/pg/ext/pgcrypto.js +33 -0
  20. package/dist/dialects/pg/ext/unaccent.d.ts +26 -0
  21. package/dist/dialects/pg/ext/unaccent.js +21 -0
  22. package/dist/dialects/pg/ext/using.d.ts +23 -0
  23. package/dist/dialects/pg/ext/versions.d.ts +36 -0
  24. package/dist/dialects/pg/external.d.ts +19 -0
  25. package/dist/dialects/pg/fn/index.js +4 -4
  26. package/dist/dialects/pg/index.d.ts +1 -0
  27. package/dist/dialects/pg/index.js +16 -11
  28. package/dist/dialects/pg/view/index.js +5 -5
  29. package/dist/dialects/pg/view/scratch.d.ts +4 -1
  30. package/dist/runtime/artifact-file.d.ts +22 -0
  31. package/dist/runtime/client.d.ts +10 -0
  32. package/dist/runtime/drift-detail.d.ts +2 -1
  33. package/dist/runtime/drift.d.ts +3 -10
  34. package/dist/runtime/pg/bun.js +4 -4
  35. package/dist/runtime/pg/neon.js +4 -4
  36. package/dist/runtime/pg/pg.js +4 -4
  37. package/dist/runtime/pg/pglite.js +4 -4
  38. package/dist/runtime/pg/postgresjs.js +4 -4
  39. package/dist/runtime/server-check.d.ts +36 -6
  40. package/dist/runtime/traits/index.js +5 -5
  41. package/dist/runtime/validate/index.js +1 -1
  42. package/dist/shared/{4m6hskg8.js → 0j6qe91y.js} +4 -4
  43. package/dist/shared/{14x60fbf.js → 1mxm04fy.js} +5 -5
  44. package/dist/shared/{b6d6p0zc.js → 2szgv6yj.js} +5 -5
  45. package/dist/shared/{f4jy1j7x.js → 2zdxkt7b.js} +909 -100
  46. package/dist/shared/{mnvjvqyp.js → 3456242y.js} +17 -17
  47. package/dist/shared/3t6kw83m.js +1 -1
  48. package/dist/shared/{6m78c8ss.js → 5kyb3tqx.js} +1 -1
  49. package/dist/shared/61bmrmhr.js +35 -0
  50. package/dist/shared/{zbqbmmrp.js → 62b603gr.js} +8 -8
  51. package/dist/shared/{jgqj11w4.js → 6f0z3hzh.js} +4 -0
  52. package/dist/shared/{dpc2r7rb.js → 6nae0spm.js} +150 -89
  53. package/dist/shared/{0wrea3jq.js → 71n0jmhc.js} +1 -1
  54. package/dist/shared/7ba5h6pb.js +17 -0
  55. package/dist/shared/{k86n8vq3.js → 8jesqsrk.js} +1 -1
  56. package/dist/shared/{qd9hhd8f.js → 8n688yjg.js} +1 -1
  57. package/dist/shared/{zgex00fd.js → 8qzkd9f3.js} +5 -5
  58. package/dist/shared/{mkrn359n.js → 90sg0w5a.js} +159 -31
  59. package/dist/shared/{7ghwamrf.js → 99qp9vtg.js} +1 -1
  60. package/dist/shared/{bxas03mq.js → 9dtgn1z2.js} +1 -1
  61. package/dist/shared/{p5nh3r8q.js → aksb89mn.js} +2 -2
  62. package/dist/shared/{wcrheftc.js → bphrgwz9.js} +2 -2
  63. package/dist/shared/{wz2a78mp.js → c3mvnq7a.js} +1 -1
  64. package/dist/shared/{pan0370z.js → ccsmhv9r.js} +24 -6
  65. package/dist/shared/{n0jmpgj1.js → cexb7z6b.js} +1 -1
  66. package/dist/shared/{wvdjznah.js → cf8zdz5p.js} +5 -5
  67. package/dist/shared/{3449rcae.js → ckz05z15.js} +4 -4
  68. package/dist/shared/{35q0n9tz.js → dd5pmnky.js} +7 -7
  69. package/dist/shared/{e8zyaqvj.js → ds229x4r.js} +1 -1
  70. package/dist/{tooling/shared/yw30vnq2.js → shared/e275q7sd.js} +1 -1
  71. package/dist/shared/{mfedzr74.js → ebhz8vh6.js} +4 -4
  72. package/dist/shared/{z581d7ny.js → fdsz3w80.js} +2 -2
  73. package/dist/shared/{sjk86yrx.js → fk9vef30.js} +84 -73
  74. package/dist/shared/{needfe47.js → g89fmz5s.js} +1 -1
  75. package/dist/shared/{m4xff2a6.js → ghqzdp94.js} +2 -2
  76. package/dist/shared/h9811jjm.js +17 -0
  77. package/dist/shared/{kj9d8maq.js → jpybhf98.js} +1 -1
  78. package/dist/shared/kzgrnckd.js +29 -0
  79. package/dist/shared/{agsfb86s.js → mazpbcdj.js} +4 -4
  80. package/dist/shared/{195pzzzz.js → mgaq2sd3.js} +10 -7
  81. package/dist/shared/{5mtf6cj3.js → mvmm3xpb.js} +5 -2
  82. package/dist/shared/{p3xbdcvt.js → myk8fswx.js} +55 -6
  83. package/dist/shared/{njga14v4.js → n306gqkd.js} +8 -8
  84. package/dist/shared/n5whk3mt.js +665 -0
  85. package/dist/shared/{bah9nbg3.js → npdftanb.js} +12 -20
  86. package/dist/shared/{16kvjebh.js → pg4ezgyf.js} +7 -26
  87. package/dist/{tooling/shared/08kemxjd.js → shared/pgsak1yw.js} +1 -1
  88. package/dist/shared/{jp36k7dp.js → qvwwp1mp.js} +61 -40
  89. package/dist/shared/rbxt795q.js +1766 -0
  90. package/dist/shared/{g5yc06ka.js → s7he5e5d.js} +1 -1
  91. package/dist/shared/{hfqmpasr.js → ss2kv2rs.js} +5 -5
  92. package/dist/shared/stfa9xcw.js +450 -0
  93. package/dist/{tooling/shared/rs1jb051.js → shared/tr64w5p0.js} +1 -1
  94. package/dist/shared/{jebgrkeq.js → tw1nvvfj.js} +2 -2
  95. package/dist/shared/{v1wad97q.js → wvtjg5m3.js} +1 -1
  96. package/dist/shared/xqacq37x.js +61 -0
  97. package/dist/shared/{n05z9nwz.js → xtsydxjg.js} +1 -1
  98. package/dist/shared/{jx2m62cs.js → xv8qj97g.js} +5 -5
  99. package/dist/shared/{63f4ksbz.js → xwhdcrm4.js} +1 -1
  100. package/dist/shared/{hm5f8jby.js → yvabyg9k.js} +6 -6
  101. package/dist/shared/yybhre6n.js +136 -0
  102. package/dist/shared/zdqf8k5d.js +8 -0
  103. package/dist/tooling/cli.js +94 -22
  104. package/dist/tooling/driver-run.js +15 -332
  105. package/dist/tooling/github/comment.d.ts +50 -0
  106. package/dist/tooling/github/post-comment.d.ts +17 -0
  107. package/dist/tooling/migrate/commands.d.ts +2 -1
  108. package/dist/tooling/migrate/config.d.ts +13 -0
  109. package/dist/tooling/migrate/export.d.ts +165 -0
  110. package/dist/tooling/migrate/ext-surface.d.ts +80 -0
  111. package/dist/tooling/migrate/ext.d.ts +31 -4
  112. package/dist/tooling/migrate/import-drizzle.d.ts +40 -0
  113. package/dist/tooling/migrate/index.d.ts +3 -0
  114. package/dist/tooling/migrate/index.js +55 -10
  115. package/dist/tooling/migrate/lint-rules.d.ts +18 -1
  116. package/dist/tooling/migrate/lint.d.ts +14 -1
  117. package/dist/tooling/migrate/place.d.ts +18 -0
  118. package/dist/tooling/migrate/plan-json.d.ts +65 -0
  119. package/dist/tooling/migrate/project.d.ts +10 -1
  120. package/dist/tooling/migrate/pull-emit.d.ts +98 -0
  121. package/dist/tooling/migrate/pull-routines.d.ts +126 -0
  122. package/dist/tooling/migrate/pull-verify.d.ts +26 -0
  123. package/dist/tooling/migrate/pull.d.ts +62 -0
  124. package/dist/tooling/migrate/reprint.d.ts +32 -0
  125. package/dist/tooling/migrate/sandbox.d.ts +8 -2
  126. package/dist/tooling/migrate/schema-api.d.ts +43 -0
  127. package/dist/tooling/migrate/sql-lex.d.ts +18 -0
  128. package/dist/tooling/shared/{3m1hkg7z.js → 04svnxxj.js} +4 -4
  129. package/dist/tooling/shared/{ppnnnvj8.js → 0j0jtse1.js} +1 -1
  130. package/dist/tooling/shared/{z8d7ptht.js → 0r05zhyq.js} +5 -5
  131. package/dist/tooling/shared/{a6pp9d12.js → 1800eymw.js} +3 -3
  132. package/dist/tooling/shared/{cmptmb4f.js → 35zemrmf.js} +1 -1
  133. package/dist/tooling/shared/{w7qe8sj1.js → 3rmaz3pq.js} +1 -1
  134. package/dist/{shared/q0cqt2sp.js → tooling/shared/3yn79q5m.js} +1 -1
  135. package/dist/tooling/shared/{2revefqt.js → 57btdkgm.js} +2 -2
  136. package/dist/tooling/shared/{ma2340rx.js → 5bmksndh.js} +2 -2
  137. package/dist/tooling/shared/{9xzm7hjg.js → 5p8km5jb.js} +3 -3
  138. package/dist/tooling/shared/{xhrnjch9.js → 5x3pf400.js} +3 -3
  139. package/dist/tooling/shared/{wwnekq5n.js → 5zrzffnk.js} +1 -1
  140. package/dist/tooling/shared/{p7f08ktn.js → 62fxpc1p.js} +7 -7
  141. package/dist/tooling/shared/{7ae7rjmn.js → 68tf18v4.js} +2 -2
  142. package/dist/tooling/shared/{rf83gr2d.js → 6vk28rjp.js} +7 -3
  143. package/dist/tooling/shared/76pv6qff.js +9 -0
  144. package/dist/tooling/shared/{bz2dqhab.js → 7aews1zg.js} +3 -3
  145. package/dist/tooling/shared/{9kazs5p6.js → 7b3xp9gc.js} +3 -3
  146. package/dist/tooling/shared/{4d2w25vw.js → 7pxncnzs.js} +2 -2
  147. package/dist/tooling/shared/{zvnhh1n0.js → 829fjxyw.js} +2 -2
  148. package/dist/tooling/shared/{dzx85q70.js → 8m5znpdt.js} +1 -1
  149. package/dist/tooling/shared/{g9ad4n80.js → 8yr7ges1.js} +7 -7
  150. package/dist/tooling/shared/{tn8gay14.js → 9qr9rkbh.js} +6 -6
  151. package/dist/tooling/shared/{8sqrsw3s.js → 9sfbtwsk.js} +3 -3
  152. package/dist/{shared/bnby0esn.js → tooling/shared/9wsnsvbf.js} +1 -1
  153. package/dist/tooling/shared/{aftb2mwr.js → a2xe04bm.js} +1 -1
  154. package/dist/tooling/shared/{nf7jmhfa.js → a4pzghha.js} +2 -2
  155. package/dist/tooling/shared/{y5656f0e.js → am04v8na.js} +5 -5
  156. package/dist/tooling/shared/{417zdsk7.js → asgr07mp.js} +5 -5
  157. package/dist/tooling/shared/{pqy21k24.js → c0xevn1h.js} +4 -4
  158. package/dist/tooling/shared/dhatassp.js +134 -0
  159. package/dist/tooling/shared/{spk1jg3r.js → ezqn88nj.js} +8 -8
  160. package/dist/tooling/shared/{6nyfyw70.js → f77nnfqy.js} +2 -2
  161. package/dist/tooling/shared/{wt7j7nf6.js → fh07z1dt.js} +1 -1
  162. package/dist/tooling/shared/{3rrw5w8f.js → gqwevek4.js} +1 -1
  163. package/dist/tooling/shared/{f9mphxej.js → hfq3n3bd.js} +346 -19
  164. package/dist/tooling/shared/{vs0t6qt8.js → j664qjrt.js} +2 -2
  165. package/dist/tooling/shared/{733a1tq3.js → jpgmjsx3.js} +3 -3
  166. package/dist/tooling/shared/{mtrqn2hn.js → jr2nmr81.js} +22 -30
  167. package/dist/{shared/mtw6jz76.js → tooling/shared/jsjjz875.js} +1 -1
  168. package/dist/tooling/shared/{2wtvc7rw.js → kbqnrs1x.js} +2 -2
  169. package/dist/tooling/shared/{gfvtj6d0.js → kz715295.js} +7 -7
  170. package/dist/tooling/shared/{a7q7t4n3.js → m3xt8b1h.js} +2 -2
  171. package/dist/tooling/shared/{dw08f3m8.js → m4hhb8aa.js} +2 -2
  172. package/dist/tooling/shared/{y031jct9.js → mw5npye0.js} +2 -2
  173. package/dist/tooling/shared/{vraj6d74.js → nxq95eb6.js} +3 -3
  174. package/dist/tooling/shared/{fb9k2qwd.js → qartgazh.js} +11 -30
  175. package/dist/tooling/shared/{xjs6zqtc.js → rcywj2w8.js} +9 -9
  176. package/dist/tooling/shared/{dy672fz6.js → s6qha57m.js} +2 -2
  177. package/dist/tooling/shared/{vx86qjv8.js → shjs0379.js} +3 -3
  178. package/dist/tooling/shared/{345tbc2k.js → sjwkt1pg.js} +1 -1
  179. package/dist/tooling/shared/{rq5kk8j6.js → stebqyyd.js} +3 -3
  180. package/dist/tooling/shared/{yk9mp7vb.js → t4xveemq.js} +4 -4
  181. package/dist/tooling/shared/{djydjpqt.js → t6zjeake.js} +5 -5
  182. package/dist/tooling/shared/{zhwnfyb2.js → tcwpjvxe.js} +1 -1
  183. package/dist/tooling/shared/{72fyg4zv.js → tpssp7ac.js} +1 -1
  184. package/dist/tooling/shared/{jne7b93p.js → v6j1ep6w.js} +3 -3
  185. package/dist/tooling/shared/{ec71zqgt.js → vwr2y833.js} +2 -2
  186. package/dist/tooling/shared/{j9t5s12a.js → w17sj05d.js} +2 -2
  187. package/dist/tooling/shared/{3tq8pnb8.js → w5d89rb4.js} +1 -1
  188. package/dist/tooling/shared/{smn6kz1p.js → wbwq1jsa.js} +2 -2
  189. package/dist/tooling/shared/{pwsytxm5.js → wezxf3h8.js} +1 -1
  190. package/dist/tooling/shared/{5bvw2nev.js → yb4kd19s.js} +1 -1
  191. package/dist/tooling/shared/{gmcf9cxf.js → ybdew6j7.js} +2 -2
  192. package/dist/tooling/shared/{ep8zh3bk.js → yfedr1zb.js} +1 -1
  193. package/dist/tooling/shared/{ddjtfgnx.js → yhp829bx.js} +3 -3
  194. package/dist/tooling/shared/{yfr8hzhm.js → ytk1tjs0.js} +1 -1
  195. package/dist/tooling/shared/{03k6res6.js → zs9aymcp.js} +1 -1
  196. package/dist/tooling/shared/zx3v9phv.js +8 -0
  197. package/dist/tooling/testing/index.js +2 -2
  198. package/package.json +38 -9
  199. package/dist/shared/fjpnhqan.js +0 -71
  200. package/dist/shared/n41w4fbz.js +0 -113
  201. package/dist/tooling/shared/pw8fgahx.js +0 -69
  202. /package/dist/shared/{ae4j5f42.js → mfvx6kjx.js} +0 -0
@@ -2,7 +2,7 @@ import {
2
2
  readHandle,
3
3
  readCall,
4
4
  attachHttp
5
- } from "./bah9nbg3.js";
5
+ } from "./npdftanb.js";
6
6
  import {
7
7
  decodeResult,
8
8
  emitWhere,
@@ -1,17 +1,18 @@
1
1
  import {
2
2
  open2
3
- } from "./35q0n9tz.js";
3
+ } from "./dd5pmnky.js";
4
4
  import"./12z7aznj.js";
5
+ import"./fk9vef30.js";
5
6
  import {
6
7
  createdOf,
7
8
  testing2
8
- } from "./b6d6p0zc.js";
9
+ } from "./2szgv6yj.js";
9
10
  import"./n442h54c.js";
10
11
  import {
11
12
  projectPath,
12
13
  loadConfig,
13
14
  loadSchema
14
- } from "./f4jy1j7x.js";
15
+ } from "./2zdxkt7b.js";
15
16
  import {
16
17
  sessionFailure,
17
18
  finishQuiet,
@@ -19,8 +20,7 @@ import {
19
20
  assertDirectConnection,
20
21
  assertStableBackend,
21
22
  selectTarget
22
- } from "./dpc2r7rb.js";
23
- import"./sjk86yrx.js";
23
+ } from "./6nae0spm.js";
24
24
  import {
25
25
  OkmError2
26
26
  } from "./52szzakm.js";
@@ -0,0 +1,450 @@
1
+ import {
2
+ open2
3
+ } from "./dd5pmnky.js";
4
+ import"./12z7aznj.js";
5
+ import"./n442h54c.js";
6
+ import"./fk9vef30.js";
7
+ import {
8
+ openProject
9
+ } from "./2zdxkt7b.js";
10
+ import {
11
+ sessionFailure,
12
+ finishQuiet,
13
+ assertTargetPolicy,
14
+ selectTarget
15
+ } from "./6nae0spm.js";
16
+ import {
17
+ isExactVersion,
18
+ compareExtensionVersions
19
+ } from "./r3j8s5y0.js";
20
+ import {
21
+ OkmError2
22
+ } from "./52szzakm.js";
23
+
24
+ // src/tooling/migrate/ext.ts
25
+ import { existsSync, writeFileSync } from "node:fs";
26
+ import { isAbsolute, join } from "node:path";
27
+ import { pathToFileURL } from "node:url";
28
+
29
+ // src/tooling/migrate/ext-surface.ts
30
+ var INSTALLED = `
31
+ select e.extversion, n.nspname, e.extrelocatable::text, current_setting('server_version_num')
32
+ from pg_extension e
33
+ join pg_namespace n on n.oid = e.extnamespace
34
+ where e.extname = $1
35
+ `;
36
+ var TYPES = `
37
+ select t.typname
38
+ from pg_depend d
39
+ join pg_extension e on e.oid = d.refobjid
40
+ join pg_type t on t.oid = d.objid
41
+ where e.extname = $1
42
+ and d.deptype = 'e'
43
+ and d.classid = 'pg_type'::regclass
44
+ and t.typtype in ('b', 'e', 'd')
45
+ order by t.typname
46
+ `;
47
+ var FUNCTIONS = `
48
+ select p.proname,
49
+ pg_get_function_identity_arguments(p.oid),
50
+ pg_get_function_result(p.oid)
51
+ from pg_depend d
52
+ join pg_extension e on e.oid = d.refobjid
53
+ join pg_proc p on p.oid = d.objid
54
+ where e.extname = $1
55
+ and d.deptype = 'e'
56
+ and d.classid = 'pg_proc'::regclass
57
+ order by p.proname, pg_get_function_identity_arguments(p.oid)
58
+ `;
59
+ var OPERATORS = `
60
+ select o.oprname,
61
+ coalesce(l.typname, ''),
62
+ coalesce(r.typname, ''),
63
+ res.typname
64
+ from pg_depend d
65
+ join pg_extension e on e.oid = d.refobjid
66
+ join pg_operator o on o.oid = d.objid
67
+ left join pg_type l on l.oid = o.oprleft
68
+ left join pg_type r on r.oid = o.oprright
69
+ join pg_type res on res.oid = o.oprresult
70
+ where e.extname = $1
71
+ and d.deptype = 'e'
72
+ and d.classid = 'pg_operator'::regclass
73
+ order by o.oprname, l.typname, r.typname
74
+ `;
75
+ var OPCLASSES = `
76
+ select am.amname, oc.opcname
77
+ from pg_depend d
78
+ join pg_extension e on e.oid = d.refobjid
79
+ join pg_opclass oc on oc.oid = d.objid
80
+ join pg_am am on am.oid = oc.opcmethod
81
+ where e.extname = $1
82
+ and d.deptype = 'e'
83
+ and d.classid = 'pg_opclass'::regclass
84
+ order by am.amname, oc.opcname
85
+ `;
86
+ var SETTINGS = `
87
+ select name from pg_settings where name like $1 order by name
88
+ `;
89
+ async function readSurface(pool, name) {
90
+ const installed = await pool.execute(INSTALLED, [name]);
91
+ const row = installed.rows[0];
92
+ if (row === undefined) {
93
+ throw new OkmError2("OKM1811", `Extension ${name} is not installed on the server.`, {
94
+ fix: { summary: "Install the extension, then run okm ext scaffold again." }
95
+ });
96
+ }
97
+ const version = text(row[0]);
98
+ const schema = text(row[1]);
99
+ const relocatable = row[2] === "t" || row[2] === "true";
100
+ const serverMajor = majorOf(text(row[3]));
101
+ const [types, functions, operators, methods, settings] = await Promise.all([
102
+ pool.execute(TYPES, [name]),
103
+ pool.execute(FUNCTIONS, [name]),
104
+ pool.execute(OPERATORS, [name]),
105
+ pool.execute(OPCLASSES, [name]),
106
+ pool.execute(SETTINGS, [`${name}.%`])
107
+ ]);
108
+ return {
109
+ name,
110
+ version,
111
+ schema,
112
+ relocatable,
113
+ serverMajor,
114
+ types: types.rows.map((item) => ({ name: text(item[0]) })),
115
+ functions: functions.rows.flatMap((item) => callable(item)),
116
+ operators: operators.rows.flatMap((item) => visibleOperator(item)),
117
+ indexMethods: methods.rows.map((item) => ({
118
+ name: text(item[0]),
119
+ opclass: text(item[1])
120
+ })),
121
+ settings: settings.rows.map((item) => text(item[0]))
122
+ };
123
+ }
124
+ function renderScaffold(surface) {
125
+ const exportName = `${camel(surface.name)}Ext`;
126
+ const settings = surface.settings.length === 0 ? "none" : surface.settings.join(", ");
127
+ const body = {
128
+ schema: surface.schema,
129
+ relocatable: surface.relocatable,
130
+ requires: {
131
+ postgres: ">=15",
132
+ version: `>=${surface.version}`
133
+ },
134
+ provides: {
135
+ types: surface.types,
136
+ operators: surface.operators,
137
+ functions: surface.functions,
138
+ indexMethods: surface.indexMethods
139
+ }
140
+ };
141
+ return [
142
+ 'import { extension } from "okmodel/ext";',
143
+ "",
144
+ "/**",
145
+ ` * Starting definition for ${surface.name} ${surface.version} in schema ${surface.schema}.`,
146
+ " * Edit this file. okm ext test checks it against the connected server.",
147
+ ` * Settings: ${settings}.`,
148
+ " */",
149
+ `export const ${exportName} = extension(${JSON.stringify(surface.name)}, ${JSON.stringify(body, null, 2)});`,
150
+ ""
151
+ ].join(`
152
+ `);
153
+ }
154
+ function surfaceMismatches(declared, server) {
155
+ const lines = [];
156
+ lines.push(...versionMismatches(declared, server));
157
+ const provides = declared.provides;
158
+ if (provides === undefined)
159
+ return lines;
160
+ for (const type of provides.types ?? []) {
161
+ if (!server.types.some((item) => item.name === type.name)) {
162
+ lines.push(`type ${type.name} is not in ${declared.name}`);
163
+ }
164
+ }
165
+ for (const operator of provides.operators ?? []) {
166
+ if (!operatorMatches(operator, server.operators)) {
167
+ lines.push(operatorLine(operator));
168
+ }
169
+ }
170
+ for (const fn of provides.functions ?? []) {
171
+ if (!functionMatches(fn, server.functions)) {
172
+ lines.push(`function ${fn.name}(${fn.args.join(", ")}) -> ${fn.returns}`);
173
+ }
174
+ }
175
+ for (const method of provides.indexMethods ?? []) {
176
+ if (!methodMatches(method, server.indexMethods)) {
177
+ const opclass = method.opclass === undefined ? "" : ` ${method.opclass}`;
178
+ lines.push(`index method ${method.name}${opclass}`);
179
+ }
180
+ }
181
+ return lines;
182
+ }
183
+ function refuseMismatches(name, mismatches) {
184
+ if (mismatches.length === 0)
185
+ return;
186
+ const version = mismatches.some((line) => line.startsWith("version ") || line.startsWith("postgres "));
187
+ const code = version ? "OKM1812" : "invalid";
188
+ throw new OkmError2(code, `Extension ${name} does not match the server.
189
+ ${mismatches.join(`
190
+ `)}`, {
191
+ fix: {
192
+ summary: "Edit the definition so each signature matches the server, or install the version requires names."
193
+ }
194
+ });
195
+ }
196
+ function versionMismatches(declared, server) {
197
+ const lines = [];
198
+ const requires = {
199
+ ...declared.requires,
200
+ ...declared.version !== undefined ? { version: declared.version } : {}
201
+ };
202
+ const postgres = requires.postgres;
203
+ if (postgres !== undefined && !majorAllows(postgres, server.serverMajor)) {
204
+ lines.push(`postgres ${postgres} is not met. The server is PostgreSQL ${String(server.serverMajor)}. minPostgres: ${floorText(postgres)}.`);
205
+ }
206
+ const version = requires.version;
207
+ if (version !== undefined && !versionAllows(version, server.version)) {
208
+ lines.push(`version ${version} is not met. The server has ${server.version}.`);
209
+ }
210
+ return lines;
211
+ }
212
+ function majorAllows(declared, server) {
213
+ const floor = /^>=(\d+)$/.exec(declared);
214
+ const exact = floor?.[1] ?? (/^\d+$/.test(declared) ? declared : undefined);
215
+ if (exact === undefined)
216
+ return false;
217
+ return server >= Number(exact);
218
+ }
219
+ function versionAllows(declared, installed) {
220
+ const floor = /^>=(\d+(?:\.\d+)*)$/.exec(declared);
221
+ const pinned = floor?.[1] ?? declared;
222
+ if (!isExactVersion(pinned) || !isExactVersion(installed))
223
+ return declared === installed;
224
+ return compareExtensionVersions(installed, pinned) >= 0;
225
+ }
226
+ function floorText(declared) {
227
+ return declared.startsWith(">=") ? declared.slice(2) : declared;
228
+ }
229
+ function operatorMatches(declared, server) {
230
+ 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);
231
+ }
232
+ function functionMatches(declared, server) {
233
+ const args = declared.args.join(", ");
234
+ return server.some((item) => item.name === declared.name && item.args.join(", ") === args && item.returns === declared.returns);
235
+ }
236
+ function methodMatches(declared, server) {
237
+ return server.some((item) => item.name === declared.name && (declared.opclass === undefined || item.opclass === declared.opclass));
238
+ }
239
+ function operatorLine(operator) {
240
+ const left = operator.left ?? "";
241
+ const right = operator.right ?? "";
242
+ return `operator ${left} ${operator.name} ${right} -> ${operator.result}`.replaceAll(/\s+/g, " ").trim();
243
+ }
244
+ function callable(row) {
245
+ const args = text(row[1]);
246
+ const returns = text(row[2]);
247
+ if (args.includes("internal") || returns.includes("internal"))
248
+ return [];
249
+ return [
250
+ {
251
+ name: text(row[0]),
252
+ args: args.length === 0 ? [] : args.split(", ").filter((part) => part.length > 0),
253
+ returns
254
+ }
255
+ ];
256
+ }
257
+ function visibleOperator(row) {
258
+ const left = text(row[1]);
259
+ const right = text(row[2]);
260
+ const result = text(row[3]);
261
+ if ([left, right, result].some((part) => part === "internal"))
262
+ return [];
263
+ return [
264
+ {
265
+ name: text(row[0]),
266
+ ...left.length > 0 ? { left } : {},
267
+ ...right.length > 0 ? { right } : {},
268
+ result
269
+ }
270
+ ];
271
+ }
272
+ function text(value) {
273
+ if (typeof value === "string")
274
+ return value;
275
+ if (typeof value === "number" || typeof value === "boolean")
276
+ return String(value);
277
+ return "";
278
+ }
279
+ function majorOf(versionNum) {
280
+ const parsed = Number(versionNum);
281
+ if (!Number.isFinite(parsed))
282
+ return 0;
283
+ return Math.floor(parsed / 1e4);
284
+ }
285
+ function camel(name) {
286
+ const parts = name.split(/[^A-Za-z0-9]+/).filter((part) => part.length > 0);
287
+ const [first, ...rest] = parts;
288
+ if (first === undefined)
289
+ return "extension";
290
+ return first.toLowerCase() + rest.map((part) => part.slice(0, 1).toUpperCase() + part.slice(1).toLowerCase()).join("");
291
+ }
292
+ function isExtension(value) {
293
+ if (typeof value !== "object" || value === null)
294
+ return false;
295
+ if (!("name" in value) || !("contribute" in value) || !("schema" in value))
296
+ return false;
297
+ return typeof value.name === "string" && typeof value.contribute === "function";
298
+ }
299
+ function extensionsFromModule(imported) {
300
+ if (typeof imported !== "object" || imported === null)
301
+ return [];
302
+ const found = [];
303
+ for (const value of Object.values(imported)) {
304
+ if (isExtension(value))
305
+ found.push(value);
306
+ }
307
+ return found;
308
+ }
309
+
310
+ // src/tooling/migrate/ext.ts
311
+ async function extProject(cwd, command, flags) {
312
+ const opened = await openProject(cwd);
313
+ const target = selectTarget(opened.config, flags.target);
314
+ assertTargetPolicy(target, "check", flags.allowProtected);
315
+ const pool = open2({ url: target.url, max: 1 });
316
+ try {
317
+ if (command === "list")
318
+ return formatList(await readExtensions(pool));
319
+ return formatCheck(opened.built.catalog.objects, await readExtensions(pool));
320
+ } catch (error) {
321
+ throw sessionFailure(error) ?? error;
322
+ } finally {
323
+ await finishQuiet(() => pool.close());
324
+ }
325
+ }
326
+ var LIST_SQL = `
327
+ select a.name, a.default_version, e.extversion, n.nspname
328
+ from pg_available_extensions a
329
+ left join pg_extension e on e.extname = a.name
330
+ left join pg_namespace n on n.oid = e.extnamespace
331
+ order by a.name
332
+ `;
333
+ async function readExtensions(pool) {
334
+ const result = await pool.execute(LIST_SQL);
335
+ return result.rows.map((row) => ({
336
+ name: cell(row[0]),
337
+ defaultVersion: cell(row[1]),
338
+ installedVersion: cell(row[2]),
339
+ schema: cell(row[3])
340
+ }));
341
+ }
342
+ function cell(value) {
343
+ return typeof value === "string" ? value : "";
344
+ }
345
+ function formatList(rows) {
346
+ const lines = ["name\tdefault\tinstalled\tschema"];
347
+ for (const row of rows) {
348
+ lines.push([row.name, row.defaultVersion, row.installedVersion, row.schema].join("\t"));
349
+ }
350
+ return `${lines.join(`
351
+ `)}
352
+ `;
353
+ }
354
+ function formatCheck(objects, server) {
355
+ const declared = objects.filter((object) => object.kind === "extension");
356
+ if (declared.length === 0)
357
+ return `no extensions
358
+ `;
359
+ const installed = new Map(server.map((row) => [row.name, row.installedVersion]));
360
+ const lines = ["name\tdeclared\tinstalled"];
361
+ for (const object of [...declared].sort((left, right) => left.identity.name < right.identity.name ? -1 : 1)) {
362
+ const name = object.identity.name;
363
+ const have = installed.get(name) ?? "";
364
+ if (have.length === 0) {
365
+ throw new OkmError2("OKM1811", `Extension ${name} is not installed on the server.`, {
366
+ fix: { summary: "Install the extension, or remove the declaration." }
367
+ });
368
+ }
369
+ const want = object.definition.version;
370
+ if (!versionAccepted(want, have)) {
371
+ throw new OkmError2("OKM1812", extensionNeeds(name, want ?? "", have), {
372
+ fix: { summary: "Install a version the declaration accepts, or change the pin." }
373
+ });
374
+ }
375
+ lines.push([name, want ?? "-", have].join("\t"));
376
+ }
377
+ return `${lines.join(`
378
+ `)}
379
+ `;
380
+ }
381
+ function extensionNeeds(name, want, have) {
382
+ const floor = /^>=(\d+(?:\.\d+)*)$/.exec(want);
383
+ const need = floor?.[1] ?? want;
384
+ const higher = floor === null ? "" : " or higher";
385
+ return `Extension ${name} needs ${need}${higher}. The server has ${have}. Install a version the declaration accepts, or change the pin.`;
386
+ }
387
+ async function extScaffold(cwd, name, flags, out) {
388
+ if (out !== undefined) {
389
+ const path = isAbsolute(out) ? out : join(cwd, out);
390
+ if (existsSync(path)) {
391
+ 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." } });
392
+ }
393
+ }
394
+ const text = await withServer(cwd, flags, async (pool) => renderScaffold(await readSurface(pool, name)));
395
+ if (out === undefined)
396
+ return text;
397
+ const path = isAbsolute(out) ? out : join(cwd, out);
398
+ writeFileSync(path, text);
399
+ return `wrote ${path}
400
+ `;
401
+ }
402
+ async function extTest(cwd, file, flags) {
403
+ const path = isAbsolute(file) ? file : join(cwd, file);
404
+ const imported = await import(pathToFileURL(path).href);
405
+ const declared = extensionsFromModule(imported);
406
+ if (declared.length === 0) {
407
+ throw new OkmError2("invalid", `okm ext test found no extension() in ${path}.`, {
408
+ fix: { summary: "Export the value extension() returns." }
409
+ });
410
+ }
411
+ return withServer(cwd, flags, async (pool) => {
412
+ const lines = [];
413
+ for (const extension of declared) {
414
+ const server = await readSurface(pool, extension.name);
415
+ refuseMismatches(extension.name, surfaceMismatches(extension, server));
416
+ lines.push(`ok ${extension.name}`);
417
+ }
418
+ return `${lines.join(`
419
+ `)}
420
+ `;
421
+ });
422
+ }
423
+ async function withServer(cwd, flags, body) {
424
+ const opened = await openProject(cwd);
425
+ const target = selectTarget(opened.config, flags.target);
426
+ assertTargetPolicy(target, "check", flags.allowProtected);
427
+ const pool = open2({ url: target.url, max: 1 });
428
+ try {
429
+ return await body(pool);
430
+ } catch (error) {
431
+ throw sessionFailure(error) ?? error;
432
+ } finally {
433
+ await finishQuiet(() => pool.close());
434
+ }
435
+ }
436
+ function versionAccepted(declared, installed) {
437
+ if (declared === undefined)
438
+ return true;
439
+ const floor = /^>=(\d+(?:\.\d+)*)$/.exec(declared);
440
+ const minimum = floor?.[1];
441
+ if (minimum !== undefined) {
442
+ return isExactVersion(installed) && compareExtensionVersions(installed, minimum) >= 0;
443
+ }
444
+ return declared === installed;
445
+ }
446
+ export {
447
+ extProject,
448
+ extScaffold,
449
+ extTest
450
+ };
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  rejectUncancellable
3
- } from "./xhrnjch9.js";
3
+ } from "./mfvx6kjx.js";
4
4
 
5
5
  // src/adapters/pg/no-inflight-timeout.ts
6
6
  function noTimeout(options) {
@@ -1,9 +1,9 @@
1
1
  import {
2
2
  build3
3
- } from "./n0jmpgj1.js";
3
+ } from "./cexb7z6b.js";
4
4
  import {
5
5
  attachHttp
6
- } from "./bah9nbg3.js";
6
+ } from "./npdftanb.js";
7
7
  import {
8
8
  rejectKeys,
9
9
  readLimit,
@@ -8,7 +8,7 @@ import {
8
8
  openClient,
9
9
  withHttp,
10
10
  settleCall
11
- } from "./bah9nbg3.js";
11
+ } from "./npdftanb.js";
12
12
  import {
13
13
  rejectKeys,
14
14
  isRecord,
@@ -0,0 +1,61 @@
1
+ import {
2
+ quotedIdent
3
+ } from "./h9811jjm.js";
4
+ import {
5
+ sqlExpression
6
+ } from "./bsek72fg.js";
7
+ import {
8
+ OkmError2
9
+ } from "./52szzakm.js";
10
+
11
+ // src/dialects/pg/ext/call.ts
12
+ function fnEqualsArg(schema, name, value) {
13
+ const fn = `${quotedIdent(schema)}.${quotedIdent(name)}`;
14
+ return sqlExpression([
15
+ { k: "t", s: `${fn}(` },
16
+ { k: "c" },
17
+ { k: "t", s: `) = ${fn}(` },
18
+ { k: "p", v: value },
19
+ { k: "t", s: ")" }
20
+ ], true);
21
+ }
22
+ function fnDistance(schema, name, value, distance) {
23
+ if (!Number.isInteger(distance)) {
24
+ throw new OkmError2("OKM1120", `${name} distance must be an integer.`, {
25
+ fix: { summary: "Pass a whole number of edits." }
26
+ });
27
+ }
28
+ const fn = `${quotedIdent(schema)}.${quotedIdent(name)}`;
29
+ return sqlExpression([
30
+ { k: "t", s: `${fn}(` },
31
+ { k: "c" },
32
+ { k: "t", s: ", " },
33
+ { k: "p", v: value },
34
+ { k: "t", s: ") = " },
35
+ { k: "p", v: String(distance) },
36
+ { k: "t", s: "::integer" }
37
+ ], true);
38
+ }
39
+ function opArg(op, value, cast) {
40
+ const parts = [{ k: "c" }, { k: "t", s: ` ${op} ` }, { k: "p", v: value }];
41
+ if (cast !== undefined)
42
+ parts.push({ k: "t", s: `::${cast}` });
43
+ return sqlExpression(parts, true);
44
+ }
45
+ function bareCall(schema, name) {
46
+ const fn = `${quotedIdent(schema)}.${quotedIdent(name)}`;
47
+ return sqlExpression([{ k: "t", s: `${fn}()` }], true);
48
+ }
49
+ function digestEquals(schema, algorithm, hex) {
50
+ const fn = `${quotedIdent(schema)}.${quotedIdent("digest")}`;
51
+ return sqlExpression([
52
+ { k: "t", s: `encode(${fn}(` },
53
+ { k: "c" },
54
+ { k: "t", s: ", " },
55
+ { k: "p", v: algorithm },
56
+ { k: "t", s: "), 'hex') = " },
57
+ { k: "p", v: hex }
58
+ ], true);
59
+ }
60
+
61
+ export { fnEqualsArg, fnDistance, opArg, bareCall, digestEquals };
@@ -3,7 +3,7 @@ import {
3
3
  readHandle,
4
4
  readCall,
5
5
  attachHttp
6
- } from "./bah9nbg3.js";
6
+ } from "./npdftanb.js";
7
7
  import {
8
8
  emitWhere,
9
9
  emitOrder,
@@ -4,23 +4,23 @@ import {
4
4
  import {
5
5
  connectClient2,
6
6
  send3
7
- } from "./agsfb86s.js";
7
+ } from "./mazpbcdj.js";
8
8
  import {
9
9
  resetSession2
10
- } from "./7ghwamrf.js";
10
+ } from "./99qp9vtg.js";
11
11
  import {
12
12
  isConnectionLost
13
13
  } from "./cnkky55j.js";
14
14
  import {
15
15
  noTimeout
16
- } from "./q0cqt2sp.js";
16
+ } from "./tr64w5p0.js";
17
17
  import {
18
18
  WireSession
19
- } from "./mtw6jz76.js";
19
+ } from "./e275q7sd.js";
20
20
  import {
21
21
  rejectClosed,
22
22
  runCall
23
- } from "./ae4j5f42.js";
23
+ } from "./mfvx6kjx.js";
24
24
 
25
25
  // src/adapters/pg/neon-extra.ts
26
26
  async function checkout(held) {
@@ -1,7 +1,7 @@
1
1
  import {
2
2
  touchFields,
3
3
  fieldSealed
4
- } from "./bxas03mq.js";
4
+ } from "./9dtgn1z2.js";
5
5
  import {
6
6
  projectExpr,
7
7
  quote,
@@ -1,24 +1,24 @@
1
1
  import {
2
2
  open2
3
- } from "./35q0n9tz.js";
3
+ } from "./dd5pmnky.js";
4
4
  import"./12z7aznj.js";
5
+ import"./fk9vef30.js";
5
6
  import"./n442h54c.js";
6
7
  import {
7
8
  assertRoleHealth
8
- } from "./kj9d8maq.js";
9
- import"./p3xbdcvt.js";
9
+ } from "./jpybhf98.js";
10
+ import"./myk8fswx.js";
10
11
  import {
11
12
  errorDoc,
12
13
  openProject
13
- } from "./f4jy1j7x.js";
14
+ } from "./2zdxkt7b.js";
14
15
  import {
15
16
  omitManagedObjects,
16
17
  sessionFailure,
17
18
  finishQuiet,
18
19
  assertTargetPolicy,
19
20
  selectTarget
20
- } from "./dpc2r7rb.js";
21
- import"./sjk86yrx.js";
21
+ } from "./6nae0spm.js";
22
22
  import {
23
23
  OkmError2
24
24
  } from "./52szzakm.js";