@sdxc/kit 2026.10.17 → 2026.10.20

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 (282) hide show
  1. package/README.md +390 -20
  2. package/changelog.jsonl +1160 -1092
  3. package/config.schema.json +47 -1
  4. package/dist/cli.js +12 -0
  5. package/dist/commands/deploy.d.ts +23 -0
  6. package/dist/commands/deploy.js +167 -0
  7. package/dist/commands/destroy.d.ts +22 -0
  8. package/dist/commands/destroy.js +92 -0
  9. package/dist/commands/doctor.d.ts +26 -0
  10. package/dist/commands/doctor.js +65 -0
  11. package/dist/commands/initializers.d.ts +16 -0
  12. package/dist/commands/initializers.js +23 -0
  13. package/dist/commands/make.d.ts +72 -6
  14. package/dist/commands/make.js +127 -19
  15. package/dist/commands/middleware.d.ts +16 -0
  16. package/dist/commands/middleware.js +21 -0
  17. package/dist/commands/models.d.ts +18 -0
  18. package/dist/commands/models.js +29 -0
  19. package/dist/commands/notes.d.ts +17 -0
  20. package/dist/commands/notes.js +27 -0
  21. package/dist/commands/routes.d.ts +25 -0
  22. package/dist/commands/routes.js +50 -0
  23. package/dist/commands/run.d.ts +16 -0
  24. package/dist/commands/run.js +32 -11
  25. package/dist/commands/scaffold.d.ts +29 -0
  26. package/dist/commands/scaffold.js +33 -0
  27. package/dist/commands/schedule.d.ts +16 -0
  28. package/dist/commands/schedule.js +21 -0
  29. package/dist/commands/stats.d.ts +16 -0
  30. package/dist/commands/stats.js +21 -0
  31. package/dist/commands/ui/update.d.ts +6 -3
  32. package/dist/commands/ui/update.js +24 -7
  33. package/dist/commands/upgrade.d.ts +3 -1
  34. package/dist/commands/upgrade.js +88 -23
  35. package/dist/config.d.ts +18 -0
  36. package/dist/config.js +28 -1
  37. package/dist/contract.d.ts +97 -3
  38. package/dist/contract.js +360 -26
  39. package/dist/create/templates.js +3 -2
  40. package/dist/dependencies.d.ts +4 -1
  41. package/dist/dependencies.js +13 -1
  42. package/dist/deploy/plan.d.ts +49 -0
  43. package/dist/deploy/plan.js +68 -0
  44. package/dist/destroy.d.ts +40 -0
  45. package/dist/destroy.js +311 -0
  46. package/dist/doctor/check.d.ts +71 -0
  47. package/dist/doctor/check.js +53 -0
  48. package/dist/doctor/checks.d.ts +23 -0
  49. package/dist/doctor/checks.js +68 -0
  50. package/dist/doctor/define.d.ts +59 -0
  51. package/dist/doctor/define.js +16 -0
  52. package/dist/doctor/emails.d.ts +18 -0
  53. package/dist/doctor/emails.js +243 -0
  54. package/dist/doctor/env.d.ts +26 -0
  55. package/dist/doctor/env.js +88 -0
  56. package/dist/doctor/files.d.ts +14 -0
  57. package/dist/doctor/files.js +34 -0
  58. package/dist/doctor/fixture.d.ts +23 -0
  59. package/dist/doctor/fixture.js +46 -0
  60. package/dist/doctor/install.d.ts +17 -0
  61. package/dist/doctor/install.js +37 -0
  62. package/dist/doctor/installed.d.ts +11 -0
  63. package/dist/doctor/installed.js +79 -0
  64. package/dist/doctor/layout.d.ts +23 -0
  65. package/dist/doctor/layout.js +83 -0
  66. package/dist/doctor/migrations.d.ts +16 -0
  67. package/dist/doctor/migrations.js +96 -0
  68. package/dist/doctor/models.d.ts +13 -0
  69. package/dist/doctor/models.js +69 -0
  70. package/dist/doctor/pins.d.ts +15 -0
  71. package/dist/doctor/pins.js +79 -0
  72. package/dist/doctor/project.d.ts +58 -0
  73. package/dist/doctor/project.js +261 -0
  74. package/dist/doctor/remix.d.ts +14 -0
  75. package/dist/doctor/remix.js +44 -0
  76. package/dist/doctor/routes.d.ts +11 -0
  77. package/dist/doctor/routes.js +49 -0
  78. package/dist/doctor/typegen.d.ts +13 -0
  79. package/dist/doctor/typegen.js +57 -0
  80. package/dist/doctor/ui.d.ts +14 -0
  81. package/dist/doctor/ui.js +51 -0
  82. package/dist/initializers.d.ts +25 -0
  83. package/dist/initializers.js +89 -0
  84. package/dist/lock.d.ts +2 -2
  85. package/dist/make/actions.d.ts +23 -0
  86. package/dist/make/actions.js +82 -0
  87. package/dist/make/declare.d.ts +31 -3
  88. package/dist/make/declare.js +284 -9
  89. package/dist/make/email.d.ts +23 -0
  90. package/dist/make/email.js +111 -0
  91. package/dist/make/from-fields.d.ts +30 -0
  92. package/dist/make/from-fields.js +162 -0
  93. package/dist/make/from-model.d.ts +39 -0
  94. package/dist/make/from-model.js +161 -0
  95. package/dist/make/generate.d.ts +16 -5
  96. package/dist/make/generate.js +38 -15
  97. package/dist/make/guard.d.ts +35 -0
  98. package/dist/make/guard.js +73 -0
  99. package/dist/make/imports.d.ts +6 -0
  100. package/dist/make/imports.js +19 -0
  101. package/dist/make/index.d.ts +47 -4
  102. package/dist/make/index.js +287 -29
  103. package/dist/make/kinds.d.ts +29 -2
  104. package/dist/make/kinds.js +79 -7
  105. package/dist/make/mount.d.ts +25 -0
  106. package/dist/make/mount.js +135 -0
  107. package/dist/make/schema-diff.d.ts +58 -0
  108. package/dist/make/schema-diff.js +609 -0
  109. package/dist/make/schema.d.ts +76 -0
  110. package/dist/make/schema.js +206 -0
  111. package/dist/make/stubs.d.ts +7 -5
  112. package/dist/make/stubs.js +16 -5
  113. package/dist/make/test.d.ts +43 -0
  114. package/dist/make/test.js +149 -0
  115. package/dist/make/trigger.d.ts +31 -0
  116. package/dist/make/trigger.js +163 -0
  117. package/dist/models.d.ts +42 -0
  118. package/dist/models.js +149 -0
  119. package/dist/notes.d.ts +28 -0
  120. package/dist/notes.js +66 -0
  121. package/dist/reference.d.ts +27 -0
  122. package/dist/reference.js +103 -0
  123. package/dist/releases.d.ts +9 -0
  124. package/dist/releases.js +29 -8
  125. package/dist/routes/chains.d.ts +34 -0
  126. package/dist/routes/chains.js +95 -0
  127. package/dist/routes/filter.d.ts +53 -0
  128. package/dist/routes/filter.js +147 -0
  129. package/dist/routes/format.d.ts +23 -0
  130. package/dist/routes/format.js +123 -0
  131. package/dist/routes/helpers.d.ts +21 -0
  132. package/dist/routes/helpers.js +165 -0
  133. package/dist/routes/index.d.ts +56 -0
  134. package/dist/routes/index.js +167 -0
  135. package/dist/routes/modules.d.ts +116 -0
  136. package/dist/routes/modules.js +235 -0
  137. package/dist/routes/parse.d.ts +161 -0
  138. package/dist/routes/parse.js +621 -0
  139. package/dist/routes/routers.d.ts +69 -0
  140. package/dist/routes/routers.js +327 -0
  141. package/dist/scaffold/fields.d.ts +129 -0
  142. package/dist/scaffold/fields.js +421 -0
  143. package/dist/scaffold/index.d.ts +37 -0
  144. package/dist/scaffold/index.js +613 -0
  145. package/dist/scaffold/render.d.ts +51 -0
  146. package/dist/scaffold/render.js +332 -0
  147. package/dist/schedule.d.ts +45 -0
  148. package/dist/schedule.js +124 -0
  149. package/dist/stats.d.ts +37 -0
  150. package/dist/stats.js +126 -0
  151. package/dist/ui/commands.d.ts +10 -3
  152. package/dist/ui/commands.js +85 -15
  153. package/dist/ui/registry.d.ts +8 -8
  154. package/dist/upgrade/agents.d.ts +49 -0
  155. package/dist/upgrade/agents.js +110 -0
  156. package/dist/upgrade/changelog.d.ts +2 -2
  157. package/dist/upgrade/project.d.ts +4 -0
  158. package/dist/upgrade/project.js +11 -1
  159. package/dist/upgrade/prompt.d.ts +11 -0
  160. package/dist/upgrade/prompt.js +50 -7
  161. package/package.json +6 -4
  162. package/registry/ui/alert-dialog.json +2 -2
  163. package/registry/ui/attachment.json +2 -2
  164. package/registry/ui/calendar.json +2 -2
  165. package/registry/ui/color-picker.json +2 -2
  166. package/registry/ui/command.json +2 -2
  167. package/registry/ui/date-picker.json +2 -2
  168. package/registry/ui/date-range-picker.json +2 -2
  169. package/registry/ui/dialog.json +2 -2
  170. package/registry/ui/file-trigger.json +2 -2
  171. package/registry/ui/heading-scope.json +2 -2
  172. package/registry/ui/message-scroller.json +2 -2
  173. package/registry/ui/number-field.json +2 -2
  174. package/registry/ui/range-calendar.json +2 -2
  175. package/registry/ui/resizable.json +2 -2
  176. package/registry/ui/select.json +2 -2
  177. package/registry/ui/shared-element.json +2 -2
  178. package/stubs/controller.api.resource.stub +23 -0
  179. package/stubs/controller.form.stub +2 -2
  180. package/stubs/controller.form.test.stub +2 -2
  181. package/stubs/controller.resource.form.stub +67 -0
  182. package/stubs/controller.resource.stub +28 -0
  183. package/stubs/email.stub +9 -14
  184. package/stubs/email.test.stub +9 -9
  185. package/stubs/factory.stub +1 -1
  186. package/stubs/model.stub +3 -3
  187. package/stubs/policy.test.stub +34 -8
  188. package/stubs/scaffold.api.create.stub +34 -0
  189. package/stubs/scaffold.api.create.test.stub +37 -0
  190. package/stubs/scaffold.api.destroy.stub +34 -0
  191. package/stubs/scaffold.api.destroy.test.stub +44 -0
  192. package/stubs/scaffold.api.index.stub +23 -0
  193. package/stubs/scaffold.api.index.test.stub +31 -0
  194. package/stubs/scaffold.api.show.stub +27 -0
  195. package/stubs/scaffold.api.show.test.stub +41 -0
  196. package/stubs/scaffold.api.update.stub +44 -0
  197. package/stubs/scaffold.api.update.test.stub +46 -0
  198. package/stubs/scaffold.command.create.stub +22 -0
  199. package/stubs/scaffold.command.create.test.stub +30 -0
  200. package/stubs/scaffold.command.delete.stub +20 -0
  201. package/stubs/scaffold.command.delete.test.stub +39 -0
  202. package/stubs/scaffold.command.list.stub +18 -0
  203. package/stubs/scaffold.command.list.test.stub +31 -0
  204. package/stubs/scaffold.command.show.stub +19 -0
  205. package/stubs/scaffold.command.show.test.stub +37 -0
  206. package/stubs/scaffold.controller.destroy.stub +35 -0
  207. package/stubs/scaffold.controller.destroy.test.stub +65 -0
  208. package/stubs/scaffold.controller.edit.stub +97 -0
  209. package/stubs/scaffold.controller.edit.test.stub +91 -0
  210. package/stubs/scaffold.controller.index.stub +55 -0
  211. package/stubs/scaffold.controller.index.test.stub +32 -0
  212. package/stubs/scaffold.controller.new.stub +70 -0
  213. package/stubs/scaffold.controller.new.test.stub +81 -0
  214. package/stubs/scaffold.controller.show.stub +59 -0
  215. package/stubs/scaffold.controller.show.test.stub +43 -0
  216. package/stubs/scaffold.factory.stub +16 -0
  217. package/stubs/scaffold.form.stub +75 -0
  218. package/stubs/scaffold.mcp.create.stub +24 -0
  219. package/stubs/scaffold.mcp.create.test.stub +36 -0
  220. package/stubs/scaffold.mcp.delete.stub +31 -0
  221. package/stubs/scaffold.mcp.delete.test.stub +43 -0
  222. package/stubs/scaffold.mcp.get.stub +21 -0
  223. package/stubs/scaffold.mcp.get.test.stub +31 -0
  224. package/stubs/scaffold.mcp.list.stub +23 -0
  225. package/stubs/scaffold.mcp.list.test.stub +25 -0
  226. package/stubs/scaffold.mcp.update.stub +37 -0
  227. package/stubs/scaffold.mcp.update.test.stub +40 -0
  228. package/stubs/scaffold.migration.stub +2 -0
  229. package/stubs/scaffold.model.stub +35 -0
  230. package/stubs/scaffold.model.test.stub +25 -0
  231. package/stubs/scaffold.test-database.stub +33 -0
  232. package/stubs/scaffold.test-mcp.stub +92 -0
  233. package/stubs/scaffold.validator.stub +18 -0
  234. package/stubs/scaffold.validator.test.stub +26 -0
  235. package/templates/app/AGENTS.md +163 -0
  236. package/templates/app/CLAUDE.md +1 -0
  237. package/templates/app/README.md +28 -13
  238. package/templates/app/app/commands/console.test.ts +26 -0
  239. package/templates/app/app/commands/console.ts +19 -0
  240. package/templates/app/app/commands/db/fresh.test.ts +57 -0
  241. package/templates/app/app/commands/db/fresh.ts +37 -0
  242. package/templates/app/app/commands/db/migrate.test.ts +17 -1
  243. package/templates/app/app/commands/db/migrate.ts +51 -18
  244. package/templates/app/app/commands/db/prepare.test.ts +39 -0
  245. package/templates/app/app/commands/db/prepare.ts +35 -0
  246. package/templates/app/app/commands/db/seed.test.ts +38 -0
  247. package/templates/app/app/commands/db/seed.ts +26 -0
  248. package/templates/app/app/commands/deploy.test.ts +34 -0
  249. package/templates/app/app/commands/deploy.ts +18 -0
  250. package/templates/app/app/commands/emails/preview.test.tsx +63 -0
  251. package/templates/app/app/commands/emails/preview.ts +24 -0
  252. package/templates/app/app/commands/index.ts +57 -2
  253. package/templates/app/app/emails/index.ts +10 -0
  254. package/templates/app/app/http/middleware/access.test.ts +43 -0
  255. package/templates/app/app/http/middleware/access.ts +41 -0
  256. package/templates/app/app/http/middleware/api.ts +12 -3
  257. package/templates/app/app/http/middleware/page.test.ts +4 -1
  258. package/templates/app/app/http/middleware/page.ts +7 -5
  259. package/templates/app/app/initializers/cli.ts +28 -2
  260. package/templates/app/app/initializers/dispatcher.ts +9 -1
  261. package/templates/app/app/initializers/mail-transport.test.ts +27 -0
  262. package/templates/app/app/initializers/mail-transport.ts +26 -0
  263. package/templates/app/app/initializers/mail.test.ts +17 -17
  264. package/templates/app/app/initializers/mail.ts +15 -7
  265. package/templates/app/app/initializers/router.test.ts +7 -0
  266. package/templates/app/app/initializers/router.tsx +13 -3
  267. package/templates/app/app/jobs/email.test.tsx +70 -0
  268. package/templates/app/app/jobs/email.ts +16 -0
  269. package/templates/app/app/jobs/index.ts +6 -2
  270. package/templates/app/app/policies/abilities.ts +13 -0
  271. package/templates/app/app/policies/policy.test.ts +15 -0
  272. package/templates/app/app/policies/policy.ts +30 -0
  273. package/templates/app/app/services/commands.ts +30 -0
  274. package/templates/app/app/services/migrations.test.ts +48 -1
  275. package/templates/app/app/services/migrations.ts +66 -9
  276. package/templates/app/app/test/local-database.ts +67 -0
  277. package/templates/app/app/test/session.ts +28 -0
  278. package/templates/app/bootstrap/console.ts +13 -0
  279. package/templates/app/cloudflare.config.ts +3 -3
  280. package/templates/app/database/seed.ts +12 -0
  281. package/templates/app/package.json +2 -1
  282. package/stubs/policy.stub +0 -16
