@intentius/sql-yodeler 0.0.0-stage → 0.1.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 (264) hide show
  1. package/LICENSE +202 -0
  2. package/README.md +110 -2
  3. package/dist/bin.d.ts +2 -0
  4. package/dist/bin.js +14 -0
  5. package/dist/bin.js.map +1 -0
  6. package/dist/chant/apply.d.ts +51 -0
  7. package/dist/chant/apply.js +104 -0
  8. package/dist/chant/apply.js.map +1 -0
  9. package/dist/chant/build.d.ts +34 -0
  10. package/dist/chant/build.js +48 -0
  11. package/dist/chant/build.js.map +1 -0
  12. package/dist/chant/drift.d.ts +44 -0
  13. package/dist/chant/drift.js +91 -0
  14. package/dist/chant/drift.js.map +1 -0
  15. package/dist/chant/plan.d.ts +45 -0
  16. package/dist/chant/plan.js +61 -0
  17. package/dist/chant/plan.js.map +1 -0
  18. package/dist/chant/process.d.ts +41 -0
  19. package/dist/chant/process.js +87 -0
  20. package/dist/chant/process.js.map +1 -0
  21. package/dist/cli.d.ts +4 -0
  22. package/dist/cli.js +59 -0
  23. package/dist/cli.js.map +1 -0
  24. package/dist/command.d.ts +17 -0
  25. package/dist/command.js +13 -0
  26. package/dist/command.js.map +1 -0
  27. package/dist/commands/apply.d.ts +3 -0
  28. package/dist/commands/apply.js +306 -0
  29. package/dist/commands/apply.js.map +1 -0
  30. package/dist/commands/drift.d.ts +3 -0
  31. package/dist/commands/drift.js +38 -0
  32. package/dist/commands/drift.js.map +1 -0
  33. package/dist/commands/index.d.ts +3 -0
  34. package/dist/commands/index.js +22 -0
  35. package/dist/commands/index.js.map +1 -0
  36. package/dist/commands/init.d.ts +3 -0
  37. package/dist/commands/init.js +135 -0
  38. package/dist/commands/init.js.map +1 -0
  39. package/dist/commands/lint.d.ts +3 -0
  40. package/dist/commands/lint.js +193 -0
  41. package/dist/commands/lint.js.map +1 -0
  42. package/dist/commands/new.d.ts +3 -0
  43. package/dist/commands/new.js +168 -0
  44. package/dist/commands/new.js.map +1 -0
  45. package/dist/commands/plan.d.ts +3 -0
  46. package/dist/commands/plan.js +171 -0
  47. package/dist/commands/plan.js.map +1 -0
  48. package/dist/commands/rebase.d.ts +3 -0
  49. package/dist/commands/rebase.js +167 -0
  50. package/dist/commands/rebase.js.map +1 -0
  51. package/dist/commands/repair.d.ts +3 -0
  52. package/dist/commands/repair.js +117 -0
  53. package/dist/commands/repair.js.map +1 -0
  54. package/dist/commands/status.d.ts +7 -0
  55. package/dist/commands/status.js +54 -0
  56. package/dist/commands/status.js.map +1 -0
  57. package/dist/config/define.d.ts +50 -0
  58. package/dist/config/define.js +20 -0
  59. package/dist/config/define.js.map +1 -0
  60. package/dist/config/index.d.ts +11 -0
  61. package/dist/config/index.js +12 -0
  62. package/dist/config/index.js.map +1 -0
  63. package/dist/config/load.d.ts +17 -0
  64. package/dist/config/load.js +102 -0
  65. package/dist/config/load.js.map +1 -0
  66. package/dist/config/settings.d.ts +40 -0
  67. package/dist/config/settings.js +88 -0
  68. package/dist/config/settings.js.map +1 -0
  69. package/dist/env-args.d.ts +18 -0
  70. package/dist/env-args.js +62 -0
  71. package/dist/env-args.js.map +1 -0
  72. package/dist/history/client.d.ts +17 -0
  73. package/dist/history/client.js +19 -0
  74. package/dist/history/client.js.map +1 -0
  75. package/dist/history/ddl.d.ts +58 -0
  76. package/dist/history/ddl.js +100 -0
  77. package/dist/history/ddl.js.map +1 -0
  78. package/dist/history/index.d.ts +25 -0
  79. package/dist/history/index.js +26 -0
  80. package/dist/history/index.js.map +1 -0
  81. package/dist/history/lock.d.ts +100 -0
  82. package/dist/history/lock.js +224 -0
  83. package/dist/history/lock.js.map +1 -0
  84. package/dist/history/postgres/ddl.d.ts +22 -0
  85. package/dist/history/postgres/ddl.js +47 -0
  86. package/dist/history/postgres/ddl.js.map +1 -0
  87. package/dist/history/postgres/index.d.ts +12 -0
  88. package/dist/history/postgres/index.js +13 -0
  89. package/dist/history/postgres/index.js.map +1 -0
  90. package/dist/history/postgres/lock.d.ts +48 -0
  91. package/dist/history/postgres/lock.js +95 -0
  92. package/dist/history/postgres/lock.js.map +1 -0
  93. package/dist/history/postgres/store.d.ts +39 -0
  94. package/dist/history/postgres/store.js +68 -0
  95. package/dist/history/postgres/store.js.map +1 -0
  96. package/dist/history/rows.d.ts +96 -0
  97. package/dist/history/rows.js +73 -0
  98. package/dist/history/rows.js.map +1 -0
  99. package/dist/history/store.d.ts +72 -0
  100. package/dist/history/store.js +134 -0
  101. package/dist/history/store.js.map +1 -0
  102. package/dist/history/topology.d.ts +41 -0
  103. package/dist/history/topology.js +54 -0
  104. package/dist/history/topology.js.map +1 -0
  105. package/dist/index.d.ts +10 -0
  106. package/dist/index.js +10 -0
  107. package/dist/index.js.map +1 -0
  108. package/dist/init/adopt.d.ts +70 -0
  109. package/dist/init/adopt.js +138 -0
  110. package/dist/init/adopt.js.map +1 -0
  111. package/dist/init/baseline.d.ts +61 -0
  112. package/dist/init/baseline.js +88 -0
  113. package/dist/init/baseline.js.map +1 -0
  114. package/dist/init/files.d.ts +23 -0
  115. package/dist/init/files.js +77 -0
  116. package/dist/init/files.js.map +1 -0
  117. package/dist/init/index.d.ts +16 -0
  118. package/dist/init/index.js +17 -0
  119. package/dist/init/index.js.map +1 -0
  120. package/dist/init/live.d.ts +28 -0
  121. package/dist/init/live.js +45 -0
  122. package/dist/init/live.js.map +1 -0
  123. package/dist/lint/check.d.ts +81 -0
  124. package/dist/lint/check.js +208 -0
  125. package/dist/lint/check.js.map +1 -0
  126. package/dist/lint/config.d.ts +21 -0
  127. package/dist/lint/config.js +43 -0
  128. package/dist/lint/config.js.map +1 -0
  129. package/dist/lint/index.d.ts +31 -0
  130. package/dist/lint/index.js +43 -0
  131. package/dist/lint/index.js.map +1 -0
  132. package/dist/lint/project-rules.d.ts +19 -0
  133. package/dist/lint/project-rules.js +32 -0
  134. package/dist/lint/project-rules.js.map +1 -0
  135. package/dist/lint/report.d.ts +7 -0
  136. package/dist/lint/report.js +48 -0
  137. package/dist/lint/report.js.map +1 -0
  138. package/dist/lint/rules.d.ts +53 -0
  139. package/dist/lint/rules.js +42 -0
  140. package/dist/lint/rules.js.map +1 -0
  141. package/dist/lint/silences.d.ts +49 -0
  142. package/dist/lint/silences.js +91 -0
  143. package/dist/lint/silences.js.map +1 -0
  144. package/dist/lint/statements.d.ts +38 -0
  145. package/dist/lint/statements.js +120 -0
  146. package/dist/lint/statements.js.map +1 -0
  147. package/dist/migrations/checksum.d.ts +56 -0
  148. package/dist/migrations/checksum.js +72 -0
  149. package/dist/migrations/checksum.js.map +1 -0
  150. package/dist/migrations/create.d.ts +73 -0
  151. package/dist/migrations/create.js +119 -0
  152. package/dist/migrations/create.js.map +1 -0
  153. package/dist/migrations/directory.d.ts +119 -0
  154. package/dist/migrations/directory.js +225 -0
  155. package/dist/migrations/directory.js.map +1 -0
  156. package/dist/migrations/document.d.ts +83 -0
  157. package/dist/migrations/document.js +82 -0
  158. package/dist/migrations/document.js.map +1 -0
  159. package/dist/migrations/index.d.ts +20 -0
  160. package/dist/migrations/index.js +21 -0
  161. package/dist/migrations/index.js.map +1 -0
  162. package/dist/pr/comment.d.ts +32 -0
  163. package/dist/pr/comment.js +99 -0
  164. package/dist/pr/comment.js.map +1 -0
  165. package/dist/pr/forge.d.ts +50 -0
  166. package/dist/pr/forge.js +105 -0
  167. package/dist/pr/forge.js.map +1 -0
  168. package/dist/pr/model.d.ts +91 -0
  169. package/dist/pr/model.js +113 -0
  170. package/dist/pr/model.js.map +1 -0
  171. package/dist/pr/render.d.ts +27 -0
  172. package/dist/pr/render.js +246 -0
  173. package/dist/pr/render.js.map +1 -0
  174. package/dist/project.d.ts +62 -0
  175. package/dist/project.js +92 -0
  176. package/dist/project.js.map +1 -0
  177. package/dist/rebase/index.d.ts +121 -0
  178. package/dist/rebase/index.js +390 -0
  179. package/dist/rebase/index.js.map +1 -0
  180. package/dist/rebase/repair.d.ts +41 -0
  181. package/dist/rebase/repair.js +68 -0
  182. package/dist/rebase/repair.js.map +1 -0
  183. package/dist/replay/clickhouse.d.ts +33 -0
  184. package/dist/replay/clickhouse.js +106 -0
  185. package/dist/replay/clickhouse.js.map +1 -0
  186. package/dist/replay/index.d.ts +36 -0
  187. package/dist/replay/index.js +54 -0
  188. package/dist/replay/index.js.map +1 -0
  189. package/dist/replay/postgres.d.ts +31 -0
  190. package/dist/replay/postgres.js +140 -0
  191. package/dist/replay/postgres.js.map +1 -0
  192. package/dist/replay/replay.d.ts +114 -0
  193. package/dist/replay/replay.js +98 -0
  194. package/dist/replay/replay.js.map +1 -0
  195. package/dist/replay/report.d.ts +18 -0
  196. package/dist/replay/report.js +72 -0
  197. package/dist/replay/report.js.map +1 -0
  198. package/dist/steps/backfill.d.ts +128 -0
  199. package/dist/steps/backfill.js +307 -0
  200. package/dist/steps/backfill.js.map +1 -0
  201. package/dist/steps/index.d.ts +52 -0
  202. package/dist/steps/index.js +52 -0
  203. package/dist/steps/index.js.map +1 -0
  204. package/dist/steps/kinds.d.ts +101 -0
  205. package/dist/steps/kinds.js +143 -0
  206. package/dist/steps/kinds.js.map +1 -0
  207. package/dist/steps/postgres-migration.d.ts +95 -0
  208. package/dist/steps/postgres-migration.js +149 -0
  209. package/dist/steps/postgres-migration.js.map +1 -0
  210. package/dist/steps/rebuild.d.ts +97 -0
  211. package/dist/steps/rebuild.js +162 -0
  212. package/dist/steps/rebuild.js.map +1 -0
  213. package/dist/steps/run.d.ts +45 -0
  214. package/dist/steps/run.js +72 -0
  215. package/dist/steps/run.js.map +1 -0
  216. package/dist/topology/render.d.ts +17 -0
  217. package/dist/topology/render.js +17 -0
  218. package/dist/topology/render.js.map +1 -0
  219. package/dist/version.d.ts +2 -0
  220. package/dist/version.js +11 -0
  221. package/dist/version.js.map +1 -0
  222. package/dist/versioned/approval.d.ts +35 -0
  223. package/dist/versioned/approval.js +53 -0
  224. package/dist/versioned/approval.js.map +1 -0
  225. package/dist/versioned/clickhouse.d.ts +24 -0
  226. package/dist/versioned/clickhouse.js +34 -0
  227. package/dist/versioned/clickhouse.js.map +1 -0
  228. package/dist/versioned/digest.d.ts +77 -0
  229. package/dist/versioned/digest.js +69 -0
  230. package/dist/versioned/digest.js.map +1 -0
  231. package/dist/versioned/driver.d.ts +41 -0
  232. package/dist/versioned/driver.js +13 -0
  233. package/dist/versioned/driver.js.map +1 -0
  234. package/dist/versioned/engine.d.ts +152 -0
  235. package/dist/versioned/engine.js +277 -0
  236. package/dist/versioned/engine.js.map +1 -0
  237. package/dist/versioned/explain.d.ts +123 -0
  238. package/dist/versioned/explain.js +289 -0
  239. package/dist/versioned/explain.js.map +1 -0
  240. package/dist/versioned/index.d.ts +37 -0
  241. package/dist/versioned/index.js +54 -0
  242. package/dist/versioned/index.js.map +1 -0
  243. package/dist/versioned/op.d.ts +62 -0
  244. package/dist/versioned/op.js +153 -0
  245. package/dist/versioned/op.js.map +1 -0
  246. package/dist/versioned/postgres/catalog.d.ts +33 -0
  247. package/dist/versioned/postgres/catalog.js +34 -0
  248. package/dist/versioned/postgres/catalog.js.map +1 -0
  249. package/dist/versioned/postgres/driver.d.ts +69 -0
  250. package/dist/versioned/postgres/driver.js +113 -0
  251. package/dist/versioned/postgres/driver.js.map +1 -0
  252. package/dist/versioned/postgres/executor.d.ts +104 -0
  253. package/dist/versioned/postgres/executor.js +172 -0
  254. package/dist/versioned/postgres/executor.js.map +1 -0
  255. package/dist/versioned/postgres/index.d.ts +11 -0
  256. package/dist/versioned/postgres/index.js +12 -0
  257. package/dist/versioned/postgres/index.js.map +1 -0
  258. package/dist/versioned/report.d.ts +22 -0
  259. package/dist/versioned/report.js +81 -0
  260. package/dist/versioned/report.js.map +1 -0
  261. package/dist/versioned/state.d.ts +108 -0
  262. package/dist/versioned/state.js +153 -0
  263. package/dist/versioned/state.js.map +1 -0
  264. package/package.json +51 -4
