okmodel 0.5.1 → 0.7.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 (233) hide show
  1. package/README.md +100 -1116
  2. package/dist/adapters/capabilities.d.ts +3 -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/bunsql-extra.d.ts +54 -3
  6. package/dist/adapters/pg/bunsql.d.ts +14 -1
  7. package/dist/adapters/pg/cursor.d.ts +17 -0
  8. package/dist/adapters/pg/no-inflight-timeout.d.ts +20 -0
  9. package/dist/adapters/pg/nodepostgres-extra.d.ts +22 -1
  10. package/dist/adapters/pg/nodepostgres.d.ts +12 -0
  11. package/dist/adapters/pg/pglite-wire.d.ts +24 -0
  12. package/dist/adapters/pg/pglite.d.ts +10 -0
  13. package/dist/adapters/pg/postgres-extra.d.ts +41 -3
  14. package/dist/adapters/pg/reserved.d.ts +42 -0
  15. package/dist/adapters/pg/session.d.ts +0 -18
  16. package/dist/contracts/catalog/document.d.ts +19 -5
  17. package/dist/contracts/catalog/object.d.ts +2 -1
  18. package/dist/contracts/catalog/policy.d.ts +48 -0
  19. package/dist/contracts/catalog/types.d.ts +25 -1
  20. package/dist/contracts/catalog/view.d.ts +2 -0
  21. package/dist/contracts/connection.d.ts +7 -6
  22. package/dist/contracts/internal.js +1 -1
  23. package/dist/contracts/location.d.ts +10 -0
  24. package/dist/dialects/pg/column.d.ts +13 -2
  25. package/dist/dialects/pg/ddl.d.ts +37 -1
  26. package/dist/dialects/pg/emit.d.ts +19 -1
  27. package/dist/dialects/pg/errors.d.ts +32 -1
  28. package/dist/dialects/pg/ext/citext.js +1 -1
  29. package/dist/dialects/pg/ext/index.js +1 -1
  30. package/dist/dialects/pg/ext/pg-trgm.js +1 -1
  31. package/dist/dialects/pg/filter-parse.d.ts +5 -4
  32. package/dist/dialects/pg/floor.d.ts +68 -0
  33. package/dist/dialects/pg/fn/index.js +2 -2
  34. package/dist/dialects/pg/index.d.ts +8 -2
  35. package/dist/dialects/pg/index.js +67 -171
  36. package/dist/dialects/pg/introspect.d.ts +7 -0
  37. package/dist/dialects/pg/keys.d.ts +11 -8
  38. package/dist/dialects/pg/model.d.ts +47 -2
  39. package/dist/dialects/pg/morph.d.ts +43 -0
  40. package/dist/dialects/pg/operator-fit.d.ts +2 -2
  41. package/dist/dialects/pg/operators.d.ts +14 -7
  42. package/dist/dialects/pg/ops/bucket.d.ts +65 -0
  43. package/dist/dialects/pg/ops/inc.d.ts +2 -2
  44. package/dist/dialects/pg/ops/matches.d.ts +9 -12
  45. package/dist/dialects/pg/ops/relevance.d.ts +13 -0
  46. package/dist/dialects/pg/ops/search-query.d.ts +22 -0
  47. package/dist/dialects/pg/ops/window.d.ts +103 -0
  48. package/dist/dialects/pg/owner.d.ts +42 -0
  49. package/dist/dialects/pg/path-endpoint.d.ts +20 -0
  50. package/dist/dialects/pg/preset.d.ts +1 -1
  51. package/dist/dialects/pg/relations.d.ts +100 -3
  52. package/dist/dialects/pg/role/check.d.ts +3 -0
  53. package/dist/dialects/pg/role/index.d.ts +71 -6
  54. package/dist/dialects/pg/role/sql.d.ts +11 -0
  55. package/dist/dialects/pg/schema.d.ts +33 -3
  56. package/dist/dialects/pg/table.d.ts +25 -3
  57. package/dist/dialects/pg/tenancy.d.ts +45 -3
  58. package/dist/dialects/pg/view/client.d.ts +19 -1
  59. package/dist/dialects/pg/view/index.d.ts +4 -0
  60. package/dist/dialects/pg/view/index.js +21 -178
  61. package/dist/dialects/pg/view/refresh.d.ts +24 -0
  62. package/dist/runtime/aggregate.d.ts +8 -2
  63. package/dist/runtime/batch.d.ts +1 -1
  64. package/dist/runtime/bucket-group.d.ts +70 -0
  65. package/dist/runtime/conflict.d.ts +24 -6
  66. package/dist/runtime/drift.d.ts +9 -0
  67. package/dist/runtime/include.d.ts +0 -8
  68. package/dist/runtime/inflight.d.ts +14 -0
  69. package/dist/runtime/page.d.ts +4 -1
  70. package/dist/runtime/pg/bun.js +12 -5
  71. package/dist/runtime/pg/pg.js +5 -5
  72. package/dist/runtime/pg/pglite.d.ts +1 -0
  73. package/dist/runtime/pg/pglite.js +9 -8
  74. package/dist/runtime/pg/postgresjs.js +5 -5
  75. package/dist/runtime/plan.d.ts +113 -15
  76. package/dist/runtime/predicate.d.ts +19 -0
  77. package/dist/runtime/read-stream.d.ts +13 -16
  78. package/dist/runtime/result-name.d.ts +17 -0
  79. package/dist/runtime/safety/index.js +1 -1
  80. package/dist/runtime/server-check.d.ts +3 -3
  81. package/dist/runtime/sort-bind.d.ts +21 -0
  82. package/dist/runtime/sort.d.ts +56 -0
  83. package/dist/runtime/sync.d.ts +70 -0
  84. package/dist/runtime/tenancy/composite.d.ts +26 -0
  85. package/dist/runtime/tenancy/context.d.ts +16 -0
  86. package/dist/runtime/tenancy/index.d.ts +9 -5
  87. package/dist/runtime/tenancy/index.js +1511 -38
  88. package/dist/runtime/tenancy/path.d.ts +87 -0
  89. package/dist/runtime/tenancy/rls.d.ts +67 -0
  90. package/dist/runtime/tenancy/via.d.ts +22 -0
  91. package/dist/runtime/text-search.d.ts +20 -0
  92. package/dist/runtime/traits/index.d.ts +80 -0
  93. package/dist/runtime/traits/index.js +187 -17
  94. package/dist/runtime/tree.d.ts +38 -0
  95. package/dist/runtime/types.d.ts +231 -23
  96. package/dist/runtime/validate/index.js +4 -4
  97. package/dist/runtime/version.d.ts +39 -0
  98. package/dist/runtime/window.d.ts +21 -0
  99. package/dist/runtime/write.d.ts +55 -3
  100. package/dist/shared/{krxx77g0.js → 14vx95q4.js} +12 -18
  101. package/dist/shared/1est4ezg.js +313 -0
  102. package/dist/shared/{4az561fn.js → 1qa0qajz.js} +8 -23
  103. package/dist/shared/1w508jbr.js +1611 -0
  104. package/dist/shared/2c13q96h.js +18 -0
  105. package/dist/shared/2d3xq4ps.js +9 -0
  106. package/dist/shared/2shdbn8q.js +23 -0
  107. package/dist/shared/{t4tbsy9h.js → 358zsv4r.js} +1 -1
  108. package/dist/shared/3v7t1yrv.js +208 -0
  109. package/dist/shared/5e3tf63j.js +220 -0
  110. package/dist/shared/5fe3kbsh.js +10 -0
  111. package/dist/shared/5v3xf80k.js +37 -0
  112. package/dist/shared/{51mvgj8w.js → 63qtkrca.js} +130 -3
  113. package/dist/shared/{gbtcc2d7.js → 67txcrcw.js} +62 -66
  114. package/dist/shared/79dt02vc.js +12 -0
  115. package/dist/shared/{v36c5g6p.js → 7k9grvf6.js} +407 -14
  116. package/dist/shared/7kms6fvj.js +20 -0
  117. package/dist/shared/7mnme5tn.js +8 -0
  118. package/dist/shared/7n7ddwt4.js +6 -0
  119. package/dist/shared/{87jvvhnt.js → 81ebdx9p.js} +48 -68
  120. package/dist/shared/{szm0cksa.js → 8skf0cam.js} +34 -6
  121. package/dist/shared/{gjthds9j.js → 9628a9xt.js} +1 -1
  122. package/dist/shared/9a4ae4p8.js +31 -0
  123. package/dist/shared/{8xsbagad.js → 9s0ypp87.js} +88 -7
  124. package/dist/shared/9y3mmmh1.js +436 -0
  125. package/dist/shared/ab9gmbwy.js +213 -0
  126. package/dist/shared/{sycnx8gt.js → ax7qv55k.js} +18 -8
  127. package/dist/shared/{f5cw5q5r.js → aytqh5y2.js} +6 -4
  128. package/dist/shared/{fancm5pt.js → b5pftnn2.js} +138 -15
  129. package/dist/shared/{efmy2gcg.js → b76b8d95.js} +2 -2
  130. package/dist/shared/bdk4sty6.js +58 -0
  131. package/dist/shared/{32zqc1dw.js → bg3rym3g.js} +63 -32
  132. package/dist/shared/{0t22wwh1.js → bm22fvzr.js} +16 -14
  133. package/dist/shared/bz84tkzm.js +342 -0
  134. package/dist/shared/{31vm914h.js → cm3w0ywp.js} +15 -16
  135. package/dist/shared/cn957f8d.js +179 -0
  136. package/dist/shared/{pf0d8f77.js → cnkky55j.js} +25 -14
  137. package/dist/shared/{5fqx9yh4.js → dk8v79p3.js} +3 -1
  138. package/dist/shared/{nkaxvt9q.js → dkxgzaqd.js} +224 -19
  139. package/dist/shared/dzj09cye.js +10 -0
  140. package/dist/shared/{4m9fn52z.js → ed0b8k4s.js} +1 -1
  141. package/dist/shared/{z2rnngj4.js → ek2wt2dz.js} +8 -5
  142. package/dist/shared/exn3sd90.js +359 -0
  143. package/dist/shared/g6evj1j3.js +66 -0
  144. package/dist/shared/ga9j92qj.js +25 -0
  145. package/dist/shared/{qv2ydck9.js → gs74dbj5.js} +651 -76
  146. package/dist/shared/gzaveazc.js +285 -0
  147. package/dist/shared/{8rsy3hxz.js → h15jx9bc.js} +1 -1
  148. package/dist/shared/{dyj86cmj.js → hyh73qk6.js} +3 -3
  149. package/dist/shared/je4axnm8.js +22 -0
  150. package/dist/shared/{ycatkxmq.js → jgqj11w4.js} +1 -1
  151. package/dist/shared/{6qd27mx0.js → jvd0mqag.js} +5 -5
  152. package/dist/shared/jznfax0y.js +155 -0
  153. package/dist/shared/{cgbamx3e.js → kb2sdhfb.js} +7 -4
  154. package/dist/shared/{ps7a6h14.js → kr0jzbw2.js} +12 -8
  155. package/dist/shared/{janx09m5.js → ktz42yez.js} +20 -8
  156. package/dist/shared/{gde73es6.js → m6p12kbr.js} +56 -55
  157. package/dist/shared/{r6nwkxnt.js → m7n9h2a5.js} +4 -4
  158. package/dist/shared/{672t5vym.js → mss6ctgv.js} +2 -2
  159. package/dist/shared/{nxdp2ze3.js → mtaszv5a.js} +144 -12
  160. package/dist/shared/n816peh1.js +45 -0
  161. package/dist/shared/nbw1z4yd.js +18 -0
  162. package/dist/shared/{cctw17hj.js → p6qc5gcp.js} +38 -34
  163. package/dist/shared/{6rk2gen5.js → pbp1ss85.js} +20 -17
  164. package/dist/shared/pt94kz7f.js +6 -0
  165. package/dist/shared/{wq9n6pwr.js → pz6rj8ay.js} +82 -9
  166. package/dist/shared/q5c6ngn3.js +13 -0
  167. package/dist/shared/{8bwbwy8h.js → qq3899ht.js} +128 -18
  168. package/dist/shared/{8ktwd3rh.js → r3j8s5y0.js} +1 -1
  169. package/dist/shared/rhs3xe4k.js +7 -0
  170. package/dist/shared/{ntneex2a.js → rpycarcr.js} +6 -6
  171. package/dist/shared/{sdc7r2ww.js → rs73fca9.js} +8 -8
  172. package/dist/shared/{tm5ab8we.js → sfz1ksn6.js} +7 -4
  173. package/dist/shared/{6mnp99hx.js → svncdeh5.js} +16 -12
  174. package/dist/shared/{hf22e0wt.js → tbrvgw6z.js} +62 -42
  175. package/dist/shared/te5as7z7.js +622 -0
  176. package/dist/shared/{ga3sfy93.js → tsvww22q.js} +535 -200
  177. package/dist/shared/{47x8x9ze.js → ttsqgp4p.js} +20 -13
  178. package/dist/shared/{x72jb7ad.js → v8g1vgv8.js} +1 -1
  179. package/dist/shared/vb6qfyve.js +152 -0
  180. package/dist/shared/{r2sp8hrc.js → vczs8gd4.js} +22 -13
  181. package/dist/shared/{1g0drakv.js → vqrjpcqn.js} +145 -3
  182. package/dist/shared/{2pqx26h8.js → w72kgg4q.js} +31 -22
  183. package/dist/shared/{96qcj21c.js → w79hsckn.js} +16 -51
  184. package/dist/shared/wa07eas9.js +730 -0
  185. package/dist/shared/{k8v5v5wj.js → x933k9a3.js} +75 -34
  186. package/dist/shared/{cr74e96e.js → xhfsfkgk.js} +62 -28
  187. package/dist/shared/xjk7hnn5.js +272 -0
  188. package/dist/shared/{5enne4ma.js → xnxsed62.js} +66 -113
  189. package/dist/shared/xqve9598.js +53 -0
  190. package/dist/shared/{9x25fxhc.js → y34a8714.js} +1 -1
  191. package/dist/shared/{k7dwkhvq.js → y6jdds7g.js} +4 -1
  192. package/dist/shared/y6njgyda.js +249 -0
  193. package/dist/shared/{c9z5g0fm.js → ywr8hmey.js} +5 -2
  194. package/dist/shared/{g7ez901n.js → ywspezzx.js} +1 -1
  195. package/dist/shared/z7s6fpxv.js +62 -0
  196. package/dist/shared/{n7mcc1gk.js → zchaghkf.js} +4 -3
  197. package/dist/shared/{9m80mkac.js → ze4hxsmy.js} +1 -1
  198. package/dist/shared/zm0ptry0.js +40 -0
  199. package/dist/shared/{nsva2a6b.js → znm0bpp5.js} +3 -0
  200. package/dist/shared/zp9fmend.js +145 -0
  201. package/dist/shared/{y005b761.js → zy8r7qvz.js} +6 -2
  202. package/dist/tooling/cli.js +41 -15
  203. package/dist/tooling/migrate/apply.d.ts +14 -0
  204. package/dist/tooling/migrate/check.d.ts +3 -4
  205. package/dist/tooling/migrate/classify.d.ts +4 -0
  206. package/dist/tooling/migrate/config.d.ts +3 -2
  207. package/dist/tooling/migrate/engine.d.ts +3 -2
  208. package/dist/tooling/migrate/files.d.ts +11 -1
  209. package/dist/tooling/migrate/index.js +14 -14
  210. package/dist/tooling/migrate/lint.d.ts +1 -1
  211. package/dist/tooling/migrate/lost.d.ts +28 -0
  212. package/dist/tooling/migrate/paths.d.ts +14 -0
  213. package/dist/tooling/migrate/plan.d.ts +6 -3
  214. package/dist/tooling/migrate/runner.d.ts +25 -0
  215. package/dist/tooling/migrate/sandbox.d.ts +57 -0
  216. package/dist/tooling/migrate/sql-lex.d.ts +20 -3
  217. package/dist/tooling/migrate/text.d.ts +42 -0
  218. package/dist/tooling/node-version.d.ts +21 -0
  219. package/dist/tooling/testing/facts.d.ts +33 -5
  220. package/dist/tooling/testing/index.d.ts +1 -1
  221. package/dist/tooling/testing/index.js +3 -3
  222. package/dist/tooling/testing/isolation.d.ts +11 -5
  223. package/package.json +8 -3
  224. package/dist/shared/7m88x3e9.js +0 -45
  225. package/dist/shared/7zwwyh0v.js +0 -448
  226. package/dist/shared/aj2qxyhj.js +0 -90
  227. package/dist/shared/caw8b9d8.js +0 -204
  228. package/dist/shared/jwtxdj06.js +0 -76
  229. package/dist/shared/kfjp0gck.js +0 -212
  230. package/dist/shared/q58y17hy.js +0 -21
  231. package/dist/shared/qm7cdtvr.js +0 -912
  232. package/dist/shared/r8x5qhd7.js +0 -86
  233. package/dist/shared/zqrnhwsq.js +0 -31
