okmodel 0.9.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 (175) hide show
  1. package/README.md +9 -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/fuzzystrmatch.js +1 -1
  11. package/dist/dialects/pg/ext/hstore.js +1 -1
  12. package/dist/dialects/pg/ext/ltree.js +1 -1
  13. package/dist/dialects/pg/ext/pgcrypto.js +1 -1
  14. package/dist/dialects/pg/ext/unaccent.js +1 -1
  15. package/dist/dialects/pg/filters.d.ts +2 -2
  16. package/dist/dialects/pg/fn/index.js +1 -1
  17. package/dist/dialects/pg/index.js +3 -3
  18. package/dist/dialects/pg/introspect.d.ts +12 -0
  19. package/dist/dialects/pg/view/index.js +2 -2
  20. package/dist/runtime/param-limit.d.ts +20 -0
  21. package/dist/runtime/pg/bun.js +3 -3
  22. package/dist/runtime/pg/neon.js +3 -3
  23. package/dist/runtime/pg/pg.js +3 -3
  24. package/dist/runtime/pg/pglite.js +2 -2
  25. package/dist/runtime/pg/postgresjs.js +10 -10
  26. package/dist/runtime/tenancy/index.js +1 -1
  27. package/dist/runtime/traits/index.js +2 -2
  28. package/dist/runtime/validate/index.js +2 -2
  29. package/dist/runtime/write.d.ts +1 -1
  30. package/dist/shared/{5kyb3tqx.js → 1h5h1rf5.js} +1 -1
  31. package/dist/shared/{4vbf83xx.js → 2vcnpf0n.js} +1 -1
  32. package/dist/shared/{8n688yjg.js → 3ap5hxvj.js} +2 -1
  33. package/dist/shared/{wvtjg5m3.js → 3d7a80fq.js} +1 -1
  34. package/dist/shared/{bphrgwz9.js → 3dr444ny.js} +57 -78
  35. package/dist/shared/{yvabyg9k.js → 3vvpcphd.js} +7 -6
  36. package/dist/shared/{760ppr76.js → 4a3mmhhe.js} +2 -2
  37. package/dist/shared/{90sg0w5a.js → 4pkz5nvw.js} +65 -10
  38. package/dist/shared/{mazpbcdj.js → 4te76xc5.js} +1 -1
  39. package/dist/shared/{xwhdcrm4.js → 60y4ahmw.js} +1 -1
  40. package/dist/shared/{9dtgn1z2.js → 63qjmhnp.js} +100 -17
  41. package/dist/shared/{s7he5e5d.js → 67w3kn71.js} +1 -1
  42. package/dist/shared/{n306gqkd.js → 6vfvsdkt.js} +9 -7
  43. package/dist/shared/{jpybhf98.js → 6xqvesa5.js} +1 -1
  44. package/dist/shared/{n5whk3mt.js → 8gdbty5v.js} +8 -8
  45. package/dist/shared/{ccsmhv9r.js → 8ma6drzr.js} +194 -31
  46. package/dist/shared/{3456242y.js → 8p2bgye0.js} +110 -18
  47. package/dist/shared/{ebhz8vh6.js → 8qwqrxed.js} +11 -3
  48. package/dist/shared/{ss2kv2rs.js → 8v7vzpgt.js} +10 -7
  49. package/dist/shared/{8qzkd9f3.js → ak61ye1f.js} +3 -3
  50. package/dist/shared/{6nae0spm.js → bdekbvmt.js} +69 -7
  51. package/dist/shared/{tw1nvvfj.js → bxjq6xqv.js} +2 -2
  52. package/dist/shared/{rbxt795q.js → c7dqd3gk.js} +81 -41
  53. package/dist/shared/ddh72ym5.js +20 -0
  54. package/dist/shared/e1c55v04.js +10 -0
  55. package/dist/shared/{8jesqsrk.js → ekhq3ytz.js} +1 -1
  56. package/dist/shared/{7ba5h6pb.js → esy4dyxe.js} +5 -5
  57. package/dist/shared/{gcefca6p.js → f9t9g54z.js} +22 -9
  58. package/dist/shared/fkjne6gx.js +8 -0
  59. package/dist/shared/{ds229x4r.js → fne90dvz.js} +4 -1
  60. package/dist/shared/{cexb7z6b.js → gr9sn4za.js} +1 -1
  61. package/dist/shared/{mvmm3xpb.js → gzgfsspx.js} +1 -1
  62. package/dist/shared/{fdsz3w80.js → hgt69zjf.js} +2 -2
  63. package/dist/shared/{dd5pmnky.js → jvxcp1qk.js} +70 -86
  64. package/dist/shared/{yybhre6n.js → k73e8n9d.js} +3 -3
  65. package/dist/shared/{mgaq2sd3.js → kzgrcy8s.js} +8 -7
  66. package/dist/shared/{myk8fswx.js → mz48rs74.js} +14 -3
  67. package/dist/shared/{62b603gr.js → n6je5b28.js} +10 -23
  68. package/dist/shared/{2szgv6yj.js → ns35jqz0.js} +71 -45
  69. package/dist/shared/{xtsydxjg.js → nstwgzn8.js} +1 -1
  70. package/dist/shared/{stfa9xcw.js → py2zrrm6.js} +7 -6
  71. package/dist/shared/{9dr2qnx7.js → qqm3ze6q.js} +1 -1
  72. package/dist/shared/{cf8zdz5p.js → rcjm0yn7.js} +27 -34
  73. package/dist/shared/{ckz05z15.js → rged92v6.js} +7 -4
  74. package/dist/shared/{qvwwp1mp.js → rw4tpcd0.js} +30 -21
  75. package/dist/shared/{bsek72fg.js → s5qe47a6.js} +3 -0
  76. package/dist/shared/{1d9q9cv2.js → smxzjz60.js} +2 -2
  77. package/dist/shared/{c3mvnq7a.js → th5rnaxw.js} +1 -1
  78. package/dist/shared/{1mxm04fy.js → tyqapcgk.js} +71 -8
  79. package/dist/shared/{zdqf8k5d.js → vsna85qf.js} +1 -1
  80. package/dist/shared/{63qtkrca.js → vy47ryqa.js} +55 -5
  81. package/dist/shared/{xv8qj97g.js → wbdh9qbg.js} +3 -1
  82. package/dist/shared/{2zdxkt7b.js → wp7y8q3y.js} +41 -9
  83. package/dist/shared/{pg4ezgyf.js → xbd9xs6p.js} +2 -2
  84. package/dist/shared/{npdftanb.js → xbvz446k.js} +16 -13
  85. package/dist/shared/{aksb89mn.js → y6tfjk9q.js} +2 -2
  86. package/dist/shared/{3bb7wsqt.js → ycnft340.js} +1 -1
  87. package/dist/shared/{z7s6fpxv.js → ymenf259.js} +1 -1
  88. package/dist/shared/{71n0jmhc.js → ysdw2fg3.js} +10 -2
  89. package/dist/shared/{xqacq37x.js → zecrwdk9.js} +1 -1
  90. package/dist/shared/{3t6kw83m.js → zm2rzqba.js} +2 -1
  91. package/dist/tooling/cli.js +122 -44
  92. package/dist/tooling/driver-run.js +107 -24
  93. package/dist/tooling/github/comment.d.ts +8 -2
  94. package/dist/tooling/migrate/apply.d.ts +17 -2
  95. package/dist/tooling/migrate/drift.d.ts +12 -0
  96. package/dist/tooling/migrate/driver-url.d.ts +17 -0
  97. package/dist/tooling/migrate/index.js +9 -7
  98. package/dist/tooling/migrate/policy.d.ts +17 -5
  99. package/dist/tooling/migrate/pooler-probe.d.ts +23 -0
  100. package/dist/tooling/migrate/pull.d.ts +3 -0
  101. package/dist/tooling/migrate/runner.d.ts +24 -1
  102. package/dist/tooling/shared/{0j0jtse1.js → 09a6vsys.js} +1 -1
  103. package/dist/tooling/shared/{68tf18v4.js → 0v9ptnxp.js} +8 -8
  104. package/dist/tooling/shared/{qartgazh.js → 0wtzps9p.js} +6 -6
  105. package/dist/tooling/shared/{1800eymw.js → 0yhf1db4.js} +6 -6
  106. package/dist/tooling/shared/{s6qha57m.js → 19msgrsc.js} +2 -2
  107. package/dist/tooling/shared/{3yn79q5m.js → 1fwfm5m3.js} +1 -1
  108. package/dist/tooling/shared/{hfq3n3bd.js → 2jdn09e2.js} +55 -5
  109. package/dist/tooling/shared/{v6j1ep6w.js → 2qrte2ct.js} +5 -5
  110. package/dist/tooling/shared/{yb4kd19s.js → 2v4nwnkb.js} +1 -1
  111. package/dist/tooling/shared/{ezqn88nj.js → 33z39trp.js} +106 -23
  112. package/dist/tooling/shared/{0r05zhyq.js → 353vnw9z.js} +5 -5
  113. package/dist/tooling/shared/{m4hhb8aa.js → 390kry9g.js} +2 -2
  114. package/dist/tooling/shared/{rcywj2w8.js → 3f6etb9z.js} +18 -31
  115. package/dist/tooling/shared/{9wsnsvbf.js → 3t2cqmsx.js} +1 -1
  116. package/dist/tooling/shared/{5zrzffnk.js → 4dzvjtpy.js} +1 -1
  117. package/dist/tooling/shared/{am04v8na.js → 4ec0nxvw.js} +10 -10
  118. package/dist/tooling/shared/{04svnxxj.js → 4tg2bn41.js} +59 -78
  119. package/dist/tooling/shared/{829fjxyw.js → 5rah55z0.js} +2 -2
  120. package/dist/tooling/shared/{c0xevn1h.js → 804w1t69.js} +4 -4
  121. package/dist/tooling/shared/{dhatassp.js → 8g0m0rvd.js} +6 -6
  122. package/dist/tooling/shared/{zx3v9phv.js → 8msbtw5s.js} +1 -1
  123. package/dist/tooling/shared/{7pxncnzs.js → 8t22h3h7.js} +2 -2
  124. package/dist/tooling/shared/{wbwq1jsa.js → 91c59b7b.js} +2 -2
  125. package/dist/tooling/shared/{a2xe04bm.js → adk9k6va.js} +1 -1
  126. package/dist/tooling/shared/{w17sj05d.js → ajjd5cwz.js} +2 -2
  127. package/dist/tooling/shared/{35zemrmf.js → angjck01.js} +1 -1
  128. package/dist/tooling/shared/{jsjjz875.js → asnnc3v5.js} +1 -1
  129. package/dist/tooling/shared/{5bmksndh.js → bj1kyqc8.js} +2 -2
  130. package/dist/tooling/shared/{kbqnrs1x.js → bt3tjemb.js} +11 -3
  131. package/dist/tooling/shared/{vwr2y833.js → chk2bh4f.js} +2 -2
  132. package/dist/tooling/shared/{ybdew6j7.js → ckq4z5ax.js} +5 -2
  133. package/dist/tooling/shared/{3rmaz3pq.js → d3rhb24q.js} +1 -1
  134. package/dist/tooling/shared/{mw5npye0.js → d8q00vxg.js} +4 -4
  135. package/dist/tooling/shared/{j664qjrt.js → dx188rxs.js} +2 -2
  136. package/dist/tooling/shared/{8yr7ges1.js → efq6p9df.js} +35 -42
  137. package/dist/tooling/shared/{yhp829bx.js → en6rwzq0.js} +3 -3
  138. package/dist/tooling/shared/{f77nnfqy.js → f2r5g0fs.js} +2 -2
  139. package/dist/tooling/shared/{zs9aymcp.js → f4gep0nk.js} +1 -1
  140. package/dist/tooling/shared/{kz715295.js → f8a010fm.js} +13 -11
  141. package/dist/tooling/shared/{w5d89rb4.js → fdsek6pa.js} +1 -1
  142. package/dist/tooling/shared/fvmrxsd1.js +8 -0
  143. package/dist/tooling/shared/{jpgmjsx3.js → g3xybeqf.js} +4 -3
  144. package/dist/tooling/shared/{wezxf3h8.js → gefmpwsa.js} +1 -1
  145. package/dist/tooling/shared/{jr2nmr81.js → gjj71hfh.js} +23 -20
  146. package/dist/tooling/shared/{9sfbtwsk.js → jgzt69pa.js} +5 -5
  147. package/dist/tooling/shared/{a4pzghha.js → jm30k2ca.js} +10 -8
  148. package/dist/tooling/shared/{shjs0379.js → kayqzpbk.js} +6 -3
  149. package/dist/tooling/shared/{tcwpjvxe.js → kvw1672d.js} +1 -1
  150. package/dist/tooling/shared/{stebqyyd.js → mr1kcgpw.js} +3 -3
  151. package/dist/tooling/shared/{tpssp7ac.js → mwbdf409.js} +1 -1
  152. package/dist/tooling/shared/{fh07z1dt.js → ns9207v3.js} +1 -1
  153. package/dist/tooling/shared/{5p8km5jb.js → p6tjv97k.js} +3 -3
  154. package/dist/tooling/shared/{ytk1tjs0.js → p73evwf0.js} +1 -1
  155. package/dist/tooling/shared/{8m5znpdt.js → phc1nc4g.js} +1 -1
  156. package/dist/tooling/shared/{asgr07mp.js → ppybjw50.js} +79 -16
  157. package/dist/tooling/shared/{t4xveemq.js → qdrn8ghn.js} +5 -4
  158. package/dist/tooling/shared/rd8h01ta.js +20 -0
  159. package/dist/tooling/shared/{7aews1zg.js → rwg8y90m.js} +3 -3
  160. package/dist/tooling/shared/{5x3pf400.js → ry2f3w8p.js} +3 -3
  161. package/dist/tooling/shared/{m3xt8b1h.js → ryc5sa58.js} +8 -8
  162. package/dist/tooling/shared/{57btdkgm.js → ss87qxwv.js} +2 -2
  163. package/dist/tooling/shared/{6vk28rjp.js → vg68k11z.js} +3 -3
  164. package/dist/tooling/shared/{62fxpc1p.js → vms9dta5.js} +73 -89
  165. package/dist/tooling/shared/{gqwevek4.js → xchpnbdv.js} +1 -1
  166. package/dist/tooling/shared/{t6zjeake.js → xn6p01fh.js} +5 -5
  167. package/dist/tooling/shared/{7b3xp9gc.js → xwr6q618.js} +3 -3
  168. package/dist/tooling/shared/{yfedr1zb.js → xx3gmq94.js} +1 -1
  169. package/dist/tooling/shared/{9qr9rkbh.js → y2bd7yfx.js} +21 -13
  170. package/dist/tooling/shared/{nxq95eb6.js → y4gq9rbe.js} +11 -11
  171. package/dist/tooling/shared/{76pv6qff.js → y4vwft92.js} +2 -2
  172. package/dist/tooling/shared/{sjwkt1pg.js → yz68xcmc.js} +1 -1
  173. package/dist/tooling/testing/factories.d.ts +1 -3
  174. package/dist/tooling/testing/index.js +1 -1
  175. package/package.json +2 -1
