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
@@ -1,31 +1,43 @@
1
1
  import {
2
2
  noticeBuffer,
3
3
  WireSession
4
- } from "./jsjjz875.js";
4
+ } from "./asnnc3v5.js";
5
5
  import {
6
6
  NODE_POSTGRES_CAPABILITIES,
7
7
  driverErrors,
8
8
  rejectClosed,
9
+ rejectCancelled,
10
+ rejectTimedOut,
9
11
  mapFailure,
10
12
  runCall
11
- } from "./5x3pf400.js";
13
+ } from "./ry2f3w8p.js";
12
14
 
13
15
  // src/adapters/pg/nodepostgres.ts
14
16
  import net from "node:net";
15
17
  import pg from "pg";
16
18
  var CANCEL_CODE = 80877102;
19
+ var ABORT_GRACE_MS = 250;
17
20
  var identity = (value) => value;
18
21
  function armDriverError2(source, handle = () => {}) {
19
22
  source.on("error", handle);
20
23
  }
24
+ function logClientError2(notices, error) {
25
+ const message = error instanceof Error ? error.message : typeof error === "string" ? error : "client error";
26
+ const code = typeof error === "object" && error !== null && "code" in error ? Reflect.get(error, "code") : undefined;
27
+ notices.push({
28
+ severity: "ERROR",
29
+ message,
30
+ ...typeof code === "string" && code.length > 0 ? { code } : {}
31
+ });
32
+ }
21
33
  var WIRE = {
22
34
  getTypeParser() {
23
35
  return identity;
24
36
  }
25
37
  };
