okmodel 0.7.0 → 0.9.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (258) hide show
  1. package/README.md +14 -0
  2. package/dist/adapters/capabilities.d.ts +32 -0
  3. package/dist/adapters/failure.d.ts +1 -1
  4. package/dist/adapters/pg/bun-sql.d.ts +53 -0
  5. package/dist/adapters/pg/bunsql-extra.d.ts +1 -1
  6. package/dist/adapters/pg/bunsql.d.ts +1 -1
  7. package/dist/adapters/pg/neon-extra.d.ts +18 -0
  8. package/dist/adapters/pg/neon.d.ts +104 -0
  9. package/dist/adapters/pg/no-inflight-timeout.d.ts +1 -1
  10. package/dist/contracts/error.d.ts +1 -1
  11. package/dist/dialects/pg/ext/btree-gin.d.ts +26 -0
  12. package/dist/dialects/pg/ext/btree-gin.js +20 -0
  13. package/dist/dialects/pg/ext/btree-gist.d.ts +26 -0
  14. package/dist/dialects/pg/ext/btree-gist.js +20 -0
  15. package/dist/dialects/pg/ext/call.d.ts +53 -0
  16. package/dist/dialects/pg/ext/citext.js +1 -1
  17. package/dist/dialects/pg/ext/feature.d.ts +26 -0
  18. package/dist/dialects/pg/ext/fuzzystrmatch.d.ts +34 -0
  19. package/dist/dialects/pg/ext/fuzzystrmatch.js +33 -0
  20. package/dist/dialects/pg/ext/hstore.d.ts +41 -0
  21. package/dist/dialects/pg/ext/hstore.js +29 -0
  22. package/dist/dialects/pg/ext/index.d.ts +56 -0
  23. package/dist/dialects/pg/ext/index.js +1 -1
  24. package/dist/dialects/pg/ext/ltree.d.ts +41 -0
  25. package/dist/dialects/pg/ext/ltree.js +29 -0
  26. package/dist/dialects/pg/ext/pg-trgm.js +4 -13
  27. package/dist/dialects/pg/ext/pgcrypto.d.ts +33 -0
  28. package/dist/dialects/pg/ext/pgcrypto.js +33 -0
  29. package/dist/dialects/pg/ext/unaccent.d.ts +26 -0
  30. package/dist/dialects/pg/ext/unaccent.js +21 -0
  31. package/dist/dialects/pg/ext/using.d.ts +23 -0
  32. package/dist/dialects/pg/ext/versions.d.ts +36 -0
  33. package/dist/dialects/pg/external.d.ts +19 -0
  34. package/dist/dialects/pg/fn/index.d.ts +39 -1
  35. package/dist/dialects/pg/fn/index.js +118 -26
  36. package/dist/dialects/pg/index.d.ts +3 -0
  37. package/dist/dialects/pg/index.js +394 -14
  38. package/dist/dialects/pg/introspect.d.ts +11 -0
  39. package/dist/dialects/pg/operators.d.ts +1 -1
  40. package/dist/dialects/pg/ops/fragment.d.ts +119 -0
  41. package/dist/dialects/pg/ops/lane.d.ts +49 -0
  42. package/dist/dialects/pg/view/client.d.ts +14 -6
  43. package/dist/dialects/pg/view/index.d.ts +73 -1
  44. package/dist/dialects/pg/view/index.js +156 -5
  45. package/dist/dialects/pg/view/scratch.d.ts +11 -5
  46. package/dist/runtime/artifact-file.d.ts +22 -0
  47. package/dist/runtime/client.d.ts +10 -0
  48. package/dist/runtime/drift-detail.d.ts +2 -1
  49. package/dist/runtime/drift.d.ts +3 -10
  50. package/dist/runtime/otel.d.ts +105 -0
  51. package/dist/runtime/otel.js +97 -0
  52. package/dist/runtime/pg/bun.js +4 -4
  53. package/dist/runtime/pg/neon.d.ts +38 -0
  54. package/dist/runtime/pg/neon.js +64 -0
  55. package/dist/runtime/pg/pg.js +4 -4
  56. package/dist/runtime/pg/pglite.js +4 -4
  57. package/dist/runtime/pg/postgresjs.js +4 -4
  58. package/dist/runtime/plan.d.ts +1 -1
  59. package/dist/runtime/server-check.d.ts +36 -6
  60. package/dist/runtime/sql-fragment.d.ts +43 -0
  61. package/dist/runtime/tenancy/index.js +10 -10
  62. package/dist/runtime/topology.d.ts +1 -1
  63. package/dist/runtime/traits/index.js +16 -17
  64. package/dist/runtime/types.d.ts +15 -1
  65. package/dist/runtime/validate/index.js +4 -4
  66. package/dist/shared/{81ebdx9p.js → 0j6qe91y.js} +4 -4
  67. package/dist/shared/{qq3899ht.js → 12z7aznj.js} +243 -14
  68. package/dist/shared/{gzaveazc.js → 1d9q9cv2.js} +29 -2
  69. package/dist/shared/{w79hsckn.js → 1mxm04fy.js} +5 -5
  70. package/dist/shared/{7k9grvf6.js → 2szgv6yj.js} +5 -5
  71. package/dist/shared/{gs74dbj5.js → 2zdxkt7b.js} +933 -111
  72. package/dist/shared/{m6p12kbr.js → 3456242y.js} +23 -23
  73. package/dist/shared/3bb7wsqt.js +99 -0
  74. package/dist/shared/{y6njgyda.js → 3t6kw83m.js} +2 -2
  75. package/dist/shared/{xhfsfkgk.js → 4vbf83xx.js} +9 -2
  76. package/dist/shared/{pt94kz7f.js → 5kyb3tqx.js} +1 -1
  77. package/dist/shared/61bmrmhr.js +35 -0
  78. package/dist/shared/{x933k9a3.js → 62b603gr.js} +10 -10
  79. package/dist/shared/{jgqj11w4.js → 6f0z3hzh.js} +4 -0
  80. package/dist/shared/{tsvww22q.js → 6nae0spm.js} +156 -95
  81. package/dist/shared/{mtaszv5a.js → 71n0jmhc.js} +102 -4
  82. package/dist/shared/{5e3tf63j.js → 760ppr76.js} +14 -6
  83. package/dist/shared/7ba5h6pb.js +17 -0
  84. package/dist/shared/{sfz1ksn6.js → 8jesqsrk.js} +2 -2
  85. package/dist/shared/{5v3xf80k.js → 8n688yjg.js} +1 -1
  86. package/dist/shared/{rs73fca9.js → 8qzkd9f3.js} +6 -6
  87. package/dist/shared/{ax7qv55k.js → 90sg0w5a.js} +202 -25
  88. package/dist/shared/{zm0ptry0.js → 99qp9vtg.js} +1 -1
  89. package/dist/shared/{xnxsed62.js → 9dr2qnx7.js} +14 -14
  90. package/dist/shared/{1w508jbr.js → 9dtgn1z2.js} +21 -17
  91. package/dist/shared/{h15jx9bc.js → 9dvh1dr6.js} +1 -1
  92. package/dist/shared/{q5c6ngn3.js → a62rb2da.js} +1 -1
  93. package/dist/shared/{te5as7z7.js → aksb89mn.js} +3 -3
  94. package/dist/shared/{bz84tkzm.js → bphrgwz9.js} +2 -2
  95. package/dist/shared/bsek72fg.js +225 -0
  96. package/dist/shared/{7mnme5tn.js → c3mvnq7a.js} +1 -1
  97. package/dist/shared/{p6qc5gcp.js → ccsmhv9r.js} +25 -7
  98. package/dist/shared/{pbp1ss85.js → cexb7z6b.js} +2 -2
  99. package/dist/shared/{ab9gmbwy.js → cf8zdz5p.js} +5 -5
  100. package/dist/shared/{jvd0mqag.js → ckz05z15.js} +5 -5
  101. package/dist/shared/{dk8v79p3.js → d5nmj7vv.js} +1 -1
  102. package/dist/shared/{14vx95q4.js → dd5pmnky.js} +7 -7
  103. package/dist/shared/{vb6qfyve.js → ds229x4r.js} +2 -2
  104. package/dist/shared/{1qa0qajz.js → e275q7sd.js} +1 -1
  105. package/dist/shared/{zp9fmend.js → ebhz8vh6.js} +4 -4
  106. package/dist/shared/{hyh73qk6.js → ecn8mfdq.js} +5 -5
  107. package/dist/shared/{je4axnm8.js → fdsz3w80.js} +2 -2
  108. package/dist/shared/{9s0ypp87.js → fk9vef30.js} +85 -74
  109. package/dist/shared/{g6evj1j3.js → g89fmz5s.js} +1 -1
  110. package/dist/shared/{aytqh5y2.js → ghqzdp94.js} +2 -2
  111. package/dist/shared/h9811jjm.js +17 -0
  112. package/dist/shared/{dkxgzaqd.js → hqpxf4a4.js} +1 -1
  113. package/dist/shared/{8skf0cam.js → jpybhf98.js} +1 -1
  114. package/dist/shared/{67txcrcw.js → kgwp4jdd.js} +4 -4
  115. package/dist/shared/kzgrnckd.js +29 -0
  116. package/dist/shared/mazpbcdj.js +233 -0
  117. package/dist/shared/{kb2sdhfb.js → mfvx6kjx.js} +17 -1
  118. package/dist/shared/{svncdeh5.js → mgaq2sd3.js} +11 -8
  119. package/dist/shared/{5mtf6cj3.js → mvmm3xpb.js} +5 -2
  120. package/dist/shared/{b5pftnn2.js → myk8fswx.js} +66 -21
  121. package/dist/shared/{2shdbn8q.js → n306gqkd.js} +9 -9
  122. package/dist/shared/{n816peh1.js → n454kcnw.js} +1 -1
  123. package/dist/shared/n5whk3mt.js +665 -0
  124. package/dist/shared/n7kg8mmx.js +61 -0
  125. package/dist/shared/{vqrjpcqn.js → nmnsgj7x.js} +1 -1
  126. package/dist/shared/{tbrvgw6z.js → npdftanb.js} +19 -26
  127. package/dist/shared/{ek2wt2dz.js → pg4ezgyf.js} +11 -30
  128. package/dist/shared/{5fe3kbsh.js → pgsak1yw.js} +1 -1
  129. package/dist/shared/{bm22fvzr.js → qfw14tna.js} +2 -2
  130. package/dist/shared/{wa07eas9.js → qvwwp1mp.js} +62 -41
  131. package/dist/shared/rbxt795q.js +1766 -0
  132. package/dist/shared/{xjk7hnn5.js → s7he5e5d.js} +2 -2
  133. package/dist/shared/{w72kgg4q.js → ss2kv2rs.js} +6 -6
  134. package/dist/shared/stfa9xcw.js +450 -0
  135. package/dist/shared/{3v7t1yrv.js → th3be82n.js} +2 -2
  136. package/dist/shared/{79dt02vc.js → tr64w5p0.js} +1 -1
  137. package/dist/shared/{cn957f8d.js → tw1nvvfj.js} +3 -3
  138. package/dist/shared/{ed0b8k4s.js → typ3vy7t.js} +1 -1
  139. package/dist/shared/{9628a9xt.js → vk7rag46.js} +1 -1
  140. package/dist/shared/{ze4hxsmy.js → w9ejzaqf.js} +1 -1
  141. package/dist/shared/{vczs8gd4.js → wvtjg5m3.js} +2 -2
  142. package/dist/shared/{9y3mmmh1.js → xfhe73sb.js} +1 -1
  143. package/dist/shared/xqacq37x.js +61 -0
  144. package/dist/shared/{1est4ezg.js → xtsydxjg.js} +3 -3
  145. package/dist/shared/xv8qj97g.js +96 -0
  146. package/dist/shared/{bg3rym3g.js → xwhdcrm4.js} +2 -2
  147. package/dist/shared/{kr0jzbw2.js → yvabyg9k.js} +7 -7
  148. package/dist/shared/yybhre6n.js +136 -0
  149. package/dist/shared/zdqf8k5d.js +8 -0
  150. package/dist/shared/{jznfax0y.js → zq1he88x.js} +4 -4
  151. package/dist/tooling/cli.js +108 -23
  152. package/dist/tooling/driver-run.js +4654 -0
  153. package/dist/tooling/driver-test.d.ts +36 -0
  154. package/dist/tooling/github/comment.d.ts +50 -0
  155. package/dist/tooling/github/post-comment.d.ts +17 -0
  156. package/dist/tooling/migrate/commands.d.ts +3 -2
  157. package/dist/tooling/migrate/config.d.ts +13 -0
  158. package/dist/tooling/migrate/export.d.ts +165 -0
  159. package/dist/tooling/migrate/ext-surface.d.ts +80 -0
  160. package/dist/tooling/migrate/ext.d.ts +31 -4
  161. package/dist/tooling/migrate/import-drizzle.d.ts +40 -0
  162. package/dist/tooling/migrate/index.d.ts +3 -0
  163. package/dist/tooling/migrate/index.js +55 -10
  164. package/dist/tooling/migrate/lint-rules.d.ts +18 -1
  165. package/dist/tooling/migrate/lint.d.ts +14 -1
  166. package/dist/tooling/migrate/place.d.ts +18 -0
  167. package/dist/tooling/migrate/plan-json.d.ts +65 -0
  168. package/dist/tooling/migrate/project.d.ts +13 -1
  169. package/dist/tooling/migrate/pull-emit.d.ts +98 -0
  170. package/dist/tooling/migrate/pull-routines.d.ts +126 -0
  171. package/dist/tooling/migrate/pull-verify.d.ts +26 -0
  172. package/dist/tooling/migrate/pull.d.ts +62 -0
  173. package/dist/tooling/migrate/reprint.d.ts +32 -0
  174. package/dist/tooling/migrate/sandbox.d.ts +8 -2
  175. package/dist/tooling/migrate/schema-api.d.ts +43 -0
  176. package/dist/tooling/migrate/sql-lex.d.ts +18 -0
  177. package/dist/tooling/shared/04svnxxj.js +344 -0
  178. package/dist/tooling/shared/0j0jtse1.js +13 -0
  179. package/dist/tooling/shared/0r05zhyq.js +618 -0
  180. package/dist/tooling/shared/1800eymw.js +49 -0
  181. package/dist/tooling/shared/35zemrmf.js +12 -0
  182. package/dist/tooling/shared/3rmaz3pq.js +140 -0
  183. package/dist/tooling/shared/3yn79q5m.js +12 -0
  184. package/dist/tooling/shared/54tqkxja.js +51 -0
  185. package/dist/tooling/shared/57btdkgm.js +209 -0
  186. package/dist/tooling/shared/5bmksndh.js +118 -0
  187. package/dist/tooling/shared/5p8km5jb.js +38 -0
  188. package/dist/tooling/shared/5x3pf400.js +185 -0
  189. package/dist/tooling/shared/5zrzffnk.js +6 -0
  190. package/dist/tooling/shared/62fxpc1p.js +332 -0
  191. package/dist/tooling/shared/68tf18v4.js +20 -0
  192. package/dist/tooling/shared/6vk28rjp.js +98 -0
  193. package/dist/tooling/shared/76pv6qff.js +9 -0
  194. package/dist/tooling/shared/7aews1zg.js +311 -0
  195. package/dist/tooling/shared/7b3xp9gc.js +195 -0
  196. package/dist/tooling/shared/7kms6fvj.js +20 -0
  197. package/dist/tooling/shared/7pxncnzs.js +40 -0
  198. package/dist/tooling/shared/829fjxyw.js +198 -0
  199. package/dist/tooling/shared/8m5znpdt.js +66 -0
  200. package/dist/tooling/shared/8yr7ges1.js +211 -0
  201. package/dist/tooling/shared/96ps4g1z.js +32 -0
  202. package/dist/tooling/shared/9qr9rkbh.js +143 -0
  203. package/dist/tooling/shared/9sfbtwsk.js +49 -0
  204. package/dist/tooling/shared/9wsnsvbf.js +10 -0
  205. package/dist/tooling/shared/a2xe04bm.js +18 -0
  206. package/dist/tooling/shared/a4pzghha.js +20 -0
  207. package/dist/tooling/shared/am04v8na.js +233 -0
  208. package/dist/tooling/shared/asgr07mp.js +194 -0
  209. package/dist/tooling/shared/c0xevn1h.js +312 -0
  210. package/dist/tooling/shared/dhatassp.js +134 -0
  211. package/dist/tooling/shared/ezqn88nj.js +1696 -0
  212. package/dist/tooling/shared/f77nnfqy.js +231 -0
  213. package/dist/tooling/shared/fh07z1dt.js +15 -0
  214. package/dist/tooling/shared/gqwevek4.js +81 -0
  215. package/dist/tooling/shared/hfq3n3bd.js +4116 -0
  216. package/dist/tooling/shared/htnaj77v.js +17 -0
  217. package/dist/tooling/shared/j664qjrt.js +64 -0
  218. package/dist/tooling/shared/jpgmjsx3.js +38 -0
  219. package/dist/tooling/shared/jr2nmr81.js +497 -0
  220. package/dist/tooling/shared/jsjjz875.js +139 -0
  221. package/dist/tooling/shared/kbqnrs1x.js +1425 -0
  222. package/dist/tooling/shared/kz715295.js +94 -0
  223. package/dist/tooling/shared/m3xt8b1h.js +22 -0
  224. package/dist/tooling/shared/m4hhb8aa.js +9 -0
  225. package/dist/tooling/shared/mw5npye0.js +16 -0
  226. package/dist/tooling/shared/n4jqhpqz.js +27 -0
  227. package/dist/tooling/shared/nxq95eb6.js +42 -0
  228. package/dist/tooling/shared/qartgazh.js +70 -0
  229. package/dist/tooling/shared/rcywj2w8.js +190 -0
  230. package/dist/tooling/shared/s6qha57m.js +16 -0
  231. package/dist/tooling/shared/shjs0379.js +150 -0
  232. package/dist/tooling/shared/sjwkt1pg.js +16 -0
  233. package/dist/tooling/shared/stebqyyd.js +401 -0
  234. package/dist/tooling/shared/t4xveemq.js +250 -0
  235. package/dist/tooling/shared/t6zjeake.js +261 -0
  236. package/dist/tooling/shared/tcwpjvxe.js +9 -0
  237. package/dist/tooling/shared/tpssp7ac.js +160 -0
  238. package/dist/tooling/shared/v6j1ep6w.js +42 -0
  239. package/dist/tooling/shared/vwr2y833.js +270 -0
  240. package/dist/tooling/shared/w17sj05d.js +7 -0
  241. package/dist/tooling/shared/w5d89rb4.js +131 -0
  242. package/dist/tooling/shared/wbwq1jsa.js +157 -0
  243. package/dist/tooling/shared/wezxf3h8.js +17 -0
  244. package/dist/tooling/shared/yb4kd19s.js +12 -0
  245. package/dist/tooling/shared/ybdew6j7.js +294 -0
  246. package/dist/tooling/shared/yfedr1zb.js +6 -0
  247. package/dist/tooling/shared/yhp829bx.js +177 -0
  248. package/dist/tooling/shared/ytk1tjs0.js +604 -0
  249. package/dist/tooling/shared/zs9aymcp.js +210 -0
  250. package/dist/tooling/shared/zx3v9phv.js +8 -0
  251. package/dist/tooling/testing/index.js +3 -3
  252. package/package.json +50 -9
  253. package/dist/shared/ktz42yez.js +0 -113
  254. package/dist/shared/ttsqgp4p.js +0 -71
  255. package/dist/shared/y34a8714.js +0 -150
  256. package/dist/shared/zy8r7qvz.js +0 -116
  257. package/dist/shared/{ywr8hmey.js → 606g0nbf.js} +3 -3
  258. package/dist/shared/{rpycarcr.js → gcefca6p.js} +4 -4
