okmodel 0.6.0 → 0.8.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 (267) hide show
  1. package/README.md +100 -1131
  2. package/dist/adapters/capabilities.d.ts +35 -0
  3. package/dist/adapters/failure.d.ts +13 -2
  4. package/dist/adapters/lazy-errors.d.ts +22 -0
  5. package/dist/adapters/pg/bun-sql.d.ts +53 -0
  6. package/dist/adapters/pg/bunsql-extra.d.ts +54 -3
  7. package/dist/adapters/pg/bunsql.d.ts +15 -2
  8. package/dist/adapters/pg/cursor.d.ts +17 -0
  9. package/dist/adapters/pg/neon-extra.d.ts +18 -0
  10. package/dist/adapters/pg/neon.d.ts +104 -0
  11. package/dist/adapters/pg/no-inflight-timeout.d.ts +11 -8
  12. package/dist/adapters/pg/nodepostgres-extra.d.ts +22 -1
  13. package/dist/adapters/pg/nodepostgres.d.ts +12 -0
  14. package/dist/adapters/pg/pglite-wire.d.ts +24 -0
  15. package/dist/adapters/pg/pglite.d.ts +10 -0
  16. package/dist/adapters/pg/postgres-extra.d.ts +27 -11
  17. package/dist/adapters/pg/reserved.d.ts +42 -0
  18. package/dist/adapters/pg/session.d.ts +0 -18
  19. package/dist/contracts/connection.d.ts +7 -6
  20. package/dist/contracts/error.d.ts +1 -1
  21. package/dist/dialects/pg/floor.d.ts +68 -0
  22. package/dist/dialects/pg/fn/index.d.ts +39 -1
  23. package/dist/dialects/pg/fn/index.js +118 -26
  24. package/dist/dialects/pg/index.d.ts +8 -1
  25. package/dist/dialects/pg/index.js +435 -170
  26. package/dist/dialects/pg/introspect.d.ts +11 -0
  27. package/dist/dialects/pg/keys.d.ts +11 -8
  28. package/dist/dialects/pg/model.d.ts +40 -0
  29. package/dist/dialects/pg/morph.d.ts +43 -0
  30. package/dist/dialects/pg/operator-fit.d.ts +2 -2
  31. package/dist/dialects/pg/operators.d.ts +14 -7
  32. package/dist/dialects/pg/ops/bucket.d.ts +65 -0
  33. package/dist/dialects/pg/ops/fragment.d.ts +119 -0
  34. package/dist/dialects/pg/ops/inc.d.ts +2 -2
  35. package/dist/dialects/pg/ops/lane.d.ts +49 -0
  36. package/dist/dialects/pg/ops/matches.d.ts +9 -12
  37. package/dist/dialects/pg/ops/relevance.d.ts +13 -0
  38. package/dist/dialects/pg/ops/search-query.d.ts +22 -0
  39. package/dist/dialects/pg/ops/window.d.ts +103 -0
  40. package/dist/dialects/pg/preset.d.ts +1 -1
  41. package/dist/dialects/pg/relations.d.ts +100 -3
  42. package/dist/dialects/pg/schema.d.ts +31 -3
  43. package/dist/dialects/pg/view/client.d.ts +14 -6
  44. package/dist/dialects/pg/view/index.d.ts +73 -1
  45. package/dist/dialects/pg/view/index.js +156 -5
  46. package/dist/dialects/pg/view/scratch.d.ts +8 -5
  47. package/dist/runtime/aggregate.d.ts +8 -2
  48. package/dist/runtime/bucket-group.d.ts +70 -0
  49. package/dist/runtime/conflict.d.ts +22 -4
  50. package/dist/runtime/include.d.ts +0 -8
  51. package/dist/runtime/inflight.d.ts +1 -1
  52. package/dist/runtime/otel.d.ts +105 -0
  53. package/dist/runtime/otel.js +97 -0
  54. package/dist/runtime/page.d.ts +4 -1
  55. package/dist/runtime/pg/bun.js +12 -6
  56. package/dist/runtime/pg/neon.d.ts +38 -0
  57. package/dist/runtime/pg/neon.js +64 -0
  58. package/dist/runtime/pg/pg.js +5 -5
  59. package/dist/runtime/pg/pglite.d.ts +1 -0
  60. package/dist/runtime/pg/pglite.js +9 -9
  61. package/dist/runtime/pg/postgresjs.js +5 -5
  62. package/dist/runtime/plan.d.ts +95 -5
  63. package/dist/runtime/read-stream.d.ts +13 -16
  64. package/dist/runtime/result-name.d.ts +17 -0
  65. package/dist/runtime/server-check.d.ts +3 -3
  66. package/dist/runtime/sort-bind.d.ts +21 -0
  67. package/dist/runtime/sort.d.ts +56 -0
  68. package/dist/runtime/sql-fragment.d.ts +43 -0
  69. package/dist/runtime/sync.d.ts +70 -0
  70. package/dist/runtime/tenancy/index.js +15 -13
  71. package/dist/runtime/text-search.d.ts +20 -0
  72. package/dist/runtime/topology.d.ts +1 -1
  73. package/dist/runtime/traits/index.d.ts +80 -0
  74. package/dist/runtime/traits/index.js +184 -21
  75. package/dist/runtime/tree.d.ts +38 -0
  76. package/dist/runtime/types.d.ts +232 -22
  77. package/dist/runtime/validate/index.js +4 -4
  78. package/dist/runtime/version.d.ts +39 -0
  79. package/dist/runtime/window.d.ts +21 -0
  80. package/dist/runtime/write.d.ts +54 -2
  81. package/dist/shared/{929h19xp.js → 0wrea3jq.js} +141 -13
  82. package/dist/shared/{qq3899ht.js → 12z7aznj.js} +243 -14
  83. package/dist/shared/{1z04fa85.js → 14x60fbf.js} +12 -57
  84. package/dist/shared/{ek2wt2dz.js → 16kvjebh.js} +4 -4
  85. package/dist/shared/{wynzeggs.js → 195pzzzz.js} +8 -8
  86. package/dist/shared/1d9q9cv2.js +312 -0
  87. package/dist/shared/2c13q96h.js +18 -0
  88. package/dist/shared/{b4v57v3x.js → 2d3xq4ps.js} +2 -2
  89. package/dist/shared/{1f0xa3cb.js → 3449rcae.js} +5 -5
  90. package/dist/shared/{wkme6tep.js → 35q0n9tz.js} +8 -16
  91. package/dist/shared/3bb7wsqt.js +99 -0
  92. package/dist/shared/3t6kw83m.js +249 -0
  93. package/dist/shared/{5j36z8dn.js → 4m6hskg8.js} +39 -70
  94. package/dist/shared/{n076ydsc.js → 4vbf83xx.js} +69 -28
  95. package/dist/shared/{vmfkhszw.js → 63f4ksbz.js} +33 -26
  96. package/dist/shared/{c58secgj.js → 63qtkrca.js} +38 -4
  97. package/dist/shared/6m78c8ss.js +6 -0
  98. package/dist/shared/{x3jc53kg.js → 760ppr76.js} +15 -7
  99. package/dist/shared/7ghwamrf.js +40 -0
  100. package/dist/shared/7kms6fvj.js +20 -0
  101. package/dist/shared/7n7ddwt4.js +6 -0
  102. package/dist/shared/9a4ae4p8.js +31 -0
  103. package/dist/shared/{hazqqecq.js → 9dr2qnx7.js} +63 -34
  104. package/dist/shared/{h15jx9bc.js → 9dvh1dr6.js} +1 -1
  105. package/dist/shared/a62rb2da.js +13 -0
  106. package/dist/shared/{cgbamx3e.js → ae4j5f42.js} +23 -4
  107. package/dist/shared/agsfb86s.js +233 -0
  108. package/dist/shared/{8x72s86k.js → b6d6p0zc.js} +13 -7
  109. package/dist/shared/{ag4c7516.js → b76b8d95.js} +2 -2
  110. package/dist/shared/{j60w0dvr.js → bah9nbg3.js} +58 -38
  111. package/dist/shared/bnby0esn.js +10 -0
  112. package/dist/shared/bsek72fg.js +225 -0
  113. package/dist/shared/{2cg3wnxc.js → bxas03mq.js} +608 -141
  114. package/dist/shared/{31vm914h.js → cm3w0ywp.js} +15 -16
  115. package/dist/shared/{gwn6v667.js → cnkky55j.js} +25 -14
  116. package/dist/shared/{dk8v79p3.js → d5nmj7vv.js} +1 -1
  117. package/dist/shared/{ttmg09vd.js → dpc2r7rb.js} +8 -8
  118. package/dist/shared/dzj09cye.js +10 -0
  119. package/dist/shared/{sbdme3vy.js → e8zyaqvj.js} +60 -10
  120. package/dist/shared/{2jd1sn0e.js → ecn8mfdq.js} +6 -6
  121. package/dist/shared/exn3sd90.js +359 -0
  122. package/dist/shared/{t3g0k88x.js → f4jy1j7x.js} +39 -22
  123. package/dist/shared/{y2t3jktd.js → fjpnhqan.js} +20 -13
  124. package/dist/shared/g5yc06ka.js +272 -0
  125. package/dist/shared/ga9j92qj.js +25 -0
  126. package/dist/shared/{3fqwmr09.js → hfqmpasr.js} +6 -6
  127. package/dist/shared/{wt5rzv1h.js → hm5f8jby.js} +7 -7
  128. package/dist/shared/{ys0xzyaj.js → hqpxf4a4.js} +224 -19
  129. package/dist/shared/jebgrkeq.js +179 -0
  130. package/dist/shared/{09p049xa.js → jp36k7dp.js} +44 -16
  131. package/dist/shared/jx2m62cs.js +96 -0
  132. package/dist/shared/{r11n8grd.js → k86n8vq3.js} +7 -4
  133. package/dist/shared/{2z7wv5tj.js → kgwp4jdd.js} +56 -35
  134. package/dist/shared/{knmes2kh.js → kj9d8maq.js} +1 -1
  135. package/dist/shared/{g90m9b0g.js → m4xff2a6.js} +6 -5
  136. package/dist/shared/{r6nwkxnt.js → m7n9h2a5.js} +4 -4
  137. package/dist/shared/mfedzr74.js +145 -0
  138. package/dist/shared/{f0f1n281.js → mkrn359n.js} +60 -11
  139. package/dist/shared/{p248q79y.js → mnvjvqyp.js} +10 -10
  140. package/dist/shared/{672t5vym.js → mss6ctgv.js} +2 -2
  141. package/dist/shared/{4az561fn.js → mtw6jz76.js} +8 -23
  142. package/dist/shared/n05z9nwz.js +313 -0
  143. package/dist/shared/{pjr6xrm5.js → n0jmpgj1.js} +20 -17
  144. package/dist/shared/{p6bjzq9q.js → n41w4fbz.js} +14 -6
  145. package/dist/shared/{b3awxn7h.js → n454kcnw.js} +1 -1
  146. package/dist/shared/n7kg8mmx.js +61 -0
  147. package/dist/shared/nbw1z4yd.js +18 -0
  148. package/dist/shared/needfe47.js +66 -0
  149. package/dist/shared/{1nw1f3vs.js → njga14v4.js} +9 -9
  150. package/dist/shared/{5yv4k6a6.js → nmnsgj7x.js} +145 -3
  151. package/dist/shared/{vjpnzwjz.js → p3xbdcvt.js} +14 -18
  152. package/dist/shared/p5nh3r8q.js +622 -0
  153. package/dist/shared/{nx9hh281.js → pan0370z.js} +13 -12
  154. package/dist/shared/q0cqt2sp.js +12 -0
  155. package/dist/shared/qd9hhd8f.js +37 -0
  156. package/dist/shared/{mb2ycs1p.js → qfw14tna.js} +15 -15
  157. package/dist/shared/{9s0ypp87.js → sjk86yrx.js} +1 -1
  158. package/dist/shared/th3be82n.js +208 -0
  159. package/dist/shared/{ed0b8k4s.js → typ3vy7t.js} +1 -1
  160. package/dist/shared/{5d8t84hg.js → v1wad97q.js} +14 -14
  161. package/dist/shared/{x72jb7ad.js → v8g1vgv8.js} +1 -1
  162. package/dist/shared/{9628a9xt.js → vk7rag46.js} +1 -1
  163. package/dist/shared/{ze4hxsmy.js → w9ejzaqf.js} +1 -1
  164. package/dist/shared/{q3j1tq7a.js → wcrheftc.js} +148 -23
  165. package/dist/shared/wvdjznah.js +213 -0
  166. package/dist/shared/wz2a78mp.js +8 -0
  167. package/dist/shared/xfhe73sb.js +436 -0
  168. package/dist/shared/{r1fdd0f6.js → z581d7ny.js} +5 -2
  169. package/dist/shared/{8etn7d8w.js → z7s6fpxv.js} +1 -1
  170. package/dist/shared/{32cnm7kn.js → zbqbmmrp.js} +76 -40
  171. package/dist/shared/{n7mcc1gk.js → zchaghkf.js} +4 -3
  172. package/dist/shared/{xq0mvhts.js → zgex00fd.js} +6 -6
  173. package/dist/shared/{nsva2a6b.js → znm0bpp5.js} +3 -0
  174. package/dist/shared/zq1he88x.js +155 -0
  175. package/dist/tooling/cli.js +26 -13
  176. package/dist/tooling/driver-run.js +4971 -0
  177. package/dist/tooling/driver-test.d.ts +36 -0
  178. package/dist/tooling/migrate/commands.d.ts +2 -2
  179. package/dist/tooling/migrate/engine.d.ts +3 -2
  180. package/dist/tooling/migrate/index.js +9 -9
  181. package/dist/tooling/migrate/project.d.ts +3 -0
  182. package/dist/tooling/shared/03k6res6.js +210 -0
  183. package/dist/tooling/shared/08kemxjd.js +10 -0
  184. package/dist/tooling/shared/2revefqt.js +209 -0
  185. package/dist/tooling/shared/2wtvc7rw.js +1425 -0
  186. package/dist/tooling/shared/345tbc2k.js +16 -0
  187. package/dist/tooling/shared/3m1hkg7z.js +344 -0
  188. package/dist/tooling/shared/3rrw5w8f.js +81 -0
  189. package/dist/tooling/shared/3tq8pnb8.js +131 -0
  190. package/dist/tooling/shared/417zdsk7.js +194 -0
  191. package/dist/tooling/shared/4d2w25vw.js +40 -0
  192. package/dist/tooling/shared/54tqkxja.js +51 -0
  193. package/dist/tooling/shared/5bvw2nev.js +12 -0
  194. package/dist/tooling/shared/6nyfyw70.js +231 -0
  195. package/dist/tooling/shared/72fyg4zv.js +160 -0
  196. package/dist/tooling/shared/733a1tq3.js +38 -0
  197. package/dist/tooling/shared/7ae7rjmn.js +20 -0
  198. package/dist/tooling/shared/7kms6fvj.js +20 -0
  199. package/dist/tooling/shared/8sqrsw3s.js +49 -0
  200. package/dist/tooling/shared/96ps4g1z.js +32 -0
  201. package/dist/tooling/shared/9kazs5p6.js +195 -0
  202. package/dist/tooling/shared/9xzm7hjg.js +38 -0
  203. package/dist/tooling/shared/a6pp9d12.js +49 -0
  204. package/dist/tooling/shared/a7q7t4n3.js +22 -0
  205. package/dist/tooling/shared/aftb2mwr.js +18 -0
  206. package/dist/tooling/shared/bz2dqhab.js +311 -0
  207. package/dist/tooling/shared/cmptmb4f.js +12 -0
  208. package/dist/tooling/shared/ddjtfgnx.js +177 -0
  209. package/dist/tooling/shared/djydjpqt.js +261 -0
  210. package/dist/tooling/shared/dw08f3m8.js +9 -0
  211. package/dist/tooling/shared/dy672fz6.js +16 -0
  212. package/dist/tooling/shared/dzx85q70.js +66 -0
  213. package/dist/tooling/shared/ec71zqgt.js +270 -0
  214. package/dist/{shared/d5azex6s.js → tooling/shared/ep8zh3bk.js} +1 -1
  215. package/dist/tooling/shared/f9mphxej.js +3789 -0
  216. package/dist/tooling/shared/fb9k2qwd.js +89 -0
  217. package/dist/tooling/shared/g9ad4n80.js +211 -0
  218. package/dist/tooling/shared/gfvtj6d0.js +94 -0
  219. package/dist/tooling/shared/gmcf9cxf.js +294 -0
  220. package/dist/tooling/shared/htnaj77v.js +17 -0
  221. package/dist/tooling/shared/j9t5s12a.js +7 -0
  222. package/dist/tooling/shared/jne7b93p.js +42 -0
  223. package/dist/tooling/shared/ma2340rx.js +118 -0
  224. package/dist/tooling/shared/mtrqn2hn.js +505 -0
  225. package/dist/tooling/shared/n4jqhpqz.js +27 -0
  226. package/dist/tooling/shared/nf7jmhfa.js +20 -0
  227. package/dist/tooling/shared/p7f08ktn.js +332 -0
  228. package/dist/tooling/shared/ppnnnvj8.js +13 -0
  229. package/dist/tooling/shared/pqy21k24.js +312 -0
  230. package/dist/tooling/shared/pw8fgahx.js +69 -0
  231. package/dist/tooling/shared/pwsytxm5.js +17 -0
  232. package/dist/tooling/shared/rf83gr2d.js +94 -0
  233. package/dist/tooling/shared/rq5kk8j6.js +401 -0
  234. package/dist/tooling/shared/rs1jb051.js +12 -0
  235. package/dist/tooling/shared/smn6kz1p.js +157 -0
  236. package/dist/tooling/shared/spk1jg3r.js +1696 -0
  237. package/dist/tooling/shared/tn8gay14.js +143 -0
  238. package/dist/tooling/shared/vraj6d74.js +42 -0
  239. package/dist/tooling/shared/vs0t6qt8.js +64 -0
  240. package/dist/tooling/shared/vx86qjv8.js +150 -0
  241. package/dist/tooling/shared/w7qe8sj1.js +140 -0
  242. package/dist/tooling/shared/wt7j7nf6.js +15 -0
  243. package/dist/tooling/shared/wwnekq5n.js +6 -0
  244. package/dist/tooling/shared/xhrnjch9.js +185 -0
  245. package/dist/tooling/shared/xjs6zqtc.js +190 -0
  246. package/dist/tooling/shared/y031jct9.js +16 -0
  247. package/dist/tooling/shared/y5656f0e.js +233 -0
  248. package/dist/tooling/shared/yfr8hzhm.js +604 -0
  249. package/dist/tooling/shared/yk9mp7vb.js +250 -0
  250. package/dist/tooling/shared/yw30vnq2.js +139 -0
  251. package/dist/tooling/shared/z8d7ptht.js +618 -0
  252. package/dist/tooling/shared/zhwnfyb2.js +9 -0
  253. package/dist/tooling/shared/zvnhh1n0.js +198 -0
  254. package/dist/tooling/testing/index.js +3 -3
  255. package/package.json +17 -3
  256. package/dist/shared/3qnhc7w5.js +0 -38
  257. package/dist/shared/7m88x3e9.js +0 -45
  258. package/dist/shared/8dqhth8c.js +0 -12
  259. package/dist/shared/j3rkk835.js +0 -99
  260. package/dist/shared/k68eedmy.js +0 -85
  261. package/dist/shared/venqrjna.js +0 -216
  262. package/dist/shared/wxr8cwns.js +0 -6
  263. package/dist/shared/y34a8714.js +0 -150
  264. package/dist/shared/zm0mafk4.js +0 -92
  265. package/dist/shared/zy8r7qvz.js +0 -116
  266. package/dist/shared/{ywr8hmey.js → 606g0nbf.js} +3 -3
  267. package/dist/shared/{rpycarcr.js → gcefca6p.js} +4 -4
