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,36 @@
1
+ /**
2
+ * `okm driver test`.
3
+ *
4
+ * The runner lives in the harness and reuses the conformance suites. This
5
+ * file only finds that runner and prints what it writes. Tooling does not
6
+ * import the harness.
7
+ */
8
+ /**
9
+ * Runs the conformance suites for the driver named on the command line.
10
+ *
11
+ * `<driver>` is `pglite`, `postgresjs`, `pg`, `bun`, `neon`, or a module path.
12
+ * `--url` is the Postgres URL. `pglite` does not use it. The other built-in
13
+ * drivers need `--url` or `DATABASE_URL`. A module whose export sets
14
+ * `memory: true` does not need a URL.
15
+ *
16
+ * The report is one header (`driver`, `dialect postgres`) and one row per
17
+ * case: id, behavior, result (`pass`, `fail`, or `unsupported`), and the
18
+ * capability when the result is unsupported. A failure exits through
19
+ * {@link OkmError}. An unsupported case does not.
20
+ *
21
+ * @param args - Arguments after `driver test`
22
+ * @param stdout - Where the report is written
23
+ */
24
+ export declare function driverTest(args: readonly string[], stdout: (text: string) => void): Promise<void>;
25
+ /**
26
+ * Path of the `okm driver test` runner.
27
+ *
28
+ * A source checkout finds `packages/harness/src/driver-run.ts` and the
29
+ * command spawns `bun`. The packed build writes
30
+ * `dist/tooling/driver-run.js`. Splitting puts this module in
31
+ * `dist/shared/`, so that file is one directory up from the chunk.
32
+ *
33
+ * @param here - Directory of this module
34
+ * @returns Runner path. The caller checks that the file exists
35
+ */
36
+ export declare function driverRunnerPath(here: string): string;
@@ -0,0 +1,50 @@
1
+ /**
2
+ * Pull-request comment for `okm migrate plan --json` (D279).
3
+ *
4
+ * The text comes from the plan document. It does not read the human plan.
5
+ */
6
+ import { type PlanDocument } from "../migrate/plan-json.js";
7
+ /**
8
+ * Hidden marker that identifies the sticky comment.
9
+ *
10
+ * A later push updates the comment whose body contains this marker.
11
+ */
12
+ export declare const PLAN_COMMENT_MARKER = "<!-- okmodel-migrate-plan -->";
13
+ /** A comment the sticky update may replace. */
14
+ export type StickyComment = {
15
+ readonly id: number;
16
+ readonly body: string;
17
+ };
18
+ /**
19
+ * Renders the plan comment.
20
+ *
21
+ * The first heading is the strictest class. Each step is one table row
22
+ * with its class and lock. The lock is the plan's lock line, including a
23
+ * row estimate when the plan printed one. Lint findings keep their codes.
24
+ *
25
+ * @param plan - Document from `okm migrate plan --json`
26
+ * @returns Markdown, including {@link PLAN_COMMENT_MARKER}
27
+ */
28
+ export declare function renderPlanComment(plan: PlanDocument): string;
29
+ /**
30
+ * Comment body for a plan file, or a status line when the file is not a document.
31
+ *
32
+ * The status line records exit codes only. It does not include command text.
33
+ *
34
+ * @param text - Stdout of `okm migrate plan --json`, when the file exists
35
+ * @param checkStatus - Exit code of `okm migrate check`
36
+ * @param planStatus - Exit code of `okm migrate plan --json`
37
+ * @returns The comment body
38
+ */
39
+ export declare function planCommentBody(text: string | undefined, checkStatus: string, planStatus: string): string;
40
+ /**
41
+ * The comment to update, when one already carries the marker.
42
+ *
43
+ * The first match wins. A missing match means the caller creates a comment.
44
+ *
45
+ * @param comments - Comments already on the pull request
46
+ * @returns The id to update, or `undefined` to create one
47
+ */
48
+ export declare function stickyCommentTarget(comments: readonly StickyComment[]): {
49
+ readonly updateId: number;
50
+ } | undefined;
@@ -0,0 +1,17 @@
1
+ /**
2
+ * Creates or updates the sticky plan comment (D279).
3
+ *
4
+ * Uses `GITHUB_TOKEN` only. The workflow needs `pull-requests: write`.
5
+ * The token is not written to stdout or stderr.
6
+ */
7
+ /**
8
+ * Posts the plan comment for one pull request.
9
+ *
10
+ * An existing comment that contains the marker is updated. Otherwise a
11
+ * comment is created. The body comes from {@link planCommentBody}.
12
+ *
13
+ * @param planPath - File written by `okm migrate plan --json`
14
+ * @param checkStatus - Exit code of `okm migrate check`
15
+ * @param planStatus - Exit code of `okm migrate plan --json`
16
+ */
17
+ export declare function postPlanComment(planPath: string, checkStatus: string, planStatus: string): Promise<void>;
@@ -22,8 +22,9 @@ export declare function formatFailure(error: unknown, verbose?: boolean): string
22
22
  * Runs one `okm` invocation.