@@ -0,0 +1,285 @@
1
+ import {
2
+ refusePrototypeKey
3
+ } from "./q5c6ngn3.js";
4
+ import {
5
+ isWindow
6
+ } from "./9a4ae4p8.js";
7
+ import {
8
+ emitWhere,
9
+ emitOrder,
10
+ refuseHidden,
11
+ emitLimit,
12
+ parseOrder,
13
+ projectExpr,
14
+ indexes,
15
+ quote,
16
+ list,
17
+ isRecord,
18
+ fail2
19
+ } from "./67txcrcw.js";
20
+ import {
21
+ throwNamed2
22
+ } from "./52szzakm.js";
23
+
24
+ // src/runtime/window.ts
25
+ var AS_NUMBER = (wire) => Number(wire);
26
+ var AS_TEXT = (wire) => wire;
27
+ var NUMERIC = /^(smallint|integer|bigint|real|double precision|numeric|decimal)\b/;
28
+ var OPTION_KEYS = ["as", "orderBy", "partitionBy"];
29
+ function attach(schema, call) {
30
+ const table = indexesOf(schema, call.table);
31
+ return { ...call, build: statement(readSpec(table, call.select)) };
32
+ }
33
+ function statement(spec) {
34
+ return (schema, table, sink, outputs, call, hooks) => {
35
+ sink.mark(`${call.op}|${table.model.name}|`);
36
+ if (call.include !== undefined && hooks === undefined) {
37
+ fail2("OKM1120", "An include needs the include planner.");
38
+ }
39
+ const includes = hooks === undefined || call.include === undefined ? [] : hooks.read(schema, table, call.include, call.all);
40
+ sink.text("select ");
41
+ let column = 0;
42
+ for (const item of spec.items) {
43
+ if (column > 0)
44
+ sink.text(", ");
45
+ if (item.kind === "column") {
46
+ sink.text(projectExpr(`t.${quote(item.column.sql)}`, item.column.dataType));
47
+ sink.mark(`s:${item.column.field}`);
48
+ outputs?.fields.push({ key: item.column.field, at: column, decode: item.column.decode });
49
+ } else {
50
+ emitWindow(table, item.window, sink);
51
+ sink.text("::text");
52
+ outputs?.fields.push({ key: item.window.as, at: column, decode: item.window.decode });
53
+ }
54
+ column += 1;
55
+ }
56
+ if (spec.items.length === 0 && includes.length === 0)
57
+ sink.text("1");
58
+ for (let index = 0;index < includes.length; index += 1) {
59
+ const include = includes[index];
60
+ if (include === undefined || hooks === undefined)
61
+ continue;
62
+ column = hooks.select(include, `i${String(index)}`, sink, outputs, column);
63
+ }
64
+ sink.text(" from ");
65
+ sink.text(quote(table.model.sql));
66
+ sink.text(" t");
67
+ for (let index = 0;index < includes.length; index += 1) {
68
+ const include = includes[index];
69
+ if (include === undefined || hooks === undefined)
70
+ continue;
71
+ hooks.join(schema, include, sink, "t", `i${String(index)}`, 0);
72
+ }
73
+ emitWhere(schema, table, call.where, sink, "t", 0, false, call.after);
74
+ emitResultOrder(table, call.orderBy, sink, spec.ordinals);
75
+ emitLimit(call, sink);
76
+ call.tail?.(sink);
77
+ };
78
+ }
79
+ function emitResultOrder(table, orderBy, sink, ordinals) {
80
+ if (!isRecord(orderBy) || !mentionsOrdinal(orderBy, ordinals)) {
81
+ emitOrder(table, orderBy, sink, "t");
82
+ return;
83
+ }
84
+ const keys = Object.keys(orderBy);
85
+ sink.text(" order by ");
86
+ for (let index = 0;index < keys.length; index += 1) {
87
+ const key = keys[index];
88
+ if (key === undefined)
89
+ continue;
90
+ const parsed = parseOrder(key, orderBy[key]);
91
+ if (index > 0)
92
+ sink.text(", ");
93
+ const ordinal = ordinals.get(key);
94
+ if (ordinal !== undefined) {
95
+ sink.text(ordinal);
96
+ } else {
97
+ const column = table.columns.get(key);
98
+ if (column === undefined) {
99
+ throwNamed2("OKM1120", key, table.names, `Field ${key} is not on ${table.model.name}. Accepted names: ${list(table.names)}.`);
100
+ }
101
+ refuseHidden(column);
102
+ sink.text("t.");
103
+ sink.text(quote(column.sql));
104
+ }
105
+ sink.text(parsed.dir === "asc" ? " asc" : " desc");
106
+ sink.text(parsed.nulls === "first" ? " nulls first" : " nulls last");
107
+ sink.mark(`o:${key}:${parsed.dir}:${parsed.nulls}`);
108
+ }
109
+ }
110
+ function mentionsOrdinal(orderBy, ordinals) {
111
+ if (ordinals.size === 0)
112
+ return false;
113
+ for (const key of Object.keys(orderBy)) {
114
+ if (ordinals.has(key))
115
+ return true;
116
+ }
117
+ return false;
118
+ }
119
+ function emitWindow(table, win, sink) {
120
+ sink.mark(`w:${win.fn}:${win.as}:p:${win.partition.map((column) => column.field).join("+")}`);
121
+ if (win.fn === "sum") {
122
+ const column = win.column;
123
+ if (column === undefined)
124
+ fail2("OKM1120", "runningTotal needs a column.");
125
+ sink.text("sum(t.");
126
+ sink.text(quote(column.sql));
127
+ sink.text(")");
128
+ } else {
129
+ sink.text(win.fn);
130
+ sink.text("()");
131
+ }
132
+ sink.text(" over (");
133
+ if (win.partition.length > 0) {
134
+ sink.text("partition by ");
135
+ for (let index = 0;index < win.partition.length; index += 1) {
136
+ const column = win.partition[index];
137
+ if (column === undefined)
138
+ continue;
139
+ if (index > 0)
140
+ sink.text(", ");
141
+ sink.text("t.");
142
+ sink.text(quote(column.sql));
143
+ }
144
+ }
145
+ emitOrder(table, win.orderBy, sink, "t");
146
+ if (win.tieBreak) {
147
+ const named = isRecord(win.orderBy) ? Object.keys(win.orderBy) : [];
148
+ for (const field of table.model.primary) {
149
+ if (named.includes(field))
150
+ continue;
151
+ const column = table.columns.get(field);
152
+ if (column === undefined)
153
+ continue;
154
+ sink.text(", t.");
155
+ sink.text(quote(column.sql));
156
+ sink.text(" asc");
157
+ }
158
+ }
159
+ sink.text(")");
160
+ }
161
+ function readSpec(table, select) {
162
+ if (!Array.isArray(select))
163
+ fail2("OKM1120", "select must be a list of field names.");
164
+ const items = [];
165
+ const ordinals = new Map;
166
+ const names = new Set;
167
+ for (const entry of select) {
168
+ if (typeof entry === "string") {
169
+ const column = columnOn(table, entry, "select");
170
+ names.add(column.field);
171
+ items.push({ kind: "column", column });
172
+ continue;
173
+ }
174
+ if (!isWindow(entry)) {
175
+ fail2("OKM1120", "select takes field names or a window helper. A plain object is not a window.", "Pass rowNumber, rank, denseRank, or runningTotal.");
176
+ }
177
+ const win = readWindow(table, entry, names);
178
+ names.add(win.as);
179
+ ordinals.set(win.as, String(items.length + 1));
180
+ items.push({ kind: "window", window: win });
181
+ }
182
+ return { items, ordinals };
183
+ }
184
+ function readWindow(table, call, taken) {
185
+ if (!isRecord(call))
186
+ fail2("OKM1120", "A window helper was not created by its function.");
187
+ for (const key of Object.keys(call)) {
188
+ if (key === "label" || key === "fn" || key === "column")
189
+ continue;
190
+ if (OPTION_KEYS.includes(key))
191
+ continue;
192
+ fail2("OKM1120", `${call.label} does not take ${key}. Accepted: partitionBy, orderBy, as.`, "Pass partitionBy, orderBy, and as.");
193
+ }
194
+ const as = readAs(call.as, call.label);
195
+ if (taken.has(as) || table.columns.has(as)) {
196
+ fail2("OKM1120", `${call.label} as ${as} clashes with a column of ${table.model.name}.`, "Pick an as name that is not a column.");
197
+ }
198
+ const partition = readPartition(table, call.partitionBy, call.label);
199
+ if (!isRecord(call.orderBy) || Object.keys(call.orderBy).length === 0) {
200
+ fail2("OKM1120", `${call.label} needs orderBy, the order inside the group.`, 'Pass orderBy: { field: "desc" }.');
201
+ }
202
+ for (const field of Object.keys(call.orderBy))
203
+ columnOn(table, field, `${call.label} orderBy`);
204
+ let column;
205
+ let decode = AS_NUMBER;
206
+ if (call.fn === "sum") {
207
+ if (typeof call.column !== "string") {
208
+ fail2("OKM1120", "runningTotal needs the column to total.");
209
+ }
210
+ column = columnOn(table, call.column, "runningTotal");
211
+ if (!NUMERIC.test(column.dataType)) {
212
+ fail2("OKM1124", `runningTotal does not apply to ${column.dataType} column ${column.field}. It takes integer, real, and numeric columns.`);
213
+ }
214
+ decode = totalDecode(column);
215
+ }
216
+ return {
217
+ fn: call.fn,
218
+ label: call.label,
219
+ column,
220
+ partition,
221
+ orderBy: call.orderBy,
222
+ as,
223
+ decode,
224
+ tieBreak: call.fn === "row_number" || call.fn === "sum"
225
+ };
226
+ }
227
+ function readPartition(table, value, label) {
228
+ if (value === undefined)
229
+ return [];
230
+ if (!Array.isArray(value) || value.length === 0) {
231
+ fail2("OKM1120", `${label} partitionBy needs the fields that form the group.`, 'Pass partitionBy: ["status"], or leave it out to use the whole result.');
232
+ }
233
+ const columns = [];
234
+ const seen = new Set;
235
+ for (const name of value) {
236
+ if (typeof name !== "string") {
237
+ fail2("OKM1120", `${label} partitionBy takes field names.`);
238
+ }
239
+ const column = columnOn(table, name, `${label} partitionBy`);
240
+ if (seen.has(column.field)) {
241
+ fail2("OKM1120", `${label} partitionBy lists ${column.field} twice.`);
242
+ }
243
+ seen.add(column.field);
244
+ columns.push(column);
245
+ }
246
+ return columns;
247
+ }
248
+ function readAs(value, label) {
249
+ if (typeof value !== "string" || value.length === 0) {
250
+ fail2("OKM1120", `${label} needs as, the name of the result key.`, "Set as to a name, such as n.");
251
+ }
252
+ for (let index = 0;index < value.length; index += 1) {
253
+ if ((value.charCodeAt(index) ?? 0) < 32) {
254
+ fail2("OKM1120", `${label} as has a control character.`);
255
+ }
256
+ }
257
+ refusePrototypeKey(value, `${label} as`);
258
+ return value;
259
+ }
260
+ function totalDecode(column) {
261
+ const kind = typeof (column.decode?.("0") ?? "");
262
+ if (kind === "string")
263
+ return AS_TEXT;
264
+ if (kind === "number")
265
+ return AS_NUMBER;
266
+ return fail2("OKM1124", `runningTotal needs a column whose value is a number or a string. ${column.field} reads as ${kind}.`);
267
+ }
268
+ function columnOn(table, name, where) {
269
+ const column = table.columns.get(name);
270
+ if (column === undefined) {
271
+ throwNamed2("OKM1120", name, table.names, `Field ${name} is not on ${table.model.name}. ${where} accepts: ${list(table.names)}.`);
272
+ }
273
+ if (where !== "select")
274
+ refuseHidden(column);
275
+ return column;
276
+ }
277
+ function indexesOf(schema, name) {
278
+ const table = indexes(schema).get(name);
279
+ if (table === undefined)
280
+ fail2("OKM1120", `Table ${name} is not in the schema.`);
281
+ return table;
282
+ }
283
+ export {
284
+ attach
285
+ };
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  validationGate
3
- } from "./9m80mkac.js";
3
+ } from "./ze4hxsmy.js";
4
4
  import {
5
5
  isOperator
6
6
  } from "./cn0n68ft.js";
