okmodel 0.8.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 (202) hide show
  1. package/README.md +14 -0
  2. package/dist/dialects/pg/ext/btree-gin.d.ts +26 -0
  3. package/dist/dialects/pg/ext/btree-gin.js +20 -0
  4. package/dist/dialects/pg/ext/btree-gist.d.ts +26 -0
  5. package/dist/dialects/pg/ext/btree-gist.js +20 -0
  6. package/dist/dialects/pg/ext/call.d.ts +53 -0
  7. package/dist/dialects/pg/ext/citext.js +1 -1
  8. package/dist/dialects/pg/ext/feature.d.ts +26 -0
  9. package/dist/dialects/pg/ext/fuzzystrmatch.d.ts +34 -0
  10. package/dist/dialects/pg/ext/fuzzystrmatch.js +33 -0
  11. package/dist/dialects/pg/ext/hstore.d.ts +41 -0
  12. package/dist/dialects/pg/ext/hstore.js +29 -0
  13. package/dist/dialects/pg/ext/index.d.ts +56 -0
  14. package/dist/dialects/pg/ext/index.js +1 -1
  15. package/dist/dialects/pg/ext/ltree.d.ts +41 -0
  16. package/dist/dialects/pg/ext/ltree.js +29 -0
  17. package/dist/dialects/pg/ext/pg-trgm.js +4 -13
  18. package/dist/dialects/pg/ext/pgcrypto.d.ts +33 -0
  19. package/dist/dialects/pg/ext/pgcrypto.js +33 -0
  20. package/dist/dialects/pg/ext/unaccent.d.ts +26 -0
  21. package/dist/dialects/pg/ext/unaccent.js +21 -0
  22. package/dist/dialects/pg/ext/using.d.ts +23 -0
  23. package/dist/dialects/pg/ext/versions.d.ts +36 -0
  24. package/dist/dialects/pg/external.d.ts +19 -0
  25. package/dist/dialects/pg/fn/index.js +4 -4
  26. package/dist/dialects/pg/index.d.ts +1 -0
  27. package/dist/dialects/pg/index.js +16 -11
  28. package/dist/dialects/pg/view/index.js +5 -5
  29. package/dist/dialects/pg/view/scratch.d.ts +4 -1
  30. package/dist/runtime/artifact-file.d.ts +22 -0
  31. package/dist/runtime/client.d.ts +10 -0
  32. package/dist/runtime/drift-detail.d.ts +2 -1
  33. package/dist/runtime/drift.d.ts +3 -10
  34. package/dist/runtime/pg/bun.js +4 -4
  35. package/dist/runtime/pg/neon.js +4 -4
  36. package/dist/runtime/pg/pg.js +4 -4
  37. package/dist/runtime/pg/pglite.js +4 -4
  38. package/dist/runtime/pg/postgresjs.js +4 -4
  39. package/dist/runtime/server-check.d.ts +36 -6
  40. package/dist/runtime/traits/index.js +5 -5
  41. package/dist/runtime/validate/index.js +1 -1
  42. package/dist/shared/{4m6hskg8.js → 0j6qe91y.js} +4 -4
  43. package/dist/shared/{14x60fbf.js → 1mxm04fy.js} +5 -5
  44. package/dist/shared/{b6d6p0zc.js → 2szgv6yj.js} +5 -5
  45. package/dist/shared/{f4jy1j7x.js → 2zdxkt7b.js} +909 -100
  46. package/dist/shared/{mnvjvqyp.js → 3456242y.js} +17 -17
  47. package/dist/shared/3t6kw83m.js +1 -1
  48. package/dist/shared/{6m78c8ss.js → 5kyb3tqx.js} +1 -1
  49. package/dist/shared/61bmrmhr.js +35 -0
  50. package/dist/shared/{zbqbmmrp.js → 62b603gr.js} +8 -8
  51. package/dist/shared/{jgqj11w4.js → 6f0z3hzh.js} +4 -0
  52. package/dist/shared/{dpc2r7rb.js → 6nae0spm.js} +150 -89
  53. package/dist/shared/{0wrea3jq.js → 71n0jmhc.js} +1 -1
  54. package/dist/shared/7ba5h6pb.js +17 -0
  55. package/dist/shared/{k86n8vq3.js → 8jesqsrk.js} +1 -1
  56. package/dist/shared/{qd9hhd8f.js → 8n688yjg.js} +1 -1
  57. package/dist/shared/{zgex00fd.js → 8qzkd9f3.js} +5 -5
  58. package/dist/shared/{mkrn359n.js → 90sg0w5a.js} +159 -31
  59. package/dist/shared/{7ghwamrf.js → 99qp9vtg.js} +1 -1
  60. package/dist/shared/{bxas03mq.js → 9dtgn1z2.js} +1 -1
  61. package/dist/shared/{p5nh3r8q.js → aksb89mn.js} +2 -2
  62. package/dist/shared/{wcrheftc.js → bphrgwz9.js} +2 -2
  63. package/dist/shared/{wz2a78mp.js → c3mvnq7a.js} +1 -1
  64. package/dist/shared/{pan0370z.js → ccsmhv9r.js} +24 -6
  65. package/dist/shared/{n0jmpgj1.js → cexb7z6b.js} +1 -1
  66. package/dist/shared/{wvdjznah.js → cf8zdz5p.js} +5 -5
  67. package/dist/shared/{3449rcae.js → ckz05z15.js} +4 -4
  68. package/dist/shared/{35q0n9tz.js → dd5pmnky.js} +7 -7
  69. package/dist/shared/{e8zyaqvj.js → ds229x4r.js} +1 -1
  70. package/dist/{tooling/shared/yw30vnq2.js → shared/e275q7sd.js} +1 -1
  71. package/dist/shared/{mfedzr74.js → ebhz8vh6.js} +4 -4
  72. package/dist/shared/{z581d7ny.js → fdsz3w80.js} +2 -2
  73. package/dist/shared/{sjk86yrx.js → fk9vef30.js} +84 -73
  74. package/dist/shared/{needfe47.js → g89fmz5s.js} +1 -1
  75. package/dist/shared/{m4xff2a6.js → ghqzdp94.js} +2 -2
  76. package/dist/shared/h9811jjm.js +17 -0
  77. package/dist/shared/{kj9d8maq.js → jpybhf98.js} +1 -1
  78. package/dist/shared/kzgrnckd.js +29 -0
  79. package/dist/shared/{agsfb86s.js → mazpbcdj.js} +4 -4
  80. package/dist/shared/{195pzzzz.js → mgaq2sd3.js} +10 -7
  81. package/dist/shared/{5mtf6cj3.js → mvmm3xpb.js} +5 -2
  82. package/dist/shared/{p3xbdcvt.js → myk8fswx.js} +55 -6
  83. package/dist/shared/{njga14v4.js → n306gqkd.js} +8 -8
  84. package/dist/shared/n5whk3mt.js +665 -0
  85. package/dist/shared/{bah9nbg3.js → npdftanb.js} +12 -20
  86. package/dist/shared/{16kvjebh.js → pg4ezgyf.js} +7 -26
  87. package/dist/{tooling/shared/08kemxjd.js → shared/pgsak1yw.js} +1 -1
  88. package/dist/shared/{jp36k7dp.js → qvwwp1mp.js} +61 -40
  89. package/dist/shared/rbxt795q.js +1766 -0
  90. package/dist/shared/{g5yc06ka.js → s7he5e5d.js} +1 -1
  91. package/dist/shared/{hfqmpasr.js → ss2kv2rs.js} +5 -5
  92. package/dist/shared/stfa9xcw.js +450 -0
  93. package/dist/{tooling/shared/rs1jb051.js → shared/tr64w5p0.js} +1 -1
  94. package/dist/shared/{jebgrkeq.js → tw1nvvfj.js} +2 -2
  95. package/dist/shared/{v1wad97q.js → wvtjg5m3.js} +1 -1
  96. package/dist/shared/xqacq37x.js +61 -0
  97. package/dist/shared/{n05z9nwz.js → xtsydxjg.js} +1 -1
  98. package/dist/shared/{jx2m62cs.js → xv8qj97g.js} +5 -5
  99. package/dist/shared/{63f4ksbz.js → xwhdcrm4.js} +1 -1
  100. package/dist/shared/{hm5f8jby.js → yvabyg9k.js} +6 -6
  101. package/dist/shared/yybhre6n.js +136 -0
  102. package/dist/shared/zdqf8k5d.js +8 -0
  103. package/dist/tooling/cli.js +94 -22
  104. package/dist/tooling/driver-run.js +15 -332
  105. package/dist/tooling/github/comment.d.ts +50 -0
  106. package/dist/tooling/github/post-comment.d.ts +17 -0
  107. package/dist/tooling/migrate/commands.d.ts +2 -1
  108. package/dist/tooling/migrate/config.d.ts +13 -0
  109. package/dist/tooling/migrate/export.d.ts +165 -0
  110. package/dist/tooling/migrate/ext-surface.d.ts +80 -0
  111. package/dist/tooling/migrate/ext.d.ts +31 -4
  112. package/dist/tooling/migrate/import-drizzle.d.ts +40 -0
  113. package/dist/tooling/migrate/index.d.ts +3 -0
  114. package/dist/tooling/migrate/index.js +55 -10
  115. package/dist/tooling/migrate/lint-rules.d.ts +18 -1
  116. package/dist/tooling/migrate/lint.d.ts +14 -1
  117. package/dist/tooling/migrate/place.d.ts +18 -0
  118. package/dist/tooling/migrate/plan-json.d.ts +65 -0
  119. package/dist/tooling/migrate/project.d.ts +10 -1
  120. package/dist/tooling/migrate/pull-emit.d.ts +98 -0
  121. package/dist/tooling/migrate/pull-routines.d.ts +126 -0
  122. package/dist/tooling/migrate/pull-verify.d.ts +26 -0
  123. package/dist/tooling/migrate/pull.d.ts +62 -0
  124. package/dist/tooling/migrate/reprint.d.ts +32 -0
  125. package/dist/tooling/migrate/sandbox.d.ts +8 -2
  126. package/dist/tooling/migrate/schema-api.d.ts +43 -0
  127. package/dist/tooling/migrate/sql-lex.d.ts +18 -0
  128. package/dist/tooling/shared/{3m1hkg7z.js → 04svnxxj.js} +4 -4
  129. package/dist/tooling/shared/{ppnnnvj8.js → 0j0jtse1.js} +1 -1
  130. package/dist/tooling/shared/{z8d7ptht.js → 0r05zhyq.js} +5 -5
  131. package/dist/tooling/shared/{a6pp9d12.js → 1800eymw.js} +3 -3
  132. package/dist/tooling/shared/{cmptmb4f.js → 35zemrmf.js} +1 -1
  133. package/dist/tooling/shared/{w7qe8sj1.js → 3rmaz3pq.js} +1 -1
  134. package/dist/{shared/q0cqt2sp.js → tooling/shared/3yn79q5m.js} +1 -1
  135. package/dist/tooling/shared/{2revefqt.js → 57btdkgm.js} +2 -2
  136. package/dist/tooling/shared/{ma2340rx.js → 5bmksndh.js} +2 -2
  137. package/dist/tooling/shared/{9xzm7hjg.js → 5p8km5jb.js} +3 -3
  138. package/dist/tooling/shared/{xhrnjch9.js → 5x3pf400.js} +3 -3
  139. package/dist/tooling/shared/{wwnekq5n.js → 5zrzffnk.js} +1 -1
  140. package/dist/tooling/shared/{p7f08ktn.js → 62fxpc1p.js} +7 -7
  141. package/dist/tooling/shared/{7ae7rjmn.js → 68tf18v4.js} +2 -2
  142. package/dist/tooling/shared/{rf83gr2d.js → 6vk28rjp.js} +7 -3
  143. package/dist/tooling/shared/76pv6qff.js +9 -0
  144. package/dist/tooling/shared/{bz2dqhab.js → 7aews1zg.js} +3 -3
  145. package/dist/tooling/shared/{9kazs5p6.js → 7b3xp9gc.js} +3 -3
  146. package/dist/tooling/shared/{4d2w25vw.js → 7pxncnzs.js} +2 -2
  147. package/dist/tooling/shared/{zvnhh1n0.js → 829fjxyw.js} +2 -2
  148. package/dist/tooling/shared/{dzx85q70.js → 8m5znpdt.js} +1 -1
  149. package/dist/tooling/shared/{g9ad4n80.js → 8yr7ges1.js} +7 -7
  150. package/dist/tooling/shared/{tn8gay14.js → 9qr9rkbh.js} +6 -6
  151. package/dist/tooling/shared/{8sqrsw3s.js → 9sfbtwsk.js} +3 -3
  152. package/dist/{shared/bnby0esn.js → tooling/shared/9wsnsvbf.js} +1 -1
  153. package/dist/tooling/shared/{aftb2mwr.js → a2xe04bm.js} +1 -1
  154. package/dist/tooling/shared/{nf7jmhfa.js → a4pzghha.js} +2 -2
  155. package/dist/tooling/shared/{y5656f0e.js → am04v8na.js} +5 -5
  156. package/dist/tooling/shared/{417zdsk7.js → asgr07mp.js} +5 -5
  157. package/dist/tooling/shared/{pqy21k24.js → c0xevn1h.js} +4 -4
  158. package/dist/tooling/shared/dhatassp.js +134 -0
  159. package/dist/tooling/shared/{spk1jg3r.js → ezqn88nj.js} +8 -8
  160. package/dist/tooling/shared/{6nyfyw70.js → f77nnfqy.js} +2 -2
  161. package/dist/tooling/shared/{wt7j7nf6.js → fh07z1dt.js} +1 -1
  162. package/dist/tooling/shared/{3rrw5w8f.js → gqwevek4.js} +1 -1
  163. package/dist/tooling/shared/{f9mphxej.js → hfq3n3bd.js} +346 -19
  164. package/dist/tooling/shared/{vs0t6qt8.js → j664qjrt.js} +2 -2
  165. package/dist/tooling/shared/{733a1tq3.js → jpgmjsx3.js} +3 -3
  166. package/dist/tooling/shared/{mtrqn2hn.js → jr2nmr81.js} +22 -30
  167. package/dist/{shared/mtw6jz76.js → tooling/shared/jsjjz875.js} +1 -1
  168. package/dist/tooling/shared/{2wtvc7rw.js → kbqnrs1x.js} +2 -2
  169. package/dist/tooling/shared/{gfvtj6d0.js → kz715295.js} +7 -7
  170. package/dist/tooling/shared/{a7q7t4n3.js → m3xt8b1h.js} +2 -2
  171. package/dist/tooling/shared/{dw08f3m8.js → m4hhb8aa.js} +2 -2
  172. package/dist/tooling/shared/{y031jct9.js → mw5npye0.js} +2 -2
  173. package/dist/tooling/shared/{vraj6d74.js → nxq95eb6.js} +3 -3
  174. package/dist/tooling/shared/{fb9k2qwd.js → qartgazh.js} +11 -30
  175. package/dist/tooling/shared/{xjs6zqtc.js → rcywj2w8.js} +9 -9
  176. package/dist/tooling/shared/{dy672fz6.js → s6qha57m.js} +2 -2
  177. package/dist/tooling/shared/{vx86qjv8.js → shjs0379.js} +3 -3
  178. package/dist/tooling/shared/{345tbc2k.js → sjwkt1pg.js} +1 -1
  179. package/dist/tooling/shared/{rq5kk8j6.js → stebqyyd.js} +3 -3
  180. package/dist/tooling/shared/{yk9mp7vb.js → t4xveemq.js} +4 -4
  181. package/dist/tooling/shared/{djydjpqt.js → t6zjeake.js} +5 -5
  182. package/dist/tooling/shared/{zhwnfyb2.js → tcwpjvxe.js} +1 -1
  183. package/dist/tooling/shared/{72fyg4zv.js → tpssp7ac.js} +1 -1
  184. package/dist/tooling/shared/{jne7b93p.js → v6j1ep6w.js} +3 -3
  185. package/dist/tooling/shared/{ec71zqgt.js → vwr2y833.js} +2 -2
  186. package/dist/tooling/shared/{j9t5s12a.js → w17sj05d.js} +2 -2
  187. package/dist/tooling/shared/{3tq8pnb8.js → w5d89rb4.js} +1 -1
  188. package/dist/tooling/shared/{smn6kz1p.js → wbwq1jsa.js} +2 -2
  189. package/dist/tooling/shared/{pwsytxm5.js → wezxf3h8.js} +1 -1
  190. package/dist/tooling/shared/{5bvw2nev.js → yb4kd19s.js} +1 -1
  191. package/dist/tooling/shared/{gmcf9cxf.js → ybdew6j7.js} +2 -2
  192. package/dist/tooling/shared/{ep8zh3bk.js → yfedr1zb.js} +1 -1
  193. package/dist/tooling/shared/{ddjtfgnx.js → yhp829bx.js} +3 -3
  194. package/dist/tooling/shared/{yfr8hzhm.js → ytk1tjs0.js} +1 -1
  195. package/dist/tooling/shared/{03k6res6.js → zs9aymcp.js} +1 -1
  196. package/dist/tooling/shared/zx3v9phv.js +8 -0
  197. package/dist/tooling/testing/index.js +2 -2
  198. package/package.json +38 -9
  199. package/dist/shared/fjpnhqan.js +0 -71
  200. package/dist/shared/n41w4fbz.js +0 -113
  201. package/dist/tooling/shared/pw8fgahx.js +0 -69
  202. /package/dist/shared/{ae4j5f42.js → mfvx6kjx.js} +0 -0
