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,37 @@
1
+ import {
2
+ WRITE_PARAM_BUDGET2,
3
+ executeWrite2,
4
+ explainWrite2,
5
+ updateSliceBody2,
6
+ rejectDuplicateTargets2,
7
+ emitSet2,
8
+ Sql2,
9
+ writeSet2,
10
+ rejectMixedSets2,
11
+ readClaim2,
12
+ rejectUpdateKeys2,
13
+ requireFilter2,
14
+ returningOption2,
15
+ expectOf2,
16
+ allowSet2,
17
+ noteGuarded2
18
+ } from "./bxas03mq.js";
19
+ import"./mss6ctgv.js";
20
+ export {
21
+ Sql2 as Sql,
22
+ WRITE_PARAM_BUDGET2 as WRITE_PARAM_BUDGET,
23
+ allowSet2 as allowSet,
24
+ emitSet2 as emitSet,
25
+ executeWrite2 as executeWrite,
26
+ expectOf2 as expectOf,
27
+ explainWrite2 as explainWrite,
28
+ noteGuarded2 as noteGuarded,
29
+ readClaim2 as readClaim,
30
+ rejectDuplicateTargets2 as rejectDuplicateTargets,
31
+ rejectMixedSets2 as rejectMixedSets,
32
+ rejectUpdateKeys2 as rejectUpdateKeys,
33
+ requireFilter2 as requireFilter,
34
+ returningOption2 as returningOption,
35
+ updateSliceBody2 as updateSliceBody,
36
+ writeSet2 as writeSet
37
+ };
@@ -1,9 +1,9 @@
1
1
  import {
2
- effectivePredicate
3
- } from "./b3awxn7h.js";
2
+ stack2
3
+ } from "./mss6ctgv.js";
4
4
  import {
5
- stack
6
- } from "./672t5vym.js";
5
+ effectivePredicate
6
+ } from "./n454kcnw.js";
7
7
  import {
8
8
  runWrite
9
9
  } from "./n4jqhpqz.js";