@@ -0,0 +1,609 @@
1
+ /**
2
+ * The migration that brings a chain's schema in step with a model's tables: the chain is replayed
3
+ * into an in-memory SQLite, each table is read back and compared with its data-table definition,
4
+ * and the cheapest statements SQLite and D1 apply without losing rows are chosen and verified.
5
+ *
6
+ * @author [Sergio Xalambrí](https://sergiodxa.com)
7
+ * @copyright Sergio Xalambrí 2026
8
+ */
9
+ import { DatabaseSync } from "node:sqlite";
10
+ import { failure, isFailure, success, wrap } from "@sdxc/result";
11
+ import { checksOf, columnClause, createTable, createTableStatement, defaultClause, isKey, isNotNull, quote, uniqueIndex, } from "./schema.js";
12
+ /**
13
+ * The affinities whose columns already hold each data-table type's values, so a column declared
14
+ * `VARCHAR(36)`, `BOOLEAN`, `DATETIME` or `DECIMAL` matches its model without a rebuild.
15
+ */
16
+ const ACCEPTED_AFFINITIES = {
17
+ varchar: ["TEXT"],
18
+ text: ["TEXT"],
19
+ uuid: ["TEXT"],
20
+ enum: ["TEXT"],
21
+ json: ["TEXT"],
22
+ date: ["TEXT", "NUMERIC"],
23
+ time: ["TEXT", "NUMERIC"],
24
+ timestamp: ["TEXT", "NUMERIC"],
25
+ integer: ["INTEGER"],
26
+ bigint: ["INTEGER"],
27
+ boolean: ["INTEGER", "NUMERIC"],
28
+ decimal: ["NUMERIC", "REAL"],
29
+ binary: ["BLOB"],
30
+ };
31
+ /** Drizzle's marker between the statements of one migration file. */
32
+ const STATEMENT_BREAKPOINT = "--> statement-breakpoint";
33
+ /** The prefix of the table a rebuild creates beside the one it replaces. */
34
+ const REBUILD_PREFIX = "__sdxc_new_";
35
+ /**
36
+ * Plans the migration that makes the schema `migrations` build match `tables`, then applies it to
37
+ * that schema and compares again, so a plan that errors or leaves a difference fails here rather
38
+ * than in production.
39
+ */
40
+ export function planMigration(migrations, tables) {
41
+ let replayed = replayChain(migrations);
42
+ if (isFailure(replayed))
43
+ return replayed;
44
+ let db = replayed.data.db;
45
+ try {
46
+ let change = diffTables(db, tables);
47
+ if (isFailure(change) || change.data.statements.length === 0)
48
+ return change;
49
+ let applied = wrap(() => db.exec(change.data.statements.join("\n")));
50
+ if (isFailure(applied)) {
51
+ return failure(new Error(`The generated migration does not apply: ${applied.error.message}`, {
52
+ cause: applied.error,
53
+ }));
54
+ }
55
+ let again = diffTables(db, tables);
56
+ if (isFailure(again))
57
+ return again;
58
+ if (again.data.statements.length > 0) {
59
+ return failure(new Error(`The generated migration leaves the schema short of the model; still needed:\n${again.data.statements.join("\n")}`));
60
+ }
61
+ return change;
62
+ }
63
+ finally {
64
+ db.close();
65
+ }
66
+ }
67
+ /**
68
+ * A fresh in-memory database with `migrations` applied in order of their leading number, with
69
+ * double-quoted string literals disabled so a copy reading a missing column errors instead of
70
+ * writing the column's name into every row. An error the caller accepts is stepped past.
71
+ *
72
+ * @returns The database, with every accepted error in replay order; the first other error stops
73
+ * the replay with a failure naming its file.
74
+ */
75
+ export function replayChain(migrations, options = {}) {
76
+ let db = new DatabaseSync(":memory:", { enableDoubleQuotedStringLiterals: false });
77
+ let accepted = [];
78
+ let ordered = [...migrations].sort((a, b) => leadingNumber(a.name) - leadingNumber(b.name));
79
+ for (let migration of ordered) {
80
+ for (let statement of statementsOf(migration.sql)) {
81
+ let applied = wrap(() => db.exec(statement));
82
+ if (!isFailure(applied))
83
+ continue;
84
+ let message = applied.error.message;
85
+ if (options.accepts?.(migration.name, message) === true) {
86
+ accepted.push({ file: migration.name, message });
87
+ continue;
88
+ }
89
+ db.close();
90
+ return failure(new Error(`${migration.name} does not replay: ${message}`, { cause: applied.error }));
91
+ }
92
+ }
93
+ return success({ db, accepted });
94
+ }
95
+ /**
96
+ * A file's steps: each piece between Drizzle's statement breakpoints, or the whole file as one
97
+ * step. Stepping past an accepted error skips only the statement that raised it in a Drizzle
98
+ * file, so the rest of that file still builds the schema later files read.
99
+ */
100
+ function statementsOf(sql) {
101
+ return sql.split(STATEMENT_BREAKPOINT).filter((piece) => piece.trim() !== "");
102
+ }
103
+ /** A file's leading number, which orders a chain; a file without one sorts last. */
104
+ function leadingNumber(name) {
105
+ let match = /^(\d+)/.exec(name);
106
+ return match === null ? Number.POSITIVE_INFINITY : Number(match[1]);
107
+ }
108
+ /** The statements and warnings of every table, in the order the model declares them. */
109
+ function diffTables(db, tables) {
110
+ let change = { statements: [], warnings: [] };
111
+ for (let table of tables) {
112
+ let current = readTable(db, table.name);
113
+ if (current === null) {
114
+ change.statements.push(...createTableStatement(table).split("\n\n"));
115
+ continue;
116
+ }
117
+ let diffed = diffTable(db, table, current);
118
+ if (isFailure(diffed))
119
+ return diffed;
120
+ change.statements.push(...diffed.data.statements);
121
+ change.warnings.push(...diffed.data.warnings);
122
+ }
123
+ return success(change);
124
+ }
125
+ /**
126
+ * The change one existing table needs. Columns are added and dropped in place where SQLite
127
+ * allows it; any other difference rebuilds the table. A unique index the model lacks is kept
128
+ * with a warning, since dropping it would remove a guarantee the data may rely on.
129
+ */
130
+ function diffTable(db, table, current) {
131
+ let warnings = [];
132
+ let reasons = [];
133
+ let currentColumns = new Map(current.columns.map((column) => [column.name.toLowerCase(), column]));
134
+ let modelColumns = Object.entries(table.columns);
135
+ let modelNames = new Set(modelColumns.map(([name]) => name.toLowerCase()));
136
+ let added = modelColumns.filter(([name]) => !currentColumns.has(name.toLowerCase()));
137
+ let dropped = current.columns.filter((column) => !modelNames.has(column.name.toLowerCase()));
138
+ for (let [name, definition] of modelColumns) {
139
+ let existing = currentColumns.get(name.toLowerCase());
140
+ if (existing === undefined)
141
+ continue;
142
+ let reason = columnDifference(table, name, definition, existing);
143
+ if (reason !== null)
144
+ reasons.push(`${table.name}.${name} ${reason}`);
145
+ }
146
+ let currentKey = current.columns
147
+ .filter((column) => column.key > 0)
148
+ .sort((a, b) => a.key - b.key)
149
+ .map((column) => column.name.toLowerCase());
150
+ let modelKey = table.primaryKey.map((name) => name.toLowerCase());
151
+ if (currentKey.join(",") !== modelKey.join(",")) {
152
+ reasons.push(`${table.name}'s primary key changes`);
153
+ }
154
+ reasons.push(...foreignKeyDifferences(db, table, current, added, dropped));
155
+ reasons.push(...checkDifferences(table, current, added));
156
+ for (let [name, definition] of added) {
157
+ let blocker = addBlocker(table, name, definition);
158
+ if (blocker !== null)
159
+ reasons.push(`${table.name}.${name} ${blocker}`);
160
+ }
161
+ for (let column of dropped) {
162
+ warnings.push(`${table.name}.${column.name} is not in the model: the migration drops it and deletes its data`);
163
+ let blocker = dropBlocker(current, column);
164
+ if (blocker !== null)
165
+ reasons.push(`${table.name}.${column.name} ${blocker}`);
166
+ }
167
+ if (added.length > 0 && dropped.length > 0) {
168
+ let gone = dropped.map((column) => column.name).join(", ");
169
+ let fresh = added.map(([name]) => name).join(", ");
170
+ warnings.push(`${table.name} drops ${gone} and adds ${fresh}: if that is a rename, sdxc cannot tell, so the data in ${gone} is deleted; copy it in the migration before the drop`);
171
+ }
172
+ let undeclared = undeclaredUniques(table, current);
173
+ for (let column of undeclared) {
174
+ warnings.push(`${table.name}.${column} is unique in the database but not in the model: sdxc keeps it; drop it by hand if that is intended`);
175
+ }
176
+ if (reasons.length > 0) {
177
+ let rebuilt = rebuild(db, table, current, reasons);
178
+ if (isFailure(rebuilt))
179
+ return rebuilt;
180
+ return success({
181
+ statements: rebuilt.data.statements,
182
+ warnings: [...warnings, ...rebuilt.data.warnings],
183
+ });
184
+ }
185
+ let statements = added.map(([name, definition]) => `ALTER TABLE ${quote(table.name)} ADD COLUMN ${columnClause(table, name, definition, { constraints: true })};`);
186
+ for (let [name, definition] of modelColumns) {
187
+ if (!declaresUnique(definition) || hasUniqueIndex(current, name))
188
+ continue;
189
+ statements.push(uniqueIndex(table, name));
190
+ }
191
+ for (let column of dropped) {
192
+ statements.push(`ALTER TABLE ${quote(table.name)} DROP COLUMN ${quote(column.name)};`);
193
+ }
194
+ return success({ statements, warnings });
195
+ }
196
+ /**
197
+ * Why an existing column differs from its definition in a way only a rebuild changes, or `null`.
198
+ * Key columns skip nullability: data-table never writes a null key, and SQLite reports an
199
+ * `INTEGER PRIMARY KEY` as nullable.
200
+ */
201
+ function columnDifference(table, name, definition, existing) {
202
+ let generated = definition.computed === undefined ? 0 : definition.computed.stored ? 3 : 2;
203
+ let hidden = existing.hidden === 2 || existing.hidden === 3 ? existing.hidden : 0;
204
+ if (generated !== hidden)
205
+ return "changes how it is generated";
206
+ let accepted = ACCEPTED_AFFINITIES[definition.type] ?? ["TEXT"];
207
+ if (!accepted.includes(affinity(existing.type)))
208
+ return "changes type";
209
+ if (!isKey(table, name) && isNotNull(table, name) !== existing.notNull) {
210
+ return existing.notNull ? "becomes nullable" : "becomes NOT NULL";
211
+ }
212
+ if (definition.computed === undefined) {
213
+ let wanted = defaultClause(definition);
214
+ if (normalizeDefault(wanted) !== normalizeDefault(existing.default)) {
215
+ return `changes its default from ${existing.default ?? "none"} to ${wanted ?? "none"}`;
216
+ }
217
+ }
218
+ return null;
219
+ }
220
+ /**
221
+ * The affinity SQLite gives a declared type, by its rules: `INT` anywhere is INTEGER, then
222
+ * `CHAR`/`CLOB`/`TEXT` is TEXT, `BLOB` or no type is BLOB, `REAL`/`FLOA`/`DOUB` is REAL, and
223
+ * anything else is NUMERIC.
224
+ */
225
+ function affinity(declared) {
226
+ let type = declared.toUpperCase();
227
+ if (type.includes("INT"))
228
+ return "INTEGER";
229
+ if (/CHAR|CLOB|TEXT/.test(type))
230
+ return "TEXT";
231
+ if (type === "" || type.includes("BLOB"))
232
+ return "BLOB";
233
+ if (/REAL|FLOA|DOUB/.test(type))
234
+ return "REAL";
235
+ return "NUMERIC";
236
+ }
237
+ /**
238
+ * A default's SQL in a form two spellings of one default share: outer parentheses dropped,
239
+ * `TRUE`/`FALSE` as `1`/`0`, numbers by value, and unquoted keywords lowercased. `NULL` and no
240
+ * default are both `null`, which is what SQLite stores for either.
241
+ */
242
+ function normalizeDefault(sql) {
243
+ if (sql === null)
244
+ return null;
245
+ let text = sql.trim();
246
+ while (wrapped(text))
247
+ text = text.slice(1, -1).trim();
248
+ if (/^null$/i.test(text))
249
+ return null;
250
+ if (/^true$/i.test(text))
251
+ return "1";
252
+ if (/^false$/i.test(text))
253
+ return "0";
254
+ if (/^[+-]?(\d+\.?\d*|\.\d+)(e[+-]?\d+)?$/i.test(text))
255
+ return String(Number(text));
256
+ return text.includes("'") ? text : text.toLowerCase();
257
+ }
258
+ /** Whether one pair of parentheses encloses all of `text`, as in `(a + b)` but not `(a) + (b)`. */
259
+ function wrapped(text) {
260
+ if (!text.startsWith("(") || !text.endsWith(")"))
261
+ return false;
262
+ let depth = 0;
263
+ for (let index = 0; index < text.length; index++) {
264
+ let character = text[index];
265
+ if (character === "(")
266
+ depth++;
267
+ if (character === ")")
268
+ depth--;
269
+ if (depth === 0 && index < text.length - 1)
270
+ return false;
271
+ }
272
+ return true;
273
+ }
274
+ /**
275
+ * Each foreign key the model and the table disagree on, among columns both have; a key on an
276
+ * added column rides on its `ADD COLUMN`, and one on a dropped column goes with it.
277
+ */
278
+ function foreignKeyDifferences(db, table, current, added, dropped) {
279
+ let fresh = new Set(added.map(([name]) => name.toLowerCase()));
280
+ let gone = new Set(dropped.map((column) => column.name.toLowerCase()));
281
+ let wanted = new Map();
282
+ for (let [name, definition] of Object.entries(table.columns)) {
283
+ let references = definition.references;
284
+ if (references === undefined || fresh.has(name.toLowerCase()))
285
+ continue;
286
+ wanted.set(foreignKeySignature({
287
+ owner: table.name,
288
+ table: references.table.name,
289
+ from: [name],
290
+ to: references.columns,
291
+ onDelete: references.onDelete ?? "no action",
292
+ onUpdate: references.onUpdate ?? "no action",
293
+ }), name);
294
+ }
295
+ let present = new Map();
296
+ for (let key of current.foreignKeys) {
297
+ if (key.from.length > 1 || key.from.some((column) => gone.has(column.toLowerCase())))
298
+ continue;
299
+ let resolved = key.to.length > 0 ? key : { ...key, to: primaryKeyOf(db, key.table) };
300
+ present.set(foreignKeySignature(resolved), key.from.join(", "));
301
+ }
302
+ let reasons = [];
303
+ for (let [signature, column] of wanted) {
304
+ if (!present.has(signature))
305
+ reasons.push(`${table.name}.${column} changes its foreign key`);
306
+ }
307
+ for (let [signature, columns] of present) {
308
+ if (!wanted.has(signature))
309
+ reasons.push(`${table.name} drops the foreign key on ${columns}`);
310
+ }
311
+ return reasons;
312
+ }
313
+ /** A foreign key as one comparable string, case and default actions normalized. */
314
+ function foreignKeySignature(key) {
315
+ return [
316
+ key.from.join(","),
317
+ key.table,
318
+ key.to.join(","),
319
+ key.onDelete.replace(/\s+/g, " "),
320
+ key.onUpdate.replace(/\s+/g, " "),
321
+ ]
322
+ .join("|")
323
+ .toLowerCase();
324
+ }
325
+ /**
326
+ * Each named check the model and the table disagree on, by name: SQLite keeps no parsed form of
327
+ * a check, so a changed expression under an unchanged name reads as equal. A check on an added
328
+ * column rides on its `ADD COLUMN`.
329
+ */
330
+ function checkDifferences(table, current, added) {
331
+ let fresh = new Set(added.flatMap(([, definition]) => (definition.checks ?? []).map((check) => check.name.toLowerCase())));
332
+ let wanted = new Set(checksOf(table).map((check) => check.name.toLowerCase()));
333
+ let present = new Set(current.checks);
334
+ let reasons = [];
335
+ for (let name of wanted) {
336
+ if (!present.has(name) && !fresh.has(name))
337
+ reasons.push(`${table.name} adds the check ${name}`);
338
+ }
339
+ for (let name of present) {
340
+ if (!wanted.has(name))
341
+ reasons.push(`${table.name} drops the check ${name}`);
342
+ }
343
+ return reasons;
344
+ }
345
+ /**
346
+ * Why SQLite cannot `ADD COLUMN` this column, or `null` when it can. D1 enforces foreign keys,
347
+ * so a referencing column also needs a `NULL` default there.
348
+ */
349
+ function addBlocker(table, name, definition) {
350
+ if (isKey(table, name))
351
+ return "joins the primary key";
352
+ if (definition.computed?.stored === true)
353
+ return "is a stored generated column";
354
+ let fallback = definition.default;
355
+ if (fallback !== undefined && fallback.kind !== "literal") {
356
+ return "has a default SQLite cannot add in place";
357
+ }
358
+ let nullDefault = fallback === undefined || fallback.value === null;
359
+ if (definition.computed === undefined && isNotNull(table, name) && nullDefault) {
360
+ return "is NOT NULL with no default";
361
+ }
362
+ if (definition.references !== undefined && !nullDefault) {
363
+ return "references another table and has a default";
364
+ }
365
+ return null;
366
+ }
367
+ /**
368
+ * Why SQLite cannot `DROP COLUMN` this column, or `null` when it can. A table with checks,
369
+ * generated columns or expression indexes rebuilds instead, since any of them may read it.
370
+ */
371
+ function dropBlocker(current, column) {
372
+ let name = column.name.toLowerCase();
373
+ if (column.key > 0)
374
+ return "leaves the primary key";
375
+ if (column.hidden === 2 || column.hidden === 3)
376
+ return "is a generated column";
377
+ let indexed = current.indexes.some((index) => index.columns.some((indexed) => indexed === null || indexed.toLowerCase() === name));
378
+ if (indexed || current.indexes.some((index) => index.partial))
379
+ return "is indexed";
380
+ if (current.foreignKeys.some((key) => key.from.some((from) => from.toLowerCase() === name))) {
381
+ return "holds a foreign key";
382
+ }
383
+ let checked = current.checks.length + current.unnamedChecks > 0;
384
+ if (checked || current.columns.some((other) => other.hidden >= 2)) {
385
+ return "may be read by a check or a generated column";
386
+ }
387
+ return null;
388
+ }
389
+ /** Whether `.unique()` was called on the column. */
390
+ function declaresUnique(definition) {
391
+ return definition?.unique !== undefined && definition.unique !== false;
392
+ }
393
+ /** Whether a full unique index, of any origin, covers exactly `column`. */
394
+ function hasUniqueIndex(current, column) {
395
+ return current.indexes.some((index) => index.unique &&
396
+ !index.partial &&
397
+ index.columns.length === 1 &&
398
+ index.columns[0]?.toLowerCase() === column.toLowerCase());
399
+ }
400
+ /** The model's columns a single-column unique index or constraint covers without `.unique()`. */
401
+ function undeclaredUniques(table, current) {
402
+ let columns = Object.keys(table.columns);
403
+ return columns.filter((name) => !declaresUnique(table.columns[name]) &&
404
+ !(table.primaryKey.length === 1 && isKey(table, name)) &&
405
+ current.indexes.some((index) => index.unique &&
406
+ !index.partial &&
407
+ index.origin !== "pk" &&
408
+ index.columns.length === 1 &&
409
+ index.columns[0]?.toLowerCase() === name.toLowerCase()));
410
+ }
411
+ /**
412
+ * The twelve-step rebuild D1 can run: create the new table beside the old one, copy every shared
413
+ * column through its **old** name, drop the old table, rename the new one, then recreate the old
414
+ * table's indexes, triggers and unique constraints. Refused when a reference would act on rows.
415
+ */
416
+ function rebuild(db, table, current, reasons) {
417
+ let references = referencesTo(db, table.name);
418
+ for (let [name, definition] of Object.entries(table.columns)) {
419
+ let target = definition.references;
420
+ if (target === undefined || target.table.name.toLowerCase() !== table.name.toLowerCase())
421
+ continue;
422
+ references.push({
423
+ owner: table.name,
424
+ table: table.name,
425
+ from: [name],
426
+ to: target.columns,
427
+ onDelete: (target.onDelete ?? "no action").toUpperCase(),
428
+ onUpdate: (target.onUpdate ?? "no action").toUpperCase(),
429
+ });
430
+ }
431
+ let acting = references.filter((key) => key.onDelete.toUpperCase() !== "NO ACTION");
432
+ if (acting.length > 0) {
433
+ let fired = acting
434
+ .map((key) => `${key.owner}.${key.from.join(", ")} ON DELETE ${key.onDelete.toUpperCase()}`)
435
+ .join(", ");
436
+ return failure(new Error(`${table.name} needs a rebuild (${reasons.join("; ")}), and dropping it on D1 fires ${fired} on the rows that reference it; write this migration by hand`));
437
+ }
438
+ let warnings = [
439
+ `${table.name} is rebuilt (create, copy, drop, rename) because ${reasons.join("; ")}`,
440
+ ];
441
+ for (let key of current.foreignKeys.filter((candidate) => candidate.from.length > 1)) {
442
+ warnings.push(`${table.name}'s foreign key on (${key.from.join(", ")}) spans columns a model cannot declare: the rebuild drops it; add it back by hand`);
443
+ }
444
+ if (current.unnamedChecks > 0) {
445
+ warnings.push(`${table.name} has ${current.unnamedChecks} unnamed CHECK constraint(s) a model cannot declare: the rebuild drops them; add them back by hand`);
446
+ }
447
+ let temporary = `${REBUILD_PREFIX}${table.name}`;
448
+ let statements = [createTable(table, temporary)];
449
+ let currentColumns = new Map(current.columns.map((column) => [column.name.toLowerCase(), column]));
450
+ let targets = [];
451
+ let sources = [];
452
+ for (let [name, definition] of Object.entries(table.columns)) {
453
+ if (definition.computed !== undefined)
454
+ continue;
455
+ let existing = currentColumns.get(name.toLowerCase());
456
+ let notNull = isNotNull(table, name);
457
+ let fallback = defaultClause(definition);
458
+ if (existing === undefined || existing.hidden >= 2) {
459
+ if (notNull && (fallback === null || normalizeDefault(fallback) === null)) {
460
+ warnings.push(`${table.name}.${name} is NOT NULL with no default: the rebuild fails on a table with rows; give it a default or fill it in the INSERT`);
461
+ }
462
+ continue;
463
+ }
464
+ targets.push(quote(name));
465
+ let source = quote(existing.name);
466
+ if (notNull && !existing.notNull && !isKey(table, name)) {
467
+ if (fallback === null || normalizeDefault(fallback) === null) {
468
+ warnings.push(`${table.name}.${name} becomes NOT NULL with no default: the rebuild fails if a row holds NULL in it`);
469
+ }
470
+ else {
471
+ source = `COALESCE(${source}, ${fallback})`;
472
+ }
473
+ }
474
+ sources.push(source);
475
+ }
476
+ if (targets.length > 0) {
477
+ statements.push(`INSERT INTO ${quote(temporary)} (${targets.join(", ")}) SELECT ${sources.join(", ")} FROM ${quote(table.name)};`);
478
+ }
479
+ else {
480
+ warnings.push(`${table.name} shares no column with the model: the rebuild keeps none of its rows`);
481
+ }
482
+ statements.push(`DROP TABLE ${quote(table.name)};`, `ALTER TABLE ${quote(temporary)} RENAME TO ${quote(table.name)};`);
483
+ let kept = new Set(Object.keys(table.columns).map((name) => name.toLowerCase()));
484
+ let unique = new Set();
485
+ for (let index of current.indexes) {
486
+ if (index.origin === "pk")
487
+ continue;
488
+ let missing = index.columns.filter((column) => column !== null && !kept.has(column.toLowerCase()));
489
+ if (missing.length > 0) {
490
+ warnings.push(`The index ${index.name} on ${table.name} reads ${missing.join(", ")}, which the model drops: the rebuild leaves it out`);
491
+ continue;
492
+ }
493
+ if (index.unique && !index.partial && index.columns.length === 1) {
494
+ unique.add(index.columns[0]?.toLowerCase() ?? "");
495
+ }
496
+ if (index.sql !== null) {
497
+ statements.push(`${index.sql};`);
498
+ continue;
499
+ }
500
+ let columns = index.columns.filter((column) => column !== null);
501
+ let name = `${table.name}_${columns.join("_")}_unique`;
502
+ statements.push(`CREATE UNIQUE INDEX ${quote(name)} ON ${quote(table.name)} (${columns.map(quote).join(", ")});`);
503
+ }
504
+ for (let [name, definition] of Object.entries(table.columns)) {
505
+ if (declaresUnique(definition) && !unique.has(name.toLowerCase())) {
506
+ statements.push(uniqueIndex(table, name));
507
+ }
508
+ }
509
+ statements.push(...current.triggers.map((trigger) => `${trigger};`));
510
+ if (references.length > 0) {
511
+ statements.unshift("PRAGMA defer_foreign_keys = on;");
512
+ statements.push("PRAGMA defer_foreign_keys = off;");
513
+ }
514
+ return success({ statements, warnings });
515
+ }
516
+ /** Every foreign key in the database that points at `name`, the table's own included. */
517
+ function referencesTo(db, name) {
518
+ let tables = db
519
+ .prepare(`SELECT "name" FROM "sqlite_master" WHERE "type" = 'table' AND "name" NOT LIKE 'sqlite\\_%' ESCAPE '\\'`)
520
+ .all();
521
+ return tables
522
+ .flatMap((owner) => foreignKeysOf(db, owner.name))
523
+ .filter((key) => key.table.toLowerCase() === name.toLowerCase());
524
+ }
525
+ /** The table named `name`, compared without case as SQLite does, or `null` when it is absent. */
526
+ function readTable(db, name) {
527
+ let row = db
528
+ .prepare(`SELECT "name", "sql" FROM "sqlite_master" WHERE "type" = 'table' AND "name" = ? COLLATE NOCASE`)
529
+ .get(name);
530
+ if (row === undefined)
531
+ return null;
532
+ let columns = db.prepare(`SELECT * FROM pragma_table_xinfo(?)`).all(row.name).map((column) => ({
533
+ name: column.name,
534
+ type: column.type,
535
+ notNull: column.notnull === 1,
536
+ default: column.dflt_value,
537
+ key: column.pk,
538
+ hidden: column.hidden,
539
+ }));
540
+ let indexes = db.prepare(`SELECT * FROM pragma_index_list(?)`).all(row.name).map((index) => ({
541
+ name: index.name,
542
+ unique: index.unique === 1,
543
+ origin: index.origin,
544
+ partial: index.partial === 1,
545
+ columns: db
546
+ .prepare(`SELECT * FROM pragma_index_xinfo(?) WHERE "key" = 1 ORDER BY "seqno"`)
547
+ .all(index.name).map((column) => column.name),
548
+ sql: db
549
+ .prepare(`SELECT "sql" FROM "sqlite_master" WHERE "type" = 'index' AND "name" = ?`)
550
+ .get(index.name)?.sql ?? null,
551
+ }));
552
+ let triggers = db
553
+ .prepare(`SELECT "sql" FROM "sqlite_master" WHERE "type" = 'trigger' AND "tbl_name" = ? COLLATE NOCASE`)
554
+ .all(row.name).map((trigger) => trigger.sql);
555
+ return {
556
+ name: row.name,
557
+ columns,
558
+ indexes,
559
+ foreignKeys: foreignKeysOf(db, row.name),
560
+ checks: checkNames(row.sql),
561
+ unnamedChecks: Math.max(0, (row.sql.match(/\bCHECK\s*\(/gi)?.length ?? 0) - checkNames(row.sql).length),
562
+ triggers,
563
+ };
564
+ }
565
+ /** The foreign keys `owner` holds, one per constraint, with their columns in order. */
566
+ function foreignKeysOf(db, owner) {
567
+ let rows = db
568
+ .prepare(`SELECT * FROM pragma_foreign_key_list(?) ORDER BY "id", "seq"`)
569
+ .all(owner);
570
+ let keys = new Map();
571
+ for (let row of rows) {
572
+ let key = keys.get(row.id);
573
+ if (key === undefined) {
574
+ key = {
575
+ owner,
576
+ table: row.table,
577
+ from: [],
578
+ to: [],
579
+ onDelete: row.on_delete,
580
+ onUpdate: row.on_update,
581
+ };
582
+ keys.set(row.id, key);
583
+ }
584
+ key.from.push(row.from);
585
+ if (row.to !== null)
586
+ key.to.push(row.to);
587
+ }
588
+ return [...keys.values()];
589
+ }
590
+ /** The primary key columns of `table`, which a `REFERENCES table` without columns points at. */
591
+ function primaryKeyOf(db, table) {
592
+ let rows = db
593
+ .prepare(`SELECT "name" FROM pragma_table_info(?) WHERE "pk" > 0 ORDER BY "pk"`)
594
+ .all(table);
595
+ return rows.map((row) => row.name);
596
+ }
597
+ /** The lowercased names of the `CONSTRAINT <name> CHECK` clauses in a `CREATE TABLE`. */
598
+ function checkNames(sql) {
599
+ let pattern = /CONSTRAINT\s+("(?:[^"]|"")+"|`[^`]+`|\[[^\]]+\]|[A-Za-z_][\w$]*)\s+CHECK\b/gi;
600
+ return [...sql.matchAll(pattern)].map((match) => unquote(match[1] ?? "").toLowerCase());
601
+ }
602
+ /** An identifier without the quotes SQLite accepts around it. */
603
+ function unquote(name) {
604
+ if (name.startsWith('"'))
605
+ return name.slice(1, -1).replaceAll('""', '"');
606
+ if (name.startsWith("`") || name.startsWith("["))
607
+ return name.slice(1, -1);
608
+ return name;
609
+ }
@@ -0,0 +1,76 @@
1
+ /**
2
+ * SQLite DDL for a `remix/data-table` table: the `CREATE TABLE` a model's table needs, its unique
3
+ * indexes, and the column clauses `ALTER TABLE` reuses. One renderer serves `make migration
4
+ * --from-model` and every generator that writes a table, so a table is spelled one way everywhere.
5
+ *
6
+ * @author [Sergio Xalambrí](https://sergiodxa.com)
7
+ * @copyright Sergio Xalambrí 2026
8
+ */
9
+ import type { AnyTable, ColumnDefinition, ColumnTypeName } from "remix/data-table";
10
+ /**
11
+ * A table as its data-table definition describes it, in a form that survives JSON: what a model
12
+ * module loaded in the project's own runtime reports back. Column order is declaration order.
13
+ */
14
+ export interface TableShape {
15
+ name: string;
16
+ /** The primary key's columns in order; data-table defaults it to `["id"]`. */
17
+ primaryKey: readonly string[];
18
+ columns: Readonly<Record<string, ColumnDefinition>>;
19
+ }
20
+ /**
21
+ * The shape of a data-table table, or `null` for anything else. The metadata is found by its
22
+ * symbol's description, so a table built by the project's own copy of `remix/data-table` reads
23
+ * the same as one built by this package's copy.
24
+ */
25
+ export declare function tableShape(value: unknown): TableShape | null;
26
+ /**
27
+ * The SQL that creates `table` on an empty database: its `CREATE TABLE`, then a `CREATE UNIQUE
28
+ * INDEX` per `.unique()` column, each statement ending in `;` and separated by a blank line.
29
+ * Every column is `NOT NULL` unless declared `.nullable()`, as data-table types its rows.
30
+ *
31
+ * @example createTableStatement(postsTable)
32
+ */
33
+ export declare function createTableStatement(table: AnyTable | TableShape): string;
34
+ /** The `CREATE TABLE` statement alone, under `name` when the table is built beside its original. */
35
+ export declare function createTable(table: TableShape, name?: string): string;
36
+ /** One `CREATE UNIQUE INDEX` per `.unique()` column of `table`. */
37
+ export declare function uniqueIndexes(table: TableShape): string[];
38
+ /**
39
+ * The unique index `.unique(name)` names, or `<table>_<column>_unique`. An index keeps the
40
+ * column addable with `ALTER TABLE ADD COLUMN`, which refuses an inline `UNIQUE`.
41
+ */
42
+ export declare function uniqueIndex(table: TableShape, column: string): string;
43
+ /** How a column is written inside `CREATE TABLE` or after `ADD COLUMN`. */
44
+ interface ColumnClauseOptions {
45
+ /** Whether a single-column primary key is declared on the column itself. */
46
+ inlineKey?: boolean;
47
+ /** Whether foreign keys and checks ride on the column, as `ADD COLUMN` needs them to. */
48
+ constraints?: boolean;
49
+ }
50
+ /**
51
+ * The column's definition: name, type, key, nullability, default, collation and generation, plus
52
+ * its foreign key and checks when `constraints` asks for them.
53
+ */
54
+ export declare function columnClause(table: TableShape, column: string, definition: ColumnDefinition, options?: ColumnClauseOptions): string;
55
+ /** The SQLite type a data-table column type is declared with. */
56
+ export declare function sqliteType(type: ColumnTypeName): string;
57
+ /** Whether `column` is part of the table's primary key; names compare as SQLite does, ignoring case. */
58
+ export declare function isKey(table: TableShape, column: string): boolean;
59
+ /** Whether the column refuses `NULL`: a key column always does, any other unless `.nullable()`. */
60
+ export declare function isNotNull(table: TableShape, column: string): boolean;
61
+ /**
62
+ * The default's SQL, or `null` without one. A literal becomes a SQL literal (booleans as 0 and 1,
63
+ * dates as ISO text, objects as JSON text), `defaultNow()` becomes `CURRENT_TIMESTAMP`, and a
64
+ * `defaultSql()` expression is wrapped in parentheses, as SQLite requires of an expression.
65
+ */
66
+ export declare function defaultClause(definition: ColumnDefinition): string | null;
67
+ /** `value` as a SQL literal. */
68
+ export declare function literal(value: unknown): string;
69
+ /** `name` as a double-quoted SQL identifier, which SQLite reads as a name and never as text. */
70
+ export declare function quote(name: string): string;
71
+ /** Every check declared on the table's columns, in column order. */
72
+ export declare function checksOf(table: TableShape): {
73
+ name: string;
74
+ expression: string;
75
+ }[];
76
+ export {};