@@ -1,11 +1,11 @@
1
1
  import {
2
2
  encodeText,
3
3
  decodeText
4
- } from "./4m9fn52z.js";
4
+ } from "./ed0b8k4s.js";
5
5
  import {
6
6
  required,
7
7
  openColumn
8
- } from "./c9z5g0fm.js";
8
+ } from "./ywr8hmey.js";
9
9
  import {
10
10
  definition,
11
11
  rejected
@@ -35,7 +35,7 @@ function id2(options) {
35
35
  ...client !== undefined ? { clientDefault: client } : {},
36
36
  ...okid ? { collation: "C" } : {},
37
37
  idSource: chosen === undefined ? "implicit" : "column",
38
- ...client === undefined && !supplied ? { defaultSql: chosen === "uuidv4" ? "gen_random_uuid()" : "uuidv7()" } : {},
38
+ ...client === undefined && !supplied ? { defaultSql: chosen === "uuidv7" ? "uuidv7()" : "gen_random_uuid()" } : {},
39
39
  primaryKey: true,
40
40
  encode: okid ? encodeText : encodeUuid,
41
41
  decode: okid ? decodeText : decodeUuid,
@@ -0,0 +1,22 @@
1
+ import {
2
+ checkout2,
3
+ describe2,
4
+ stream2,
5
+ runBatch2,
6
+ watchReserved2,
7
+ holdCheckout2,
8
+ holdListener2,
9
+ watchQuery2
10
+ } from "./bz84tkzm.js";
11
+ import"./14vx95q4.js";
12
+ import"./cm3w0ywp.js";
13
+ export {
14
+ checkout2 as checkout,
15
+ describe2 as describe,
16
+ holdCheckout2 as holdCheckout,
17
+ holdListener2 as holdListener,
18
+ runBatch2 as runBatch,
19
+ stream2 as stream,
20
+ watchQuery2 as watchQuery,
21
+ watchReserved2 as watchReserved
22
+ };
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  extensionObject
3
- } from "./8ktwd3rh.js";
3
+ } from "./r3j8s5y0.js";
4
4
  import {
5
5
  OkmError2
6
6
  } from "./52szzakm.js";
