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,270 @@
1
+ import {
2
+ readHandle,
3
+ readCall,
4
+ attachHttp
5
+ } from "./jr2nmr81.js";
6
+ import {
7
+ OkmError,
8
+ throwNamed,
9
+ decodeResult,
10
+ emitWhere,
11
+ emitOrder,
12
+ selectedColumns,
13
+ rejectKeys,
14
+ projectExpr,
15
+ indexes,
16
+ quote,
17
+ list,
18
+ isRecord,
19
+ fail2
20
+ } from "./hfq3n3bd.js";
21
+
22
+ // src/runtime/tree.ts
23
+ var OPTIONS = [
24
+ "where",
25
+ "select",
26
+ "orderBy",
27
+ "depth",
28
+ "self",
29
+ "relation",
30
+ "route",
31
+ "signal",
32
+ "timeout"
33
+ ];
34
+ function build2(session, table, options, mods, view) {
35
+ try {
36
+ return open(session, table, options, mods, view);
37
+ } catch (error) {
38
+ throw error instanceof OkmError ? attachHttp(session.http, error) : error;
39
+ }
40
+ }
41
+ function open(session, table, options, mods, view) {
42
+ const packed = readPacked(options);
43
+ const user = packed.user;
44
+ rejectKeys(user, OPTIONS, packed.walk);
45
+ const indexed = indexes(session.schema).get(table);
46
+ if (indexed === undefined)
47
+ fail2("OKM1120", `Table ${table} is not in the schema.`);
48
+ const edge = pickEdge(indexed, user.relation);
49
+ const identity = identityColumn2(session, indexed);
50
+ const depth = readDepth(user.depth);
51
+ const self = readSelf(user.self);
52
+ const id = userId(identity, packed.id);
53
+ const shared = {
54
+ ...user.where !== undefined ? { where: user.where } : {},
55
+ ...user.select !== undefined ? { select: user.select } : {},
56
+ ...user.orderBy !== undefined ? { orderBy: user.orderBy } : {},
57
+ ...user.signal !== undefined ? { signal: user.signal } : {},
58
+ ...user.timeout !== undefined ? { timeout: user.timeout } : {},
59
+ ...user.route !== undefined ? { route: user.route } : {}
60
+ };
61
+ const base = readCall("find", table, shared, mods.all, session.scope, session.schema.model[table], session.schema, view);
62
+ const spec = { direction: packed.walk, edge, identity, depth, self, id };
63
+ const call = {
64
+ ...base,
65
+ op: packed.walk,
66
+ build: (schema, planned, sink, outputs, source) => {
67
+ emitTree(schema, planned, sink, outputs, source, spec);
68
+ }
69
+ };
70
+ return readHandle(session, table, call, mods, (compiled, rows) => decodeResult(compiled, rows, table));
71
+ }
72
+ function emitTree(schema, table, sink, outputs, call, spec) {
73
+ const { direction, edge, identity, depth, self, id } = spec;
74
+ sink.mark(`walk:${direction}|rel:${edge.name}|self:${self ? "1" : "0"}|depth:${depth === undefined ? "all" : String(depth)}|`);
75
+ const selected = selectedColumns(table, call.select);
76
+ sink.text("with recursive walk as (select ");
77
+ emitKeyList(sink, "s", edge.parent, "k");
78
+ emitKeyList(sink, "s", edge.child, "f");
79
+ sink.text(", 0 as depth, array[s.");
80
+ sink.text(quote(identity.sql));
81
+ sink.text("] as seen from ");
82
+ sink.text(quote(table.model.sql));
83
+ sink.text(" s where s.");
84
+ sink.text(quote(identity.sql));
85
+ sink.text(" = ");
86
+ sink.param(identity.encode(id));
87
+ emitWhere(schema, table, undefined, sink, "s", 0, true);
88
+ sink.text(" union all select ");
89
+ let started = emitBare(sink, "c", edge.parent, false);
90
+ emitBare(sink, "c", edge.child, started);
91
+ sink.text(", w.depth + 1, w.seen || c.");
92
+ sink.text(quote(identity.sql));
93
+ sink.text(" from ");
94
+ sink.text(quote(table.model.sql));
95
+ sink.text(" c join walk w on ");
96
+ if (direction === "descendants")
97
+ emitStep(sink, "c", edge.child, edge.parent, "k");
98
+ else
99
+ emitStep(sink, "c", edge.parent, edge.child, "f");
100
+ sink.text(" where c.");
101
+ sink.text(quote(identity.sql));
102
+ sink.text(" <> all(w.seen)");
103
+ if (depth !== undefined) {
104
+ sink.text(" and w.depth < ");
105
+ sink.text(String(depth));
106
+ }
107
+ emitWhere(schema, table, undefined, sink, "c", 0, true);
108
+ sink.text(") select ");
109
+ let column = 0;
110
+ for (let index = 0;index < selected.length; index += 1) {
111
+ const item = selected[index];
112
+ if (item === undefined)
113
+ continue;
114
+ if (column > 0)
115
+ sink.text(", ");
116
+ sink.text(projectExpr(`t.${quote(item.sql)}`, item.dataType));
117
+ sink.mark(`s:${item.field}`);
118
+ outputs?.fields.push({ key: item.field, at: column, decode: item.decode });
119
+ column += 1;
120
+ }
121
+ if (column === 0)
122
+ sink.text("1");
123
+ sink.text(" from ");
124
+ sink.text(quote(table.model.sql));
125
+ sink.text(" t join walk w on ");
126
+ emitStep(sink, "t", edge.parent, edge.parent, "k");
127
+ if (self)
128
+ emitWhere(schema, table, call.where, sink, "t", 0, false);
129
+ else {
130
+ sink.text(" where w.depth > 0");
131
+ emitWhere(schema, table, call.where, sink, "t", 0, true);
132
+ }
133
+ if (call.orderBy !== undefined) {
134
+ emitOrder(table, call.orderBy, sink, "t");
135
+ return;
136
+ }
137
+ sink.text(" order by w.depth asc");
138
+ sink.mark("order:depth");
139
+ for (const field of table.model.primary) {
140
+ const item = table.columns.get(field);
141
+ if (item === undefined)
142
+ continue;
143
+ sink.text(", t.");
144
+ sink.text(quote(item.sql));
145
+ sink.text(" asc");
146
+ }
147
+ }
148
+ function emitKeyList(sink, alias, columns, prefix) {
149
+ for (let index = 0;index < columns.length; index += 1) {
150
+ const name = columns[index];
151
+ if (name === undefined)
152
+ continue;
153
+ if (index > 0 || prefix === "f")
154
+ sink.text(", ");
155
+ sink.text(alias);
156
+ sink.text(".");
157
+ sink.text(quote(name));
158
+ sink.text(" as ");
159
+ sink.text(prefix);
160
+ sink.text(String(index));
161
+ }
162
+ }
163
+ function emitBare(sink, alias, columns, lead) {
164
+ let started = lead;
165
+ for (const name of columns) {
166
+ if (started)
167
+ sink.text(", ");
168
+ started = true;
169
+ sink.text(alias);
170
+ sink.text(".");
171
+ sink.text(quote(name));
172
+ }
173
+ return started;
174
+ }
175
+ function emitStep(sink, alias, columns, against, prefix) {
176
+ for (let index = 0;index < columns.length; index += 1) {
177
+ const name = columns[index];
178
+ if (name === undefined || against[index] === undefined)
179
+ continue;
180
+ if (index > 0)
181
+ sink.text(" and ");
182
+ sink.text(alias);
183
+ sink.text(".");
184
+ sink.text(quote(name));
185
+ sink.text(" = w.");
186
+ sink.text(prefix);
187
+ sink.text(String(index));
188
+ }
189
+ }
190
+ function readPacked(options) {
191
+ if (!isRecord(options) || options.walk !== "descendants" && options.walk !== "ancestors") {
192
+ fail2("OKM1120", "descendants and ancestors are table methods.");
193
+ }
194
+ const user = options.options;
195
+ if (user === undefined)
196
+ return { id: options.id, walk: options.walk, user: {} };
197
+ if (!isRecord(user))
198
+ fail2("OKM1120", `${options.walk} options must be an object.`);
199
+ return { id: options.id, walk: options.walk, user };
200
+ }
201
+ function pickEdge(table, relation) {
202
+ const edges = selfEdges(table);
203
+ if (edges.length === 0) {
204
+ fail2("OKM1120", `${table.model.name} has no relation to itself.`, `Declare children: many("${table.model.name}") or parent: one("${table.model.name}").`);
205
+ }
206
+ const groups = new Set(edges.map((edge) => edge.child.join("\x00")));
207
+ if (relation === undefined) {
208
+ if (groups.size !== 1) {
209
+ fail2("OKM1120", `${table.model.name} has more than one relation to itself. Pass relation.`, `Accepted names: ${edges.map((edge) => edge.name).join(", ")}.`);
210
+ }
211
+ const only = edges[0];
212
+ if (only === undefined)
213
+ fail2("OKM1120", `${table.model.name} has no relation to itself.`);
214
+ return only;
215
+ }
216
+ if (typeof relation !== "string" || relation.length === 0) {
217
+ fail2("OKM1120", "relation must be a name.");
218
+ }
219
+ const found = edges.find((edge) => edge.name === relation);
220
+ if (found === undefined) {
221
+ throwNamed("OKM1120", relation, edges.map((edge) => edge.name), `Relation ${relation} is not a self-relation of ${table.model.name}. Accepted names: ${list(edges.map((edge) => edge.name))}.`);
222
+ }
223
+ return found;
224
+ }
225
+ function selfEdges(table) {
226
+ const edges = [];
227
+ for (const relation of table.model.relations) {
228
+ if (relation.table !== table.model.name || relation.through !== undefined)
229
+ continue;
230
+ edges.push(relation.kind === "many" ? { name: relation.name, parent: relation.local, child: relation.remote } : { name: relation.name, parent: relation.remote, child: relation.local });
231
+ }
232
+ return edges;
233
+ }
234
+ function identityColumn2(session, table) {
235
+ const tenancy = session.schema.tenancy;
236
+ const keys = tenancy === undefined ? [] : tenancy.keys ?? [tenancy.key];
237
+ const fields = table.model.primary.filter((field) => !keys.includes(field));
238
+ if (fields.length !== 1) {
239
+ fail2("OKM1120", `${table.model.name} needs one primary key column besides the tenant key.`, "Use a single-column primary key.");
240
+ }
241
+ const field = fields[0];
242
+ const column = field === undefined ? undefined : table.columns.get(field);
243
+ if (column === undefined) {
244
+ fail2("OKM1120", `${table.model.name} needs one primary key column besides the tenant key.`);
245
+ }
246
+ return column;
247
+ }
248
+ function readDepth(value) {
249
+ if (value === undefined)
250
+ return;
251
+ if (typeof value !== "number" || !Number.isInteger(value) || value < 0) {
252
+ fail2("OKM1120", "depth must be an integer from 0 up.");
253
+ }
254
+ return value;
255
+ }
256
+ function readSelf(value) {
257
+ if (value === undefined)
258
+ return false;
259
+ if (typeof value !== "boolean")
260
+ fail2("OKM1120", "self must be true or false.");
261
+ return value;
262
+ }
263
+ function userId(column, id) {
264
+ if (id === undefined || id === null) {
265
+ fail2("OKM1121", `${column.field} needs a value.`);
266
+ }
267
+ return id;
268
+ }
269
+
270
+ export { build2, identityColumn2 };
@@ -0,0 +1,7 @@
1
+ import {
2
+ build3
3
+ } from "./829fjxyw.js";
4
+ import"./jr2nmr81.js";
5
+ export {
6
+ build3 as build
7
+ };
@@ -0,0 +1,131 @@
1
+ import {
2
+ OkmError,
3
+ writeArray
4
+ } from "./hfq3n3bd.js";
5
+
6
+ // src/dialects/pg/operator-fit.ts
7
+ var FAMILIES = {
8
+ startsWith: ["text"],
9
+ endsWith: ["text"],
10
+ like: ["text"],
11
+ ilike: ["text"],
12
+ contains: ["text", "array", "jsonb", "range"],
13
+ containedBy: ["array", "jsonb", "range"],
14
+ overlaps: ["array", "range"],
15
+ hasKey: ["jsonb"],
16
+ hasAnyKey: ["jsonb"],
17
+ path: ["json", "jsonb"],
18
+ matches: ["tsvector"],
19
+ relevance: ["tsvector"],
20
+ "json.set": ["json", "jsonb"],
21
+ "arr.append": ["array"],
22
+ "arr.remove": ["array"]
23
+ };
24
+ var ACCEPTED = {
25
+ text: [
26
+ "eq",
27
+ "not",
28
+ "lt",
29
+ "lte",
30
+ "gt",
31
+ "gte",
32
+ "between",
33
+ "startsWith",
34
+ "contains",
35
+ "endsWith",
36
+ "like",
37
+ "ilike",
38
+ "inList",
39
+ "notIn"
40
+ ],
41
+ array: [
42
+ "eq",
43
+ "not",
44
+ "contains",
45
+ "containedBy",
46
+ "overlaps",
47
+ "inList",
48
+ "notIn",
49
+ "arr.append",
50
+ "arr.remove"
51
+ ],
52
+ jsonb: ["eq", "not", "contains", "containedBy", "hasKey", "hasAnyKey", "path", "json.set"],
53
+ json: ["eq", "not", "path", "json.set"],
54
+ range: ["eq", "not", "lt", "lte", "gt", "gte", "contains", "containedBy", "overlaps"],
55
+ tsvector: ["eq", "not", "matches", "relevance"],
56
+ scalar: ["eq", "not", "lt", "lte", "gt", "gte", "between", "inList", "notIn", "inc"]
57
+ };
58
+ var SAFE_TYPE = /^[A-Za-z_][A-Za-z0-9_]*(\(\d+\))?(\[\])*$/;
59
+ var REGCONFIG = /^[A-Za-z_][A-Za-z0-9_]*(\.[A-Za-z_][A-Za-z0-9_]*)?$/;
60
+ function columnFamily(dataType) {
61
+ if (dataType.endsWith("[]"))
62
+ return "array";
63
+ if (dataType === "jsonb")
64
+ return "jsonb";
65
+ if (dataType === "json")
66
+ return "json";
67
+ if (dataType === "tsvector")
68
+ return "tsvector";
69
+ if (dataType.endsWith("range"))
70
+ return "range";
71
+ if (dataType === "text" || dataType === "citext" || dataType.startsWith("varchar(") || dataType.startsWith("char(") || dataType.startsWith("character")) {
72
+ return "text";
73
+ }
74
+ return "scalar";
75
+ }
76
+ function assertOperatorFits(column, name) {
77
+ const families = FAMILIES[name];
78
+ if (families === undefined)
79
+ return;
80
+ if (families.includes(columnFamily(column.dataType)))
81
+ return;
82
+ const accepted = ACCEPTED[columnFamily(column.dataType)];
83
+ const search = (name === "matches" || name === "relevance") && columnFamily(column.dataType) === "text" ? " Search needs a column built for search, not a plain text column." : "";
84
+ throw new OkmError("OKM1124", `Operator ${name} does not apply to ${column.dataType} column ${column.field}. Accepted operators: ${accepted.join(", ")}.${search}`, { fix: { summary: `Use one of: ${accepted.join(", ")}.` } });
85
+ }
86
+ function sqlType(dataType, column) {
87
+ if (SAFE_TYPE.test(dataType))
88
+ return dataType;
89
+ assertOperatorFits(column, "contains");
90
+ throw new OkmError("OKM1124", `Operator contains does not apply to ${column.dataType} column ${column.field}. Accepted operators: ${ACCEPTED[columnFamily(column.dataType)].join(", ")}.`, { fix: { summary: "Use a column type this operator accepts." } });
91
+ }
92
+ function assertNoControl(value, role) {
93
+ for (let index = 0;index < value.length; index += 1) {
94
+ const code = value.charCodeAt(index);
95
+ if (code <= 31 || code === 127) {
96
+ throw new OkmError("OKM1122", `${role} contains a control character.`, {
97
+ fix: { summary: "Remove NUL and other control characters. The value is not sent." }
98
+ });
99
+ }
100
+ }
101
+ }
102
+ function assertBoundText(value, role) {
103
+ if (value.length === 0) {
104
+ throw new OkmError("OKM1122", `${role} is empty.`, {
105
+ fix: { summary: "Pass a non-empty key or path segment." }
106
+ });
107
+ }
108
+ assertNoControl(value, role);
109
+ }
110
+ function assertRegconfig(config) {
111
+ if (!REGCONFIG.test(config)) {
112
+ throw new OkmError("OKM1122", `Language ${config} is not a text search language. Pass a name such as english.`, { fix: { summary: "Pass a language name such as english." } });
113
+ }
114
+ }
115
+ function textArray(values, role) {
116
+ for (const value of values)
117
+ assertBoundText(value, role);
118
+ return writeArray(values, 1, (value) => String(value), false);
119
+ }
120
+ function arrayElementType(dataType, column) {
121
+ if (!dataType.endsWith("[]")) {
122
+ assertOperatorFits(column, "arr.append");
123
+ }
124
+ const element = dataType.slice(0, -2);
125
+ if (!SAFE_TYPE.test(element)) {
126
+ throw new OkmError("OKM1124", `Operator arr.append does not apply to ${column.dataType} column ${column.field}. Accepted operators: ${ACCEPTED.array.join(", ")}.`, { fix: { summary: "Use arr.append on an array column." } });
127
+ }
128
+ return element;
129
+ }
130
+
131
+ export { assertOperatorFits, sqlType, assertNoControl, assertBoundText, assertRegconfig, textArray, arrayElementType };
@@ -0,0 +1,157 @@
1
+ import {
2
+ assertNoControl
3
+ } from "./w5d89rb4.js";
4
+ import {
5
+ throwNamed,
6
+ isOperator,
7
+ operatorName,
8
+ operatorValue,
9
+ tag,
10
+ refuseHidden,
11
+ indexes,
12
+ list,
13
+ isRecord,
14
+ fail2
15
+ } from "./hfq3n3bd.js";
16
+
17
+ // src/dialects/pg/ops/search-query.ts
18
+ function searchValue(query, options) {
19
+ return {
20
+ query,
21
+ match: options?.match ?? "natural",
22
+ language: options?.language
23
+ };
24
+ }
25
+
26
+ // src/runtime/text-search.ts
27
+ var MATCHES = ["natural", "all-words", "phrase", "advanced"];
28
+ var SEARCH_KEYS = ["for", "in", "match", "language"];
29
+ function applyTextSearch(schema, call) {
30
+ const table = indexes(schema).get(call.table);
31
+ if (table === undefined)
32
+ fail2("OKM1120", `Table ${call.table} is not in the schema.`);
33
+ const spec = parseSearch(table, call.search);
34
+ const options = { match: spec.match, language: spec.language };
35
+ const where = withMatch(call.where, spec.column.field, spec.text, options);
36
+ const orderBy = call.op === "find" && call.orderBy === undefined ? ranked(table, spec.column.field, spec.text, options) : call.orderBy;
37
+ const { search: dropped, ...rest } = call;
38
+ return {
39
+ ...rest,
40
+ where,
41
+ ...orderBy !== undefined ? { orderBy } : {}
42
+ };
43
+ }
44
+ function parseSearch(table, search) {
45
+ if (typeof search === "string") {
46
+ return { text: textOf(search), column: columnFor(table, undefined), ...natural() };
47
+ }
48
+ if (!isRecord(search)) {
49
+ fail2("OKM1120", "search needs the text to look for, or { for, in, match, language }.", "Pass a string, or search: { for, in }.");
50
+ }
51
+ for (const key of Object.keys(search)) {
52
+ if (SEARCH_KEYS.includes(key))
53
+ continue;
54
+ fail2("OKM1120", `search does not take ${key}. Accepted: for, in, match, language.`, "Pass for, in, match, and language.");
55
+ }
56
+ if (typeof search.for !== "string") {
57
+ fail2("OKM1120", "search.for needs text to look for.", "Set for to the text you want to find.");
58
+ }
59
+ const named = search.in;
60
+ if (named !== undefined && typeof named !== "string") {
61
+ fail2("OKM1120", "search.in names the column to search.", "Set in to a column name.");
62
+ }
63
+ return {
64
+ text: textOf(search.for),
65
+ column: columnFor(table, named),
66
+ match: matchOf(search.match),
67
+ language: languageOf(search.language)
68
+ };
69
+ }
70
+ function natural() {
71
+ return { match: "natural", language: undefined };
72
+ }
73
+ function textOf(text) {
74
+ if (text.length === 0) {
75
+ fail2("OKM1120", "search needs text to look for.", "Pass the words you want to find.");
76
+ }
77
+ assertNoControl(text, "search");
78
+ return text;
79
+ }
80
+ function matchOf(value) {
81
+ if (value === undefined)
82
+ return "natural";
83
+ if (typeof value === "string" && isMatch(value))
84
+ return value;
85
+ fail2("OKM1120", "search.match must be natural, all-words, phrase, or advanced.", "Use natural, all-words, phrase, or advanced.");
86
+ }
87
+ function isMatch(value) {
88
+ return MATCHES.includes(value);
89
+ }
90
+ function languageOf(value) {
91
+ if (value === undefined)
92
+ return;
93
+ if (typeof value !== "string") {
94
+ fail2("OKM1120", "search.language must be a text search language such as english.", "Pass a language name such as english, or leave it out.");
95
+ }
96
+ return value;
97
+ }
98
+ function columnFor(table, name) {
99
+ const columns = searchable(table);
100
+ const names = columns.map((column) => column.field);
101
+ if (name === undefined) {
102
+ const only = columns[0];
103
+ if (columns.length === 1 && only !== undefined)
104
+ return only;
105
+ if (columns.length === 0) {
106
+ fail2("OKM1120", `Table ${table.model.name} has no column you can search.`, "Add a column built for search.");
107
+ }
108
+ 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)}.`);
109
+ }
110
+ const column = table.columns.get(name);
111
+ if (column === undefined) {
112
+ throwNamed("OKM1120", name, names, `Column ${name} is not on ${table.model.name}. Columns you can search: ${list(names)}.`);
113
+ }
114
+ if (column.dataType !== "tsvector") {
115
+ 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)}.`);
116
+ }
117
+ if (column.hidden === true)
118
+ refuseHidden(column);
119
+ return column;
120
+ }
121
+ function searchable(table) {
122
+ const found = [];
123
+ for (const column of table.model.columns) {
124
+ if (column.dataType === "tsvector" && column.hidden !== true)
125
+ found.push(column);
126
+ }
127
+ return found;
128
+ }
129
+ function withMatch(where, field, text, options) {
130
+ const filter = { [field]: tag("matches", searchValue(text, passed(options))) };
131
+ if (where === undefined)
132
+ return filter;
133
+ if (isOperator(where) && operatorName(where) === "and") {
134
+ const branches = operatorValue(where);
135
+ if (Array.isArray(branches))
136
+ return tag("and", [...branches, filter]);
137
+ }
138
+ return tag("and", [where, filter]);
139
+ }
140
+ function ranked(table, field, text, options) {
141
+ const order = {
142
+ [field]: tag("relevance", searchValue(text, passed(options)))
143
+ };
144
+ for (const key of table.model.primary) {
145
+ if (!Object.hasOwn(order, key))
146
+ order[key] = "asc";
147
+ }
148
+ return order;
149
+ }
150
+ function passed(options) {
151
+ if (options.language === undefined)
152
+ return { match: options.match };
153
+ return { match: options.match, language: options.language };
154
+ }
155
+ export {
156
+ applyTextSearch
157
+ };
@@ -0,0 +1,17 @@
1
+ import {
2
+ primaryUrl
3
+ } from "./hfq3n3bd.js";
4
+
5
+ // packages/harness/src/postgres.ts
6
+ import postgres from "postgres";
7
+ function openPostgres(url = primaryUrl()) {
8
+ return postgres(url, {
9
+ max: 1,
10
+ connect_timeout: 5,
11
+ idle_timeout: 1,
12
+ onnotice: () => {}
13
+ });
14
+ }
15
+ export {
16
+ openPostgres
17
+ };
@@ -0,0 +1,12 @@
1
+ import {
2
+ creationOrder2,
3
+ catalogHash2,
4
+ loadTrustedCatalog2,
5
+ catalogFileText2
6
+ } from "./hfq3n3bd.js";
7
+ export {
8
+ catalogFileText2 as catalogFileText,
9
+ catalogHash2 as catalogHash,
10
+ creationOrder2 as creationOrder,
11
+ loadTrustedCatalog2 as loadTrustedCatalog
12
+ };