@@ -36,41 +36,29 @@ class PoolSockets {
36
36
  this.park();
37
37
  });
38
38
  }
39
- busyGate() {
39
+ gate(key) {
40
40
  return {
41
41
  enter: () => {
42
- this.busy += 1;
42
+ this[key] += 1;
43
43
  this.wake();
44
44
  },
45
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;
46
+ this[key] -= 1;
59
47
  this.park();
60
48
  }
61
49
  };
62
50
  }
63
51
  wake() {
64
- for (const socket of this.held)
65
- if (socket.writable)
66
- socket.ref();
52
+ for (const s of this.held)
53
+ if (s.writable)
54
+ s.ref();
67
55
  }
68
56
  park() {
69
57
  if (this.busy > 0 || this.listeners > 0)
70
58
  return;
71
- for (const socket of this.held)
72
- if (socket.writable)
73
- socket.unref();
59
+ for (const s of this.held)
60
+ if (s.writable)
61
+ s.unref();
74
62
  }
75
63
  }
76
64
  function driverOptions(config, state) {
@@ -80,6 +68,7 @@ function driverOptions(config, state) {
80
68
  idle_timeout: state.plain ? 0 : 30,
81
69
  ...state.plain ? { max_lifetime: null } : {},
82
70
  connect_timeout: 5,
71
+ backoff: () => 0.05 + Math.random() * 0.2,
83
72
  types: WIRE_TYPES,
84
73
  ...state.plain ? { socket: (options) => state.sockets.connect(options) } : {},
85
74
  ...config.ssl !== undefined ? { ssl: config.ssl } : {},
@@ -92,9 +81,24 @@ function driverOptions(config, state) {
92
81
  }
93
82
  };
94
83
  }