@@ -2,11 +2,11 @@ import {
2
2
  assertAuthorDrift2,
3
3
  catalogQuery2,
4
4
  managedRoleOptions2
5
- } from "./sycnx8gt.js";
6
- import"./fancm5pt.js";
7
- import"./ga3sfy93.js";
8
- import"./8xsbagad.js";
9
- import"./8bwbwy8h.js";
5
+ } from "./ax7qv55k.js";
6
+ import"./b5pftnn2.js";
7
+ import"./tsvww22q.js";
8
+ import"./9s0ypp87.js";
9
+ import"./qq3899ht.js";
10
10
  export {
11
11
  assertAuthorDrift2 as assertAuthorDrift,
12
12
  catalogQuery2 as catalogQuery,
@@ -0,0 +1,155 @@
1
+ import {
2
+ assertNoControl
3
+ } from "./zchaghkf.js";
4
+ import {
5
+ searchValue
6
+ } from "./dzj09cye.js";
7
+ import {
8
+ refuseHidden,
9
+ indexes,
10
+ list,
11
+ isRecord,
12
+ fail2
13
+ } from "./67txcrcw.js";
14
+ import {
15
+ isOperator,
16
+ operatorName,
17
+ operatorValue,
18
+ tag
19
+ } from "./cn0n68ft.js";
20
+ import {
21
+ throwNamed2
22
+ } from "./52szzakm.js";
23
+
24
+ // src/runtime/text-search.ts
25
+ var MATCHES = ["natural", "all-words", "phrase", "advanced"];
26
+ var SEARCH_KEYS = ["for", "in", "match", "language"];
27
+ function applyTextSearch(schema, call) {
28
+ const table = indexes(schema).get(call.table);
29
+ if (table === undefined)
30
+ fail2("OKM1120", `Table ${call.table} is not in the schema.`);
31
+ const spec = parseSearch(table, call.search);
32
+ const options = { match: spec.match, language: spec.language };
33
+ const where = withMatch(call.where, spec.column.field, spec.text, options);
34
+ const orderBy = call.op === "find" && call.orderBy === undefined ? ranked(table, spec.column.field, spec.text, options) : call.orderBy;
35
+ const { search: dropped, ...rest } = call;
36
+ return {
37
+ ...rest,
38
+ where,
39
+ ...orderBy !== undefined ? { orderBy } : {}
40
+ };
41
+ }
42
+ function parseSearch(table, search) {
43
+ if (typeof search === "string") {
44
+ return { text: textOf(search), column: columnFor(table, undefined), ...natural() };
45
+ }
46
+ if (!isRecord(search)) {
47
+ fail2("OKM1120", "search needs the text to look for, or { for, in, match, language }.", "Pass a string, or search: { for, in }.");
48
+ }
49
+ for (const key of Object.keys(search)) {
50
+ if (SEARCH_KEYS.includes(key))
51
+ continue;
52
+ fail2("OKM1120", `search does not take ${key}. Accepted: for, in, match, language.`, "Pass for, in, match, and language.");
53
+ }
54
+ if (typeof search.for !== "string") {
55
+ fail2("OKM1120", "search.for needs text to look for.", "Set for to the text you want to find.");
56
+ }
57
+ const named = search.in;
58
+ if (named !== undefined && typeof named !== "string") {
59
+ fail2("OKM1120", "search.in names the column to search.", "Set in to a column name.");
60
+ }
61
+ return {
62
+ text: textOf(search.for),
63
+ column: columnFor(table, named),
64
+ match: matchOf(search.match),
65
+ language: languageOf(search.language)
66
+ };
67
+ }
68
+ function natural() {
69
+ return { match: "natural", language: undefined };
70
+ }
71
+ function textOf(text) {
72
+ if (text.length === 0) {
73
+ fail2("OKM1120", "search needs text to look for.", "Pass the words you want to find.");
74
+ }
75
+ assertNoControl(text, "search");
76
+ return text;
77
+ }
78
+ function matchOf(value) {
79
+ if (value === undefined)
80
+ return "natural";
81
+ if (typeof value === "string" && isMatch(value))
82
+ return value;
83
+ fail2("OKM1120", "search.match must be natural, all-words, phrase, or advanced.", "Use natural, all-words, phrase, or advanced.");
84
+ }
85
+ function isMatch(value) {
86
+ return MATCHES.includes(value);
87
+ }
88
+ function languageOf(value) {
89
+ if (value === undefined)
90
+ return;
91
+ if (typeof value !== "string") {
92
+ fail2("OKM1120", "search.language must be a text search language such as english.", "Pass a language name such as english, or leave it out.");
93
+ }
94
+ return value;
95
+ }
96
+ function columnFor(table, name) {
97
+ const columns = searchable(table);
98
+ const names = columns.map((column) => column.field);
99
+ if (name === undefined) {
100
+ const only = columns[0];
101
+ if (columns.length === 1 && only !== undefined)
102
+ return only;
103
+ if (columns.length === 0) {
104
+ fail2("OKM1120", `Table ${table.model.name} has no column you can search.`, "Add a column built for search.");
105
+ }
106
+ fail2("OKM1120", `Table ${table.model.name} has more than one column you can search. Name one with search: { for, in }. Columns: ${list(names)}.`, `Set in to one of: ${list(names)}.`);
107
+ }
108
+ const column = table.columns.get(name);
109
+ if (column === undefined) {
110
+ throwNamed2("OKM1120", name, names, `Column ${name} is not on ${table.model.name}. Columns you can search: ${list(names)}.`);
111
+ }
112
+ if (column.dataType !== "tsvector") {
113
+ fail2("OKM1120", `Column ${name} cannot be searched. Columns you can search: ${list(names)}.`, names.length === 0 ? "This table has no column you can search." : `Search one of: ${list(names)}.`);
114
+ }
115
+ if (column.hidden === true)
116
+ refuseHidden(column);
117
+ return column;
118
+ }
119
+ function searchable(table) {
120
+ const found = [];
121
+ for (const column of table.model.columns) {
122
+ if (column.dataType === "tsvector" && column.hidden !== true)
123
+ found.push(column);
124
+ }
125
+ return found;
126
+ }
127
+ function withMatch(where, field, text, options) {
128
+ const filter = { [field]: tag("matches", searchValue(text, passed(options))) };
129
+ if (where === undefined)
130
+ return filter;
131
+ if (isOperator(where) && operatorName(where) === "and") {
132
+ const branches = operatorValue(where);
133
+ if (Array.isArray(branches))
134
+ return tag("and", [...branches, filter]);
135
+ }
136
+ return tag("and", [where, filter]);
137
+ }
138
+ function ranked(table, field, text, options) {
139
+ const order = {
140
+ [field]: tag("relevance", searchValue(text, passed(options)))
141
+ };
142
+ for (const key of table.model.primary) {
143
+ if (!Object.hasOwn(order, key))
144
+ order[key] = "asc";
145
+ }
146
+ return order;
147
+ }
148
+ function passed(options) {
149
+ if (options.language === undefined)
150
+ return { match: options.match };
151
+ return { match: options.match, language: options.language };
152
+ }
153
+ export {
154
+ applyTextSearch
155
+ };
@@ -41,11 +41,14 @@ function hasCapability2(flags, name) {
41
41
  // src/adapters/failure.ts
42
42
  var loading;
43
43
  function driverErrors() {
44
- loading ??= import("./x72jb7ad.js");
44
+ loading ??= import("./v8g1vgv8.js");
45
45
  return loading;
46
46
  }
47
- function rejectClosed(message = "The pool is closed.") {
48
- return driverErrors().then((mod) => Promise.reject(new mod.DriverError(message)));
47
+ function rejectClosed() {
48
+ return import("./2c13q96h.js").then((mod) => mod.closed());
49
+ }
50
+ function rejectUncancellable() {
51
+ return import("./2c13q96h.js").then((mod) => mod.refused());
49
52
  }
50
53
  function rejectCancelled() {
51
54
  return driverErrors().then((mod) => Promise.reject(mod.cancelled()));
@@ -163,4 +166,4 @@ function countFrom(value, rows) {
163
166
  return rows;
164
167
  }
165
168
 
166
- export { POSTGRESJS_CAPABILITIES, PGLITE_CAPABILITIES, NODE_POSTGRES_CAPABILITIES, BUNSQL_CAPABILITIES, readCapability2, hasCapability2, driverErrors, rejectClosed, rejectCancelled, rejectTimedOut, mapFailure, nextTransactionDepth, runCall, EMPTY_NOTICES, rowsFrom, resultFrom };
169
+ export { POSTGRESJS_CAPABILITIES, PGLITE_CAPABILITIES, NODE_POSTGRES_CAPABILITIES, BUNSQL_CAPABILITIES, readCapability2, hasCapability2, driverErrors, rejectClosed, rejectUncancellable, rejectCancelled, rejectTimedOut, mapFailure, nextTransactionDepth, runCall, EMPTY_NOTICES, rowsFrom, resultFrom };
@@ -1,22 +1,24 @@
1
1
  import {
2
2
  open2
3
- } from "./krxx77g0.js";
4
- import"./8bwbwy8h.js";
3
+ } from "./14vx95q4.js";
4
+ import"./qq3899ht.js";
5
5
  import"./n442h54c.js";
6
6
  import {
7
7
  assertRoleHealth
8
- } from "./szm0cksa.js";
9
- import"./fancm5pt.js";
8
+ } from "./8skf0cam.js";
9
+ import"./b5pftnn2.js";
10
10
  import {
11
11
  errorDoc,
12
12
  openProject
13
- } from "./qv2ydck9.js";
13
+ } from "./gs74dbj5.js";
14
14
  import {
15
15
  omitManagedObjects,
16
+ sessionFailure,
17
+ finishQuiet,
16
18
  assertTargetPolicy,
17
19
  selectTarget
18
- } from "./ga3sfy93.js";
19
- import"./8xsbagad.js";
20
+ } from "./tsvww22q.js";
21
+ import"./9s0ypp87.js";
20
22
  import {
21
23
  OkmError2
22
24
  } from "./52szzakm.js";