23
23
  *
24
24
  * `--version` stays in the bin. This function handles `build`, `check`,
25
- * `generate`, `dev`, `push`, `seed`, `ext list`, `ext check`, `doctor`, and
26
- * `migrate plan`, `apply`, `status`, and `check`.
25
+ * `generate`, `dev`, `push`, `seed`, `ext list`, `ext check`, `ext scaffold`,
26
+ * `ext test`, `doctor`,
27
+ * `driver test`, and `migrate plan`, `apply`, `status`, and `check`.
27
28
  *
28
29
  * @param argv - Arguments after the program name
29
30
  * @param io - Working directory and stdout. Defaults to the process
@@ -45,6 +45,19 @@ export type MigrateConfig = {
45
45
  * migration.
46
46
  */
47
47
  readonly lintFrom?: string;
48
+ /**
49
+ * Postgres schema this catalog owns.
50
+ *
51
+ * Omitted means `public`. `schema()` still compiles `public`. Tooling
52
+ * places the catalog here before it plans, and stores `okm_meta` here.
53
+ */
54
+ readonly namespace?: string;
55
+ /**
56
+ * Snapshots from `okm catalog export`, one path per owning catalog.
57
+ *
58
+ * `external()` tables are verified against these files.
59
+ */
60
+ readonly external?: readonly string[];
48
61
  /**
49
62
  * Batched backfill (D195).
50
63
  *
@@ -0,0 +1,165 @@
1
+ /**
2
+ * `okm catalog export` and the check that a dependent catalog runs.
3
+ *
4
+ * The snapshot is derived from the schema source. It stores the catalog
5
+ * hash and, separately, a logical identity. It has no function and no
6
+ * connection URL. Column names and types are what a dependent verifies.
7
+ */
8
+ import type { Catalog } from "../../contracts/catalog/types.js";
9
+ import type { MigrateConfig } from "./config.js";
10
+ import type { Finding } from "./lint.js";
11
+ /** Snapshot file format. Not the logical schema format. */
12
+ export declare const EXPORT_FORMAT = 1;
13
+ /** Logical schema format. A hash change does not move this. */
14
+ export declare const LOGICAL_FORMAT = 1;
15
+ /** One column a dependent verifies. No default and no expression. */
16
+ export type ExportColumn = {
17
+ readonly name: string;
18
+ readonly type: string;
19
+ readonly nullable: boolean;
20
+ };
21
+ /** One table in a snapshot. */
22
+ export type ExportTable = {
23
+ readonly namespace: string;
24
+ readonly name: string;
25
+ readonly columns: readonly ExportColumn[];
26
+ };
27
+ /**
28
+ * Logical schema identity.
29
+ *
30
+ * `namespace` and `name` name the schema. `format` is {@link LOGICAL_FORMAT}.
31
+ * None of these is the catalog hash.
32
+ */
33
+ export type LogicalIdentity = {
34
+ readonly namespace: string;
35
+ readonly name: string;
36
+ readonly format: typeof LOGICAL_FORMAT;
37
+ };
38
+ /**
39
+ * A catalog snapshot.
40
+ *
41
+ * `catalogHash` is the physical identity. `logical` is not that hash.
42
+ * `database` is the database name only, never a URL.
43
+ */
44
+ export type CatalogSnapshot = {
45
+ readonly format: typeof EXPORT_FORMAT;
46
+ readonly logical: LogicalIdentity;
47
+ readonly catalogHash: string;
48
+ readonly database?: string;
49
+ readonly tables: readonly ExportTable[];
50
+ };
51
+ /**
52
+ * Builds a snapshot from a placed catalog.
53
+ *
54
+ * @param source - Catalog tooling plans, after namespace placement
55
+ * @param namespace - `defineConfig({ namespace })`, or `public`
56
+ * @param database - Database name, when the config has a target URL
57
+ * @returns A snapshot with no functions and no connection URL
58
+ */
59
+ export declare function snapshotFromCatalog(source: Catalog, namespace: string, database?: string): CatalogSnapshot;
60
+ /**
61
+ * Serializes a snapshot.
62
+ *
63
+ * The same catalog returns the same bytes, including the trailing newline.
64
+ *
65
+ * @param snapshot - Snapshot to write
66
+ * @returns UTF-8 JSON
67
+ */
68
+ export declare function serializeSnapshot(snapshot: CatalogSnapshot): string;
69
+ /**
70
+ * Reads a snapshot file.
71
+ *
72
+ * A missing file and a file that is not this format are OKM1841.
73
+ *
74
+ * @param path - Absolute or project-relative path, as the message should name it
75
+ * @param text - File contents
76
+ * @returns The snapshot
77
+ */
78
+ export declare function parseSnapshot(path: string, text: string): CatalogSnapshot;
79
+ /**
80
+ * Database name from a Postgres URL.
81
+ *
82
+ * The user, password, host, and query are not returned.
83
+ *
84
+ * @param url - Target URL
85
+ * @returns The path segment, or `undefined` when the URL has none
86
+ */
87
+ export declare function databaseName(url: string): string | undefined;
88
+ /**
89
+ * Namespace `defineConfig` asked for.
90
+ *
91
+ * Omitted means `public`.
92
+ *
93
+ * @param config - Project config
94
+ * @returns The schema name
95
+ */
96
+ export declare function catalogNamespace(config: MigrateConfig): string;
97
+ /**
98
+ * Loads the snapshots named by `defineConfig({ external })`.
99
+ *
100
+ * A missing path is OKM1841.
101
+ *
102
+ * @param cwd - Project directory
103
+ * @param config - Project config
104
+ * @returns One snapshot per path, in config order
105
+ */
106
+ export declare function loadSnapshots(cwd: string, config: MigrateConfig): readonly LoadedSnapshot[];
107
+ /** A snapshot and the config path that named it. */
108
+ export type LoadedSnapshot = {
109
+ readonly path: string;
110
+ readonly snapshot: CatalogSnapshot;
111
+ };
112
+ /**
113
+ * SQL table name to the namespace recorded in a snapshot.
114
+ *
115
+ * @param snapshots - Loaded exports
116
+ * @returns The map `placeCatalog` reads
117
+ */
118
+ export declare function externalNamespaceMap(snapshots: readonly LoadedSnapshot[]): ReadonlyMap<string, string>;
119
+ /**
120
+ * Cross-catalog foreign keys, as `okm check` warnings.
121
+ *
122
+ * A key inside one namespace is not coupling. The warning does not fail the check.
123
+ *
124
+ * @param source - Placed catalog
125
+ * @returns One warning per foreign key whose namespaces differ
126
+ */
127
+ export declare function couplingFindings(source: Catalog): readonly Finding[];
128
+ /**
129
+ * Checks external tables against the snapshot files.
130
+ *
131
+ * This does not open a connection. With no `external` paths, a
132
+ * `withOwner(..., "external")` table stays hands-off and is not OKM1841.
133
+ * When paths are set, a missing file, a table the snapshots do not list,
134
+ * or columns that differ is OKM1841.
135
+ *
136
+ * @param cwd - Project directory
137
+ * @param config - Project config
138
+ * @param source - Placed catalog
139
+ */
140
+ export declare function assertSnapshots(cwd: string, config: MigrateConfig, source: Catalog): void;
141
+ /**
142
+ * Checks external tables against the connected database.
143
+ *
144
+ * A different database name on a cross-catalog foreign key is OKM1842.
145
+ * A hash or column mismatch is a stale snapshot. A missing relation is
146
+ * a missing object. Both are OKM1841.
147
+ *
148
+ * @param url - Target URL
149
+ * @param source - Placed catalog
150
+ * @param snapshots - Files {@link assertSnapshots} already read
151
+ */
152
+ export declare function assertLiveExternal(url: string, source: Catalog, snapshots: readonly LoadedSnapshot[]): Promise<void>;
153
+ /**
154
+ * Writes the snapshot for one project.
155
+ *
156
+ * `--json` prints the bytes. `--out` writes them. With neither, the bytes
157
+ * are printed.
158
+ *
159
+ * @param cwd - Project directory
160
+ * @param config - Project config
161
+ * @param source - Placed catalog
162
+ * @param args - Arguments after `export`
163
+ * @returns Stdout, including a trailing newline
164
+ */
165
+ export declare function renderExport(cwd: string, config: MigrateConfig, source: Catalog, args: readonly string[]): string;
@@ -0,0 +1,80 @@
1
+ /**
2
+ * Catalog reads shared by `okm ext scaffold` and `okm ext test`.
3
+ *
4
+ * Both are read-only. The queries are `pg_depend`, `pg_type`, `pg_proc`,
5
+ * `pg_operator`, and `pg_settings`. Nothing is created.
6
+ */
7
+ import type { DriverPool } from "../../contracts/driver.js";
8
+ import type { Extension, ExtensionFunction, ExtensionIndexMethod, ExtensionOperator, ExtensionProvides, ExtensionType } from "../../dialects/pg/ext/index.js";
9
+ /** One extension as the connected server describes it. */
10
+ export type ServerSurface = {
11
+ readonly name: string;
12
+ readonly version: string;
13
+ readonly schema: string;
14
+ readonly relocatable: boolean;
15
+ readonly serverMajor: number;
16
+ readonly types: readonly ExtensionType[];
17
+ readonly operators: readonly ExtensionOperator[];
18
+ readonly functions: readonly ExtensionFunction[];
19
+ readonly indexMethods: readonly ExtensionIndexMethod[];
20
+ readonly settings: readonly string[];
21
+ };
22
+ /**
23
+ * Reads one installed extension.
24
+ *
25
+ * A name that is not installed is OKM1811. The connection is not asked to
26
+ * create it.
27
+ *
28
+ * @param pool - Connected server
29
+ * @param name - Extension name
30
+ * @returns The catalog surface
31
+ */
32
+ export declare function readSurface(pool: DriverPool, name: string): Promise<ServerSurface>;
33
+ /**
34
+ * Prints a starting `extension()` definition.
35
+ *
36
+ * The developer owns the file. `requires` and `provides` are the fields
37
+ * `okm ext test` reads. Settings are a comment, because they are not part
38
+ * of the definition.
39
+ *
40
+ * @param surface - Catalog read
41
+ * @returns TypeScript source, including the trailing newline
42
+ */
43
+ export declare function renderScaffold(surface: ServerSurface): string;
44
+ /**
45
+ * Lists mismatches between a definition and the server.
46
+ *
47
+ * An empty list means the definition matches. Version failures and signature
48
+ * failures are both lines in that list.
49
+ *
50
+ * @param declared - The loaded `extension()` value
51
+ * @param server - The catalog read for `declared.name`
52
+ * @returns Mismatch lines, stable order
53
+ */
54
+ export declare function surfaceMismatches(declared: Extension, server: ServerSurface): readonly string[];
55
+ /**
56
+ * Throws when {@link surfaceMismatches} found any line.
57
+ *
58
+ * Version lines are OKM1812. A signature line is `invalid`. Both are listed
59
+ * in the message.
60
+ *
61
+ * @param name - Extension name
62
+ * @param mismatches - Lines from {@link surfaceMismatches}
63
+ */
64
+ export declare function refuseMismatches(name: string, mismatches: readonly string[]): void;
65
+ /**
66
+ * Reports whether a value is an `extension()` result.
67
+ *
68
+ * @param value - A module export
69
+ * @returns `true` when it has a name and `contribute`
70
+ */
71
+ export declare function isExtension(value: unknown): value is Extension;
72
+ /**
73
+ * Reads `extension()` values exported by a loaded module.
74
+ *
75
+ * @param imported - Module namespace
76
+ * @returns The definitions, in export order
77
+ */
78
+ export declare function extensionsFromModule(imported: unknown): readonly Extension[];
79
+ /** Provides kept on the type so a scaffold round-trip can name them. */
80
+ export type { ExtensionProvides };
@@ -1,9 +1,10 @@
1
1
  /**
2
- * `okm ext list` and `okm ext check`.
2
+ * `okm ext list`, `check`, `scaffold`, and `test`.
3
3
  *
4
- * Both talk to the selected target. List prints every extension the server
5
- * can install, and the installed version when one is present. Check compares
6
- * the schema's declarations with what is installed.
4
+ * All four talk to the selected target and are read-only, including on a
5
+ * protected target. List prints every extension the server can install.
6
+ * Check compares the schema's declarations with what is installed. Scaffold
7
+ * prints a starting definition. Test checks that definition against the server.
7
8
  */
8
9
  import { type InvokeFlags } from "./policy.js";
9
10
  /**
@@ -15,3 +16,29 @@ import { type InvokeFlags } from "./policy.js";
15
16
  * @returns Text for stdout, including the trailing newline
16
17
  */
17
18
  export declare function extProject(cwd: string, command: "list" | "check", flags: InvokeFlags): Promise<string>;
19
+ /**
20
+ * Prints a starting definition for one installed extension.
21
+ *
22
+ * `--out` writes the file when that path does not exist. An existing file
23
+ * is refused and nothing is written. Without `--out`, the text is returned
24
+ * for stdout.
25
+ *
26
+ * @param cwd - Project directory
27
+ * @param name - Extension name
28
+ * @param flags - Target and protection flags
29
+ * @param out - File to write, when the caller passed `--out`
30
+ * @returns The definition, or a one-line wrote message
31
+ */
32
+ export declare function extScaffold(cwd: string, name: string, flags: InvokeFlags, out?: string): Promise<string>;
33
+ /**
34
+ * Checks one definition file against the connected server.
35
+ *
36
+ * Every declared type, operator, function, and index method must exist with
37
+ * the declared signature. `requires` must be met (OKM1812).
38
+ *
39
+ * @param cwd - Project directory
40
+ * @param file - Definition file, relative to `cwd` or absolute
41
+ * @param flags - Target and protection flags
42
+ * @returns `ok <name>` for each definition
43
+ */
44
+ export declare function extTest(cwd: string, file: string, flags: InvokeFlags): Promise<string>;
@@ -0,0 +1,40 @@
1
+ /**
2
+ * `okm import drizzle` reads a Drizzle schema and writes table files.
3
+ *
4
+ * The schema is imported with the project's own `drizzle-orm`. That import
5
+ * runs the file. okmodel does not depend on drizzle-orm. The catalog is
6
+ * written by the same emitter as `okm pull`.
7
+ */
8
+ import { type PullSkip } from "./pull-emit.js";
9
+ /** What `okm import drizzle` prints, and the objects the files leave out. */
10
+ export type ImportDrizzleResult = {
11
+ /** Report text, including the trailing newline. */
12
+ readonly text: string;
13
+ /** Objects that were not written. */
14
+ readonly skipped: readonly PullSkip[];
15
+ /** Postgres schema the tables share. `schema()` still compiles `public`. */
16
+ readonly namespace: string;
17
+ };
18
+ /**
19
+ * Imports a Drizzle schema and writes one table file per table, plus the schema file.
20
+ *
21
+ * The path is a module in the project. `--out` is the directory that receives
22
+ * `schema.ts` and `tables/`. Without it, an `okmodel.config.ts` in `cwd`
23
+ * supplies the layout. A project that has no config yet writes `schema.ts`
24
+ * and `tables/` in `cwd`.
25
+ *
26
+ * @param cwd - Project directory the files are written into
27
+ * @param argv - Arguments after `import drizzle`
28
+ * @returns The report and the Postgres schema name
29
+ */
30
+ export declare function importDrizzle(cwd: string, argv: readonly string[]): Promise<ImportDrizzleResult>;
31
+ /**
32
+ * Reads the schema path and `--out`.
33
+ *
34
+ * @param argv - Arguments after `import drizzle`
35
+ * @returns The path and the optional output directory
36
+ */
37
+ export declare function parseImportArgs(argv: readonly string[]): {
38
+ readonly path: string;
39
+ readonly out: string | undefined;
40
+ };
@@ -2,7 +2,10 @@
2
2
  * Public entry for `okmodel/migrate`.
3
3
  *
4
4
  * `defineConfig`, its types, and `provision` for one configured target.
5
+ * `describe` and `buildCatalog` are the programmatic schema API.
5
6
  * The CLI imports planning and apply helpers from their modules.
6
7
  */
7
8
  export { defineConfig, type MigrateConfig, type TargetInput } from "./config.js";
9
+ export { type LogicalIdentity } from "./export.js";
10
+ export { buildCatalog, describe, type SchemaDescription } from "./schema-api.js";
8
11
  export { provision } from "./provision.js";
@@ -1,35 +1,78 @@
1
- import"../../shared/14vx95q4.js";
2
- import"../../shared/qq3899ht.js";
1
+ import {
2
+ serializeCatalog2,
3
+ parseCatalog2
4
+ } from "../../shared/12z7aznj.js";
5
+ import"../../shared/fk9vef30.js";
6
+ import"../../shared/dd5pmnky.js";
3
7
  import"../../shared/n442h54c.js";
4
8
  import {
5
9
  applyTarget2,
6
10
  backfillTiming2
7
- } from "../../shared/p6qc5gcp.js";
11
+ } from "../../shared/ccsmhv9r.js";
8
12
  import {
9
13
  readReference
10
- } from "../../shared/m6p12kbr.js";
11
- import"../../shared/8skf0cam.js";
12
- import"../../shared/b5pftnn2.js";
14
+ } from "../../shared/3456242y.js";
15
+ import"../../shared/jpybhf98.js";
16
+ import"../../shared/myk8fswx.js";
13
17
  import {
14
18
  projectPath,
19
+ LOGICAL_FORMAT,
15
20
  loadMigrations,
16
21
  loadHeadSnapshot,
17
22
  loadBuiltSchema,
18
23
  loadConfig
19
- } from "../../shared/gs74dbj5.js";
24
+ } from "../../shared/2zdxkt7b.js";
20
25
  import {
21
26
  assertTargetPolicy,
22
27
  selectTarget
23
- } from "../../shared/tsvww22q.js";
24
- import"../../shared/9s0ypp87.js";
28
+ } from "../../shared/6nae0spm.js";
29
+ import {
30
+ canonicalJson
31
+ } from "../../shared/358zsv4r.js";
25
32
  import {
26
- OkmError2
33
+ OkmError2,
34
+ catalogError2
27
35
  } from "../../shared/52szzakm.js";