84
+ var lives = [];
85
+ process.on("uncaughtException", (e) => {
86
+ if (e instanceof TypeError && /socket\.write|reading 'write'/.test(e.message)) {
87
+ for (const x of lives) {
88
+ if (!x.on)
89
+ continue;
90
+ const prev = x.sql;
91
+ x.m();
92
+ prev.end({ timeout: 0 }).catch(() => {});
93
+ }
94
+ return;
95
+ }
96
+ console.error(e);
97
+ process.exitCode = 1;
98
+ });
95
99
  function open2(config) {
96
100
  const max = config.max ?? 10;
97
- const acquireMs = config.timeouts?.acquire;
101
+ const acquireMs = config.timeouts?.acquire ?? 1e4;
98
102
  const counters = { reserved: 0, busy: 0, reservedBusy: 0, waiting: 0 };
99
103
  const poolInflight = new Set;
100
104
  const notices = noticeBuffer();
@@ -103,48 +107,56 @@ function open2(config) {
103
107
  const named = config.prepared === "named";
104
108
  const plain = config.ssl === undefined;
105
109
  const sockets = new PoolSockets;
106
- const sql = postgres(config.url, driverOptions(config, {
107
- max,
108
- named,
109
- plain,
110
+ const opts = { max, named, plain, notices, sockets };
111
+ const make = () => postgres(config.url, driverOptions(config, opts));
112
+ const root = new PgSession(make(), counters, "pool", poolInflight, isClosed, undefined, notices, named);
113
+ const held = {
114
+ on: true,
115
+ m: () => root.sql = make(),
116
+ get sql() {
117
+ return root.sql;
118
+ },
119
+ acquireMs,
120
+ counters,
121
+ isClosed,
110
122
  notices,
111
- sockets
112
- }));
113
- const root = new PgSession(sql, counters, "pool", poolInflight, isClosed, undefined, notices, named);
114
- const held = { sql, acquireMs, counters, isClosed, notices, named, poolInflight };
123
+ named,
124
+ poolInflight
125
+ };
126
+ lives.push(held);
115
127
  return {
116
128
  capabilities: POSTGRESJS_CAPABILITIES,
117
129
  execute(text, params, options) {
118
130
  return sockets.occupy(() => runCall(closed, options, (watch) => root.query(text, params, watch)));
119
131
  },
120
132
  batch(statements, options) {
121
- return sockets.occupy(() => import("./fdsz3w80.js").then((mod) => mod.runBatch(held, statements, options)));
133
+ return sockets.occupy(() => import("./hgt69zjf.js").then((mod) => mod.runBatch(held, statements, options)));
122
134
  },
123
135
  reserve() {
124
- const gate = sockets.busyGate();
136
+ const gate = sockets.gate("busy");
125
137
  gate.enter();
126
- return import("./fdsz3w80.js").then((mod) => mod.holdCheckout(gate, () => mod.checkout(held)), (error) => {
138
+ return import("./hgt69zjf.js").then((mod) => mod.holdCheckout(gate, () => mod.checkout(held)), (error) => {
127
139
  gate.leave();
128
140
  throw error;
129
141
  });
130
142
  },
131
- describe: (text, params) => sockets.occupy(() => import("./fdsz3w80.js").then((mod) => mod.describe(sql, text, params))),
143
+ describe: (text, params) => sockets.occupy(() => import("./hgt69zjf.js").then((mod) => mod.describe(root.sql, text, params))),
132
144
  stream(text, params) {
133
- const gate = sockets.busyGate();
145
+ const gate = sockets.gate("busy");
134
146
  return async function* () {
135
147
  gate.enter();
136
148
  try {
137
- yield* loadStream(sql, text, params);
149
+ yield* (await import("./hgt69zjf.js")).stream(root.sql, text, params);
138
150
  } finally {
139
151
  gate.leave();
140
152
  }
141
153
  }();
142
154
  },
143
155
  listen(channel, onNotify) {
144
- const gate = sockets.listenerGate();
156
+ const gate = sockets.gate("listeners");
145
157
  gate.enter();
146
- return import("./fdsz3w80.js").then((mod) => mod.holdListener(gate, async () => {
147
- const listening = await sql.listen(channel, onNotify);
158
+ return import("./hgt69zjf.js").then((mod) => mod.holdListener(gate, async () => {
159
+ const listening = await root.sql.listen(channel, onNotify);
148
160
  return async () => {
149
161
  await listening.unlisten();
150
162
  };
@@ -160,7 +172,8 @@ function open2(config) {
160
172
  stats: () => statsOf(counters, max),
161
173
  async close() {
162
174
  closed = true;
163
- await sql.end({ timeout: 5 });
175
+ held.on = false;
176
+ await root.sql.end({ timeout: 5 });
164
177
  }
165
178
  };
166
179
  }
@@ -213,7 +226,7 @@ class PgSession {
213
226
  onAbort();
214
227
  else
215
228
  watch.signal.addEventListener("abort", onAbort, { once: true });
216
- return import("./fdsz3w80.js").then((mod) => mod.watchQuery(pending, watch, onAbort, {
229
+ return import("./hgt69zjf.js").then((mod) => mod.watchQuery(pending, watch, onAbort, {
217
230
  start,
218
231
  text,
219
232
  notices: this.notices,
@@ -252,67 +265,38 @@ class PgSession {
252
265
  this.transactionDepth = nextTransactionDepth(this.transactionDepth, text);
253
266
  }
254
267
  enter() {
255
- if (this.scope === "pool")
256
- this.counters.busy += 1;
257
- else
258
- this.counters.reservedBusy += 1;
268
+ this.counters[this.scope === "pool" ? "busy" : "reservedBusy"] += 1;
259
269
  }
260
270
  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);
271
+ const k = this.scope === "pool" ? "busy" : "reservedBusy";
272
+ this.counters[k] = Math.max(0, this.counters[k] - 1);
265
273
  }
266
274
  }
267
- async function* loadStream(sql, text, params) {
268
- const { stream } = await import("./fdsz3w80.js");
269
- yield* stream(sql, text, params);
270
- }
271
275
  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
- };
276
+ return !named && (params === undefined || params.length === 0) ? sql.unsafe(text).raw() : sql.unsafe(text, asParams(params), { prepare: named }).raw();
288
277
  }
278
+ var asParams = (params) => params ?? [];
279
+ var statsOf = (c, size) => ({
280
+ size,
281
+ idle: Math.max(0, size - c.reserved - c.busy),
282
+ inflight: c.busy + c.reservedBusy,
283
+ waiting: c.waiting
284
+ });
289
285
  function noticeBuffer() {
290
286
  let notices;
291
287
  return {
292
288
  push(notice) {
293
289
  const severity = typeof notice.severity === "string" ? notice.severity : "";
294
290
  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;
291
+ const code = typeof notice.code === "string" && notice.code ? notice.code : undefined;
292
+ (notices ??= []).push(code ? { severity, message, code } : { severity, message });
301
293
  },
302
- since(start) {
303
- if (notices === undefined || notices.length === start)
304
- return EMPTY_NOTICES;
305
- return notices.slice(start);
306
- }
294
+ start: () => notices?.length ?? 0,
295
+ since: (start) => notices === undefined || notices.length === start ? EMPTY_NOTICES : notices.slice(start)
307
296
  };
308
297
  }
309
298
  function wire(to, from) {
310
- return {
311
- to,
312
- from: [...from],
313
- serialize: (value) => value,
314
- parse: (value) => value
315
- };
299
+ return { to, from, serialize: String, parse: String };
316
300
  }
317
301
  var WIRE_TYPES = {
318
302
  number: wire(0, [21, 23, 26, 700, 701]),
@@ -8,7 +8,7 @@ import {
8
8
  withHttp,
9
9
  attachHttp,
10
10
  mapOptions
11
- } from "./npdftanb.js";
11
+ } from "./xbvz446k.js";
12
12
  import {
13
13
  OkmError2
14
14
  } from "./52szzakm.js";
@@ -75,7 +75,7 @@ async function acceptServer2(pool, schema, http, requireMeta, options, source) {
75
75
  const result = await pool.execute(await versionSql(namespace), undefined, options);
76
76
  rows = result.rows;
77
77
  } catch (error) {
78
- const { mapPostgresError } = await import("./63qtkrca.js");
78
+ const { mapPostgresError } = await import("./vy47ryqa.js");
79
79
  throw mapPostgresError(error, mapOptions(http, false, schema));
80
80
  }
81
81
  for (const name in schema.model) {
@@ -100,7 +100,7 @@ async function acceptServer2(pool, schema, http, requireMeta, options, source) {
100
100
  }));
101
101
  }
102
102
  } else {
103
- const { assertCompatible } = await import("./pg4ezgyf.js");
103
+ const { assertCompatible } = await import("./xbd9xs6p.js");
104
104
  try {
105
105
  await assertCompatible(pool, schema, recorded, source, options, namespace);
106
106
  } catch (error) {
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  open2
3
- } from "./dd5pmnky.js";
3
+ } from "./jvxcp1qk.js";
4
4
  import"./12z7aznj.js";
5
5
  import"./fk9vef30.js";
6
6
  import"./n442h54c.js";
@@ -15,21 +15,22 @@ import {
15
15
  import {
16
16
  expandProvisioned,
17
17
  provisionHistoryIsKnown
18
- } from "./3456242y.js";
19
- import"./jpybhf98.js";
20
- import"./myk8fswx.js";
18
+ } from "./8p2bgye0.js";
19
+ import"./6xqvesa5.js";
20
+ import"./mz48rs74.js";
21
21
  import {
22
22
  projectPath,
23
23
  catalogNamespace,
24
24
  loadMigrations,
25
25
  loadConfig
26
- } from "./2zdxkt7b.js";
26
+ } from "./wp7y8q3y.js";
27
27
  import {
28
+ driverUrl,
28
29
  sessionFailure,
29
30
  finishQuiet,
30
31
  assertTargetPolicy,
31
32
  listTargets
32
- } from "./6nae0spm.js";
33
+ } from "./bdekbvmt.js";
33
34
  import {
34
35
  OkmError2
35
36
  } from "./52szzakm.js";
@@ -83,7 +84,7 @@ function describeStatus(migrations, history, recorded) {
83
84
  async function readTargetStatus(input) {
84
85
  assertTargetPolicy({ name: input.target, protected: input.protected }, "status");
85
86
  const pool = open2({
86
- url: input.url,
87
+ url: driverUrl(input.url),
87
88
  max: 1,
88
89
  ...input.searchPath !== undefined ? { searchPath: input.searchPath } : {}
89
90
  });
@@ -14,7 +14,7 @@ import {
14
14
  } from "./fk9vef30.js";
15
15
  import {
16
16
  columnPrivilege
17
- } from "./6nae0spm.js";
17
+ } from "./bdekbvmt.js";
18
18
  import {
19
19
  policyObject
20
20
  } from "./bdk4sty6.js";
@@ -373,7 +373,7 @@ async function introspectSchema(runner, concrete, logical = "public", options) {
373
373
  events: triggerEvents(bits),
374
374
  level: (bits & 1) === 1 ? "row" : "statement",
375
375
  calls: {
376
- namespace: staticNamespace2(text(row, "function_schema")),
376
+ namespace: referencedNamespace(text(row, "function_schema"), concrete, namespace),
377
377
  name: text(row, "function"),
378
378
  argTypes
379
379
  },
@@ -741,6 +741,17 @@ function indexExpression(row, columns) {
741
741
  }).join(", ");
742
742
  return `using ${method} (${body.length > 0 ? body : stored})`;
743
743
  }
744
+ async function reprintDomainCheck(runner, base, expression) {
745
+ await runner.query("drop domain if exists okm_expr_domain");
746
+ await runner.query(`create domain okm_expr_domain as ${base} check (${expression})`);
747
+ const rows = await runner.query(`select pg_get_constraintdef(c.oid) as definition
748
+ from pg_constraint c
749
+ join pg_type t on t.oid = c.contypid
750
+ join pg_namespace n on n.oid = t.typnamespace
751
+ where t.typname = 'okm_expr_domain' and n.nspname = current_schema()`);
752
+ await runner.query("drop domain okm_expr_domain");
753
+ return checkExpression(text(rows[0] ?? {}, "definition"));
754
+ }
744
755
  var CHILD = "not exists (select 1 from pg_inherits i where i.inhrelid = c.oid)";
745
756
  var TABLES = `
746
757
  select c.relname as name, pt.partstrat as partstrat,
@@ -1082,4 +1093,4 @@ function flag(row, key) {
1082
1093
  return value === true || value === "true" || value === "t";
1083
1094
  }
1084
1095
 
1085
- export { cellText, VIEW_DEPENDENCIES, viewDependencyEdges, PUBLIC, introspectSchema, FUNCTION_ARG_TYPES, atomicBody };
1096
+ export { cellText, VIEW_DEPENDENCIES, viewDependencyEdges, PUBLIC, introspectSchema, FUNCTION_ARG_TYPES, atomicBody, reprintDomainCheck };
@@ -30,7 +30,6 @@ function open5(config) {
30
30
  let closed = false;
31
31
  const isClosed = () => closed;
32
32
  const named = config.prepared === "named";
33
- const parked = [];
34
33
  let dropped = 0;
35
34
  let closures = 0;
36
35
  const sql = new BunSQL(config.url, {
@@ -57,7 +56,6 @@ function open5(config) {
57
56
  });
58
57
  const held = {
59
58
  sql,
60
- parked,
61
59
  acquireMs,
62
60
  counters,
63
61
  notices,
@@ -66,26 +64,26 @@ function open5(config) {
66
64
  };
67
65
  const run = (text, params, watch) => {
68
66
  const sent = dropped;
69
- return root.query(text, params, watch).catch((error) => import("./cf8zdz5p.js").then((mod) => mod.recover(sql, error, text, root.depth(), clientPools.has(pool), dropped > sent, () => root.query(text, params, watch))));
67
+ return root.query(text, params, watch).catch((error) => import("./rcjm0yn7.js").then((mod) => mod.recover(sql, error, text, root.depth(), clientPools.has(pool), dropped > sent, () => root.query(text, params, watch))));
70
68
  };
71
69
  const afterDrop = (text, params, watch) => {
72
70
  if (dropped === 0)
73
71
  return run(text, params, watch);
74
72
  const seen = dropped;
75
- return import("./cf8zdz5p.js").then((mod) => mod.drainClosed(sql).then(() => {
73
+ return import("./rcjm0yn7.js").then((mod) => mod.drainClosed(sql).then(() => {
76
74
  if (dropped === seen)
77
75
  dropped = 0;
78
76
  return run(text, params, watch);
79
77
  }));
80
78
  };
81
- const checkout = () => closed ? rejectClosed() : import("./cf8zdz5p.js").then((mod) => mod.checkout(held));
79
+ const checkout = () => closed ? rejectClosed() : import("./rcjm0yn7.js").then((mod) => mod.checkout(held));
82
80
  const pool = {
83
81
  capabilities: BUNSQL_CAPABILITIES,
84
82
  execute(text, params, options) {
85
83
  const refused = noTimeout(options);
86
84
  if (refused !== undefined)
87
85
  return refused;
88
- return runCall(closed, options, (watch) => releaseParked(parked).then(() => afterDrop(text, params, watch)));
86
+ return runCall(closed, options, (watch) => afterDrop(text, params, watch));
89
87
  },
90
88
  async batch(statements, options) {
91
89
  const refused = noTimeout(options);
@@ -101,17 +99,16 @@ function open5(config) {
101
99
  reserve: () => checkout(),
102
100
  stream(text, params) {
103
101
  return async function* () {
104
- const { streamRows } = await import("./cf8zdz5p.js");
102
+ const { streamRows } = await import("./rcjm0yn7.js");
105
103
  yield* streamRows(checkout, text, params);
106
104
  }();
107
105
  },
108
106
  listen(channel, onNotify) {
109
- return import("./cf8zdz5p.js").then((mod) => mod.listen(sql, parked, closed, channel, onNotify));
107
+ return import("./rcjm0yn7.js").then((mod) => mod.listen(sql, closed, channel, onNotify));
110
108
  },
111
109
  stats: () => statsOf(counters, max),
112
110
  async close() {
113
111
  closed = true;
114
- await releaseParked(parked);
115
112
  await sql.close();
116
113
  }
117
114
  };
@@ -149,24 +146,14 @@ async function reserve(sql, acquireMs, counters) {
149
146
  const errors = await driverErrors();
150
147
  throw errors.acquireTimeout();
151
148
  }
149
+ if (error instanceof Error && (error.message === "Connection closed" || error.message === "connection must be a PostgresSQLConnection")) {
150
+ throw new DriverError2(error.message, { cause: error, sqlstate: "08006" });
151
+ }
152
152
  throw await mapFailure(error);
153
153
  } finally {
154
154
  counters.waiting = Math.max(0, counters.waiting - 1);
155
155
  }
156
156
  }
157
- async function park(parked, reserved) {
158
- parked.push(reserved);
159
- while (parked.length > 1) {
160
- const extra = parked.shift();
161
- if (extra !== undefined)
162
- await releaseReserved(extra);
163
- }
164
- }
165
- async function releaseParked(parked) {
166
- const pending = parked.splice(0);
167
- for (const reserved of pending)
168
- await releaseReserved(reserved);
169
- }
170
157
  function releaseReserved(reserved) {
171
158
  const done = reserved.release();
172
159
  return done instanceof Promise ? done.then(() => {
@@ -187,4 +174,4 @@ function statsOf(counters, size) {
187
174
  };
188
175
  }
189
176
 
190
- export { markClientPool, open5, send2, reserve, park };
177
+ export { markClientPool, open5, send2, reserve, releaseReserved };