@@ -0,0 +1,198 @@
1
+ import {
2
+ decodeRows,
3
+ readHandle,
4
+ readCall,
5
+ attachHttp
6
+ } from "./jr2nmr81.js";
7
+ import {
8
+ OkmError,
9
+ throwNamed,
10
+ selectedColumns,
11
+ parseOrder,
12
+ rejectKeys,
13
+ readLimit,
14
+ indexes,
15
+ quote,
16
+ list,
17
+ isRecord,
18
+ registerFailFix,
19
+ fail2
20
+ } from "./hfq3n3bd.js";
21
+
22
+ // src/runtime/page.ts
23
+ registerFailFix("OKM1130", "Request the next page with the same orderBy and the exact next value the previous page returned. The cursor encodes that order.");
24
+ var OPTIONS = [
25
+ "where",
26
+ "select",
27
+ "orderBy",
28
+ "limit",
29
+ "include",
30
+ "after",
31
+ "route",
32
+ "signal",
33
+ "timeout"
34
+ ];
35
+ function build3(session, table, options, mods, view, pin) {
36
+ try {
37
+ return plan(session, table, options, mods, view, pin);
38
+ } catch (error) {
39
+ throw error instanceof OkmError ? attachHttp(session.http, error) : error;
40
+ }
41
+ }
42
+ function plan(session, table, options, mods, view, pin) {
43
+ const record = isRecord(options) ? options : {};
44
+ if (Object.hasOwn(record, "search")) {
45
+ fail2("OKM1120", "page() does not take search in this version. Use find({ search, limit }) for a ranked list.", "Ranked pages are later. find({ search, limit }) returns one ranked list.");
46
+ }
47
+ rejectKeys(record, OPTIONS, "page");
48
+ const indexed = indexes(session.schema).get(table);
49
+ if (indexed === undefined)
50
+ fail2("OKM1120", `Table ${table} is not in the schema.`);
51
+ if (record.limit === undefined)
52
+ fail2("OKM1101", "page() needs a limit.");
53
+ const size = readLimit(record.limit);
54
+ if (size < 1) {
55
+ throw new OkmError("invalid", "page() limit must be at least 1.", { kind: "invalid" });
56
+ }
57
+ const keys = orderKeys(indexed, record.orderBy);
58
+ const signature = `${table}:${keys.map((key) => `${key.column.field}.${key.dir}.${key.nulls}`).join(",")}`;
59
+ const after = record.after === undefined || record.after === null ? undefined : keyset(keys, signature, record.after);
60
+ const wanted = selectedColumns(indexed, record.select);
61
+ const extra = keys.filter((key) => !wanted.includes(key.column)).map((key) => key.column.field);
62
+ const select = extra.length === 0 ? record.select : [...wanted.map((column) => column.field), ...extra];
63
+ const orderBy = {};
64
+ for (const key of keys)
65
+ orderBy[key.column.field] = { dir: key.dir, nulls: key.nulls };
66
+ const call = {
67
+ ...readCall("find", table, {
68
+ where: record.where,
69
+ select,
70
+ orderBy,
71
+ limit: size + 1,
72
+ include: record.include,
73
+ signal: record.signal,
74
+ timeout: record.timeout,
75
+ route: record.route
76
+ }, undefined, session.scope, session.schema.model[table], session.schema, view),
77
+ ...after !== undefined ? { after } : {},
78
+ ...pin !== undefined ? { pin } : {}
79
+ };
80
+ return readHandle(session, table, call, mods, async (compiled, rows) => {
81
+ const items = await decodeRows(compiled, rows, table);
82
+ const more = items.length > size;
83
+ const kept = more ? items.slice(0, size) : items;
84
+ const last = rows[size - 1];
85
+ const next = more && last !== undefined ? makeCursor(compiled, last, keys, signature) : null;
86
+ if (extra.length > 0) {
87
+ for (const item of kept) {
88
+ for (const field of extra)
89
+ delete item[field];
90
+ }
91
+ }
92
+ return { items: kept, next };
93
+ });
94
+ }
95
+ function orderKeys(table, orderBy) {
96
+ if (orderBy !== undefined && !isRecord(orderBy)) {
97
+ fail2("OKM1120", "orderBy must be an object of fields.");
98
+ }
99
+ const keys = [];
100
+ for (const field of Object.keys(orderBy ?? {})) {
101
+ const column = table.columns.get(field);
102
+ if (column === undefined) {
103
+ throwNamed("OKM1120", field, table.names, `Field ${field} is not on ${table.model.name}. Accepted names: ${list(table.names)}.`);
104
+ }
105
+ keys.push({ column, ...parseOrder(field, orderBy?.[field]) });
106
+ }
107
+ if (table.model.primary.length === 0) {
108
+ fail2("OKM1120", `page() needs a primary key on ${table.model.name} to break ties.`);
109
+ }
110
+ for (const field of table.model.primary) {
111
+ const column = table.columns.get(field);
112
+ if (column === undefined || keys.some((key) => key.column === column))
113
+ continue;
114
+ keys.push({ column, dir: "asc", nulls: "last" });
115
+ }
116
+ return keys;
117
+ }
118
+ function keyset(keys, signature, token) {
119
+ const values = readCursor(token, signature, keys.length);
120
+ return (sink, alias) => {
121
+ sink.mark(`k:${signature}:${values.map((value) => value === null ? "n" : "v").join("")}`);
122
+ let wrote = false;
123
+ for (let index = 0;index < keys.length; index += 1) {
124
+ const key = keys[index];
125
+ const value = values[index];
126
+ if (key === undefined || value === undefined)
127
+ continue;
128
+ if (value === null && key.nulls === "last")
129
+ continue;
130
+ sink.text(wrote ? " or (" : "(");
131
+ wrote = true;
132
+ for (let before = 0;before < index; before += 1) {
133
+ const prior = keys[before];
134
+ const held = values[before];
135
+ if (prior === undefined || held === undefined)
136
+ continue;
137
+ const ref = `${alias}.${quote(prior.column.sql)}`;
138
+ if (held === null) {
139
+ sink.text(`${ref} is null and `);
140
+ } else {
141
+ sink.text(`${ref} = `);
142
+ sink.param(held);
143
+ sink.text(" and ");
144
+ }
145
+ }
146
+ const ref = `${alias}.${quote(key.column.sql)}`;
147
+ if (value === null) {
148
+ sink.text(`${ref} is not null`);
149
+ } else {
150
+ sink.text(key.nulls === "last" ? `(${ref} ${compare(key)} ` : `${ref} ${compare(key)} `);
151
+ sink.param(value);
152
+ sink.text(key.nulls === "last" ? ` or ${ref} is null)` : "");
153
+ }
154
+ sink.text(")");
155
+ }
156
+ if (!wrote)
157
+ sink.text("false");
158
+ };
159
+ }
160
+ function compare(key) {
161
+ return key.dir === "asc" ? ">" : "<";
162
+ }
163
+ function makeCursor(plan, row, keys, signature) {
164
+ const values = keys.map((key) => {
165
+ const at = plan.outputs.fields.find((field) => field.key === key.column.field)?.at;
166
+ return at === undefined ? null : row[at] ?? null;
167
+ });
168
+ const bytes = new TextEncoder().encode(JSON.stringify([signature, ...values]));
169
+ let binary = "";
170
+ for (const byte of bytes)
171
+ binary += String.fromCharCode(byte);
172
+ return btoa(binary).replaceAll("+", "-").replaceAll("/", "_").replaceAll("=", "");
173
+ }
174
+ function readCursor(token, signature, count) {
175
+ let parsed;
176
+ if (typeof token === "string") {
177
+ try {
178
+ const binary = atob(token.replaceAll("-", "+").replaceAll("_", "/"));
179
+ const bytes = Uint8Array.from(binary, (char) => char.charCodeAt(0));
180
+ parsed = JSON.parse(new TextDecoder().decode(bytes));
181
+ } catch {
182
+ parsed = undefined;
183
+ }
184
+ }
185
+ if (!Array.isArray(parsed) || typeof parsed[0] !== "string") {
186
+ fail2("OKM1130", "after is not a cursor that page() returned.");
187
+ }
188
+ if (parsed[0] !== signature) {
189
+ fail2("OKM1130", `The cursor was made for another order: ${parsed[0]}. This page orders by ${signature}.`);
190
+ }
191
+ const values = parsed.slice(1);
192
+ if (values.length !== count || !values.every((value) => value === null || typeof value === "string")) {
193
+ fail2("OKM1130", "after is not a cursor that page() returned.");
194
+ }
195
+ return values;
196
+ }
197
+
198
+ export { build3 };
@@ -0,0 +1,66 @@
1
+ import {
2
+ mapFailure
3
+ } from "./5x3pf400.js";
4
+
5
+ // src/adapters/pg/pglite-wire.ts
6
+ var OIDS = [
7
+ 16,
8
+ 17,
9
+ 20,
10
+ 21,
11
+ 23,
12
+ 25,
13
+ 114,
14
+ 700,
15
+ 701,
16
+ 1043,
17
+ 1082,
18
+ 1114,
19
+ 1184,
20
+ 1700,
21
+ 2950,
22
+ 3802,
23
+ 1000,
24
+ 1005,
25
+ 1007,
26
+ 1009,
27
+ 1016,
28
+ 1115,
29
+ 1182,
30
+ 1185,
31
+ 1231,
32
+ 199,
33
+ 3807
34
+ ];
35
+ function identity(value) {
36
+ return value;
37
+ }
38
+ function serialize(value) {
39
+ if (typeof value === "number" || typeof value === "bigint")
40
+ return String(value);
41
+ if (typeof value === "boolean")
42
+ return value ? "t" : "f";
43
+ return value;
44
+ }
45
+ var parsers = {};
46
+ var serializers = {};
47
+ for (const oid of OIDS) {
48
+ parsers[oid] = identity;
49
+ serializers[oid] = serialize;
50
+ }
51
+ function fail(error) {
52
+ return mapFailure(protocol(error));
53
+ }
54
+ function protocol(error) {
55
+ if (typeof error !== "object" || error === null || !("code" in error))
56
+ return error;
57
+ if (error.code !== "08P01")
58
+ return error;
59
+ const message = error instanceof Error ? error.message : "";
60
+ return new Error(message.length > 0 ? message : "protocol error");
61
+ }
62
+ export {
63
+ fail,
64
+ parsers,
65
+ serializers
66
+ };
@@ -0,0 +1,211 @@
1
+ import {
2
+ DriverError2,
3
+ isConnectionFailure
4
+ } from "./hfq3n3bd.js";
5
+ import {
6
+ send2,
7
+ reserve2,
8
+ park2
9
+ } from "./rcywj2w8.js";
10
+ import {
11
+ resetSession2,
12
+ refuseWhenLost2
13
+ } from "./7pxncnzs.js";
14
+ import {
15
+ cursorStream
16
+ } from "./7kms6fvj.js";
17
+ import {
18
+ WireSession
19
+ } from "./jsjjz875.js";
20
+ import {
21
+ noTimeout
22
+ } from "./3yn79q5m.js";
23
+ import {
24
+ rejectClosed,
25
+ runCall
26
+ } from "./5x3pf400.js";
27
+
28
+ // src/adapters/pg/bunsql-extra.ts
29
+ async function recover(sql, error, text, depth, clientRead, closedDuring, again) {
30
+ if (!lostQuery(error))
31
+ throw error;
32
+ await flushClosed(sql);
33
+ const alreadyDead = closedDuring || socketClosed(error);
34
+ if (!clientRead && !alreadyDead || depth !== 0 || !readStatement(text))
35
+ throw error;
36
+ try {
37
+ return await again();
38
+ } catch (next) {
39
+ if (lostQuery(next))
40
+ await flushClosed(sql);
41
+ throw next;
42
+ }
43
+ }
44
+ function drainClosed(sql) {
45
+ return flushClosed(sql).then(() => {
46
+ return;
47
+ });
48
+ }
49
+ function readStatement(text) {
50
+ const head = text.trimStart().toLowerCase().replace(/\s+/g, " ");
51
+ if (head.length === 0 || head.includes("pg_advisory"))
52
+ return false;
53
+ if (/\sfor (?:no key update|key share|update|share)\b/.test(head))
54
+ return false;
55
+ return !/^(?:insert|update|delete|refresh|with|create|alter|drop|truncate|grant|revoke|comment|vacuum|analyze|reindex|copy|begin|start|commit|rollback|savepoint|release|set|reset)\b/.test(head);
56
+ }
57
+ function lostQuery(error) {
58
+ return isConnectionFailure(error) || socketClosed(error);
59
+ }
60
+ function socketClosed(error) {
61
+ if (!(error instanceof Error))
62
+ return false;
63
+ if (error.message === "Connection closed")
64
+ return true;
65
+ return error.cause instanceof Error && error.cause.message === "Connection closed";
66
+ }
67
+ async function listen(sql, parked, closed, channel, onNotify) {
68
+ if (closed)
69
+ return rejectClosed();
70
+ const pending = parked.splice(0);
71
+ for (const reserved of pending) {
72
+ const done = reserved.release();
73
+ if (done instanceof Promise)
74
+ await done;
75
+ }
76
+ const subscription = await sql.listen(channel, onNotify);
77
+ return async () => {
78
+ await subscription.unlisten();
79
+ };
80
+ }
81
+ async function checkout(held) {
82
+ const { counters, isClosed } = held;
83
+ if (isClosed())
84
+ return rejectClosed();
85
+ const reserved = await takeOpen(held) ?? await reserve2(held.sql, held.acquireMs, counters);
86
+ counters.reserved += 1;
87
+ const session = new WireSession((text, params) => send2(reserved, text, params), held.notices, isClosed, false, () => {
88
+ counters.reservedBusy += 1;
89
+ }, () => {
90
+ counters.reservedBusy = Math.max(0, counters.reservedBusy - 1);
91
+ });
92
+ let lost = { on: false };
93
+ const opened = held.closures();
94
+ const reconnected = () => {
95
+ if (held.closures() === opened)
96
+ return;
97
+ lost.on = true;
98
+ return Promise.reject(new DriverError2("Connection closed", { sqlstate: "08006" }));
99
+ };
100
+ const guard = (run) => refuseWhenLost2(lost, () => run().catch((error) => {
101
+ if (error instanceof Error && bunClosed(error.message)) {
102
+ throw new DriverError2(error.message, { cause: error, sqlstate: "08006" });
103
+ }
104
+ throw error;
105
+ }));
106
+ let released = false;
107
+ return {
108
+ execute: (text, params, options) => {
109
+ const refused = noTimeout(options);
110
+ if (refused !== undefined)
111
+ return refused;
112
+ const gone = reconnected();
113
+ if (gone !== undefined)
114
+ return gone;
115
+ return guard(() => runCall(isClosed(), options, (watch) => session.query(text, params, watch)));
116
+ },
117
+ batch: (statements, options) => {
118
+ const refused = noTimeout(options);
119
+ if (refused !== undefined)
120
+ return refused;
121
+ const gone = reconnected();
122
+ if (gone !== undefined)
123
+ return gone;
124
+ return guard(() => runCall(isClosed(), options, async (watch) => {
125
+ const { runAtomicBatch } = await import("./gqwevek4.js");
126
+ return runAtomicBatch(session, statements, watch);
127
+ }));
128
+ },
129
+ evict() {
130
+ lost.on = true;
131
+ },
132
+ async release() {
133
+ if (released)
134
+ return;
135
+ released = true;
136
+ if (!lost.on && reportsClosed(reserved))
137
+ lost.on = true;
138
+ try {
139
+ if (!lost.on)
140
+ await reset(session, reserved);
141
+ } catch (error) {
142
+ if (lostQuery(error) || reportsClosed(reserved))
143
+ lost.on = true;
144
+ else
145
+ throw error;
146
+ } finally {
147
+ counters.reserved = Math.max(0, counters.reserved - 1);
148
+ if (lost.on) {
149
+ try {
150
+ reserved.release();
151
+ } catch {}
152
+ await flushClosed(held.sql);
153
+ } else
154
+ await park2(held.parked, reserved);
155
+ }
156
+ }
157
+ };
158
+ }
159
+ function reportsClosed(reserved) {
160
+ return Reflect.get(reserved, "closed") === true;
161
+ }
162
+ async function takeOpen(held) {
163
+ while (held.parked.length > 0) {
164
+ const next = held.parked.pop();
165
+ if (next === undefined)
166
+ return;
167
+ if (!reportsClosed(next))
168
+ return next;
169
+ try {
170
+ next.release();
171
+ } catch {}
172
+ await flushClosed(held.sql);
173
+ }
174
+ return;
175
+ }
176
+ async function flushClosed(sql) {
177
+ for (let attempt = 0;attempt < 3; attempt += 1) {
178
+ try {
179
+ await sql.unsafe("select 1");
180
+ return true;
181
+ } catch {}
182
+ }
183
+ return false;
184
+ }
185
+ function bunClosed(message) {
186
+ return message === "Connection closed" || message === "connection must be a PostgresSQLConnection";
187
+ }
188
+ async function reset(session, sql) {
189
+ const run = (text) => sql.unsafe(text);
190
+ await resetSession2(session.depth(), run);
191
+ }
192
+ function streamRows(checkout, text, params) {
193
+ return async function* () {
194
+ const connection = await checkout();
195
+ try {
196
+ yield* cursorStream((statement, values) => connection.execute(statement, values), text, params);
197
+ } catch (error) {
198
+ connection.evict?.();
199
+ throw error;
200
+ } finally {
201
+ await connection.release();
202
+ }
203
+ }();
204
+ }
205
+ export {
206
+ checkout,
207
+ drainClosed,
208
+ listen,
209
+ recover,
210
+ streamRows
211
+ };
@@ -0,0 +1,32 @@
1
+ // src/runtime/hookm.ts
2
+ function notices(hookm, notices) {
3
+ if (hookm === undefined)
4
+ return;
5
+ for (const notice of notices) {
6
+ for (const hook of hookm)
7
+ call(() => hook.onNotice?.(notice));
8
+ }
9
+ }
10
+ function phase(hookm, phase, depth) {
11
+ if (hookm === undefined)
12
+ return;
13
+ const event = { phase, depth };
14
+ for (const hook of hookm)
15
+ call(() => hook.onTransaction?.(event));
16
+ }
17
+ function report(session, error) {
18
+ for (const hook of session.hookm ?? [])
19
+ call(() => hook.onError?.(error));
20
+ const entry = error instanceof Error ? { code: "code" in error ? String(error.code) : error.name, summary: error.message } : { code: "error", summary: String(error) };
21
+ call(() => session.logger?.error?.(entry));
22
+ }
23
+ function call(fn) {
24
+ try {
25
+ fn();
26
+ } catch {}
27
+ }
28
+ export {
29
+ notices,
30
+ phase,
31
+ report
32
+ };
@@ -0,0 +1,143 @@
1
+ import {
2
+ DriverError2,
3
+ isConnectionLost
4
+ } from "./hfq3n3bd.js";
5
+ import {
6
+ armDriverError2,
7
+ send3,
8
+ connectClient2
9
+ } from "./asgr07mp.js";
10
+ import {
11
+ resetSession2
12
+ } from "./7pxncnzs.js";
13
+ import {
14
+ cursorStream
15
+ } from "./7kms6fvj.js";
16
+ import {
17
+ WireSession
18
+ } from "./jsjjz875.js";
19
+ import {
20
+ rejectClosed,
21
+ runCall
22
+ } from "./5x3pf400.js";
23
+
24
+ // src/adapters/pg/nodepostgres-extra.ts
25
+ async function checkout(held) {
26
+ const { pool, counters, named, isClosed } = held;
27
+ if (isClosed())
28
+ return rejectClosed();
29
+ const client = await connectClient2(pool, held.acquireMs, counters);
30
+ counters.reserved += 1;
31
+ let lost = false;
32
+ const onError = () => {
33
+ lost = true;
34
+ };
35
+ const events = client;
36
+ events.on("error", onError);
37
+ const local = new Set;
38
+ const session = new WireSession((text, params) => {
39
+ const pending = send3(client, text, params, named, client);
40
+ const guarded = pending.catch((error) => {
41
+ if (isConnectionLost(error) || lost) {
42
+ lost = true;
43
+ if (isConnectionLost(error))
44
+ throw error;
45
+ throw Object.assign(new DriverError2("CONNECTION_CLOSED", { cause: error }), {
46
+ code: "CONNECTION_CLOSED"
47
+ });
48
+ }
49
+ throw error;
50
+ });
51
+ guarded.cancel = () => {
52
+ pending.cancel?.();
53
+ };
54
+ return guarded;
55
+ }, held.notices, isClosed, true, () => {
56
+ counters.reservedBusy += 1;
57
+ }, () => {
58
+ counters.reservedBusy = Math.max(0, counters.reservedBusy - 1);
59
+ }, local);
60
+ const guard = (run) => lost ? rejectClosed() : run();
61
+ let released = false;
62
+ return {
63
+ execute: (text, params, options) => guard(() => runCall(isClosed(), options, (watch) => session.query(text, params, watch))),
64
+ batch: (statements, options) => guard(() => runCall(isClosed(), options, async (watch) => {
65
+ const { runAtomicBatch } = await import("./gqwevek4.js");
66
+ return runAtomicBatch(session, statements, watch);
67
+ })),
68
+ cancel() {
69
+ session.cancel();
70
+ },
71
+ async release() {
72
+ if (released)
73
+ return;
74
+ released = true;
75
+ try {
76
+ if (!lost)
77
+ await reset(session, client);
78
+ } finally {
79
+ counters.reserved = Math.max(0, counters.reserved - 1);
80
+ events.removeListener("error", onError);
81
+ client.release(lost);
82
+ }
83
+ }
84
+ };
85
+ }
86
+ async function reset(session, client) {
87
+ await resetSession2(session.depth(), (text) => client.query(text));
88
+ }
89
+ async function listen(held, channel, onNotify) {
90
+ const { pool, counters } = held;
91
+ const client = await connectClient2(pool, held.acquireMs, counters);
92
+ counters.reserved += 1;
93
+ const quoted = quoteIdent(channel);
94
+ const onNotification = (message) => {
95
+ if (message.channel === channel)
96
+ onNotify(message.payload ?? "");
97
+ };
98
+ client.on("notification", onNotification);
99
+ let released = false;
100
+ const release = (dead) => {
101
+ if (released)
102
+ return;
103
+ released = true;
104
+ client.removeListener("notification", onNotification);
105
+ client.removeListener("error", release);
106
+ counters.reserved = Math.max(0, counters.reserved - 1);
107
+ client.release(Boolean(dead));
108
+ };
109
+ armDriverError2(client, release);
110
+ try {
111
+ await client.query(`LISTEN ${quoted}`);
112
+ } catch (error) {
113
+ release(false);
114
+ throw error;
115
+ }
116
+ return async () => {
117
+ if (released)
118
+ return;
119
+ try {
120
+ await client.query(`UNLISTEN ${quoted}`);
121
+ } finally {
122
+ release(false);
123
+ }
124
+ };
125
+ }
126
+ function streamRows(checkout, text, params) {
127
+ return async function* () {
128
+ const connection = await checkout();
129
+ try {
130
+ yield* cursorStream((statement, values) => connection.execute(statement, values), text, params);
131
+ } finally {
132
+ await connection.release();
133
+ }
134
+ }();
135
+ }
136
+ function quoteIdent(name) {
137
+ return `"${name.replaceAll('"', '""')}"`;
138
+ }
139
+ export {
140
+ checkout,
141
+ listen,
142
+ streamRows
143
+ };
@@ -0,0 +1,49 @@
1
+ import {
2
+ open5
3
+ } from "./am04v8na.js";
4
+ import {
5
+ createClient
6
+ } from "./jr2nmr81.js";
7
+
8
+ // src/runtime/pg/neon.ts
9
+ function connect(target, options) {
10
+ if (typeof target === "object" && !isPool(target)) {
11
+ return import("./kbqnrs1x.js").then((mod) => mod.default(target, options, (config) => open5({
12
+ url: config.url,
13
+ ...options.mode !== undefined ? { mode: options.mode } : {},
14
+ ...config.max !== undefined ? { max: config.max } : {},
15
+ ...config.timeouts !== undefined ? { timeouts: config.timeouts } : {},
16
+ ...config.prepared !== undefined ? { prepared: config.prepared } : {},
17
+ ...config.searchPath !== undefined ? { searchPath: config.searchPath } : {}
18
+ })));
19
+ }
20
+ const owned = !isPool(target);
21
+ const opened = isPool(target) ? Promise.resolve(target) : open5({
22
+ url: target,
23
+ ...options.mode !== undefined ? { mode: options.mode } : {},
24
+ ...options.max !== undefined ? { max: options.max } : {},
25
+ ...options.timeouts !== undefined ? { timeouts: options.timeouts } : {},
26
+ ...options.prepared !== undefined ? { prepared: options.prepared } : {},
27
+ ...options.searchPath !== undefined ? { searchPath: options.searchPath } : {}
28
+ });
29
+ return opened.then((pool) => createClient(options.schema, pool, {
30
+ ownsPool: owned,
31
+ http: options.errors?.http,
32
+ includeValues: options.errors?.includeValues,
33
+ logger: options.logger,
34
+ signal: options.signal,
35
+ timeout: options.timeout,
36
+ timeouts: options.timeouts,
37
+ hookm: options.hookm,
38
+ catalog: options.catalog,
39
+ catalogDir: options.catalogDir,
40
+ requireMeta: options.requireMeta,
41
+ generators: options.generators
42
+ }));
43
+ }
44
+ function isPool(target) {
45
+ return typeof target === "object" && "execute" in target && "capabilities" in target;
46
+ }
47
+ export {
48
+ connect
49
+ };
@@ -0,0 +1,10 @@
1
+ import {
2
+ resetSession2,
3
+ resetQueried2,
4
+ refuseWhenLost2
5
+ } from "./7pxncnzs.js";
6
+ export {
7
+ refuseWhenLost2 as refuseWhenLost,
8
+ resetQueried2 as resetQueried,
9
+ resetSession2 as resetSession
10
+ };