@@ -0,0 +1,233 @@
1
+ import {
2
+ outcomeUnknown2
3
+ } from "./cm3w0ywp.js";
4
+ import {
5
+ noTimeout
6
+ } from "./q0cqt2sp.js";
7
+ import {
8
+ noticeBuffer,
9
+ WireSession
10
+ } from "./mtw6jz76.js";
11
+ import {
12
+ NEON_WEBSOCKET_CAPABILITIES,
13
+ NEON_HTTP_CAPABILITIES,
14
+ driverErrors,
15
+ rejectClosed,
16
+ mapFailure,
17
+ runCall,
18
+ EMPTY_NOTICES,
19
+ resultFrom
20
+ } from "./ae4j5f42.js";
21
+
22
+ // src/adapters/pg/neon.ts
23
+ import {
24
+ Pool,
25
+ neon,
26
+ neonConfig
27
+ } from "@neondatabase/serverless";
28
+ var CONNECT_MS = 30000;
29
+ var WIRE = {
30
+ getTypeParser() {
31
+ return (value) => value;
32
+ }
33
+ };
34
+ var names = new Map;
35
+ async function open6(config) {
36
+ if (config.mode === "http")
37
+ return openHttp(config);
38
+ return openWebSocket(config);
39
+ }
40
+ function connectClient2(pool, acquireMs, counters) {
41
+ counters.waiting += 1;
42
+ let settled = false;
43
+ return new Promise((resolve, reject) => {
44
+ let timer;
45
+ if (acquireMs !== undefined) {
46
+ timer = setTimeout(() => {
47
+ settled = true;
48
+ counters.waiting = Math.max(0, counters.waiting - 1);
49
+ driverErrors().then((errors) => {
50
+ reject(errors.acquireTimeout());
51
+ });
52
+ }, acquireMs);
53
+ }
54
+ take(pool).then((client) => {
55
+ if (settled) {
56
+ client.release();
57
+ return;
58
+ }
59
+ if (timer !== undefined)
60
+ clearTimeout(timer);
61
+ counters.waiting = Math.max(0, counters.waiting - 1);
62
+ resolve(client);
63
+ }, (error) => {
64
+ if (settled)
65
+ return;
66
+ if (timer !== undefined)
67
+ clearTimeout(timer);
68
+ counters.waiting = Math.max(0, counters.waiting - 1);
69
+ mapFailure(error).then(reject);
70
+ });
71
+ });
72
+ }
73
+ function send3(runner, text, params, named) {
74
+ const query = {
75
+ text,
76
+ rowMode: "array",
77
+ types: WIRE,
78
+ ...params !== undefined && params.length > 0 ? { values: params } : {},
79
+ ...named ? { name: statementName(text) } : {}
80
+ };
81
+ return runner.query(query);
82
+ }
83
+ async function openWebSocket(config) {
84
+ ensureWebSocket();
85
+ const max = config.max ?? 10;
86
+ const acquireMs = config.timeouts?.acquire;
87
+ const counters = { reserved: 0, busy: 0, reservedBusy: 0, waiting: 0 };
88
+ const notices = noticeBuffer();
89
+ let closed = false;
90
+ const isClosed = () => closed;
91
+ const named = config.prepared === "named";
92
+ const pool = new Pool({
93
+ connectionString: config.url,
94
+ max,
95
+ idleTimeoutMillis: 0,
96
+ allowExitOnIdle: true,
97
+ connectionTimeoutMillis: CONNECT_MS,
98
+ application_name: "okmodel",
99
+ types: WIRE,
100
+ ...config.searchPath !== undefined ? { options: `-c search_path=${config.searchPath}` } : {}
101
+ });
102
+ pool.on("error", () => {
103
+ return;
104
+ });
105
+ try {
106
+ const warmed = await take(pool);
107
+ warmed.release();
108
+ } catch (error) {
109
+ await pool.end().catch(() => {
110
+ return;
111
+ });
112
+ throw await mapFailure(error);
113
+ }
114
+ const root = new WireSession((text, params) => send3(pool, text, params, named), notices, isClosed, false, () => {
115
+ counters.busy += 1;
116
+ }, () => {
117
+ counters.busy = Math.max(0, counters.busy - 1);
118
+ });
119
+ const held = { pool, acquireMs, counters, notices, named, isClosed };
120
+ const checkout = () => closed ? rejectClosed() : import("./jx2m62cs.js").then((mod) => mod.checkout(held));
121
+ return {
122
+ capabilities: NEON_WEBSOCKET_CAPABILITIES,
123
+ execute(text, params, options) {
124
+ const refused = noTimeout(options);
125
+ if (refused !== undefined)
126
+ return refused;
127
+ return runCall(closed, options, (watch) => root.query(text, params, watch));
128
+ },
129
+ async batch(statements, options) {
130
+ const refused = noTimeout(options);
131
+ if (refused !== undefined)
132
+ return refused;
133
+ const connection = await checkout();
134
+ try {
135
+ return await connection.batch(statements, options);
136
+ } finally {
137
+ await connection.release();
138
+ }
139
+ },
140
+ reserve: () => checkout(),
141
+ stats: () => statsOf(counters, max),
142
+ async close() {
143
+ closed = true;
144
+ await pool.end();
145
+ }
146
+ };
147
+ }
148
+ function openHttp(config) {
149
+ const max = config.max ?? 10;
150
+ const counters = { reserved: 0, busy: 0, reservedBusy: 0, waiting: 0 };
151
+ let closed = false;
152
+ const sql = neon(config.url, { arrayMode: true, fullResults: true });
153
+ const run = async (text, params) => {
154
+ counters.busy += 1;
155
+ try {
156
+ const result = await sql.query(text, params === undefined ? [] : [...params]);
157
+ return resultFrom(result, EMPTY_NOTICES);
158
+ } finally {
159
+ counters.busy = Math.max(0, counters.busy - 1);
160
+ }
161
+ };
162
+ return {
163
+ capabilities: NEON_HTTP_CAPABILITIES,
164
+ execute(text, params, options) {
165
+ const refused = noTimeout(options);
166
+ if (refused !== undefined)
167
+ return refused;
168
+ if (closed)
169
+ return rejectClosed();
170
+ return runCall(closed, options, () => run(text, params).catch((error) => mapFailure(error).then((mapped) => Promise.reject(mapped))));
171
+ },
172
+ async batch(statements, options) {
173
+ const refused = noTimeout(options);
174
+ if (refused !== undefined)
175
+ return refused;
176
+ if (closed)
177
+ return rejectClosed();
178
+ counters.busy += 1;
179
+ try {
180
+ const queries = statements.map((statement) => sql.query(statement.text, statement.params === undefined ? [] : [...statement.params]));
181
+ const results = await sql.transaction(queries, httpOptions());
182
+ return results.map((result) => resultFrom(result, EMPTY_NOTICES));
183
+ } catch (error) {
184
+ if (!isDatabaseError(error))
185
+ throw outcomeUnknown2(error);
186
+ throw await mapFailure(error);
187
+ } finally {
188
+ counters.busy = Math.max(0, counters.busy - 1);
189
+ }
190
+ },
191
+ stats: () => statsOf(counters, max),
192
+ close() {
193
+ closed = true;
194
+ return Promise.resolve();
195
+ }
196
+ };
197
+ }
198
+ function httpOptions() {
199
+ return { arrayMode: true, fullResults: true };
200
+ }
201
+ function isDatabaseError(error) {
202
+ if (typeof error !== "object" || error === null)
203
+ return false;
204
+ const code = Reflect.get(error, "code");
205
+ return typeof code === "string" && /^[0-9A-Z]{5}$/.test(code);
206
+ }
207
+ function take(pool) {
208
+ const connect = pool.connect.bind(pool);
209
+ return connect();
210
+ }
211
+ function ensureWebSocket() {
212
+ if (neonConfig.webSocketConstructor === undefined && typeof WebSocket === "function") {
213
+ neonConfig.webSocketConstructor = WebSocket;
214
+ }
215
+ }
216
+ function statementName(text) {
217
+ const existing = names.get(text);
218
+ if (existing !== undefined)
219
+ return existing;
220
+ const name = `okm_${String(names.size)}`;
221
+ names.set(text, name);
222
+ return name;
223
+ }
224
+ function statsOf(counters, size) {
225
+ return {
226
+ size,
227
+ idle: Math.max(0, size - counters.reserved - counters.busy),
228
+ inflight: counters.busy + counters.reservedBusy,
229
+ waiting: counters.waiting
230
+ };
231
+ }
232
+
233
+ export { open6, connectClient2, send3 };
@@ -1,13 +1,13 @@
1
- import {
2
- renderCatalog
3
- } from "./9s0ypp87.js";
4
1
  import {
5
2
  viewGlobalReason,
6
3
  viewMentions
7
- } from "./x3jc53kg.js";
4
+ } from "./760ppr76.js";
5
+ import {
6
+ renderCatalog
7
+ } from "./sjk86yrx.js";
8
8
  import {
9
9
  createClient
10
- } from "./j60w0dvr.js";
10
+ } from "./bah9nbg3.js";
11
11
  import {
12
12
  OkmError2
13
13
  } from "./52szzakm.js";