26
- function open4(config) {
38
+ function open5(config) {
27
39
  const max = config.max ?? 10;
28
- const acquireMs = config.timeouts?.acquire;
40
+ const acquireMs = config.timeouts?.acquire ?? 1e4;
29
41
  const counters = { reserved: 0, busy: 0, reservedBusy: 0, waiting: 0 };
30
42
  const inflight = new Set;
31
43
  const notices = noticeBuffer();
@@ -43,37 +55,56 @@ function open4(config) {
43
55
  ...config.ssl !== undefined ? { ssl: config.ssl } : {},
44
56
  ...config.searchPath !== undefined ? { options: `-c search_path=${config.searchPath}` } : {}
45
57
  });
46
- armDriverError2(pool);
58
+ armDriverError2(pool, (error) => {
59
+ logClientError2(notices, error);
60
+ });
47
61
  pool.on("connect", (client) => {
48
62
  client.on("notice", (notice) => {
49
63
  notices.push(notice);
50
64
  });
65
+ armDriverError2(client, (error) => {
66
+ logClientError2(notices, error);
67
+ });
51
68
  });
52
- const root = new WireSession((text, params) => send3(pool, text, params, named, undefined), notices, isClosed, true, () => {
69
+ const root = new WireSession((text, params) => send4(pool, text, params, named, undefined), notices, isClosed, true, () => {
53
70
  counters.busy += 1;
54
71
  }, () => {
55
72
  counters.busy = Math.max(0, counters.busy - 1);
56
73
  }, inflight);
57
74
  const held = { pool, acquireMs, counters, notices, named, isClosed };
58
- const checkout = () => closed ? rejectClosed() : import("./9qr9rkbh.js").then((mod) => mod.checkout(held));
75
+ const checkout = () => closed ? rejectClosed() : import("./y2bd7yfx.js").then((mod) => mod.checkout(held));
59
76
  return {
60
77
  capabilities: NODE_POSTGRES_CAPABILITIES,
61
78
  execute(text, params, options) {
62
79
  return runCall(closed, options, async (watch) => {
63
80
  if (watch === undefined)
64
81
  return root.query(text, params, undefined);
65
- const client = await connectClient2(pool, acquireMs, counters);
82
+ const client = await connectClient3(pool, acquireMs, counters);
83
+ if (watch.signal.aborted) {
84
+ client.release();
85
+ return watch.reason() === "cancelled" ? rejectCancelled() : rejectTimedOut();
86
+ }
66
87
  counters.busy += 1;
67
- const session = new WireSession((statement, values) => send3(client, statement, values, named, client), notices, isClosed, true, () => {
88
+ const slot = trackCheckout(client, () => {
89
+ counters.busy = Math.max(0, counters.busy - 1);
90
+ });
91
+ const session = new WireSession((statement, values) => send4(client, statement, values, named, client), notices, isClosed, true, () => {
68
92
  return;
69
93
  }, () => {
70
94
  return;
71
95
  }, inflight);
96
+ const onAbort = () => {
97
+ slot.abandon();
98
+ };
99
+ if (watch.signal.aborted)
100
+ onAbort();
101
+ else
102
+ watch.signal.addEventListener("abort", onAbort, { once: true });
72
103
  try {
73
104
  return await session.query(text, params, watch);
74
105
  } finally {
75
- counters.busy = Math.max(0, counters.busy - 1);
76
- client.release();
106
+ watch.signal.removeEventListener("abort", onAbort);
107
+ slot.release();
77
108
  }
78
109
  });
79
110
  },
@@ -88,14 +119,14 @@ function open4(config) {
88
119
  reserve: () => checkout(),
89
120
  stream(text, params) {
90
121
  return async function* () {
91
- const { streamRows } = await import("./9qr9rkbh.js");
122
+ const { streamRows } = await import("./y2bd7yfx.js");
92
123
  yield* streamRows(checkout, text, params);
93
124
  }();
94
125
  },
95
126
  listen(channel, onNotify) {
96
127
  if (closed)
97
128
  return rejectClosed();
98
- return import("./9qr9rkbh.js").then((mod) => mod.listen(held, channel, onNotify));
129
+ return import("./y2bd7yfx.js").then((mod) => mod.listen(held, channel, onNotify));
99
130
  },
100
131
  cancel() {
101
132
  for (const pending of inflight)
@@ -108,7 +139,7 @@ function open4(config) {
108
139
  }
109
140
  };
110
141
  }
111
- function send3(runner, text, params, named, client) {
142
+ function send4(runner, text, params, named, client) {
112
143
  const query = {
113
144
  text,
114
145
  rowMode: "array",
@@ -149,7 +180,39 @@ function cancelBackend(client) {
149
180
  socket.end(bytes);
150
181
  });
151
182
  }
152
- function connectClient2(pool, acquireMs, counters) {
183
+ function trackCheckout(client, done) {
184
+ let dead = false;
185
+ let released = false;
186
+ let grace;
187
+ const onError = () => {
188
+ dead = true;
189
+ };
190
+ const events = client;
191
+ events.on("error", onError);
192
+ const release = () => {
193
+ if (released)
194
+ return;
195
+ released = true;
196
+ if (grace !== undefined)
197
+ clearTimeout(grace);
198
+ events.removeListener("error", onError);
199
+ done();
200
+ client.release(dead ? true : undefined);
201
+ };
202
+ return {
203
+ abandon() {
204
+ if (released || grace !== undefined)
205
+ return;
206
+ grace = setTimeout(() => {
207
+ dead = true;
208
+ release();
209
+ }, ABORT_GRACE_MS);
210
+ grace.unref();
211
+ },
212
+ release
213
+ };
214
+ }
215
+ function connectClient3(pool, acquireMs, counters) {
153
216
  counters.waiting += 1;
154
217
  let settled = false;
155
218
  return new Promise((resolve, reject) => {
@@ -191,4 +254,4 @@ function statsOf(counters, size) {
191
254
  };
192
255
  }
193
256
 
194
- export { armDriverError2, open4, send3, connectClient2 };
257
+ export { armDriverError2, logClientError2, open5, send4, connectClient3 };
@@ -1,6 +1,7 @@
1
1
  import {
2
2
  stack2
3
- } from "./35zemrmf.js";
3
+ } from "./angjck01.js";
4
+ import"./rd8h01ta.js";
4
5
  import {
5
6
  updateSliceBody2,
6
7
  rejectDuplicateTargets2,
@@ -15,15 +16,15 @@ import {
15
16
  expectOf2,
16
17
  allowSet2,
17
18
  noteGuarded2
18
- } from "./ezqn88nj.js";
19
- import"./w5d89rb4.js";
19
+ } from "./33z39trp.js";
20
+ import"./fdsek6pa.js";
20
21
  import {
21
22
  emitWhere,
22
23
  projectExpr,
23
24
  quote,
24
25
  isRecord,
25
26
  fail2
26
- } from "./hfq3n3bd.js";
27
+ } from "./2jdn09e2.js";
27
28
 
28
29
  // src/runtime/version.ts
29
30
  function planVersioned(schema, table, input, options, mods) {
@@ -0,0 +1,20 @@
1
+ import {
2
+ OkmError
3
+ } from "./2jdn09e2.js";
4
+
5
+ // src/runtime/param-limit.ts
6
+ var PG_PARAM_LIMIT = 65535;
7
+ function refuseParamLimit2(count) {
8
+ throw new OkmError("OKM1126", `${String(count)} parameters (max ${String(PG_PARAM_LIMIT)}).`, {
9
+ kind: "invalid",
10
+ retryable: false,
11
+ fix: { summary: "Chunk the work, or use = any(array)." }
12
+ });
13
+ }
14
+ function assertParamCount2(count) {
15
+ if (count <= PG_PARAM_LIMIT)
16
+ return;
17
+ refuseParamLimit2(count);
18
+ }
19
+
20
+ export { refuseParamLimit2, assertParamCount2 };
@@ -3,7 +3,7 @@ import {
3
3
  readHandle,
4
4
  readCall,
5
5
  attachHttp
6
- } from "./jr2nmr81.js";
6
+ } from "./gjj71hfh.js";
7
7
  import {
8
8
  OkmError,
9
9
  throwNamed,
@@ -19,13 +19,13 @@ import {
19
19
  list,
20
20
  isRecord,
21
21
  fail2
22
- } from "./hfq3n3bd.js";
22
+ } from "./2jdn09e2.js";
23
23
 
24
24
  // src/runtime/aggregate.ts
25
25
  var BUCKET = Symbol.for("okmodel.bucket");
26
26
  var bucketChunk;
27
27
  function loadBucketGroup() {
28
- return bucketChunk ??= import("./57btdkgm.js");
28
+ return bucketChunk ??= import("./ss87qxwv.js");
29
29
  }
30
30
  var OPTIONS = [
31
31
  "where",
@@ -57,14 +57,14 @@ function hasCapability2(flags, name) {
57
57
  // src/adapters/failure.ts
58
58
  var loading;
59
59
  function driverErrors() {
60
- loading ??= import("./a2xe04bm.js");
60
+ loading ??= import("./adk9k6va.js");
61
61
  return loading;
62
62
  }
63
63
  function rejectClosed() {
64
- return import("./sjwkt1pg.js").then((mod) => mod.closed());
64
+ return import("./yz68xcmc.js").then((mod) => mod.closed());
65
65
  }
66
66
  function rejectUncancellable() {
67
- return import("./sjwkt1pg.js").then((mod) => mod.refused());
67
+ return import("./yz68xcmc.js").then((mod) => mod.refused());
68
68
  }
69
69
  function rejectCancelled() {
70
70
  return driverErrors().then((mod) => Promise.reject(mod.cancelled()));
@@ -1,22 +1,22 @@
1
1
  import {
2
2
  markClientPool2,
3
- open2,
4
- send2,
3
+ open3,
4
+ send3,
5
5
  reserve2,
6
- park2
7
- } from "./rcywj2w8.js";
6
+ releaseReserved2
7
+ } from "./3f6etb9z.js";
8
8
  import {
9
9
  BUNSQL_CAPABILITIES,
10
10
  readCapability2,
11
11
  hasCapability2
12
- } from "./5x3pf400.js";
12
+ } from "./ry2f3w8p.js";
13
13
  export {
14
14
  BUNSQL_CAPABILITIES as capabilities,
15
15
  hasCapability2 as hasCapability,
16
16
  markClientPool2 as markClientPool,
17
- open2 as open,
18
- park2 as park,
17
+ open3 as open,
19
18
  readCapability2 as readCapability,
19
+ releaseReserved2 as releaseReserved,
20
20
  reserve2 as reserve,
21
- send2 as send
21
+ send3 as send
22
22
  };
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  refusePrototypeKey
3
- } from "./0j0jtse1.js";
3
+ } from "./09a6vsys.js";
4
4
  import {
5
5
  throwNamed,
6
6
  parseOrder,
@@ -9,7 +9,7 @@ import {
9
9
  list,
10
10
  isRecord,
11
11
  fail2
12
- } from "./hfq3n3bd.js";
12
+ } from "./2jdn09e2.js";
13
13
 
14
14
  // src/dialects/pg/ops/bucket.ts
15
15
  var RUNTIME = Symbol.for("okmodel.bucket");
@@ -1,10 +1,10 @@
1
1
  import {
2
2
  historySql2
3
- } from "./dhatassp.js";
4
- import"./jr2nmr81.js";
3
+ } from "./8g0m0rvd.js";
4
+ import"./gjj71hfh.js";
5
5
  import {
6
6
  OkmError
7
- } from "./hfq3n3bd.js";
7
+ } from "./2jdn09e2.js";
8
8
 
9
9
  // src/runtime/compat-words.ts
10
10
  var BEHIND_EXPAND = "behind by expand";
@@ -6,7 +6,7 @@ import {
6
6
  runCall,
7
7
  EMPTY_NOTICES,
8
8
  resultFrom
9
- } from "./5x3pf400.js";
9
+ } from "./ry2f3w8p.js";
10
10
 
11
11
  // src/adapters/pg/postgresjs.ts
12
12
  import net from "node:net";
@@ -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
  }
95
- function open3(config) {
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
+ });
99
+ function open4(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 open3(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 PgSession2(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 PgSession2(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("./04svnxxj.js").then((mod) => mod.runBatch(held, statements, options)));
133
+ return sockets.occupy(() => import("./4tg2bn41.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("./04svnxxj.js").then((mod) => mod.holdCheckout(gate, () => mod.checkout(held)), (error) => {
138
+ return import("./4tg2bn41.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("./04svnxxj.js").then((mod) => mod.describe(sql, text, params))),
143
+ describe: (text, params) => sockets.occupy(() => import("./4tg2bn41.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("./4tg2bn41.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("./04svnxxj.js").then((mod) => mod.holdListener(gate, async () => {
147
- const listening = await sql.listen(channel, onNotify);
158
+ return import("./4tg2bn41.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 open3(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 PgSession2 {
213
226
  onAbort();
214
227
  else
215
228
  watch.signal.addEventListener("abort", onAbort, { once: true });
216
- return import("./04svnxxj.js").then((mod) => mod.watchQuery(pending, watch, onAbort, {
229
+ return import("./4tg2bn41.js").then((mod) => mod.watchQuery(pending, watch, onAbort, {
217
230
  start,
218
231
  text,
219
232
  notices: this.notices,
@@ -252,67 +265,38 @@ class PgSession2 {
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("./04svnxxj.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]),
@@ -329,4 +313,4 @@ var WIRE_TYPES = {
329
313
  jsonbArray: wire(3807, [3807])
330
314
  };
331
315
 
332
- export { open3, PgSession2 };
316
+ export { open4, PgSession2 };
@@ -3,7 +3,7 @@ import {
3
3
  outcomeUnknown2,
4
4
  mapDriverError2,
5
5
  isConnectionLost
6
- } from "./hfq3n3bd.js";
6
+ } from "./2jdn09e2.js";
7
7
 
8
8
  // src/adapters/pg/batch.ts
9
9
  var savepointIds = 0;
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  noTimeout
3
- } from "./3yn79q5m.js";
3
+ } from "./1fwfm5m3.js";
4
4
  import {
5
5
  PGLITE_CAPABILITIES,
6
6
  driverErrors,
@@ -11,12 +11,12 @@ import {
11
11
  runCall,
12
12
  EMPTY_NOTICES,
13
13
  resultFrom
14
- } from "./5x3pf400.js";
14
+ } from "./ry2f3w8p.js";
15
15
 
16
16
  // src/adapters/pg/pglite.ts
17
17
  import { PGlite } from "@electric-sql/pglite";
18
18
  async function open6(config = {}) {
19
- const wire = await import("./8m5znpdt.js");
19
+ const wire = await import("./phc1nc4g.js");
20
20
  const db = new PGlite({
21
21
  dataDir: config.dataDir ?? "memory://",
22
22
  parsers: wire.parsers,
@@ -58,7 +58,7 @@ async function open6(config = {}) {
58
58
  if (refused !== undefined)
59
59
  return refused;
60
60
  return runCall(closed, options, async (watch) => {
61
- const { runAtomicBatch } = await import("./gqwevek4.js");
61
+ const { runAtomicBatch } = await import("./xchpnbdv.js");
62
62
  return runAtomicBatch(session, statements, watch);
63
63
  });
64
64
  },
@@ -67,7 +67,7 @@ async function open6(config = {}) {
67
67
  return;
68
68
  released = true;
69
69
  try {
70
- const { resetQueried } = await import("./9wsnsvbf.js");
70
+ const { resetQueried } = await import("./3t2cqmsx.js");
71
71
  await resetQueried(session);
72
72
  } finally {
73
73
  slot.release();