@@ -43,8 +45,10 @@ ${doc.fix}
43
45
  const pool = open2({ url: target.url, max: 1 });
44
46
  try {
45
47
  await assertRoleHealth(pool, opened.config.roles, objects);
48
+ } catch (error) {
49
+ throw sessionFailure(error) ?? error;
46
50
  } finally {
47
- await pool.close();
51
+ await finishQuiet(() => pool.close());
48
52
  }
49
53
  }
50
54
  return formatTriggers(objects);
@@ -1,20 +1,22 @@
1
1
  import {
2
2
  open2
3
- } from "./krxx77g0.js";
4
- import"./8bwbwy8h.js";
3
+ } from "./14vx95q4.js";
4
+ import"./qq3899ht.js";
5
5
  import"./n442h54c.js";
6
6
  import {
7
7
  openProject
8
- } from "./qv2ydck9.js";
8
+ } from "./gs74dbj5.js";
9
9
  import {
10
+ sessionFailure,
11
+ finishQuiet,
10
12
  assertTargetPolicy,
11
13
  selectTarget
12
- } from "./ga3sfy93.js";
13
- import"./8xsbagad.js";
14
+ } from "./tsvww22q.js";
15
+ import"./9s0ypp87.js";
14
16
  import {
15
17
  isExactVersion,
16
18
  compareExtensionVersions
17
- } from "./8ktwd3rh.js";
19
+ } from "./r3j8s5y0.js";
18
20
  import {
19
21
  OkmError2
20
22
  } from "./52szzakm.js";