@@ -16,8 +16,8 @@ import {
16
16
  quote,
17
17
  isRecord,
18
18
  registerFailFix,
19
- fail
20
- } from "./2z7wv5tj.js";
19
+ fail2
20
+ } from "./kgwp4jdd.js";
21
21
  import {
22
22
  safetyInstalled,
23
23
  runSafety
@@ -50,7 +50,7 @@ function explainArchive(schema, op, table, input, options, mods, scope) {
50
50
  function planArchive(schema, op, tableName, input, options, mods, scope) {
51
51
  const table = indexes(schema).get(tableName);
52
52
  if (table === undefined)
53
- fail("OKM1120", `Table ${tableName} is not in the schema.`);
53
+ fail2("OKM1120", `Table ${tableName} is not in the schema.`);
54
54
  const archive = table.model.archive;
55
55
  if (archive === undefined) {
56
56
  throw new OkmError2("OKM1052", `Table ${tableName} is not archivable.`, {
@@ -61,7 +61,7 @@ function planArchive(schema, op, tableName, input, options, mods, scope) {
61
61
  rejectKeys(record, OPTIONS, op);
62
62
  const expect = expectOf(record.expect ?? mods.expect);
63
63
  const read = readTarget(op, table, input, mods);
64
- const target = { ...read, where: stack(read.where, mods.presets) };
64
+ const target = { ...read, where: stack2(read.where, mods.presets) };
65
65
  const view = op === "restore" ? "only" : undefined;
66
66
  noteArchive(table, view);
67
67
  const statement = withRowFilters(scope, view, () => op === "archive" ? archiveSql(schema, table, target.where) : restoreSql(schema, table, target));
@@ -83,25 +83,25 @@ function noteArchive(table, view) {
83
83
  }
84
84
  function readTarget(op, table, input, mods) {
85
85
  if (!isRecord(input))
86
- fail("OKM1121", `${op} expects { where }.`);
86
+ fail2("OKM1121", `${op} expects { where }.`);
87
87
  const keys = Object.keys(input);
88
88
  if (op === "restore" && input.archiveId !== undefined) {
89
89
  if (input.where !== undefined)
90
- fail("OKM1120", "restore takes where or archiveId, not both.");
90
+ fail2("OKM1120", "restore takes where or archiveId, not both.");
91
91
  for (const key of keys) {
92
92
  if (key !== "archiveId") {
93
- fail("OKM1120", "restore accepts where or archiveId.");
93
+ fail2("OKM1120", "restore accepts where or archiveId.");
94
94
  }
95
95
  }
96
96
  if (typeof input.archiveId !== "string" || input.archiveId.length === 0) {
97
- fail("OKM1121", "restore archiveId must be a uuid.");
97
+ fail2("OKM1121", "restore archiveId must be a uuid.");
98
98
  }
99
99
  const idField = table.model.archive?.idField ?? "archiveId";
100
100
  return { where: { [idField]: input.archiveId }, archiveId: input.archiveId };
101
101
  }
102
102
  for (const key of keys) {
103
103
  if (key !== "where")
104
- fail("OKM1120", `${op} accepts where.`);
104
+ fail2("OKM1120", `${op} accepts where.`);
105
105
  }
106
106
  requireFilter(table, input.where, mods, op);
107
107
  return { where: input.where, archiveId: undefined };
@@ -358,12 +358,12 @@ function expectOf(value) {
358
358
  function requireFilter(table, where, mods, op) {
359
359
  if (mods.all !== undefined) {
360
360
  if (mods.all.trim().length === 0) {
361
- fail("OKM1102", `${op} on ${table.model.name} needs a where. .all needs a reason.`);
361
+ fail2("OKM1102", `${op} on ${table.model.name} needs a where. .all needs a reason.`);
362
362
  }
363
363
  return;
364
364
  }
365
365
  if (!effectivePredicate(where)) {
366
- fail("OKM1102", `${op} on ${table.model.name} needs a where. Pass a filter, or .all(reason).`);
366
+ fail2("OKM1102", `${op} on ${table.model.name} needs a where. Pass a filter, or .all(reason).`);
367
367
  }
368
368
  }
369
369
  function callOptions(input) {
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  creationOrder2
3
- } from "./qq3899ht.js";
3
+ } from "./12z7aznj.js";
4
4
  import {
5
5
  isDomain
6
6
  } from "./ywspezzx.js";
@@ -0,0 +1,208 @@
1
+ import {
2
+ refusePrototypeKey
3
+ } from "./a62rb2da.js";
4
+ import {
5
+ isBucket
6
+ } from "./nbw1z4yd.js";
7
+ import {
8
+ parseOrder,
9
+ projectExpr,
10
+ quote,
11
+ list,
12
+ isRecord,
13
+ fail2
14
+ } from "./kgwp4jdd.js";
15
+ import {
16
+ throwNamed2
17
+ } from "./52szzakm.js";
18
+
19
+ // src/runtime/bucket-group.ts
20
+ function readBucket(table, value, fields, aliases) {
21
+ if (!isBucket(value))
22
+ fail2("OKM1120", "bucket group");
23
+ const column = typeof value.column === "string" ? table.columns.get(value.column) : undefined;
24
+ if (typeof value.column !== "string" || column === undefined) {
25
+ throwNamed2("OKM1120", String(value.column), table.names, `Field ${String(value.column)} is not on ${table.model.name}. Accepted names: ${list(table.names)}.`);
26
+ }
27
+ if (column.hidden) {
28
+ fail2("OKM1120", `Field ${column.field} is hidden, so groupBy cannot read it.`);
29
+ }
30
+ const unit = unitOf(value.unit);
31
+ if (unit === undefined) {
32
+ fail2("OKM1120", `bucket() unit ${String(value.unit)} is not a time unit. Accepted units: second, minute, hour, day, week, month, quarter, year.`);
33
+ }
34
+ const shift = weekShift(value.weekStart, unit);
35
+ const kind = temporalKind(column.dataType);
36
+ if (kind !== "timestamptz" && kind !== "date") {
37
+ fail2("OKM1120", `bucket() does not apply to ${kind === "timestamp" ? "timestamp" : column.dataType} column ${column.field}. Use timestamptz or date.`);
38
+ }
39
+ if (kind === "date" && clockUnit(unit)) {
40
+ fail2("OKM1120", `bucket() unit ${unit} does not apply to date column ${column.field}. Accepted units: day, week, month, quarter, year.`);
41
+ }
42
+ let tz;
43
+ if (kind === "timestamptz") {
44
+ if (typeof value.tz !== "string") {
45
+ fail2("OKM1120", `bucket() on timestamptz column ${column.field} needs tz, an IANA time zone.`);
46
+ }
47
+ if (!iana(value.tz))
48
+ fail2("OKM1120", `bucket() tz ${value.tz} is not an IANA time zone.`);
49
+ tz = value.tz;
50
+ } else if (value.tz !== undefined) {
51
+ fail2("OKM1120", `bucket() on date column ${column.field} does not take tz.`);
52
+ }
53
+ if (typeof value.as !== "string" || value.as.length === 0) {
54
+ fail2("OKM1120", "bucket() needs as, the name of the result key.");
55
+ }
56
+ refusePrototypeKey(value.as, "bucket as");
57
+ if (value.as === "count" || value.as === "sum" || value.as === "avg" || value.as === "min" || value.as === "max") {
58
+ fail2("OKM1120", `bucket as ${value.as} clashes with an aggregate key.`);
59
+ }
60
+ if (fields.has(value.as) || aliases.has(value.as)) {
61
+ fail2("OKM1120", `bucket as ${value.as} clashes with another group.`);
62
+ }
63
+ aliases.add(value.as);
64
+ return { kind: "bucket", column, unit, tz, as: value.as, shift, clock: clockUnit(unit) };
65
+ }
66
+ function writeBucket(sink, outputs, wrote, group) {
67
+ if (wrote.at > 0)
68
+ sink.text(", ");
69
+ if (group.clock)
70
+ emitClock(sink, group);
71
+ else
72
+ emitCalendar(sink, group);
73
+ outputs?.fields.push({
74
+ key: `g:${group.as}`,
75
+ at: wrote.at,
76
+ decode: bucketDecode(group)
77
+ });
78
+ wrote.at += 1;
79
+ }
80
+ function writeGrouped(sink, names, orderBy) {
81
+ sink.text(ordinals(names.length));
82
+ if (isRecord(orderBy) && Object.keys(orderBy).length > 0) {
83
+ sink.text(" order by ");
84
+ const keys = Object.keys(orderBy);
85
+ for (let index = 0;index < keys.length; index += 1) {
86
+ const key = keys[index];
87
+ if (key === undefined)
88
+ continue;
89
+ const parsed = parseOrder(key, orderBy[key]);
90
+ if (index > 0)
91
+ sink.text(", ");
92
+ sink.text(String(names.indexOf(key) + 1));
93
+ sink.text(parsed.dir === "asc" ? " asc" : " desc");
94
+ sink.text(parsed.nulls === "first" ? " nulls first" : " nulls last");
95
+ sink.mark(`o:${key}:${parsed.dir}:${parsed.nulls}`);
96
+ }
97
+ return;
98
+ }
99
+ sink.text(" order by ");
100
+ const parts = [];
101
+ for (let index = 1;index <= names.length; index += 1) {
102
+ parts.push(`${String(index)} asc nulls last`);
103
+ }
104
+ sink.text(parts.join(", "));
105
+ }
106
+ function unitOf(value) {
107
+ if (value === "second" || value === "minute" || value === "hour" || value === "day" || value === "week" || value === "month" || value === "quarter" || value === "year") {
108
+ return value;
109
+ }
110
+ return;
111
+ }
112
+ function clockUnit(unit) {
113
+ return unit === "second" || unit === "minute" || unit === "hour";
114
+ }
115
+ function weekShift(value, unit) {
116
+ if (value === undefined)
117
+ return 0;
118
+ if (unit !== "week")
119
+ fail2("OKM1120", "bucket() weekStart applies to unit week.");
120
+ if (value === "monday")
121
+ return 0;
122
+ if (value === "sunday")
123
+ return 1;
124
+ if (value === "saturday")
125
+ return 2;
126
+ return fail2("OKM1120", "bucket() weekStart must be monday, sunday, or saturday.");
127
+ }
128
+ function temporalKind(dataType) {
129
+ if (dataType === "date")
130
+ return "date";
131
+ if (dataType === "timestamptz" || dataType.startsWith("timestamptz("))
132
+ return "timestamptz";
133
+ if (dataType === "timestamp" || dataType.startsWith("timestamp("))
134
+ return "timestamp";
135
+ return;
136
+ }
137
+ function iana(tz) {
138
+ try {
139
+ Intl.DateTimeFormat("en-US", { timeZone: tz });
140
+ return true;
141
+ } catch {
142
+ return false;
143
+ }
144
+ }
145
+ function bucketDecode(group) {
146
+ if (group.clock || !group.column.dataType.startsWith("timestamptz"))
147
+ return group.column.decode;
148
+ return decodeDay;
149
+ }
150
+ function decodeDay(wire) {
151
+ const temporal = globalThis.Temporal;
152
+ if (typeof temporal !== "object" || temporal === null || !("PlainDate" in temporal)) {
153
+ return fail2("OKM1120", "Date and time codecs need the Temporal global. okmodel does not ship a polyfill. Use a runtime that provides Temporal, or assign a polyfill to globalThis.Temporal before using these columns.");
154
+ }
155
+ try {
156
+ return temporal.PlainDate.from(wire);
157
+ } catch {
158
+ return fail2("OKM1120", `date ${wire} must be YYYY-MM-DD.`);
159
+ }
160
+ }
161
+ var ZONE = "\x00";
162
+ function emitClock(sink, group) {
163
+ const column = `t.${quote(group.column.sql)}`;
164
+ const wrapped = projectExpr(`date_trunc('${group.unit}', ${column}, ${ZONE})`, "timestamptz");
165
+ const at = wrapped.indexOf(ZONE);
166
+ sink.text(wrapped.slice(0, at));
167
+ sink.param(group.tz ?? "");
168
+ sink.text(wrapped.slice(at + ZONE.length));
169
+ }
170
+ function emitCalendar(sink, group) {
171
+ const column = `t.${quote(group.column.sql)}`;
172
+ sink.text("(date_trunc('");
173
+ sink.text(group.unit);
174
+ sink.text("', ");
175
+ emitLocal(sink, column, group.tz);
176
+ if (group.shift === 0) {
177
+ sink.text("))::date");
178
+ return;
179
+ }
180
+ const days = group.shift === 1 ? "1 day" : "2 days";
181
+ sink.text(" + interval '");
182
+ sink.text(days);
183
+ sink.text("') - interval '");
184
+ sink.text(days);
185
+ sink.text("')::date");
186
+ }
187
+ function emitLocal(sink, column, tz) {
188
+ if (tz === undefined) {
189
+ sink.text(column);
190
+ return;
191
+ }
192
+ sink.text("(");
193
+ sink.text(column);
194
+ sink.text(" AT TIME ZONE ");
195
+ sink.param(tz);
196
+ sink.text(")");
197
+ }
198
+ function ordinals(count) {
199
+ const parts = [];
200
+ for (let index = 1;index <= count; index += 1)
201
+ parts.push(String(index));
202
+ return parts.join(", ");
203
+ }
204
+ export {
205
+ readBucket,
206
+ writeBucket,
207
+ writeGrouped
208
+ };
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  required
3
- } from "./ywr8hmey.js";
3
+ } from "./606g0nbf.js";
4
4
  import {
5
5
  definition,
6
6
  rejected
@@ -1,19 +1,19 @@
1
1
  import {
2
2
  refuseUncancellableTimeout
3
- } from "./b4v57v3x.js";
3
+ } from "./2d3xq4ps.js";
4
4
  import {
5
5
  isConnectionLost
6
- } from "./gwn6v667.js";
6
+ } from "./cnkky55j.js";
7
7
  import {
8
8
  openClient,
9
9
  withHttp,
10
10
  settleCall
11
- } from "./j60w0dvr.js";
11
+ } from "./bah9nbg3.js";
12
12
  import {
13
13
  rejectKeys,
14
14
  isRecord,
15
- fail
16
- } from "./2z7wv5tj.js";
15
+ fail2
16
+ } from "./kgwp4jdd.js";
17
17
  import {
18
18
  OkmError2
19
19
  } from "./52szzakm.js";
@@ -96,15 +96,15 @@ class Frame {
96
96
  }
97
97
  async function tx(session, args) {
98
98
  if (typeof args[0] === "function" && args.length > 1) {
99
- fail("OKM1120", "options go first: tx(options, fn).");
99
+ fail2("OKM1120", "options go first: tx(options, fn).");
100
100
  }
101
101
  const fn = typeof args[0] === "function" ? args[0] : args[1];
102
102
  const given = typeof args[0] === "function" ? {} : args[0] ?? {};
103
103
  try {
104
104
  if (typeof fn !== "function")
105
- fail("OKM1121", "tx expects a callback: tx(fn) or tx(options, fn).");
105
+ fail2("OKM1121", "tx expects a callback: tx(fn) or tx(options, fn).");
106
106
  if (!isRecord(given))
107
- fail("OKM1121", "tx options must be an object.");
107
+ fail2("OKM1121", "tx options must be an object.");
108
108
  rejectKeys(given, ["isolation", "retry", "signal", "timeout"], "tx");
109
109
  const options = given;
110
110
  check(options);
@@ -123,14 +123,14 @@ function failWith(session, error) {
123
123
  }
124
124
  function check(options) {
125
125
  if (options.isolation !== undefined && !Object.hasOwn(BEGIN, options.isolation)) {
126
- fail("OKM1120", `isolation must be one of: ${Object.keys(BEGIN).join(", ")}.`);
126
+ fail2("OKM1120", `isolation must be one of: ${Object.keys(BEGIN).join(", ")}.`);
127
127
  }
128
128
  const { retry, timeout } = options;
129
129
  if (retry !== undefined && (!Number.isInteger(retry) || retry < 0)) {
130
- fail("OKM1121", "retry must be an integer from 0 up.");
130
+ fail2("OKM1121", "retry must be an integer from 0 up.");
131
131
  }
132
132
  if (timeout !== undefined && (typeof timeout !== "number" || !(timeout > 0))) {
133
- fail("OKM1121", "timeout must be a number of milliseconds above 0.");
133
+ fail2("OKM1121", "timeout must be a number of milliseconds above 0.");
134
134
  }
135
135
  }
136
136
  async function outer(session, fn, options) {
@@ -269,7 +269,7 @@ async function run(session, after, hear) {
269
269
  }
270
270
  async function nested(session, fn, options) {
271
271
  if (Object.keys(options).length > 0) {
272
- fail("OKM1121", "isolation, retry, timeout, and signal belong to the outermost tx(). A nested tx() is a savepoint on the same transaction.");
272
+ fail2("OKM1121", "isolation, retry, timeout, and signal belong to the outermost tx(). A nested tx() is a savepoint on the same transaction.");
273
273
  }
274
274
  const { state: frame, depth } = session.tx;
275
275
  frame.check();
@@ -347,7 +347,7 @@ function held(session, frame, after, depth) {
347
347
  extras: {
348
348
  afterCommit(callback) {
349
349
  if (typeof callback !== "function") {
350
- fail("OKM1121", "afterCommit expects a function.");
350
+ fail2("OKM1121", "afterCommit expects a function.");
351
351
  }
352
352
  frame.check();
353
353
  after.push(callback);
@@ -380,7 +380,7 @@ function lockKey(key) {
380
380
  }
381
381
  const fits = typeof key === "number" ? Number.isSafeInteger(key) : typeof key === "bigint" && key >= -(2n ** 63n) && key < 2n ** 63n;
382
382
  if (!fits)
383
- fail("OKM1121", "advisoryLock takes a string, a safe integer, or a bigint that fits in 64 bits.");
383
+ fail2("OKM1121", "advisoryLock takes a string, a safe integer, or a bigint that fits in 64 bits.");
384
384
  return ["select pg_advisory_xact_lock($1::bigint)", String(key)];
385
385
  }
386
386
  function callOf(options) {
@@ -6,7 +6,7 @@ import {
6
6
  acquireTimeout2,
7
7
  errorField2,
8
8
  mapDriverError2
9
- } from "./31vm914h.js";
9
+ } from "./cm3w0ywp.js";
10
10
  export {
11
11
  DriverError2 as DriverError,
12
12
  acquireTimeout2 as acquireTimeout,
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  required
3
- } from "./ywr8hmey.js";
3
+ } from "./606g0nbf.js";
4
4
  import {
5
5
  rejected
6
6
  } from "./tmbdywx0.js";
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  ColumnBuilder2
3
- } from "./ywr8hmey.js";
3
+ } from "./606g0nbf.js";
4
4
  import {
5
5
  definition
6
6
  } from "./tmbdywx0.js";