okmodel 0.7.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 (258) hide show
  1. package/README.md +14 -0
  2. package/dist/adapters/capabilities.d.ts +32 -0
  3. package/dist/adapters/failure.d.ts +1 -1
  4. package/dist/adapters/pg/bun-sql.d.ts +53 -0
  5. package/dist/adapters/pg/bunsql-extra.d.ts +1 -1
  6. package/dist/adapters/pg/bunsql.d.ts +1 -1
  7. package/dist/adapters/pg/neon-extra.d.ts +18 -0
  8. package/dist/adapters/pg/neon.d.ts +104 -0
  9. package/dist/adapters/pg/no-inflight-timeout.d.ts +1 -1
  10. package/dist/contracts/error.d.ts +1 -1
  11. package/dist/dialects/pg/ext/btree-gin.d.ts +26 -0
  12. package/dist/dialects/pg/ext/btree-gin.js +20 -0
  13. package/dist/dialects/pg/ext/btree-gist.d.ts +26 -0
  14. package/dist/dialects/pg/ext/btree-gist.js +20 -0
  15. package/dist/dialects/pg/ext/call.d.ts +53 -0
  16. package/dist/dialects/pg/ext/citext.js +1 -1
  17. package/dist/dialects/pg/ext/feature.d.ts +26 -0
  18. package/dist/dialects/pg/ext/fuzzystrmatch.d.ts +34 -0
  19. package/dist/dialects/pg/ext/fuzzystrmatch.js +33 -0
  20. package/dist/dialects/pg/ext/hstore.d.ts +41 -0
  21. package/dist/dialects/pg/ext/hstore.js +29 -0
  22. package/dist/dialects/pg/ext/index.d.ts +56 -0
  23. package/dist/dialects/pg/ext/index.js +1 -1
  24. package/dist/dialects/pg/ext/ltree.d.ts +41 -0
  25. package/dist/dialects/pg/ext/ltree.js +29 -0
  26. package/dist/dialects/pg/ext/pg-trgm.js +4 -13
  27. package/dist/dialects/pg/ext/pgcrypto.d.ts +33 -0
  28. package/dist/dialects/pg/ext/pgcrypto.js +33 -0
  29. package/dist/dialects/pg/ext/unaccent.d.ts +26 -0
  30. package/dist/dialects/pg/ext/unaccent.js +21 -0
  31. package/dist/dialects/pg/ext/using.d.ts +23 -0
  32. package/dist/dialects/pg/ext/versions.d.ts +36 -0
  33. package/dist/dialects/pg/external.d.ts +19 -0
  34. package/dist/dialects/pg/fn/index.d.ts +39 -1
  35. package/dist/dialects/pg/fn/index.js +118 -26
  36. package/dist/dialects/pg/index.d.ts +3 -0
  37. package/dist/dialects/pg/index.js +394 -14
  38. package/dist/dialects/pg/introspect.d.ts +11 -0
  39. package/dist/dialects/pg/operators.d.ts +1 -1
  40. package/dist/dialects/pg/ops/fragment.d.ts +119 -0
  41. package/dist/dialects/pg/ops/lane.d.ts +49 -0
  42. package/dist/dialects/pg/view/client.d.ts +14 -6
  43. package/dist/dialects/pg/view/index.d.ts +73 -1
  44. package/dist/dialects/pg/view/index.js +156 -5
  45. package/dist/dialects/pg/view/scratch.d.ts +11 -5
  46. package/dist/runtime/artifact-file.d.ts +22 -0
  47. package/dist/runtime/client.d.ts +10 -0
  48. package/dist/runtime/drift-detail.d.ts +2 -1
  49. package/dist/runtime/drift.d.ts +3 -10
  50. package/dist/runtime/otel.d.ts +105 -0
  51. package/dist/runtime/otel.js +97 -0
  52. package/dist/runtime/pg/bun.js +4 -4
  53. package/dist/runtime/pg/neon.d.ts +38 -0
  54. package/dist/runtime/pg/neon.js +64 -0
  55. package/dist/runtime/pg/pg.js +4 -4
  56. package/dist/runtime/pg/pglite.js +4 -4
  57. package/dist/runtime/pg/postgresjs.js +4 -4
  58. package/dist/runtime/plan.d.ts +1 -1
  59. package/dist/runtime/server-check.d.ts +36 -6
  60. package/dist/runtime/sql-fragment.d.ts +43 -0
  61. package/dist/runtime/tenancy/index.js +10 -10
  62. package/dist/runtime/topology.d.ts +1 -1
  63. package/dist/runtime/traits/index.js +16 -17
  64. package/dist/runtime/types.d.ts +15 -1
  65. package/dist/runtime/validate/index.js +4 -4
  66. package/dist/shared/{81ebdx9p.js → 0j6qe91y.js} +4 -4
  67. package/dist/shared/{qq3899ht.js → 12z7aznj.js} +243 -14
  68. package/dist/shared/{gzaveazc.js → 1d9q9cv2.js} +29 -2
  69. package/dist/shared/{w79hsckn.js → 1mxm04fy.js} +5 -5
  70. package/dist/shared/{7k9grvf6.js → 2szgv6yj.js} +5 -5
  71. package/dist/shared/{gs74dbj5.js → 2zdxkt7b.js} +933 -111
  72. package/dist/shared/{m6p12kbr.js → 3456242y.js} +23 -23
  73. package/dist/shared/3bb7wsqt.js +99 -0
  74. package/dist/shared/{y6njgyda.js → 3t6kw83m.js} +2 -2
  75. package/dist/shared/{xhfsfkgk.js → 4vbf83xx.js} +9 -2
  76. package/dist/shared/{pt94kz7f.js → 5kyb3tqx.js} +1 -1
  77. package/dist/shared/61bmrmhr.js +35 -0
  78. package/dist/shared/{x933k9a3.js → 62b603gr.js} +10 -10
  79. package/dist/shared/{jgqj11w4.js → 6f0z3hzh.js} +4 -0
  80. package/dist/shared/{tsvww22q.js → 6nae0spm.js} +156 -95
  81. package/dist/shared/{mtaszv5a.js → 71n0jmhc.js} +102 -4
  82. package/dist/shared/{5e3tf63j.js → 760ppr76.js} +14 -6
  83. package/dist/shared/7ba5h6pb.js +17 -0
  84. package/dist/shared/{sfz1ksn6.js → 8jesqsrk.js} +2 -2
  85. package/dist/shared/{5v3xf80k.js → 8n688yjg.js} +1 -1
  86. package/dist/shared/{rs73fca9.js → 8qzkd9f3.js} +6 -6
  87. package/dist/shared/{ax7qv55k.js → 90sg0w5a.js} +202 -25
  88. package/dist/shared/{zm0ptry0.js → 99qp9vtg.js} +1 -1
  89. package/dist/shared/{xnxsed62.js → 9dr2qnx7.js} +14 -14
  90. package/dist/shared/{1w508jbr.js → 9dtgn1z2.js} +21 -17
  91. package/dist/shared/{h15jx9bc.js → 9dvh1dr6.js} +1 -1
  92. package/dist/shared/{q5c6ngn3.js → a62rb2da.js} +1 -1
  93. package/dist/shared/{te5as7z7.js → aksb89mn.js} +3 -3
  94. package/dist/shared/{bz84tkzm.js → bphrgwz9.js} +2 -2
  95. package/dist/shared/bsek72fg.js +225 -0
  96. package/dist/shared/{7mnme5tn.js → c3mvnq7a.js} +1 -1
  97. package/dist/shared/{p6qc5gcp.js → ccsmhv9r.js} +25 -7
  98. package/dist/shared/{pbp1ss85.js → cexb7z6b.js} +2 -2
  99. package/dist/shared/{ab9gmbwy.js → cf8zdz5p.js} +5 -5
  100. package/dist/shared/{jvd0mqag.js → ckz05z15.js} +5 -5
  101. package/dist/shared/{dk8v79p3.js → d5nmj7vv.js} +1 -1
  102. package/dist/shared/{14vx95q4.js → dd5pmnky.js} +7 -7
  103. package/dist/shared/{vb6qfyve.js → ds229x4r.js} +2 -2
  104. package/dist/shared/{1qa0qajz.js → e275q7sd.js} +1 -1
  105. package/dist/shared/{zp9fmend.js → ebhz8vh6.js} +4 -4
  106. package/dist/shared/{hyh73qk6.js → ecn8mfdq.js} +5 -5
  107. package/dist/shared/{je4axnm8.js → fdsz3w80.js} +2 -2
  108. package/dist/shared/{9s0ypp87.js → fk9vef30.js} +85 -74
  109. package/dist/shared/{g6evj1j3.js → g89fmz5s.js} +1 -1
  110. package/dist/shared/{aytqh5y2.js → ghqzdp94.js} +2 -2
  111. package/dist/shared/h9811jjm.js +17 -0
  112. package/dist/shared/{dkxgzaqd.js → hqpxf4a4.js} +1 -1
  113. package/dist/shared/{8skf0cam.js → jpybhf98.js} +1 -1
  114. package/dist/shared/{67txcrcw.js → kgwp4jdd.js} +4 -4
  115. package/dist/shared/kzgrnckd.js +29 -0
  116. package/dist/shared/mazpbcdj.js +233 -0
  117. package/dist/shared/{kb2sdhfb.js → mfvx6kjx.js} +17 -1
  118. package/dist/shared/{svncdeh5.js → mgaq2sd3.js} +11 -8
  119. package/dist/shared/{5mtf6cj3.js → mvmm3xpb.js} +5 -2
  120. package/dist/shared/{b5pftnn2.js → myk8fswx.js} +66 -21
  121. package/dist/shared/{2shdbn8q.js → n306gqkd.js} +9 -9
  122. package/dist/shared/{n816peh1.js → n454kcnw.js} +1 -1
  123. package/dist/shared/n5whk3mt.js +665 -0
  124. package/dist/shared/n7kg8mmx.js +61 -0
  125. package/dist/shared/{vqrjpcqn.js → nmnsgj7x.js} +1 -1
  126. package/dist/shared/{tbrvgw6z.js → npdftanb.js} +19 -26
  127. package/dist/shared/{ek2wt2dz.js → pg4ezgyf.js} +11 -30
  128. package/dist/shared/{5fe3kbsh.js → pgsak1yw.js} +1 -1
  129. package/dist/shared/{bm22fvzr.js → qfw14tna.js} +2 -2
  130. package/dist/shared/{wa07eas9.js → qvwwp1mp.js} +62 -41
  131. package/dist/shared/rbxt795q.js +1766 -0
  132. package/dist/shared/{xjk7hnn5.js → s7he5e5d.js} +2 -2
  133. package/dist/shared/{w72kgg4q.js → ss2kv2rs.js} +6 -6
  134. package/dist/shared/stfa9xcw.js +450 -0
  135. package/dist/shared/{3v7t1yrv.js → th3be82n.js} +2 -2
  136. package/dist/shared/{79dt02vc.js → tr64w5p0.js} +1 -1
  137. package/dist/shared/{cn957f8d.js → tw1nvvfj.js} +3 -3
  138. package/dist/shared/{ed0b8k4s.js → typ3vy7t.js} +1 -1
  139. package/dist/shared/{9628a9xt.js → vk7rag46.js} +1 -1
  140. package/dist/shared/{ze4hxsmy.js → w9ejzaqf.js} +1 -1
  141. package/dist/shared/{vczs8gd4.js → wvtjg5m3.js} +2 -2
  142. package/dist/shared/{9y3mmmh1.js → xfhe73sb.js} +1 -1
  143. package/dist/shared/xqacq37x.js +61 -0
  144. package/dist/shared/{1est4ezg.js → xtsydxjg.js} +3 -3
  145. package/dist/shared/xv8qj97g.js +96 -0
  146. package/dist/shared/{bg3rym3g.js → xwhdcrm4.js} +2 -2
  147. package/dist/shared/{kr0jzbw2.js → yvabyg9k.js} +7 -7
  148. package/dist/shared/yybhre6n.js +136 -0
  149. package/dist/shared/zdqf8k5d.js +8 -0
  150. package/dist/shared/{jznfax0y.js → zq1he88x.js} +4 -4
  151. package/dist/tooling/cli.js +108 -23
  152. package/dist/tooling/driver-run.js +4654 -0
  153. package/dist/tooling/driver-test.d.ts +36 -0
  154. package/dist/tooling/github/comment.d.ts +50 -0
  155. package/dist/tooling/github/post-comment.d.ts +17 -0
  156. package/dist/tooling/migrate/commands.d.ts +3 -2
  157. package/dist/tooling/migrate/config.d.ts +13 -0
  158. package/dist/tooling/migrate/export.d.ts +165 -0
  159. package/dist/tooling/migrate/ext-surface.d.ts +80 -0
  160. package/dist/tooling/migrate/ext.d.ts +31 -4
  161. package/dist/tooling/migrate/import-drizzle.d.ts +40 -0
  162. package/dist/tooling/migrate/index.d.ts +3 -0
  163. package/dist/tooling/migrate/index.js +55 -10
  164. package/dist/tooling/migrate/lint-rules.d.ts +18 -1
  165. package/dist/tooling/migrate/lint.d.ts +14 -1
  166. package/dist/tooling/migrate/place.d.ts +18 -0
  167. package/dist/tooling/migrate/plan-json.d.ts +65 -0
  168. package/dist/tooling/migrate/project.d.ts +13 -1
  169. package/dist/tooling/migrate/pull-emit.d.ts +98 -0
  170. package/dist/tooling/migrate/pull-routines.d.ts +126 -0
  171. package/dist/tooling/migrate/pull-verify.d.ts +26 -0
  172. package/dist/tooling/migrate/pull.d.ts +62 -0
  173. package/dist/tooling/migrate/reprint.d.ts +32 -0
  174. package/dist/tooling/migrate/sandbox.d.ts +8 -2
  175. package/dist/tooling/migrate/schema-api.d.ts +43 -0
  176. package/dist/tooling/migrate/sql-lex.d.ts +18 -0
  177. package/dist/tooling/shared/04svnxxj.js +344 -0
  178. package/dist/tooling/shared/0j0jtse1.js +13 -0
  179. package/dist/tooling/shared/0r05zhyq.js +618 -0
  180. package/dist/tooling/shared/1800eymw.js +49 -0
  181. package/dist/tooling/shared/35zemrmf.js +12 -0
  182. package/dist/tooling/shared/3rmaz3pq.js +140 -0
  183. package/dist/tooling/shared/3yn79q5m.js +12 -0
  184. package/dist/tooling/shared/54tqkxja.js +51 -0
  185. package/dist/tooling/shared/57btdkgm.js +209 -0
  186. package/dist/tooling/shared/5bmksndh.js +118 -0
  187. package/dist/tooling/shared/5p8km5jb.js +38 -0
  188. package/dist/tooling/shared/5x3pf400.js +185 -0
  189. package/dist/tooling/shared/5zrzffnk.js +6 -0
  190. package/dist/tooling/shared/62fxpc1p.js +332 -0
  191. package/dist/tooling/shared/68tf18v4.js +20 -0
  192. package/dist/tooling/shared/6vk28rjp.js +98 -0
  193. package/dist/tooling/shared/76pv6qff.js +9 -0
  194. package/dist/tooling/shared/7aews1zg.js +311 -0
  195. package/dist/tooling/shared/7b3xp9gc.js +195 -0
  196. package/dist/tooling/shared/7kms6fvj.js +20 -0
  197. package/dist/tooling/shared/7pxncnzs.js +40 -0
  198. package/dist/tooling/shared/829fjxyw.js +198 -0
  199. package/dist/tooling/shared/8m5znpdt.js +66 -0
  200. package/dist/tooling/shared/8yr7ges1.js +211 -0
  201. package/dist/tooling/shared/96ps4g1z.js +32 -0
  202. package/dist/tooling/shared/9qr9rkbh.js +143 -0
  203. package/dist/tooling/shared/9sfbtwsk.js +49 -0
  204. package/dist/tooling/shared/9wsnsvbf.js +10 -0
  205. package/dist/tooling/shared/a2xe04bm.js +18 -0
  206. package/dist/tooling/shared/a4pzghha.js +20 -0
  207. package/dist/tooling/shared/am04v8na.js +233 -0
  208. package/dist/tooling/shared/asgr07mp.js +194 -0
  209. package/dist/tooling/shared/c0xevn1h.js +312 -0
  210. package/dist/tooling/shared/dhatassp.js +134 -0
  211. package/dist/tooling/shared/ezqn88nj.js +1696 -0
  212. package/dist/tooling/shared/f77nnfqy.js +231 -0
  213. package/dist/tooling/shared/fh07z1dt.js +15 -0
  214. package/dist/tooling/shared/gqwevek4.js +81 -0
  215. package/dist/tooling/shared/hfq3n3bd.js +4116 -0
  216. package/dist/tooling/shared/htnaj77v.js +17 -0
  217. package/dist/tooling/shared/j664qjrt.js +64 -0
  218. package/dist/tooling/shared/jpgmjsx3.js +38 -0
  219. package/dist/tooling/shared/jr2nmr81.js +497 -0
  220. package/dist/tooling/shared/jsjjz875.js +139 -0
  221. package/dist/tooling/shared/kbqnrs1x.js +1425 -0
  222. package/dist/tooling/shared/kz715295.js +94 -0
  223. package/dist/tooling/shared/m3xt8b1h.js +22 -0
  224. package/dist/tooling/shared/m4hhb8aa.js +9 -0
  225. package/dist/tooling/shared/mw5npye0.js +16 -0
  226. package/dist/tooling/shared/n4jqhpqz.js +27 -0
  227. package/dist/tooling/shared/nxq95eb6.js +42 -0
  228. package/dist/tooling/shared/qartgazh.js +70 -0
  229. package/dist/tooling/shared/rcywj2w8.js +190 -0
  230. package/dist/tooling/shared/s6qha57m.js +16 -0
  231. package/dist/tooling/shared/shjs0379.js +150 -0
  232. package/dist/tooling/shared/sjwkt1pg.js +16 -0
  233. package/dist/tooling/shared/stebqyyd.js +401 -0
  234. package/dist/tooling/shared/t4xveemq.js +250 -0
  235. package/dist/tooling/shared/t6zjeake.js +261 -0
  236. package/dist/tooling/shared/tcwpjvxe.js +9 -0
  237. package/dist/tooling/shared/tpssp7ac.js +160 -0
  238. package/dist/tooling/shared/v6j1ep6w.js +42 -0
  239. package/dist/tooling/shared/vwr2y833.js +270 -0
  240. package/dist/tooling/shared/w17sj05d.js +7 -0
  241. package/dist/tooling/shared/w5d89rb4.js +131 -0
  242. package/dist/tooling/shared/wbwq1jsa.js +157 -0
  243. package/dist/tooling/shared/wezxf3h8.js +17 -0
  244. package/dist/tooling/shared/yb4kd19s.js +12 -0
  245. package/dist/tooling/shared/ybdew6j7.js +294 -0
  246. package/dist/tooling/shared/yfedr1zb.js +6 -0
  247. package/dist/tooling/shared/yhp829bx.js +177 -0
  248. package/dist/tooling/shared/ytk1tjs0.js +604 -0
  249. package/dist/tooling/shared/zs9aymcp.js +210 -0
  250. package/dist/tooling/shared/zx3v9phv.js +8 -0
  251. package/dist/tooling/testing/index.js +3 -3
  252. package/package.json +50 -9
  253. package/dist/shared/ktz42yez.js +0 -113
  254. package/dist/shared/ttsqgp4p.js +0 -71
  255. package/dist/shared/y34a8714.js +0 -150
  256. package/dist/shared/zy8r7qvz.js +0 -116
  257. package/dist/shared/{ywr8hmey.js → 606g0nbf.js} +3 -3
  258. package/dist/shared/{rpycarcr.js → gcefca6p.js} +4 -4