28
36
 
29
37
  // src/tooling/migrate/config.ts
30
38
  function defineConfig(config) {
31
39
  return config;
32
40
  }
41
+ // src/tooling/migrate/schema-api.ts
42
+ var LOGICAL_NAMESPACE = "public";
43
+ function describe(schema) {
44
+ const source = schemaCatalog(schema);
45
+ const document = JSON.parse(serializeCatalog2(source));
46
+ const text = canonicalJson({
47
+ catalog: document,
48
+ logical: {
49
+ format: LOGICAL_FORMAT,
50
+ name: LOGICAL_NAMESPACE,
51
+ namespace: LOGICAL_NAMESPACE
52
+ }
53
+ });
54
+ return JSON.parse(text);
55
+ }
56
+ function buildCatalog(description) {
57
+ if (description === null || typeof description !== "object" || !("catalog" in description)) {
58
+ catalogError2("OKM1027", "Catalog document is not an object.");
59
+ }
60
+ const body = description.catalog;
61
+ if (body === null || typeof body !== "object") {
62
+ catalogError2("OKM1027", "Catalog document is not an object.");
63
+ }
64
+ return parseCatalog2(JSON.stringify(body));
65
+ }
66
+ function schemaCatalog(schema) {
67
+ if (schema === null || typeof schema !== "object") {
68
+ catalogError2("OKM1020", "describe() needs the schema() result.");
69
+ }
70
+ const catalog = schema.catalog;
71
+ if (typeof catalog !== "object" || catalog === null || !("objects" in catalog)) {
72
+ catalogError2("OKM1020", "describe() needs the schema() result.");
73
+ }
74
+ return catalog;
75
+ }
33
76
  // src/tooling/migrate/provision.ts