@@ -641,7 +641,10 @@ async function readTenant(facts, handle, where) {
641
641
  leak(facts.name, "stream", item);
642
642
  }
643
643
  } catch (error) {
644
- if (!(error instanceof OkmError2) || error.code !== "OKM1111")
644
+ if (!(error instanceof OkmError2))
645
+ throw error;
646
+ const refused = error.code === "OKM1111" || error.code === "OKM1120" && error.message.includes("primary key");
647
+ if (!refused)
645
648
  throw error;
646
649
  }
647
650
  }
@@ -988,7 +991,10 @@ async function readFiltered(name, handle, where) {
988
991
  leak(name, "stream", item);
989
992
  }
990
993
  } catch (error) {
991
- if (!(error instanceof OkmError2) || error.code !== "OKM1111")
994
+ if (!(error instanceof OkmError2))
995
+ throw error;
996
+ const refused = error.code === "OKM1111" || error.code === "OKM1120" && error.message.includes("primary key");
997
+ if (!refused)
992
998
  throw error;
993
999
  }
994
1000
  }
@@ -2,10 +2,10 @@ import {
2
2
  DriverError2,
3
3
  outcomeUnknown2,
4
4
  mapDriverError2
5
- } from "./31vm914h.js";
5
+ } from "./cm3w0ywp.js";
6
6
  import {
7
7
  isConnectionLost
8
- } from "./gwn6v667.js";
8
+ } from "./cnkky55j.js";
9
9
 