@@ -29,8 +31,10 @@ async function extProject(cwd, command, flags) {
29
31
  if (command === "list")
30
32
  return formatList(await readExtensions(pool));
31
33
  return formatCheck(opened.built.catalog.objects, await readExtensions(pool));
34
+ } catch (error) {
35
+ throw sessionFailure(error) ?? error;
32
36
  } finally {
33
- await pool.close();
37
+ await finishQuiet(() => pool.close());
34
38
  }
35
39
  }
36
40
  var LIST_SQL = `
@@ -78,7 +82,9 @@ function formatCheck(objects, server) {
78
82
  }
79
83
  const want = object.definition.version;
80
84
  if (!versionAccepted(want, have)) {
81
- throw new OkmError2("OKM1812", `Extension ${name} is ${have} on the server. The schema requires ${want ?? ""}.`, { fix: { summary: "Install a version the declaration accepts, or change the pin." } });
85
+ throw new OkmError2("OKM1812", extensionNeeds(name, want ?? "", have), {
86
+ fix: { summary: "Install a version the declaration accepts, or change the pin." }
87
+ });
82
88
  }
83
89
  lines.push([name, want ?? "-", have].join("\t"));
84
90
  }
@@ -86,6 +92,12 @@ function formatCheck(objects, server) {
86
92
  `)}
87
93
  `;
88
94
  }
95
+ function extensionNeeds(name, want, have) {
96
+ const floor = /^>=(\d+(?:\.\d+)*)$/.exec(want);
97
+ const need = floor?.[1] ?? want;
98
+ const higher = floor === null ? "" : " or higher";
99
+ return `Extension ${name} needs ${need}${higher}. The server has ${have}. Install a version the declaration accepts, or change the pin.`;
100
+ }
89
101
  function versionAccepted(declared, installed) {
90
102
  if (declared === undefined)
91
103
  return true;