@@ -0,0 +1,193 @@
1
+ import { parseArgs } from "node:util";
2
+ import { guarded } from "../env-args.js";
3
+ import { loadProject, resolveEnvironment, YodelError } from "../project.js";
4
+ import { scanMigrations } from "../migrations/index.js";
5
+ import { inspect, migrationsDir, openVersioned } from "../versioned/index.js";
6
+ import { LINT_RULES, lintExitCode, lintJson, lintMigrations, lintSettings, renderLint, updateChecksum } from "../lint/index.js";
7
+ import { projectRules, REPLAY_RULE, replayRule } from "../lint/project-rules.js";
8
+ import { renderReplay, replayHistory, replayJson } from "../replay/index.js";
9
+ const usage = "usage: yodel lint [--env <env>] [--replay <env> [--reset] [--keep]] [--json] [--dir <project>] [--update-checksum <id>]... [--rules]";
10
+ const help = `${usage}
11
+
12
+ Checks the migrations directory against every lint rule, offline: no server
13
+ and no dev database. Every rule is free and runs in CI on every pull request.
14
+
15
+ Rules (yodel lint --rules lists them with their levels):
16
+ fork two migrations follow the same parent (yodel rebase)
17
+ directory not one readable chain: a bad name or file, a missing
18
+ parent, a cycle, a migration of another dialect
19
+ checksum a migration's files no longer hash to its checksum
20
+ unreadable-object an object in a recorded schema, or a step, the sql
21
+ lexicon cannot read or classify; an error, never skipped
22
+ destructive a drop that removes data for good
23
+ pg-rewrite Postgres: a rewrite or full scan under ACCESS EXCLUSIVE
24
+ pg-lock Postgres: writes blocked for a whole index build or scan
25
+ ch-mutation ClickHouse: a mutation rewriting parts, no rollback
26
+ ch-rebuild ClickHouse: a rebuild (ClickHouseRebuildOp)
27
+ refused-step a step yodel apply refuses (a manual step, an Op it
28
+ does not run)
29
+ migration-sql migration.sql does not hold a statement migration.json
30
+ records (apply runs migration.json's)
31
+ silence a yodel:allow line that is wrong or silences nothing
32
+ replay with --replay <env>: the history, replayed into a fresh
33
+ database on <env>'s server, does not give a migration's
34
+ recorded schema (names the first that differs)
35
+
36
+ Silencing: a line above a statement in its migration.sql,
37
+ -- yodel:allow <rule> <reason>
38
+ silences that statement rule (destructive, pg-rewrite, pg-lock,
39
+ ch-mutation, ch-rebuild) for that one statement. The reason is required,
40
+ and yodel apply records the rule, the statement and the reason in every
41
+ history row the migration writes (the silences column). Adding the line
42
+ changes the migration's checksum: for a migration not yet applied anywhere,
43
+ record the new one with --update-checksum <id>.
44
+
45
+ Levels: yodel.config.ts lint.rules sets a rule to "error", "warning" or
46
+ "off", e.g. lint: { rules: { "ch-mutation": "warning" } }. fork, directory,
47
+ checksum and unreadable-object are always errors.
48
+
49
+ Options:
50
+ --env <env> also compare with <env>'s history: a
51
+ checksum error is then an applied migration whose
52
+ files changed since it ran; a pending migration's
53
+ edit is a warning
54
+ --update-checksum <id> first write <id>'s migration.json checksum to match
55
+ its files (repeatable); refused with --env when <id>
56
+ is applied there
57
+ --replay <env> also replay every migration in order into <env>'s
58
+ server (a throwaway emulator: chant emulator up
59
+ --lexicon sql) and compare each with its recorded
60
+ schema; the databases or schemas the history names
61
+ must not exist there yet
62
+ --reset with --replay: drop those databases or schemas
63
+ first when they exist. Destructive: never against a
64
+ server whose data matters
65
+ --keep with --replay: leave the replayed database in place
66
+ --rules list the rules and their levels, and exit
67
+ --json print the findings as JSON
68
+ -C, --dir <dir> the project directory (default: the working directory)
69
+
70
+ Exit codes:
71
+ 0 no errors (warnings and silenced findings do not fail)
72
+ 3 at least one error (a replay that differs counts)
73
+ 4 --replay: the target already holds what the history names, and --reset
74
+ was not given; nothing was run
75
+ 1 lint could not run: a bad config, an unknown migration for
76
+ --update-checksum, a server that does not answer (--env)
77
+ `;
78
+ function parseLintArgs(args) {
79
+ let parsed;
80
+ try {
81
+ parsed = parseArgs({
82
+ args,
83
+ allowPositionals: false,
84
+ strict: true,
85
+ options: {
86
+ env: { type: "string" },
87
+ replay: { type: "string" },
88
+ reset: { type: "boolean" },
89
+ keep: { type: "boolean" },
90
+ json: { type: "boolean" },
91
+ dir: { type: "string", short: "C" },
92
+ "update-checksum": { type: "string", multiple: true },
93
+ rules: { type: "boolean" },
94
+ },
95
+ });
96
+ }
97
+ catch (e) {
98
+ throw new YodelError(`${e instanceof Error ? e.message : String(e)}\n${usage}`);
99
+ }
100
+ const v = parsed.values;
101
+ const update = v["update-checksum"];
102
+ const replay = typeof v.replay === "string" ? v.replay : undefined;
103
+ if (replay === undefined && (v.reset === true || v.keep === true))
104
+ throw new YodelError(`--reset and --keep go with --replay <env>\n${usage}`);
105
+ return {
106
+ env: typeof v.env === "string" ? v.env : undefined,
107
+ replay,
108
+ reset: v.reset === true,
109
+ keep: v.keep === true,
110
+ json: v.json === true,
111
+ dir: typeof v.dir === "string" ? v.dir : process.cwd(),
112
+ update: Array.isArray(update) ? update.filter((u) => typeof u === "string") : [],
113
+ rules: v.rules === true,
114
+ };
115
+ }
116
+ function allRules() {
117
+ return { ...LINT_RULES, ...Object.fromEntries(projectRules.map((r) => [r.rule.id, r.rule])), [REPLAY_RULE.id]: REPLAY_RULE };
118
+ }
119
+ function listRules(io, json, project) {
120
+ const rules = allRules();
121
+ const settings = lintSettings(project.yodel?.config.lint, rules, project.yodel?.path);
122
+ const rows = Object.values(rules).map((r) => ({ ...r, configured: settings.levels[r.id] ?? r.level }));
123
+ if (json) {
124
+ io.out(`${JSON.stringify(rows, null, 2)}\n`);
125
+ return 0;
126
+ }
127
+ const width = Math.max(...rows.map((r) => r.id.length));
128
+ for (const r of rows) {
129
+ const marks = [r.configured, r.silenceable ? "silenceable" : "", r.dialect ?? ""].filter(Boolean).join(", ");
130
+ io.out(`${r.id.padEnd(width)} ${marks}\n${" ".repeat(width + 2)}${r.summary}\n`);
131
+ }
132
+ return 0;
133
+ }
134
+ /** `yodel lint`; the exit codes are in `help`. */
135
+ export const lint = {
136
+ name: "lint",
137
+ summary: "check the migrations against the lint rules",
138
+ implemented: true,
139
+ run: (args, io) => guarded("lint", io, args, help, async () => {
140
+ const a = parseLintArgs(args);
141
+ const project = await loadProject(a.dir);
142
+ if (a.rules)
143
+ return listRules(io, a.json, project);
144
+ const settings = lintSettings(project.yodel?.config.lint, allRules(), project.yodel?.path);
145
+ const dir = migrationsDir(project);
146
+ const options = { dialect: project.dialect, project, settings, rules: projectRules };
147
+ if (a.env !== undefined) {
148
+ const env = resolveEnvironment(project, a.env);
149
+ const ordered = scanMigrations(dir).ordered;
150
+ if (ordered) {
151
+ const venv = await openVersioned(project, env);
152
+ const { status } = await inspect(venv, ordered, { sync: false });
153
+ options.history = { environment: env.name, status };
154
+ }
155
+ else if (!a.json) {
156
+ io.err(`yodel lint: the migrations directory is not one chain, so it is not compared with ${env.name}'s history; fix the findings below first\n`);
157
+ }
158
+ }
159
+ if (a.update.length > 0) {
160
+ const byId = new Map(scanMigrations(dir).migrations.map((m) => [m.id, m]));
161
+ for (const id of a.update) {
162
+ const m = byId.get(id);
163
+ if (!m)
164
+ throw new YodelError(`--update-checksum ${id}: no such migration in ${dir}`);
165
+ const applied = options.history?.status.applied.some((x) => x.id === id);
166
+ if (applied)
167
+ throw new YodelError(`--update-checksum ${id}: it is applied in ${String(options.history?.environment)}; record an intended edit there with yodel repair ${id} --reason ... ${String(options.history?.environment)}`);
168
+ const changed = updateChecksum(m);
169
+ if (!a.json)
170
+ io.err(changed ? `${id}: checksum ${changed.from} is now ${changed.to}\n` : `${id}: its checksum already matches its files\n`);
171
+ }
172
+ }
173
+ let replay;
174
+ if (a.replay !== undefined) {
175
+ const env = resolveEnvironment(project, a.replay);
176
+ if (scanMigrations(dir).ordered) {
177
+ // A target that is not fresh throws here, exit 4, before anything is linted or run.
178
+ replay = await replayHistory(project, env, { reset: a.reset, keep: a.keep, log: (l) => { io.err(`replay: ${l}\n`); } });
179
+ options.rules = [...projectRules, replayRule(replay)];
180
+ }
181
+ else {
182
+ io.err(`yodel lint: the migrations directory is not one chain, so it is not replayed; fix the findings below first\n`);
183
+ }
184
+ }
185
+ const report = await lintMigrations(dir, options);
186
+ if (a.json)
187
+ io.out(`${JSON.stringify({ ...lintJson(report), ...(replay ? { replay: replayJson(replay) } : {}) }, null, 2)}\n`);
188
+ else
189
+ io.out(`${replay ? `${renderReplay(replay)}\n` : ""}${renderLint(report)}`);
190
+ return lintExitCode(report);
191
+ }),
192
+ };
193
+ //# sourceMappingURL=lint.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"l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IAAI,EAAE,GAAG,EAAE,CAAC,CAAC,EAAE,EAAE,GAAG,EAAE,CAAC,GAAG,CAAC,WAAW,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC;gBACxH,OAAO,CAAC,KAAK,GAAG,CAAC,GAAG,YAAY,EAAE,UAAU,CAAC,MAAM,CAAC,CAAC,CAAC;YACxD,CAAC;iBAAM,CAAC;gBACN,EAAE,CAAC,GAAG,CAAC,8GAA8G,CAAC,CAAC;YACzH,CAAC;QACH,CAAC;QAED,MAAM,MAAM,GAAG,MAAM,cAAc,CAAC,GAAG,EAAE,OAAO,CAAC,CAAC;QAClD,IAAI,CAAC,CAAC,IAAI;YAAE,EAAE,CAAC,GAAG,CAAC,GAAG,IAAI,CAAC,SAAS,CAAC,EAAE,GAAG,QAAQ,CAAC,MAAM,CAAC,EAAE,GAAG,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,MAAM,EAAE,UAAU,CAAC,MAAM,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,EAAE,IAAI,EAAE,CAAC,CAAC,IAAI,CAAC,CAAC;;YAC1H,EAAE,CAAC,GAAG,CAAC,GAAG,MAAM,CAAC,CAAC,CAAC,GAAG,YAAY,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,GAAG,UAAU,CAAC,MAAM,CAAC,EAAE,CAAC,CAAC;QACjF,OAAO,YAAY,CAAC,MAAM,CAAC,CAAC;IAC9B,CAAC,CAAC;CACL,CAAC"}
@@ -0,0 +1,3 @@
1
+ import type { Command } from "../command.js";
2
+ /** `yodel new <name>`; the exit codes are in `help`. */
3
+ export declare const newCommand: Command;
@@ -0,0 +1,168 @@
1
+ import { existsSync, mkdirSync, readFileSync, writeFileSync } from "node:fs";
2
+ import { dirname, join, relative, resolve } from "node:path";
3
+ import { parseArgs } from "node:util";
4
+ import { guarded } from "../env-args.js";
5
+ import { loadProject, YodelError } from "../project.js";
6
+ import { buildSchema } from "../chant/build.js";
7
+ import { createMigration, migrationId, MIGRATIONS_DIR, newestMigration, readMigrations, refusedSteps, verifyChecksum, writeMigration, } from "../migrations/index.js";
8
+ import { asBackfill, BACKFILL_FILE, backfillTemplate, loadBackfill, TEMPLATE_MARK } from "../steps/index.js";
9
+ const usage = "usage: yodel new <name> [--backfill <file>] [--json] [--dir <project>]";
10
+ const help = `${usage}
11
+
12
+ Writes the next migration, migrations/<YYYYMMDDTHHMM>-<name>/, by diffing
13
+ the newest migration's recorded schema (an empty schema for the first)
14
+ against the current build of the declared schema. Offline: no database,
15
+ dev or otherwise, is read. The name is lowercase letters and digits, words
16
+ joined by - or _. The timestamp is UTC.
17
+
18
+ The migration holds migration.sql (each statement after a comment naming its
19
+ object, rule and class) and migration.json (id, parent, checksum, the
20
+ recorded schema, the steps). A change no statement makes in place, such as a
21
+ ClickHouse sort-key change or a Postgres column rename, is an Op step:
22
+ written to migration.json with its declaration, and to migration.sql as a
23
+ comment only.
24
+
25
+ A data backfill is a step too. --backfill <file> ends the migration with a
26
+ backfill step: <file> (relative to the project directory) is a module
27
+ exporting a chant Op whose every step is an effect() batch with its own
28
+ receipt, running SQL with activity("yodelSql", { sql }). It is copied into
29
+ the migration's directory as ${BACKFILL_FILE} and counts in its checksum.
30
+ yodel apply runs it after the statements before it, and a run that fails or
31
+ is stopped part way resumes at the first batch without a receipt. When
32
+ <file> does not exist yet, a template is written there and no migration:
33
+ write the batches, then run the same command again. With --backfill a
34
+ migration is written even when the declared schema has not changed.
35
+
36
+ Options:
37
+ --backfill <file> end the migration with a backfill step running <file>
38
+ --json print what was written as JSON
39
+ -C, --dir <dir> the project directory (default: the working directory)
40
+
41
+ Exit codes:
42
+ 0 a migration was written, or the declared schema has no change from the
43
+ newest recorded schema (then nothing is written)
44
+ 1 no migration could be made: a bad config, a declaration chant cannot
45
+ build, a migrations directory that is not one chain (a fork, a missing
46
+ parent), a migration of that id already there
47
+ `;
48
+ function parseNewArgs(args) {
49
+ let parsed;
50
+ try {
51
+ parsed = parseArgs({
52
+ args,
53
+ allowPositionals: true,
54
+ strict: true,
55
+ options: { json: { type: "boolean" }, dir: { type: "string", short: "C" }, backfill: { type: "string" } },
56
+ });
57
+ }
58
+ catch (e) {
59
+ throw new YodelError(`${e instanceof Error ? e.message : String(e)}\n${usage}`);
60
+ }
61
+ const [name, ...rest] = parsed.positionals;
62
+ if (name === undefined || rest.length > 0)
63
+ throw new YodelError(usage);
64
+ migrationId(name, new Date()); // a bad name fails before anything is built
65
+ return {
66
+ name,
67
+ json: parsed.values.json === true,
68
+ dir: typeof parsed.values.dir === "string" ? parsed.values.dir : process.cwd(),
69
+ backfill: typeof parsed.values.backfill === "string" ? parsed.values.backfill : undefined,
70
+ };
71
+ }
72
+ function report(io, json, made, path, projectDir) {
73
+ const steps = made.statements.steps;
74
+ const refused = refusedSteps(steps);
75
+ const statementCount = steps.length - refused.length;
76
+ if (json) {
77
+ io.out(`${JSON.stringify({
78
+ written: true,
79
+ id: made.id,
80
+ path,
81
+ parent: made.document.parent,
82
+ checksum: made.document.checksum,
83
+ dialect: made.document.dialect,
84
+ statements: statementCount,
85
+ ops: refused.filter((s) => s.kind === "op").map((s) => ({ op: s.op, object: s.object, name: s.name, rules: s.changes.map((c) => c.rule) })),
86
+ manual: refused.filter((s) => s.kind === "manual").map((s) => ({ object: s.object, name: s.name, rules: s.changes.map((c) => c.rule), detail: s.detail })),
87
+ hints: made.document.hints,
88
+ }, null, 2)}\n`);
89
+ return;
90
+ }
91
+ const where = relative(projectDir, path) || path;
92
+ const parent = made.document.parent ? `follows ${made.document.parent}` : "the first migration";
93
+ const lines = [`Wrote ${where}/ (${String(statementCount)} statement${statementCount === 1 ? "" : "s"}; ${parent})`];
94
+ for (const s of refused) {
95
+ const rules = s.changes.map((c) => c.rule).join(", ");
96
+ const backfill = asBackfill(s);
97
+ if (backfill) {
98
+ lines.push(` This migration ends with a backfill step: the Op ${backfill.options.file} exports, copied into the migration's directory.`);
99
+ lines.push(` yodel apply runs its effect() batches after the statements before it, resuming from their receipts after a failure.`);
100
+ }
101
+ else if (s.kind === "op") {
102
+ lines.push(` This migration contains an Op step: ${s.op} for ${s.object} (${s.name}), ${rules}.`);
103
+ lines.push(` It is not SQL. migration.json holds the Op's declaration:`);
104
+ lines.push(` ${s.declaration}`);
105
+ }
106
+ else {
107
+ lines.push(` This migration contains a manual step: ${s.object} (${s.name}), ${rules}. No statement and no Op makes it:`);
108
+ lines.push(` ${s.detail}`);
109
+ }
110
+ }
111
+ for (const h of made.document.hints)
112
+ lines.push(` hint: ${h}`);
113
+ io.out(`${lines.join("\n")}\n`);
114
+ }
115
+ /** `yodel new <name>`; the exit codes are in `help`. */
116
+ export const newCommand = {
117
+ name: "new",
118
+ summary: "write the next migration from the declared schema",
119
+ implemented: true,
120
+ run: (args, io) => guarded("new", io, args, help, async () => {
121
+ const { name, json, dir, backfill: backfillArg } = parseNewArgs(args);
122
+ const project = await loadProject(dir);
123
+ let backfill;
124
+ if (backfillArg !== undefined) {
125
+ const path = resolve(project.dir, backfillArg);
126
+ if (!existsSync(path)) {
127
+ mkdirSync(dirname(path), { recursive: true });
128
+ writeFileSync(path, backfillTemplate(name, project.dialect));
129
+ const where = relative(project.dir, path) || path;
130
+ if (json)
131
+ io.out(`${JSON.stringify({ written: false, template: path }, null, 2)}\n`);
132
+ else
133
+ io.out(`Wrote a backfill template at ${where}. Write its batches, then run yodel new ${name} --backfill ${backfillArg} again. No migration written.\n`);
134
+ return 0;
135
+ }
136
+ const text = readFileSync(path, "utf8");
137
+ if (text.includes(TEMPLATE_MARK))
138
+ throw new YodelError(`${path} is still the template; write its batches' SQL first`);
139
+ await loadBackfill(path, text);
140
+ backfill = { text };
141
+ }
142
+ const migrationsDir = join(project.dir, MIGRATIONS_DIR);
143
+ const previous = newestMigration(readMigrations(migrationsDir));
144
+ if (previous && !verifyChecksum(previous).ok) {
145
+ io.err(`yodel new: warning: ${previous.id}'s files no longer match its recorded checksum; the new migration follows it as recorded\n`);
146
+ }
147
+ const build = await buildSchema(project);
148
+ let made;
149
+ try {
150
+ made = createMigration({ name, build: build.output, previous, ...(backfill ? { backfill } : {}) });
151
+ }
152
+ finally {
153
+ build.dispose();
154
+ }
155
+ if (made.id === undefined) {
156
+ const from = previous ? `the newest migration's recorded schema (${previous.id})` : "an empty schema (the declared schema declares nothing)";
157
+ if (json)
158
+ io.out(`${JSON.stringify({ written: false, parent: previous?.id ?? null, dialect: project.dialect, hints: made.statements.hints }, null, 2)}\n`);
159
+ else
160
+ io.out(`No changes: the declared schema matches ${from}. Nothing written.\n`);
161
+ return 0;
162
+ }
163
+ const path = writeMigration(migrationsDir, made);
164
+ report(io, json, made, path, project.dir);
165
+ return 0;
166
+ }),
167
+ };
168
+ //# sourceMappingURL=new.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"new.js","sourceRoot":"","sources":["../../src/commands/new.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,SAAS,EAAE,YAAY,EAAE,aAAa,EAAE,MAAM,SAAS,CAAC;AAC7E,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,QAAQ,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAC7D,OAAO,EAAE,SAAS,EAAE,MAAM,WAAW,CAAC;AAEtC,OAAO,EAAE,OAAO,EAAE,MAAM,gBAAgB,CAAC;AACzC,OAAO,EAAE,WAAW,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;AACxD,OAAO,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAChD,OAAO,EACL,eAAe,EACf,WAAW,EACX,cAAc,EACd,eAAe,EACf,cAAc,EACd,YAAY,EACZ,cAAc,EACd,cAAc,GAEf,MAAM,wBAAwB,CAAC;AAChC,OAAO,EAAE,UAAU,EAAE,aAAa,EAAE,gBAAgB,EAAE,YAAY,EAAE,aAAa,EAAE,MAAM,mBAAmB,CAAC;AAE7G,MAAM,KAAK,GAAG,wEAAwE,CAAC;AAEvF,MAAM,IAAI,GA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AI,EAAE,IAAI,EAAE,OAAO,CAAC,GAAG,CAAC,CAAC;QAC1C,OAAO,CAAC,CAAC;IACX,CAAC,CAAC;CACL,CAAC"}
@@ -0,0 +1,3 @@
1
+ import type { Command } from "../command.js";
2
+ /** `yodel plan <env>`; the exit codes are in `help`. */
3
+ export declare const plan: Command;
@@ -0,0 +1,171 @@
1
+ import { parseArgs } from "node:util";
2
+ import { guarded } from "../env-args.js";
3
+ import { loadProject, resolveEnvironment, YodelError } from "../project.js";
4
+ import { declarativeTopologyRefusal, describeSettingsTopology, environmentSettings } from "../config/settings.js";
5
+ import { buildSchema } from "../chant/build.js";
6
+ import { planEnvironment, planExitCode, planJson, renderPlan } from "../chant/plan.js";
7
+ import { hasMigrations } from "../versioned/index.js";
8
+ import { decodeSubject } from "../versioned/explain.js";
9
+ import { collectVersionedPlan } from "../pr/model.js";
10
+ import { commentMarker, planJsonVersioned, renderPlanMarkdown, renderPlanText, subjectIn } from "../pr/render.js";
11
+ import { resolveForgeTarget } from "../pr/forge.js";
12
+ import { commentClient, findComment, upsertComment } from "../pr/comment.js";
13
+ const usage = "usage: yodel plan <env> [--json] [--dir <project>] [--format text|markdown|json] [--allow-out-of-order] [--op <name>]\n" +
14
+ " [--comment [--forge github|gitlab|forgejo] [--repo <repo>] [--pr <n>] [--api-url <url>] [--token-env <VAR>]]";
15
+ const help = `${usage}
16
+
17
+ Declarative project (no migrations/ directory): shows the classified change
18
+ from the environment's live database (sql.profiles.<env>) to the declared
19
+ schema, as chant sql plan reports it.
20
+
21
+ Versioned project (a migrations/ directory): shows the pending migrations,
22
+ each step with its rule and class (an Op step with the Op that makes it, a
23
+ manual step with what it needs), integrity problems (directory problems,
24
+ checksum mismatches, out-of-order migrations), and the plan digest yodel
25
+ apply asks approval for, with the chant approve command that approves it.
26
+ When chant's gate ledger holds an approval of the migrations Op's gate for
27
+ another digest, it says what moved since. Reads only.
28
+
29
+ Options:
30
+ --json print the plan as JSON (the same as --format json)
31
+ --format <f> text (default), markdown (the pull request comment), json
32
+ --allow-out-of-order versioned: the plan yodel apply --allow-out-of-order would run
33
+ --op <name> versioned: the migrations Op, when more than one applies <env>
34
+ --comment versioned: post the markdown as one comment on the pull
35
+ (merge) request, updating the one posted before; prints
36
+ the text plan. The forge, repository, request and API
37
+ come from the CI job's environment (GitHub Actions,
38
+ GitLab CI, Forgejo Actions) unless given:
39
+ --forge <f> github, gitlab or forgejo
40
+ --repo <repo> owner/name (GitHub, Forgejo) or the project id (GitLab)
41
+ --pr <n> the pull request number or merge request iid
42
+ --api-url <url> the REST API base (https://api.github.com,
43
+ https://gitlab.example/api/v4, https://forgejo.example/api/v1)
44
+ --token-env <VAR> the variable holding the token (default GITHUB_TOKEN;
45
+ GITLAB_TOKEN; FORGEJO_TOKEN, else GITHUB_TOKEN)
46
+ -C, --dir <dir> the project directory (default: the working directory)
47
+
48
+ Exit codes:
49
+ 0 every change can be made in place, or there is none; versioned: apply
50
+ would run (or has nothing to do)
51
+ 2 a change needs its own Op: a ClickHouse rebuild, a Postgres expand and
52
+ contract (declarative); versioned: a pending migration has an Op or
53
+ manual step apply does not run yet
54
+ 4 versioned: apply would refuse: a checksum mismatch, an applied migration
55
+ gone from the directory, an out-of-order migration
56
+ 1 no plan could be made: a bad config, an unknown environment, a declaration
57
+ chant cannot build, a malformed migrations directory, a server it cannot
58
+ read, a comment the forge refused
59
+ `;
60
+ function parsePlanArgs(args) {
61
+ let parsed;
62
+ try {
63
+ parsed = parseArgs({
64
+ args,
65
+ allowPositionals: true,
66
+ strict: true,
67
+ options: {
68
+ json: { type: "boolean" },
69
+ dir: { type: "string", short: "C" },
70
+ format: { type: "string" },
71
+ comment: { type: "boolean" },
72
+ "allow-out-of-order": { type: "boolean" },
73
+ op: { type: "string" },
74
+ forge: { type: "string" },
75
+ repo: { type: "string" },
76
+ pr: { type: "string" },
77
+ "api-url": { type: "string" },
78
+ "token-env": { type: "string" },
79
+ },
80
+ });
81
+ }
82
+ catch (e) {
83
+ throw new YodelError(`${e instanceof Error ? e.message : String(e)}\n${usage}`);
84
+ }
85
+ const { values: v, positionals } = parsed;
86
+ const [env, ...rest] = positionals;
87
+ if (env === undefined || rest.length > 0)
88
+ throw new YodelError(usage);
89
+ const str = (k) => (typeof v[k] === "string" ? v[k] : undefined);
90
+ const format = str("format") ?? (v.json === true ? "json" : "text");
91
+ if (format !== "text" && format !== "markdown" && format !== "json")
92
+ throw new YodelError(`--format must be text, markdown or json, got ${JSON.stringify(format)}\n${usage}`);
93
+ if (v.json === true && format !== "json")
94
+ throw new YodelError(`--json and --format ${format} cannot be combined\n${usage}`);
95
+ const forgeFlags = ["forge", "repo", "pr", "api-url", "token-env"].filter((k) => str(k) !== undefined);
96
+ if (forgeFlags.length > 0 && v.comment !== true)
97
+ throw new YodelError(`--${forgeFlags.join(", --")} ${forgeFlags.length === 1 ? "goes" : "go"} with --comment\n${usage}`);
98
+ const forge = { forge: str("forge"), repo: str("repo"), pr: str("pr"), apiUrl: str("api-url"), tokenEnv: str("token-env") };
99
+ return {
100
+ env,
101
+ dir: str("dir") ?? process.cwd(),
102
+ format,
103
+ comment: v.comment === true,
104
+ allowOutOfOrder: v["allow-out-of-order"] === true,
105
+ op: str("op"),
106
+ forge,
107
+ versionedOnly: [
108
+ ...(format === "markdown" ? ["--format markdown"] : []),
109
+ ...(v.comment === true ? ["--comment"] : []),
110
+ ...(v["allow-out-of-order"] === true ? ["--allow-out-of-order"] : []),
111
+ ...(str("op") !== undefined ? ["--op"] : []),
112
+ ],
113
+ };
114
+ }
115
+ /** `yodel plan <env>`; the exit codes are in `help`. */
116
+ export const plan = {
117
+ name: "plan",
118
+ summary: "show what apply would change in an environment",
119
+ implemented: true,
120
+ run: (args, io) => guarded("plan", io, args, help, async () => {
121
+ const a = parsePlanArgs(args);
122
+ const project = await loadProject(a.dir);
123
+ const env = resolveEnvironment(project, a.env);
124
+ if (hasMigrations(project))
125
+ return versionedPlan(project, env, a, io);
126
+ if (a.versionedOnly.length > 0)
127
+ throw new YodelError(`${a.versionedOnly.join(", ")} ${a.versionedOnly.length === 1 ? "is" : "are"} for versioned migrations, and ${project.dir} has no migrations/ directory with a migration`);
128
+ return declarativePlan(project, env, a.format === "json", io);
129
+ }),
130
+ };
131
+ async function declarativePlan(project, env, json, io) {
132
+ const refusal = project.dialect === "clickhouse" ? declarativeTopologyRefusal(project, env.name) : undefined;
133
+ if (refusal)
134
+ throw refusal;
135
+ const topology = project.dialect === "clickhouse" ? `, topology ${describeSettingsTopology(environmentSettings(project, env.name))}` : "";
136
+ const build = await buildSchema(project);
137
+ try {
138
+ const result = await planEnvironment(project, env, build);
139
+ if (json)
140
+ io.out(`${JSON.stringify(planJson(result), null, 2)}\n`);
141
+ else
142
+ io.out(`${await renderPlan(result, `Plan for ${env.name} (${project.dialect}, sql.profiles.${env.name}${topology})`)}\n`);
143
+ return planExitCode(result);
144
+ }
145
+ finally {
146
+ build.dispose();
147
+ }
148
+ }
149
+ async function versionedPlan(project, env, a, io) {
150
+ const marker = commentMarker(env.name);
151
+ // Resolve the forge first: a job missing its token fails before it reads the server.
152
+ const target = a.comment ? resolveForgeTarget(a.forge, process.env) : undefined;
153
+ const client = target ? commentClient(target) : undefined;
154
+ const existing = client ? await findComment(client, marker) : undefined;
155
+ const carried = existing ? subjectIn(existing.body) : undefined;
156
+ const previous = carried ? decodeSubject(carried) : undefined;
157
+ const result = await collectVersionedPlan(project, env, { allowOutOfOrder: a.allowOutOfOrder, opName: a.op, previous });
158
+ const code = result.refusal?.exitCode ?? 0;
159
+ if (client && target) {
160
+ const posted = await upsertComment(client, marker, renderPlanMarkdown(result), existing);
161
+ io.err(`yodel plan: ${posted.action} the plan comment on ${target.forge} ${target.repo}#${String(target.pr)}${posted.comment.url ? ` (${posted.comment.url})` : ` (comment ${String(posted.comment.id)})`}\n`);
162
+ }
163
+ if (a.format === "json")
164
+ io.out(`${JSON.stringify(planJsonVersioned(result), null, 2)}\n`);
165
+ else if (a.format === "markdown")
166
+ io.out(renderPlanMarkdown(result));
167
+ else
168
+ io.out(renderPlanText(result));
169
+ return code;
170
+ }
171
+ //# sourceMappingURL=plan.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"plan.js","sourceRoot":"","sources":["../../src/commands/plan.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,WAAW,CAAC;AAEtC,OAAO,EAAE,OAAO,EAAE,MAAM,gBAAgB,CAAC;AACzC,OAAO,EAAE,WAAW,EAAE,kBAAkB,EAAE,UAAU,EAAkC,MAAM,eAAe,CAAC;AAC5G,OAAO,EAAE,0BAA0B,EAAE,wBAAwB,EAAE,mBAAmB,EAAE,MAAM,uBAAuB,CAAC;AAClH,OAAO,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAChD,OAAO,EAAE,eAAe,EAAE,YAAY,EAAE,QAAQ,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AACvF,OAAO,EAAE,aAAa,EAAE,MAAM,uBAAuB,CAAC;AACtD,OAAO,EAAE,aAAa,EAAE,MAAM,yBAAyB,CAAC;AACxD,OAAO,EAAE,oBAAoB,EAAE,MAAM,gBAAgB,CAAC;AACtD,OAAO,EAAE,aAAa,EAAE,iBAAiB,EAAE,kBAAkB,EAAE,cAAc,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAClH,OAAO,EAAE,kBAAkB,EAAmB,MAAM,gBAAgB,CAAC;AACrE,OAAO,EAAE,aAAa,EAAE,WAAW,EAAE,aAAa,EAAE,MAAM,kBAAkB,CAAC;AAE7E,MAAM,KAAK,GACT,yHAAyH;IACzH,sIAAsI,CAAC;AAEzI,MAAM,IAAI,GAAG,GAAG,KAAK;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CA4CpB,CAAC;AAaF,SAAS,aAAa,CAAC,IAAc;IACnC,IAAI,MAAoC,CAAC;IACzC,IAAI,CAAC;QACH,MAAM,GAAG,SAAS,CAAC;YACjB,IAAI;YACJ,gBAAgB,EA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