@@ -0,0 +1,136 @@
1
+ import {
2
+ POSTGRES_FLOOR,
3
+ isPostgresMajor,
4
+ parsePostgresFloor,
5
+ serverNeedsPostgres
6
+ } from "./ga9j92qj.js";
7
+ import {
8
+ withHttp,
9
+ attachHttp,
10
+ mapOptions
11
+ } from "./npdftanb.js";
12
+ import {
13
+ OkmError2
14
+ } from "./52szzakm.js";
15
+
16
+ // src/runtime/artifact-file.ts
17
+ function artifactDir(catalogDir) {
18
+ if (catalogDir !== undefined)
19
+ return catalogDir.replace(/[/\\]+$/, "");
20
+ const cwd = globalThis.process?.cwd?.() ?? ".";
21
+ return `${cwd}/.okm`;
22
+ }
23
+ async function readText(path) {
24
+ const bun = globalThis.Bun;
25
+ if (bun !== undefined) {
26
+ const file = bun.file(path);
27
+ if (!await file.exists())
28
+ return;
29
+ return file.text();
30
+ }
31
+ const loader = globalThis.process?.getBuiltinModule;
32
+ if (loader === undefined)
33
+ return;
34
+ try {
35
+ return await loader("node:fs/promises").readFile(path, "utf8");
36
+ } catch {
37
+ return;
38
+ }
39
+ }
40
+
41
+ // src/runtime/server-check.ts
42
+ var versionQuery = "select current_setting('server_version_num'), version(), (select (xpath('//catalog_hash/text()', query_to_xml('select catalog_hash from okm_meta where id = ''head''', true, false, '')))[1]::text where to_regclass('okm_meta') is not null)";
43
+ var historyQuery = "select migration_id, class, catalog_hash from okm_history order by migration_id, step_index";
44
+ async function versionSql(namespace) {
45
+ if (namespace === "public")
46
+ return versionQuery;
47
+ const relation = await qualified("okm_meta", namespace);
48
+ const literal = relation.replaceAll("'", "''");
49
+ return `select current_setting('server_version_num'), version(), (select (xpath('//catalog_hash/text()', query_to_xml('select catalog_hash from ${literal} where id = ''head''', true, false, '')))[1]::text where to_regclass('${literal}') is not null)`;
50
+ }
51
+ async function historySql2(namespace) {
52
+ if (namespace === "public")
53
+ return historyQuery;
54
+ return `select migration_id, class, catalog_hash from ${await qualified("okm_history", namespace)} order by migration_id, step_index`;
55
+ }
56
+ async function recordedNamespace(catalogDir) {
57
+ const text = await readText(`${artifactDir(catalogDir)}/namespace`);
58
+ if (text === undefined)
59
+ return "public";
60
+ const line = text.trim();
61
+ if (line === "" || line === "public")
62
+ return "public";
63
+ if (line.includes("\x00") || line.includes(`
64
+ `) || line.includes("\r")) {
65
+ throw new OkmError2("OKM1122", "The catalog namespace file is not one identifier.", {
66
+ fix: { summary: "Run okm build so .okm/namespace is the schema from defineConfig." }
67
+ });
68
+ }
69
+ return line;
70
+ }
71
+ async function acceptServer2(pool, schema, http, requireMeta, options, source) {
72
+ const namespace = await recordedNamespace(source.catalogDir);
73
+ let rows;
74
+ try {
75
+ const result = await pool.execute(await versionSql(namespace), undefined, options);
76
+ rows = result.rows;
77
+ } catch (error) {
78
+ const { mapPostgresError } = await import("./63qtkrca.js");
79
+ throw mapPostgresError(error, mapOptions(http, false, schema));
80
+ }
81
+ for (const name in schema.model) {
82
+ if (schema.model[name]?.presets !== undefined) {
83
+ (await import("./m7n9h2a5.js")).checkSchema(schema);
84
+ break;
85
+ }
86
+ }
87
+ const version = rows[0]?.[1];
88
+ if (version === null || version === undefined || !version.startsWith("PostgreSQL")) {
89
+ throw new OkmError2("OKM1801", "The server is not PostgreSQL. The schema dialect is postgres.", withHttp(http, {
90
+ fix: { summary: "Open the schema with the Postgres driver that matches it." }
91
+ }));
92
+ }
93
+ const recorded = rows[0]?.[2];
94
+ if (recorded === null || recorded === undefined || recorded.length === 0) {
95
+ if (requireMeta) {
96
+ throw new OkmError2("OKM1520", "okm_meta has no catalog hash.", withHttp(http, {
97
+ fix: {
98
+ summary: "Apply migrations so okm_meta records the catalog, or omit requireMeta to adopt this database."
99
+ }
100
+ }));
101
+ }
102
+ } else {
103
+ const { assertCompatible } = await import("./pg4ezgyf.js");
104
+ try {
105
+ await assertCompatible(pool, schema, recorded, source, options, namespace);
106
+ } catch (error) {
107
+ if (error instanceof OkmError2)
108
+ throw attachHttp(http, error);
109
+ throw error;
110
+ }
111
+ }
112
+ const major = Math.floor(Number(rows[0]?.[0] ?? "0") / 1e4);
113
+ const raw = schema.requires?.postgres;
114
+ if (raw === undefined) {
115
+ if (major < POSTGRES_FLOOR) {
116
+ throw new OkmError2("OKM1803", serverNeedsPostgres(major, POSTGRES_FLOOR), withHttp(http, {
117
+ fix: {
118
+ summary: `Upgrade to PostgreSQL ${String(POSTGRES_FLOOR)} or higher.`
119
+ }
120
+ }));
121
+ }
122
+ return;
123
+ }
124
+ const need = parsePostgresFloor(raw);
125
+ if (!isPostgresMajor(need) || major < need) {
126
+ throw new OkmError2("OKM1802", serverNeedsPostgres(major, isPostgresMajor(need) ? need : POSTGRES_FLOOR), withHttp(http, {
127
+ fix: { summary: "Upgrade the server, or lower minPostgres to a major the server meets." }
128
+ }));
129
+ }
130
+ }
131
+ async function qualified(table, namespace) {
132
+ const { quoteIdent } = await import("./61bmrmhr.js");
133
+ return `${quoteIdent(namespace)}.${table}`;
134
+ }
135
+
136
+ export { artifactDir, readText, historySql2, acceptServer2 };
@@ -0,0 +1,8 @@
1
+ import {
2
+ historySql2,
3
+ acceptServer2
4
+ } from "./yybhre6n.js";
5
+ export {
6
+ acceptServer2 as acceptServer,
7
+ historySql2 as historySql
8
+ };
@@ -1,6 +1,7 @@
1
1
  import"../shared/12z7aznj.js";