@@ -0,0 +1,185 @@
1
+ // src/adapters/capabilities.ts
2
+ var POSTGRESJS_CAPABILITIES = {
3
+ transactions: "interactive",
4
+ stream: true,
5
+ listen: true,
6
+ cancel: true,
7
+ prepared: "unnamed",
8
+ describe: true
9
+ };
10
+ var PGLITE_CAPABILITIES = {
11
+ transactions: "interactive",
12
+ stream: false,
13
+ listen: true,
14
+ cancel: false,
15
+ prepared: "unnamed",
16
+ describe: true
17
+ };
18
+ var NODE_POSTGRES_CAPABILITIES = {
19
+ transactions: "interactive",
20
+ stream: true,
21
+ listen: true,
22
+ cancel: true,
23
+ prepared: "unnamed",
24
+ describe: false
25
+ };
26
+ var BUNSQL_CAPABILITIES = {
27
+ transactions: "interactive",
28
+ stream: true,
29
+ listen: true,
30
+ cancel: false,
31
+ prepared: "unnamed",
32
+ describe: false
33
+ };
34
+ var NEON_WEBSOCKET_CAPABILITIES = {
35
+ transactions: "interactive",
36
+ stream: false,
37
+ listen: false,
38
+ cancel: false,
39
+ prepared: "unnamed",
40
+ describe: false
41
+ };
42
+ var NEON_HTTP_CAPABILITIES = {
43
+ transactions: "batch",
44
+ stream: false,
45
+ listen: false,
46
+ cancel: false,
47
+ prepared: "none",
48
+ describe: false
49
+ };
50
+ function readCapability2(flags, name) {
51
+ return flags[name];
52
+ }
53
+ function hasCapability2(flags, name) {
54
+ return flags[name];
55
+ }
56
+
57
+ // src/adapters/failure.ts
58
+ var loading;
59
+ function driverErrors() {
60
+ loading ??= import("./a2xe04bm.js");
61
+ return loading;
62
+ }
63
+ function rejectClosed() {
64
+ return import("./sjwkt1pg.js").then((mod) => mod.closed());
65
+ }
66
+ function rejectUncancellable() {
67
+ return import("./sjwkt1pg.js").then((mod) => mod.refused());
68
+ }
69
+ function rejectCancelled() {
70
+ return driverErrors().then((mod) => Promise.reject(mod.cancelled()));
71
+ }
72
+ function rejectTimedOut() {
73
+ return driverErrors().then((mod) => Promise.reject(mod.timedOut()));
74
+ }
75
+ async function mapFailure(error) {
76
+ const mod = await driverErrors();
77
+ return mod.mapDriverError(error);
78
+ }
79
+
80
+ // src/adapters/pg/call.ts
81
+ function needsWatch(options) {
82
+ return options?.signal !== undefined || options?.timeout !== undefined;
83
+ }
84
+ function nextTransactionDepth(depth, text) {
85
+ const command = text.trim().replace(/;\s*$/, "").trim().toLowerCase();
86
+ if (/^(?:begin|start transaction)(?:\s|$)/.test(command))
87
+ return depth + 1;
88
+ if (command === "commit" || command === "commit work" || command === "end") {
89
+ return Math.max(0, depth - 1);
90
+ }
91
+ if (command === "rollback" || command === "rollback work")
92
+ return 0;
93
+ return depth;
94
+ }
95
+ function runCall(closed, options, fn) {
96
+ if (closed)
97
+ return rejectClosed();
98
+ if (options?.signal?.aborted === true)
99
+ return rejectCancelled();
100
+ if (options?.timeout !== undefined && options.timeout <= 0)
101
+ return rejectTimedOut();
102
+ if (options === undefined || !needsWatch(options))
103
+ return fn(undefined);
104
+ const watched = options;
105
+ return import("./54tqkxja.js").then(({ openWatch }) => {
106
+ const watch = openWatch(watched);
107
+ return fn(watch).finally(() => {
108
+ watch.finish();
109
+ });
110
+ });
111
+ }
112
+
113
+ // src/adapters/pg/result.ts
114
+ var EMPTY_NOTICES = [];
115
+ function cell(value) {
116
+ if (value === null || value === undefined)
117
+ return null;
118
+ if (typeof value === "string")
119
+ return value;
120
+ if (typeof value === "bigint")
121
+ return value.toString();
122
+ if (value instanceof Uint8Array)
123
+ return new TextDecoder().decode(value);
124
+ if (typeof value === "number" || typeof value === "boolean")
125
+ return String(value);
126
+ return null;
127
+ }
128
+ function rowsFrom(value) {
129
+ const list = rowList(value);
130
+ const rows = Array.from({ length: list.length });
131
+ for (let index = 0;index < list.length; index += 1) {
132
+ rows[index] = rowCells(list[index]);
133
+ }
134
+ return rows;
135
+ }
136
+ function resultFrom(value, notices) {
137
+ const rows = rowsFrom(value);
138
+ return {
139
+ rows,
140
+ count: countFrom(value, rows.length),
141
+ notices
142
+ };
143
+ }
144
+ function rowList(value) {
145
+ if (Array.isArray(value))
146
+ return value;
147
+ if (typeof value === "object" && value !== null && "rows" in value) {
148
+ const rows = Reflect.get(value, "rows");
149
+ if (Array.isArray(rows))
150
+ return rows;
151
+ }
152
+ return [];
153
+ }
154
+ function rowCells(row) {
155
+ if (Array.isArray(row)) {
156
+ const cells = Array.from({ length: row.length });
157
+ for (let index = 0;index < row.length; index += 1)
158
+ cells[index] = cell(row[index]);
159
+ return cells;
160
+ }
161
+ if (typeof row === "object" && row !== null) {
162
+ const values = Object.values(row);
163
+ const cells = Array.from({ length: values.length });
164
+ for (let index = 0;index < values.length; index += 1)
165
+ cells[index] = cell(values[index]);
166
+ return cells;
167
+ }
168
+ return [cell(row)];
169
+ }
170
+ function countFrom(value, rows) {
171
+ if (typeof value !== "object" || value === null)
172
+ return rows;
173
+ const count = Reflect.get(value, "count");
174
+ if (typeof count === "number" && !Number.isNaN(count))
175
+ return count;
176
+ const rowCount = Reflect.get(value, "rowCount");
177
+ if (typeof rowCount === "number" && !Number.isNaN(rowCount))
178
+ return rowCount;
179
+ const affected = Reflect.get(value, "affectedRows");
180
+ if (typeof affected === "number" && !Number.isNaN(affected))
181
+ return affected;
182
+ return rows;
183
+ }
184
+
185
+ export { POSTGRESJS_CAPABILITIES, PGLITE_CAPABILITIES, NODE_POSTGRES_CAPABILITIES, BUNSQL_CAPABILITIES, NEON_WEBSOCKET_CAPABILITIES, NEON_HTTP_CAPABILITIES, readCapability2, hasCapability2, driverErrors, rejectClosed, rejectUncancellable, rejectCancelled, rejectTimedOut, mapFailure, nextTransactionDepth, runCall, EMPTY_NOTICES, rowsFrom, resultFrom };
@@ -0,0 +1,6 @@
1
+ import {
2
+ stack2
3
+ } from "./35zemrmf.js";
4
+ export {
5
+ stack2 as stack
6
+ };
@@ -0,0 +1,332 @@
1
+ import {
2
+ POSTGRESJS_CAPABILITIES,
3
+ rejectClosed,
4
+ mapFailure,
5
+ nextTransactionDepth,
6
+ runCall,
7
+ EMPTY_NOTICES,
8
+ resultFrom
9
+ } from "./5x3pf400.js";
10
+
11
+ // src/adapters/pg/postgresjs.ts
12
+ import net from "node:net";
13
+ import postgres from "postgres";
14
+ class PoolSockets {
15
+ held = [];
16
+ busy = 0;
17
+ listeners = 0;
18
+ hostCursor = 0;
19
+ connect(target) {
20
+ const path = typeof target.path === "string" ? target.path : undefined;
21
+ const hosts = target.host;
22
+ const ports = target.port;
23
+ const index = hosts.length === 0 ? 0 : this.hostCursor % hosts.length;
24
+ this.hostCursor += 1;
25
+ const host = hosts[index] ?? "localhost";
26
+ const port = ports[index] ?? ports[0] ?? 5432;
27
+ const socket = path !== undefined ? net.connect(path) : net.connect(port, host);
28
+ this.held.push(socket);
29
+ return socket;
30
+ }
31
+ occupy(run) {
32
+ this.busy += 1;
33
+ this.wake();
34
+ return run().finally(() => {
35
+ this.busy -= 1;
36
+ this.park();
37
+ });
38
+ }
39
+ busyGate() {
40
+ return {
41
+ enter: () => {
42
+ this.busy += 1;
43
+ this.wake();
44
+ },
45
+ leave: () => {
46
+ this.busy -= 1;
47
+ this.park();
48
+ }
49
+ };
50
+ }
51
+ listenerGate() {
52
+ return {
53
+ enter: () => {
54
+ this.listeners += 1;
55
+ this.wake();
56
+ },
57
+ leave: () => {
58
+ this.listeners -= 1;
59
+ this.park();
60
+ }
61
+ };
62
+ }
63
+ wake() {
64
+ for (const socket of this.held)
65
+ if (socket.writable)
66
+ socket.ref();
67
+ }
68
+ park() {
69
+ if (this.busy > 0 || this.listeners > 0)
70
+ return;
71
+ for (const socket of this.held)
72
+ if (socket.writable)
73
+ socket.unref();
74
+ }
75
+ }
76
+ function driverOptions(config, state) {
77
+ return {
78
+ max: state.max,
79
+ prepare: state.named,
80
+ idle_timeout: state.plain ? 0 : 30,
81
+ ...state.plain ? { max_lifetime: null } : {},
82
+ connect_timeout: 5,
83
+ types: WIRE_TYPES,
84
+ ...state.plain ? { socket: (options) => state.sockets.connect(options) } : {},
85
+ ...config.ssl !== undefined ? { ssl: config.ssl } : {},
86
+ connection: {
87
+ application_name: "okmodel",
88
+ ...config.searchPath !== undefined ? { search_path: config.searchPath } : {}
89
+ },
90
+ onnotice(notice) {
91
+ state.notices.push(notice);
92
+ }
93
+ };
94
+ }
95
+ function open3(config) {
96
+ const max = config.max ?? 10;
97
+ const acquireMs = config.timeouts?.acquire;
98
+ const counters = { reserved: 0, busy: 0, reservedBusy: 0, waiting: 0 };
99
+ const poolInflight = new Set;
100
+ const notices = noticeBuffer();
101
+ let closed = false;
102
+ const isClosed = () => closed;
103
+ const named = config.prepared === "named";
104
+ const plain = config.ssl === undefined;
105
+ const sockets = new PoolSockets;
106
+ const sql = postgres(config.url, driverOptions(config, {
107
+ max,
108
+ named,
109
+ plain,
110
+ notices,
111
+ sockets
112
+ }));
113
+ const root = new PgSession2(sql, counters, "pool", poolInflight, isClosed, undefined, notices, named);
114
+ const held = { sql, acquireMs, counters, isClosed, notices, named, poolInflight };
115
+ return {
116
+ capabilities: POSTGRESJS_CAPABILITIES,
117
+ execute(text, params, options) {
118
+ return sockets.occupy(() => runCall(closed, options, (watch) => root.query(text, params, watch)));
119
+ },
120
+ batch(statements, options) {
121
+ return sockets.occupy(() => import("./04svnxxj.js").then((mod) => mod.runBatch(held, statements, options)));
122
+ },
123
+ reserve() {
124
+ const gate = sockets.busyGate();
125
+ gate.enter();
126
+ return import("./04svnxxj.js").then((mod) => mod.holdCheckout(gate, () => mod.checkout(held)), (error) => {
127
+ gate.leave();
128
+ throw error;
129
+ });
130
+ },
131
+ describe: (text, params) => sockets.occupy(() => import("./04svnxxj.js").then((mod) => mod.describe(sql, text, params))),
132
+ stream(text, params) {
133
+ const gate = sockets.busyGate();
134
+ return async function* () {
135
+ gate.enter();
136
+ try {
137
+ yield* loadStream(sql, text, params);
138
+ } finally {
139
+ gate.leave();
140
+ }
141
+ }();
142
+ },
143
+ listen(channel, onNotify) {
144
+ const gate = sockets.listenerGate();
145
+ gate.enter();
146
+ return import("./04svnxxj.js").then((mod) => mod.holdListener(gate, async () => {
147
+ const listening = await sql.listen(channel, onNotify);
148
+ return async () => {
149
+ await listening.unlisten();
150
+ };
151
+ }), (error) => {
152
+ gate.leave();
153
+ throw error;
154
+ });
155
+ },
156
+ cancel() {
157
+ for (const pending of poolInflight)
158
+ pending.cancel();
159
+ },
160
+ stats: () => statsOf(counters, max),
161
+ async close() {
162
+ closed = true;
163
+ await sql.end({ timeout: 5 });
164
+ }
165
+ };
166
+ }
167
+
168
+ class PgSession2 {
169
+ canCancel = true;
170
+ transactionDepth = 0;
171
+ sql;
172
+ counters;
173
+ scope;
174
+ local;
175
+ isClosed;
176
+ shared;
177
+ notices;
178
+ named;
179
+ constructor(sql, counters, scope, local, isClosed, shared, notices, named) {
180
+ this.sql = sql;
181
+ this.counters = counters;
182
+ this.scope = scope;
183
+ this.local = local;
184
+ this.isClosed = isClosed;
185
+ this.shared = shared;
186
+ this.notices = notices;
187
+ this.named = named;
188
+ }
189
+ query(text, params, watch) {
190
+ if (this.isClosed())
191
+ return rejectClosed();
192
+ const start = this.notices.start();
193
+ this.enter();
194
+ const pending = send(this.sql, text, params, this.named);
195
+ if (watch === undefined) {
196
+ return pending.then((result) => {
197
+ this.leave();
198
+ this.note(text);
199
+ return resultFrom(result, this.notices.since(start));
200
+ }, (error) => {
201
+ this.leave();
202
+ return mapFailure(error).then((mapped) => {
203
+ throw mapped;
204
+ });
205
+ });
206
+ }
207
+ this.local.add(pending);
208
+ this.shared?.add(pending);
209
+ const onAbort = () => {
210
+ pending.cancel();
211
+ };
212
+ if (watch.signal.aborted)
213
+ onAbort();
214
+ else
215
+ watch.signal.addEventListener("abort", onAbort, { once: true });
216
+ return import("./04svnxxj.js").then((mod) => mod.watchQuery(pending, watch, onAbort, {
217
+ start,
218
+ text,
219
+ notices: this.notices,
220
+ leave: () => {
221
+ this.leave();
222
+ },
223
+ note: (sqlText) => {
224
+ this.note(sqlText);
225
+ },
226
+ untrack: (item) => {
227
+ this.local.delete(item);
228
+ this.shared?.delete(item);
229
+ }
230
+ }), (error) => {
231
+ this.leave();
232
+ this.local.delete(pending);
233
+ this.shared?.delete(pending);
234
+ watch.signal.removeEventListener("abort", onAbort);
235
+ throw error;
236
+ });
237
+ }
238
+ inTransaction() {
239
+ return this.transactionDepth > 0;
240
+ }
241
+ abandon() {
242
+ this.transactionDepth = 0;
243
+ }
244
+ depth() {
245
+ return this.transactionDepth;
246
+ }
247
+ cancel() {
248
+ for (const pending of this.local)
249
+ pending.cancel();
250
+ }
251
+ note(text) {
252
+ this.transactionDepth = nextTransactionDepth(this.transactionDepth, text);
253
+ }
254
+ enter() {
255
+ if (this.scope === "pool")
256
+ this.counters.busy += 1;
257
+ else
258
+ this.counters.reservedBusy += 1;
259
+ }
260
+ leave() {
261
+ if (this.scope === "pool")
262
+ this.counters.busy = Math.max(0, this.counters.busy - 1);
263
+ else
264
+ this.counters.reservedBusy = Math.max(0, this.counters.reservedBusy - 1);
265
+ }
266
+ }
267
+ async function* loadStream(sql, text, params) {
268
+ const { stream } = await import("./04svnxxj.js");
269
+ yield* stream(sql, text, params);
270
+ }
271
+ function send(sql, text, params, named) {
272
+ if (!named && (params === undefined || params.length === 0))
273
+ return sql.unsafe(text).raw();
274
+ return sql.unsafe(text, asParams(params), { prepare: named }).raw();
275
+ }
276
+ function asParams(params) {
277
+ if (params === undefined)
278
+ return [];
279
+ return params;
280
+ }
281
+ function statsOf(counters, size) {
282
+ return {
283
+ size,
284
+ idle: Math.max(0, size - counters.reserved - counters.busy),
285
+ inflight: counters.busy + counters.reservedBusy,
286
+ waiting: counters.waiting
287
+ };
288
+ }
289
+ function noticeBuffer() {
290
+ let notices;
291
+ return {
292
+ push(notice) {
293
+ const severity = typeof notice.severity === "string" ? notice.severity : "";
294
+ const message = typeof notice.message === "string" ? notice.message : "";
295
+ const code = typeof notice.code === "string" && notice.code.length > 0 ? notice.code : undefined;
296
+ const entry = code === undefined ? { severity, message } : { severity, message, code };
297
+ (notices ??= []).push(entry);
298
+ },
299
+ start() {
300
+ return notices?.length ?? 0;
301
+ },
302
+ since(start) {
303
+ if (notices === undefined || notices.length === start)
304
+ return EMPTY_NOTICES;
305
+ return notices.slice(start);
306
+ }
307
+ };
308
+ }
309
+ function wire(to, from) {
310
+ return {
311
+ to,
312
+ from: [...from],
313
+ serialize: (value) => value,
314
+ parse: (value) => value
315
+ };
316
+ }
317
+ var WIRE_TYPES = {
318
+ number: wire(0, [21, 23, 26, 700, 701]),
319
+ boolean: wire(16, [16]),
320
+ bytea: wire(17, [17]),
321
+ json: wire(114, [114, 3802]),
322
+ date: wire(1184, [1082, 1114, 1184]),
323
+ boolArray: wire(1000, [1000]),
324
+ int2Array: wire(1005, [1005]),
325
+ int4Array: wire(1007, [1007]),
326
+ textArray: wire(1009, [1009]),
327
+ int8Array: wire(1016, [1016]),
328
+ numericArray: wire(1231, [1231]),
329
+ jsonbArray: wire(3807, [3807])
330
+ };
331
+
332
+ export { open3, PgSession2 };
@@ -0,0 +1,20 @@
1
+ import {
2
+ open5,
3
+ connectClient3,
4
+ send4
5
+ } from "./am04v8na.js";
6
+ import {
7
+ NEON_WEBSOCKET_CAPABILITIES,
8
+ NEON_HTTP_CAPABILITIES,
9
+ readCapability2,
10
+ hasCapability2
11
+ } from "./5x3pf400.js";
12
+ export {
13
+ NEON_WEBSOCKET_CAPABILITIES as capabilities,
14
+ connectClient3 as connectClient,
15
+ hasCapability2 as hasCapability,
16
+ NEON_HTTP_CAPABILITIES as httpCapabilities,
17
+ open5 as open,
18
+ readCapability2 as readCapability,
19
+ send4 as send
20
+ };
@@ -0,0 +1,98 @@
1
+ import {
2
+ historySql2
3
+ } from "./dhatassp.js";
4
+ import"./jr2nmr81.js";
5
+ import {
6
+ OkmError
7
+ } from "./hfq3n3bd.js";
8
+
9
+ // src/runtime/compat-words.ts
10
+ var BEHIND_EXPAND = "behind by expand";
11
+ var BEHIND_CONTRACT = "behind by contract";
12
+ var AHEAD_CONTRACT = "ahead by contract";
13
+
14
+ // src/runtime/drift-detail.ts
15
+ function driftVerdict(codeHash, recordedHash, migrations) {
16
+ const codeAt = indexOfHash(migrations, codeHash);
17
+ const recordedAt = indexOfHash(migrations, recordedHash);
18
+ if (codeAt >= 0 && recordedAt >= codeAt) {
19
+ for (let index = codeAt + 1;index <= recordedAt; index += 1) {
20
+ const migration = migrations[index];
21
+ if (migration !== undefined && migration.expand !== true) {
22
+ return { state: "ahead by contract", migrationId: migration.id };
23
+ }
24
+ }
25
+ return { state: "ok" };
26
+ }
27
+ if (codeAt >= 0 && recordedAt >= 0 && recordedAt < codeAt) {
28
+ const next = migrations[recordedAt + 1];
29
+ if (next !== undefined) {
30
+ return {
31
+ state: next.expand ? "behind by expand" : "behind by contract",
32
+ migrationId: next.id
33
+ };
34
+ }
35
+ }
36
+ if (recordedAt >= 0) {
37
+ const at = migrations[recordedAt];
38
+ if (at !== undefined)
39
+ return { state: "behind", migrationId: at.id };
40
+ }
41
+ const last = migrations.at(-1);
42
+ return { state: "behind", migrationId: last?.id ?? "" };
43
+ }
44
+ async function assertDrift(pool, codeHash, recordedHash, options, namespace = "public") {
45
+ let rows;
46
+ try {
47
+ const result = await pool.execute(await historySql2(namespace), undefined, options);
48
+ rows = result.rows;
49
+ } catch (error) {
50
+ throw gapError({ state: "behind", migrationId: "" }, error);
51
+ }
52
+ const verdict = driftVerdict(codeHash, recordedHash, groupMigrations(rows));
53
+ if (verdict.state === "ok")
54
+ return;
55
+ throw gapError(verdict);
56
+ }
57
+ function indexOfHash(migrations, hash) {
58
+ let found = -1;
59
+ for (let index = 0;index < migrations.length; index += 1) {
60
+ if (migrations[index]?.catalogHash === hash)
61
+ found = index;
62
+ }
63
+ return found;
64
+ }
65
+ function groupMigrations(rows) {
66
+ const grouped = [];
67
+ for (const row of rows) {
68
+ const id = row[0];
69
+ const stepClass = row[1];
70
+ const hash = row[2];
71
+ if (id == null || stepClass == null || hash == null)
72
+ continue;
73
+ const expand = stepClass === "expand";
74
+ const last = grouped.at(-1);
75
+ if (last !== undefined && last.id === id) {
76
+ grouped[grouped.length - 1] = {
77
+ id,
78
+ catalogHash: hash,
79
+ expand: last.expand && expand
80
+ };
81
+ continue;
82
+ }
83
+ grouped.push({ id, catalogHash: hash, expand });
84
+ }
85
+ return grouped;
86
+ }
87
+ function gapError(verdict, cause) {
88
+ const named = verdict.migrationId;
89
+ const phrase = verdict.state === "ahead by contract" ? `${AHEAD_CONTRACT} migration ${named}` : verdict.state === "behind by expand" ? `${BEHIND_EXPAND} migration ${named}` : verdict.state === "behind by contract" ? `${BEHIND_CONTRACT} migration ${named}` : named.length > 0 ? `behind the app at migration ${named}` : "behind the app";
90
+ const fix = named.length > 0 ? `Apply ${named}, or change the deploy order.` : "Apply migrations, or change the deploy order.";
91
+ return new OkmError("OKM1520", `The database is ${phrase}.`, {
92
+ ...cause === undefined ? {} : { cause },
93
+ fix: { summary: fix }
94
+ });
95
+ }
96
+ export {
97
+ assertDrift
98
+ };
@@ -0,0 +1,9 @@
1
+ import {
2
+ historySql2,
3
+ acceptServer2
4
+ } from "./dhatassp.js";
5
+ import"./jr2nmr81.js";
6
+ export {
7
+ acceptServer2 as acceptServer,
8
+ historySql2 as historySql
9
+ };