34
77
  async function provision(target, cwd = process.cwd()) {
35
78
  const config = await loadConfig(cwd);
@@ -71,6 +114,8 @@ ${report.applied.map((id) => `applied ${id}`).join(`
71
114
  `;
72
115
  }
73
116
  export {
117
+ buildCatalog,
74
118
  defineConfig,
119
+ describe,
75
120
  provision
76
121
  };
@@ -42,10 +42,27 @@ export type ColumnRule = {
42
42
  * Step rules, lowest free code in each category.
43
43
  *
44
44
  * OKM1534 to OKM1537 are errors when the statement is not the safe form.
45
- * OKM1538 stays a warning: a rewriting type change has no safe form here.
45
+ * OKM1538 stays a warning, and only when the type change rewrites the table.
46
46
  */
47
47
  export declare const STEP_RULES: readonly StepRule[];
48
48
  /**
49
49
  * Type preferences. Warnings, read from the schema catalog by `okm check`.
50
50
  */
51
51
  export declare const COLUMN_RULES: readonly ColumnRule[];
52
+ /**
53
+ * Collapses whitespace and lowercases SQL outside quoted identifiers.
54
+ *
55
+ * @param sql - One statement
56
+ * @returns The comparison form
57
+ */
58
+ export declare function normalizedSql(sql: string): string;
59
+ /**
60
+ * A create or alter of a domain, or a `LANGUAGE sql` function.
61
+ *
62
+ * Offline lint cannot see the reprint. The allow is still for that statement.
63
+ * `okm migrate check` decides whether the text actually differs.
64
+ *
65
+ * @param sql - One statement
66
+ * @returns `true` when OKM1552 can fire for this statement
67
+ */
68
+ export declare function statementMayReprint(sql: string): boolean;
@@ -8,7 +8,7 @@
8
8
  import type { Catalog } from "../../contracts/catalog/types.js";
9
9
  import { OkmError } from "../../contracts/error.js";
10
10
  import { type LintSeverity } from "./lint-rules.js";
11
- import type { MigrationPlan } from "./plan.js";
11
+ import type { MigrationPlan, PlanStep } from "./plan.js";
12
12
  /** One finding. `place` is `step N`, `step N statement M`, or `table.column`. */
13
13
  export type Finding = {
14
14
  readonly severity: LintSeverity;
@@ -26,6 +26,19 @@ export type Finding = {
26
26
  * @returns Findings in step order, then code order
27
27
  */
28
28
  export declare function lintPlan(plan: MigrationPlan, before: Catalog, after: Catalog): readonly Finding[];
29
+ /**
30
+ * Warns when a replayed domain check or `LANGUAGE sql` body reprints.
31
+ *
32
+ * Called from `okm migrate check` after introspection. A warning does not
33
+ * fail the command. An allow with an empty reason, or a code the replay did
34
+ * not trigger, is OKM1510.
35
+ *
36
+ * @param declared - Catalog stored with the migration
37
+ * @param stored - Catalog read back from the scratch schema
38
+ * @param steps - Statements of that migration, including `-- okm-allow`
39
+ * @returns Findings in catalog order
40
+ */
41
+ export declare function lintReprints(declared: Catalog, stored: Catalog, steps: readonly PlanStep[]): readonly Finding[];
29
42
  /**
30
43
  * Lints type preferences on the author catalog.
31
44
  *
@@ -0,0 +1,18 @@
1
+ /**
2
+ * Places a `schema()` catalog into the namespace from `defineConfig`.
3
+ *
4
+ * `schema()` compiles `public`. Planning reads this copy, so two catalogs
5
+ * on one database do not share table identities. An `external` table keeps
6
+ * the namespace from its snapshot. A catalog that is already `public` and
7
+ * has no external namespace is returned as itself, so its hash does not change.
8
+ */
9
+ import type { Catalog } from "../../contracts/catalog/types.js";
10
+ /**
11
+ * Rewrites managed objects into `namespace` and external tables into `externalNamespaces`.
12
+ *
13
+ * @param source - Catalog from `schema()`, after ownership is stamped
14
+ * @param namespace - Postgres schema this catalog owns. `public` is the default
15
+ * @param externalNamespaces - SQL table name to the owning catalog's namespace
16
+ * @returns `source` when nothing moves, otherwise a new catalog
17
+ */
18
+ export declare function placeCatalog(source: Catalog, namespace: string, externalNamespaces: ReadonlyMap<string, string>): Catalog;