10
10
  // src/adapters/pg/batch.ts
11
11
  var savepointIds = 0;
@@ -6,8 +6,9 @@ import {
6
6
  compileCall,
7
7
  decodeResult,
8
8
  logicalIntent,
9
- appliedRules
10
- } from "./2z7wv5tj.js";
9
+ appliedRules,
10
+ rejectKeys
11
+ } from "./kgwp4jdd.js";
11
12
  import {
12
13
  OkmError2,
13
14
  safe2,
@@ -85,7 +86,7 @@ function openClient(session) {
85
86
  },
86
87
  close,
87
88
  connected: session.connected,
88
- tx: (...args) => import("./5d8t84hg.js").then((mod) => mod.tx(session, args)),
89
+ tx: (...args) => import("./v1wad97q.js").then((mod) => mod.tx(session, args)),
89
90
  batch: (ops, options) => batchHandle(session, ops, options),
90
91
  ...session.tx?.extras
91
92
  };
@@ -120,7 +121,7 @@ function tableApi(session, table, view, uses) {
120
121
  const api = {
121
122
  find(options = {}) {
122
123
  if ("lock" in options) {
123
- return lazyRead(session, () => import("./r11n8grd.js"), table, options, base, view);
124
+ return lazyRead(session, () => import("./k86n8vq3.js"), table, options, base, view);
124
125
  }
125
126
  return start(session, "find", table, options, base, view);
126
127
  },
@@ -134,10 +135,10 @@ function tableApi(session, table, view, uses) {
134
135
  return start(session, "exists", table, options, base, view);
135
136
  },
136
137
  page(options) {
137
- return lazyRead(session, () => import("./pjr6xrm5.js"), table, options, base, view);
138
+ return lazyRead(session, () => import("./6m78c8ss.js"), table, options, base, view);
138
139
  },
139
140
  aggregate(options = {}) {
140
- return lazyRead(session, () => import("./venqrjna.js"), table, options, base, view);
141
+ return lazyRead(session, () => import("./n05z9nwz.js"), table, options, base, view);
141
142
  },
142
143
  insert(data, options = {}) {
143
144
  return writeHandle(session, "insert", table, data, options, mods);
@@ -149,6 +150,10 @@ function tableApi(session, table, view, uses) {
149
150
  return writeHandle(session, "delete", table, target, options, mods);
150
151
  }
151
152
  };
153
+ for (const walk of ["descendants", "ancestors"]) {
154
+ api[walk] = (id, options) => lazyRead(session, () => import("./wz2a78mp.js"), table, { id, walk, options }, base, view);
155
+ }
156
+ api.sync = (id, relation, ids, options) => lazyRead(session, () => import("./p5nh3r8q.js"), table, { id, relation, ids, options }, base, view, true);
152
157
  const hooks = session.schema.hooks;
153
158
  if (hooks !== undefined) {
154
159
  for (const hook of hooks) {
@@ -164,16 +169,17 @@ function tableApi(session, table, view, uses) {
164
169
  for (const name in session.schema.model[table]?.presets) {
165
170
  api[name] = (...args) => tableApi(session, table, view, [uses, name, args]);
166
171
  }
172
+ api[Symbol.for("okm.lane")] = [session, table, mapError];
167
173
  return api;
168
174
  }
169
175
  function batchHandle(session, ops, options, replica) {
170
- return queryHandle(() => import("./sbdme3vy.js").then((mod) => mod.batch(session, ops, options, replica)), {
176
+ return queryHandle(() => import("./e8zyaqvj.js").then((mod) => mod.batch(session, ops, options, replica)), {
171
177
  replica: () => batchHandle(session, ops, options, true)
172
178
  });
173
179
  }
174
180
  var writers;
175
181
  function loadWrite() {
176
- writers ??= import("./2cg3wnxc.js");
182
+ writers ??= import("./qd9hhd8f.js");
177
183
  return writers;
178
184
  }
179
185
  function queryHandle(run, extra) {
@@ -258,41 +264,53 @@ function start(session, op, table, options, mods, view) {
258
264
  throw new OkmError2("not_found", `one() on ${table} matched no row.`, withHttp(session.http, { kind: "not_found", table }));
259
265
  }
260
266
  return value;
261
- }, (prepare) => ({
267
+ }, () => ({
262
268
  all(reason) {
263
269
  return start(session, op, table, options, { ...mods, all: reason }, view);
264
270
  },
265
271
  required() {
266
272
  return start(session, op, table, options, { ...mods, required: true }, view);
267
273
  },
268
- stream() {
269
- return streamLazy(session, call, prepare);
274
+ stream(batch) {
275
+ return streamLazy(session, call, mods, view, batch);
270
276
  }
271
277
  }));
272
278
  }
273
- function lazyRead(session, load, table, options, mods, view) {
279
+ function lazyRead(session, load, table, options, mods, view, sync) {
274
280
  const read = () => load().then((mod) => ({ it: mod.build(session, table, options, mods, view) }));
275
- return queryHandle(() => read().then((box) => box.it), {
276
- inspect: () => read().then((box) => box.it.inspect()),
277
- sql: () => read().then((box) => box.it.sql()),
278
- all: (reason) => lazyRead(session, load, table, options, { ...mods, all: reason }, view)
279
- });
281
+ const sql = () => read().then((box) => box.it.sql());
282
+ const extra = { sql };
283
+ if (sync) {
284
+ extra.expect = (count) => lazyRead(session, load, table, options, { ...mods, expect: count }, view, true);
285
+ } else {
286
+ extra.inspect = () => read().then((box) => box.it.inspect());
287
+ extra.all = (reason) => lazyRead(session, load, table, options, { ...mods, all: reason }, view);
288
+ }
289
+ return queryHandle(() => read().then((box) => box.it), extra);
280
290
  }
281
291
  async function decodeRows(plan, rows, table) {
282
- return plan.outputs.includes.length === 0 ? decodeResult(plan, rows, table) : (await import("./ys0xzyaj.js")).decodeIncluded(plan, rows, table);
292
+ return plan.outputs.includes.length === 0 ? decodeResult(plan, rows, table) : (await import("./hqpxf4a4.js")).decodeIncluded(plan, rows, table);
283
293
  }
284
294
  function readHandle(session, table, call, mods, decode, extra) {
285
295
  let prepared;
286
296
  const origin = call;
297
+ const searched = "search" in call;
287
298
  const prepare = async () => {
288
299
  if (prepared !== undefined)
289
300
  return prepared;
290
301
  if (mods.uses !== undefined) {
291
- call = (await import("./r6nwkxnt.js")).refine(session.schema, origin, mods.uses);
302
+ call = (await import("./m7n9h2a5.js")).refine(session.schema, origin, mods.uses);
303
+ }
304
+ if (searched) {
305
+ call = (await import("./zq1he88x.js")).applyTextSearch(session.schema, call);
292
306
  }
293
- if (readNeedsOperatorSql(session.schema, call))
294
- await loadOperatorSql();
295
307
  const hooks = await hooksFor(call);
308
+ if (readNeedsOperatorSql(session.schema, call) || hooks?.needsOperator(session.schema, call)) {
309
+ await loadOperatorSql();
310
+ }
311
+ if (call.build === undefined && selectHasWindow(call.select)) {
312
+ call = (await import("./1d9q9cv2.js")).attach(session.schema, call);
313
+ }
296
314
  const bound = bindCall(session.schema, call, hooks);
297
315
  let plan = session.cache.get(bound.key);
298
316
  if (plan === undefined) {
@@ -307,7 +325,7 @@ function readHandle(session, table, call, mods, decode, extra) {
307
325
  prepared = { plan, params: bound.params };
308
326
  return prepared;
309
327
  };
310
- const sync = () => call.include === undefined && mods.uses === undefined && !readNeedsOperatorSql(session.schema, call);
328
+ const sync = () => !searched && call.include === undefined && mods.uses === undefined && !selectHasWindow(call.select) && !readNeedsOperatorSql(session.schema, call);
311
329
  const run = async () => {
312
330
  await session.connected;
313
331
  const { plan, params } = await prepare();
@@ -352,10 +370,10 @@ function readHandle(session, table, call, mods, decode, extra) {
352
370
  ...extra?.(prepare)
353
371
  });
354
372
  }
355
- function streamLazy(session, call, prepare) {
373
+ function streamLazy(session, call, mods, view, batch) {
356
374
  return async function* () {
357
- const { streamRows } = await import("./3qnhc7w5.js");
358
- yield* streamRows(session, call, prepare, (error) => logged(session, error));
375
+ const { streamRows } = await import("./jebgrkeq.js");
376
+ yield* streamRows(session, call, mods, view, batch, (error) => logged(session, error));
359
377
  }();
360
378
  }
361
379
  function archiveRecord(model, view) {
@@ -368,12 +386,7 @@ function archiveRecord(model, view) {
368
386
  }
369
387
  function readCall(op, table, options, all, scope, model, schema, view) {
370
388
  const record = options;
371
- const accepted = readOptionNames(op);
372
- for (const key of Object.keys(record)) {
373
- if (!accepted.includes(key)) {
374
- throwNamed2("OKM1120", key, accepted, `Option ${key} is not accepted by ${op}. Accepted options: ${accepted.join(", ")}.`);
375
- }
376
- }
389
+ rejectKeys(record, readOptionNames(op), op, true);
377
390
  return {
378
391
  op,
379
392
  table,
@@ -382,6 +395,7 @@ function readCall(op, table, options, all, scope, model, schema, view) {
382
395
  ...record.orderBy !== undefined ? { orderBy: record.orderBy } : {},
383
396
  ...record.limit !== undefined ? { limit: record.limit } : {},
384
397
  ...record.include !== undefined ? { include: record.include } : {},
398
+ ..."search" in record ? { search: record.search } : {},
385
399
  ...callOptions(record),
386
400
  ...all !== undefined ? { all } : {},
387
401
  ...scope !== undefined ? { scope } : {},
@@ -391,13 +405,13 @@ function readCall(op, table, options, all, scope, model, schema, view) {
391
405
  };
392
406
  }
393
407
  async function checkServer(pool, schema, http, requireMeta, options, source) {
394
- const server = await import("./y2t3jktd.js");
408
+ const server = await import("./fjpnhqan.js");
395
409
  let rows;
396
410
  try {
397
411
  const result = await pool.execute(server.versionQuery, undefined, options);
398
412
  rows = result.rows;
399
413
  } catch (error) {
400
- const { mapPostgresError } = await import("./d5azex6s.js");
414
+ const { mapPostgresError } = await import("./63qtkrca.js");
401
415
  throw mapPostgresError(error, mapOptions(http, false, schema));
402
416
  }
403
417
  await server.acceptServer(pool, schema, rows, http, requireMeta, options, source);
@@ -406,7 +420,7 @@ async function mapError(session, error) {
406
420
  if (error instanceof OkmError2) {
407
421
  return session.http === undefined ? error : new OkmError2(error.code, error.message, { ...errorFields(error), http: session.http });
408
422
  }
409
- const { mapPostgresError } = await import("./d5azex6s.js");
423
+ const { mapPostgresError } = await import("./63qtkrca.js");
410
424
  return mapPostgresError(error, mapOptions(session.http, session.includeValues, session.schema));
411
425
  }
412
426
  function errorFields(error) {
@@ -420,15 +434,18 @@ function errorFields(error) {
420
434
  var includeHooks;
421
435
  var operatorSql;
422
436
  function loadOperatorSql() {
423
- operatorSql ??= import("./n076ydsc.js").then(() => {
437
+ operatorSql ??= import("./4vbf83xx.js").then(() => {
424
438
  return;
425
439
  });
426
440
  return operatorSql;
427
441
  }
442
+ function selectHasWindow(select) {
443
+ return Array.isArray(select) && select.some((item) => typeof item !== "string");
444
+ }
428
445
  function hooksFor(call) {
429
446
  if (call.include === undefined)
430
447
  return Promise.resolve(undefined);
431
- includeHooks ??= import("./ys0xzyaj.js").then((mod) => mod.includeHooks);
448
+ includeHooks ??= import("./hqpxf4a4.js").then((mod) => mod.includeHooks);
432
449
  return includeHooks;
433
450
  }
434
451
  function bindNow(schema, call) {
@@ -461,12 +478,15 @@ function attachHttp(http, error) {
461
478
  function callOptions(input, statement) {
462
479
  const timeout = input.timeout ?? statement;
463
480
  const route = input.route;
464
- if (input.signal === undefined && timeout === undefined && route === undefined)
481
+ const pin = input.pin;
482
+ if (input.signal === undefined && timeout === undefined && route === undefined && pin === undefined) {
465
483
  return;
484
+ }
466
485
  return {
467
486
  ...input.signal !== undefined ? { signal: input.signal } : {},
468
487
  ...timeout !== undefined ? { timeout } : {},
469
- ...route !== undefined ? { route } : {}
488
+ ...route !== undefined ? { route } : {},
489
+ ...pin !== undefined ? { pin } : {}
470
490
  };
471
491
  }
472
492
  function mapOptions(http, includeValues, schema) {
@@ -0,0 +1,10 @@
1
+ import {
2
+ resetSession2,
3
+ resetQueried2,
4
+ refuseWhenLost2
5
+ } from "./7ghwamrf.js";
6
+ export {
7
+ refuseWhenLost2 as refuseWhenLost,
8
+ resetQueried2 as resetQueried,
9
+ resetSession2 as resetSession
10
+ };