2
2
  import"../shared/n442h54c.js";
3
- import"../shared/35q0n9tz.js";
3
+ import"../shared/fk9vef30.js";
4
+ import"../shared/dd5pmnky.js";
4
5
  import {
5
6
  formatFindings,
6
7
  hasError,
@@ -8,12 +9,12 @@ import {
8
9
  buildProject,
9
10
  generateProject,
10
11
  planProject,
11
- checkProject
12
- } from "../shared/f4jy1j7x.js";
12
+ checkProject,
13
+ exportProject
14
+ } from "../shared/2zdxkt7b.js";
13
15
  import {
14
16
  sessionFailure
15
- } from "../shared/dpc2r7rb.js";
16
- import"../shared/sjk86yrx.js";
17
+ } from "../shared/6nae0spm.js";
17
18
  import {
18
19
  OkmError2
19
20
  } from "../shared/52szzakm.js";
@@ -53,6 +54,16 @@ async function run(argv, io) {
53
54
  `);
54
55
  return;
55
56
  }
57
+ if (command === "catalog") {
58
+ const sub = rest[0];
59
+ if (sub !== "export") {
60
+ throw new OkmError2("invalid", `Unknown command catalog ${sub ?? ""}.`, {
61
+ fix: { summary: "Use okm catalog export." }
62
+ });
63
+ }
64
+ stdout(await exportProject(cwd, rest.slice(1)));
65
+ return;
66
+ }
56
67
  if (command === "check") {
57
68
  const findings = await checkProject(cwd, invoke(splitFlags(rest)));
58
69
  const warnings = formatFindings(findings);
@@ -73,41 +84,62 @@ async function run(argv, io) {
73
84
  return;
74
85
  }
75
86
  if (command === "dev") {
76
- const { devProject } = await import("../shared/zgex00fd.js");
87
+ const { devProject } = await import("../shared/8qzkd9f3.js");
77
88
  stdout(await devProject(cwd));
78
89
  return;
79
90
  }
80
91
  if (command === "push") {
81
- const { pushProject } = await import("../shared/njga14v4.js");
92
+ const { pushProject } = await import("../shared/n306gqkd.js");
82
93
  stdout(await pushProject(cwd, invoke(splitFlags(rest))));
83
94
  return;
84
95
  }
96
+ if (command === "pull") {
97
+ const { pullProject } = await import("../shared/7ba5h6pb.js");
98
+ stdout((await pullProject(cwd, rest)).text);
99
+ return;
100
+ }
101
+ if (command === "import") {
102
+ const sub = rest[0];
103
+ if (sub !== "drizzle") {
104
+ throw new OkmError2("invalid", `Unknown command import ${sub ?? ""}.`, {
105
+ fix: { summary: "Use okm import drizzle <path>." }
106
+ });
107
+ }
108
+ const { importDrizzle } = await import("../shared/n5whk3mt.js");
109
+ stdout((await importDrizzle(cwd, rest.slice(1))).text);
110
+ return;
111
+ }
85
112
  if (command === "migrate") {
86
113
  const sub = rest[0];
87
- const parsed = splitFlags(rest.slice(1));
114
+ const migrateArgs = rest.slice(1);
115
+ const parsed = splitFlags(sub === "plan" ? migrateArgs.filter((arg) => arg !== "--json") : migrateArgs);
88
116
  if (sub === "plan") {
89
117
  if (parsed.name === undefined) {
90
118
  throw new OkmError2("invalid", "okm migrate plan needs a name.");
91
119
  }
92
120
  const planned = await planProject(cwd, parsed.name, parsed.flags, invoke(parsed));
93
- stdout(planned.text);
94
- stdout(formatFindings(planned.findings));
121
+ if (migrateArgs.includes("--json"))
122
+ stdout(planned.json);
123
+ else {
124
+ stdout(planned.text);
125
+ stdout(formatFindings(planned.findings));
126
+ }
95
127
  if (hasError(planned.findings))
96
128
  throw lintRefusal(planned.findings);
97
129
  return;
98
130
  }
99
131
  if (sub === "apply") {
100
- const { applyProject } = await import("../shared/njga14v4.js");
132
+ const { applyProject } = await import("../shared/n306gqkd.js");
101
133
  stdout(await applyProject(cwd, invoke(parsed), stdout));
102
134
  return;
103
135
  }
104
136
  if (sub === "status") {
105
- const { statusProject } = await import("../shared/195pzzzz.js");
137
+ const { statusProject } = await import("../shared/mgaq2sd3.js");
106
138
  stdout(await statusProject(cwd, invoke(parsed)));
107
139
  return;
108
140
  }
109
141
  if (sub === "check") {
110
- const { checkMigrations } = await import("../shared/jp36k7dp.js");
142
+ const { checkMigrations } = await import("../shared/qvwwp1mp.js");
111
143
  const provision = parsed.flags.includes("--provision") || rest.slice(1).includes("--provision");
112
144
  stdout(await checkMigrations(cwd, invoke(parsed), { provision }));
113
145
  return;
@@ -120,13 +152,13 @@ async function run(argv, io) {
120
152
  fix: { summary: "Pass okm seed <file>." }
121
153
  });
122
154
  }
123
- const { seedProject } = await import("../shared/hfqmpasr.js");
155
+ const { seedProject } = await import("../shared/ss2kv2rs.js");
124
156
  stdout(await seedProject(cwd, parsed.name, invoke(parsed)));
125
157
  return;
126
158
  }
127
159
  if (command === "doctor") {
128
160
  const parsed = splitFlags(rest);
129
- const { doctorProject } = await import("../shared/hm5f8jby.js");
161
+ const { doctorProject } = await import("../shared/yvabyg9k.js");
130
162
  stdout(await doctorProject(cwd, parsed.name, invoke(parsed)));
131
163
  return;
132
164
  }
@@ -144,22 +176,54 @@ async function run(argv, io) {
144
176
  }
145
177
  if (command === "ext") {
146
178
  const sub = rest[0];
147
- if (sub === "test" || sub === "scaffold") {
148
- throw new OkmError2("invalid", `okm ext ${sub} is not available yet.`, {
149
- fix: { summary: "okm ext list and okm ext check are the commands in this version." }
150
- });
179
+ if (sub === "scaffold" || sub === "test") {
180
+ const parsed = extInvocation(rest.slice(1));
181
+ const { extScaffold, extTest } = await import("../shared/stfa9xcw.js");
182
+ const text = sub === "scaffold" ? await extScaffold(cwd, requireName(parsed, "okm ext scaffold <name>"), parsed.flags, parsed.out) : await extTest(cwd, requireName(parsed, "okm ext test <file>"), parsed.flags);
183
+ stdout(text);
184
+ return;
151
185
  }
152
186
  if (sub === "list" || sub === "check") {
153
- const { extProject } = await import("../shared/n41w4fbz.js");
187
+ const { extProject } = await import("../shared/stfa9xcw.js");
154
188
  stdout(await extProject(cwd, sub, invoke(splitFlags(rest.slice(1)))));
155
189
  return;
156
190
  }
157
191
  throw new OkmError2("invalid", `Unknown command ext ${sub ?? ""}.`, {
158
- fix: { summary: "Use okm ext list or okm ext check." }
192
+ fix: { summary: "Use okm ext list, okm ext check, okm ext scaffold, or okm ext test." }
159
193
  });
160
194
  }
161
195
  throw new OkmError2("invalid", `Unknown command ${command ?? ""}.`);
162
196
  }
197
+ function requireName(parsed, usage) {
198
+ if (parsed.name === undefined || parsed.name.length === 0) {
199
+ throw new OkmError2("invalid", `${usage} needs a name.`, {
200
+ fix: { summary: `Pass ${usage}.` }
201
+ });
202
+ }
203
+ return parsed.name;
204
+ }
205
+ function extInvocation(args) {
206
+ const rest = [];
207
+ let out;
208
+ for (let index = 0;index < args.length; index += 1) {
209
+ const arg = args[index] ?? "";
210
+ if (arg === "--out" || arg.startsWith("--out=")) {
211
+ const value = arg === "--out" ? args[index + 1] : arg.slice("--out=".length);
212
+ if (value === undefined || value.length === 0 || value.startsWith("--")) {
213
+ throw new OkmError2("invalid", "--out needs a file.", {
214
+ fix: { summary: "Pass --out <file>. The command never overwrites." }
215
+ });
216
+ }
217
+ out = value;
218
+ if (arg === "--out")
219
+ index += 1;
220
+ continue;
221
+ }
222
+ rest.push(arg);
223
+ }
224
+ const parsed = splitFlags(rest);
225
+ return { name: parsed.name, out, flags: invoke(parsed) };
226
+ }
163
227
  function invoke(parsed) {
164
228
  return {
165
229
  ...parsed.target !== undefined ? { target: parsed.target } : {},
@@ -240,18 +304,26 @@ function splitFlags(args) {
240
304
  }
241
305
  var COMMANDS = [
242
306
  ["build", "Write the schema build."],
307
+ ["catalog export", "Write the catalog snapshot."],
243
308
  ["check", "Lint the schema and compare it with one target."],
244
309
  ["dev", "Watch the schema and reload."],
245
310
  ["doctor [code]", "Print a target report, or one error code."],
246
311
  ["driver test <driver>", "Run conformance against one driver."],
247
312
  ["ext list", "List extensions the server can install."],
248
313
  ["ext check", "Compare declared extensions with the server."],
314
+ ["ext scaffold <name>", "Print a starting extension() definition."],
315
+ ["ext test <file>", "Check an extension() definition against the server."],
249
316
  ["generate [name]", "Write the next migration."],
250
- ["migrate plan <name>", "Print the plan and its lock estimates."],
317
+ [
318
+ "import drizzle <path>",
319
+ "Import a Drizzle schema. This runs that file. Writes table files and needs no database."
320
+ ],
321
+ ["migrate plan <name>", "Print the plan and its lock estimates. --json prints a document."],
251
322
  ["migrate apply", "Apply pending migrations."],
252
323
  ["migrate status", "Print whether the target is current."],
253
324
  ["migrate check", "Replay migration history in a scratch schema."],
254
325
  ["push", "Apply the schema diff to one target."],
326
+ ["pull", "Write table files and a schema from one database."],
255
327
  ["seed <file>", "Run a seed file on one target."]
256
328
  ];
257
329
  function commandsTable() {