@quereus/quereus 4.8.0 → 4.10.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 (280) hide show
  1. package/dist/src/core/database.d.ts +6 -0
  2. package/dist/src/core/database.d.ts.map +1 -1
  3. package/dist/src/core/database.js +45 -5
  4. package/dist/src/core/database.js.map +1 -1
  5. package/dist/src/core/statement.d.ts.map +1 -1
  6. package/dist/src/core/statement.js +74 -15
  7. package/dist/src/core/statement.js.map +1 -1
  8. package/dist/src/func/builtins/aggregate.d.ts.map +1 -1
  9. package/dist/src/func/builtins/aggregate.js +88 -35
  10. package/dist/src/func/builtins/aggregate.js.map +1 -1
  11. package/dist/src/func/builtins/conversion.d.ts +5 -0
  12. package/dist/src/func/builtins/conversion.d.ts.map +1 -1
  13. package/dist/src/func/builtins/conversion.js +16 -2
  14. package/dist/src/func/builtins/conversion.js.map +1 -1
  15. package/dist/src/func/builtins/explain.d.ts.map +1 -1
  16. package/dist/src/func/builtins/explain.js +9 -2
  17. package/dist/src/func/builtins/explain.js.map +1 -1
  18. package/dist/src/func/builtins/index.d.ts.map +1 -1
  19. package/dist/src/func/builtins/index.js +5 -2
  20. package/dist/src/func/builtins/index.js.map +1 -1
  21. package/dist/src/func/builtins/scalar.d.ts.map +1 -1
  22. package/dist/src/func/builtins/scalar.js +4 -2
  23. package/dist/src/func/builtins/scalar.js.map +1 -1
  24. package/dist/src/func/builtins/string.d.ts +2 -0
  25. package/dist/src/func/builtins/string.d.ts.map +1 -1
  26. package/dist/src/func/builtins/string.js +60 -4
  27. package/dist/src/func/builtins/string.js.map +1 -1
  28. package/dist/src/func/registration.d.ts +6 -0
  29. package/dist/src/func/registration.d.ts.map +1 -1
  30. package/dist/src/func/registration.js +1 -0
  31. package/dist/src/func/registration.js.map +1 -1
  32. package/dist/src/index.d.ts +7 -3
  33. package/dist/src/index.d.ts.map +1 -1
  34. package/dist/src/index.js +21 -2
  35. package/dist/src/index.js.map +1 -1
  36. package/dist/src/planner/building/constraint-builder.js +1 -1
  37. package/dist/src/planner/building/constraint-builder.js.map +1 -1
  38. package/dist/src/planner/nodes/scalar.d.ts.map +1 -1
  39. package/dist/src/planner/nodes/scalar.js +13 -1
  40. package/dist/src/planner/nodes/scalar.js.map +1 -1
  41. package/dist/src/planner/rules/retrieve/rule-grow-retrieve.d.ts.map +1 -1
  42. package/dist/src/planner/rules/retrieve/rule-grow-retrieve.js +121 -51
  43. package/dist/src/planner/rules/retrieve/rule-grow-retrieve.js.map +1 -1
  44. package/dist/src/planner/rules/shared/index-style-context.d.ts +14 -4
  45. package/dist/src/planner/rules/shared/index-style-context.d.ts.map +1 -1
  46. package/dist/src/planner/rules/shared/index-style-context.js +14 -4
  47. package/dist/src/planner/rules/shared/index-style-context.js.map +1 -1
  48. package/dist/src/runtime/emission-context.d.ts +14 -1
  49. package/dist/src/runtime/emission-context.d.ts.map +1 -1
  50. package/dist/src/runtime/emission-context.js +17 -5
  51. package/dist/src/runtime/emission-context.js.map +1 -1
  52. package/dist/src/runtime/emit/aggregate-setup.d.ts +44 -8
  53. package/dist/src/runtime/emit/aggregate-setup.d.ts.map +1 -1
  54. package/dist/src/runtime/emit/aggregate-setup.js +79 -15
  55. package/dist/src/runtime/emit/aggregate-setup.js.map +1 -1
  56. package/dist/src/runtime/emit/aggregate.d.ts.map +1 -1
  57. package/dist/src/runtime/emit/aggregate.js +21 -106
  58. package/dist/src/runtime/emit/aggregate.js.map +1 -1
  59. package/dist/src/runtime/emit/alter-table.d.ts.map +1 -1
  60. package/dist/src/runtime/emit/alter-table.js +212 -155
  61. package/dist/src/runtime/emit/alter-table.js.map +1 -1
  62. package/dist/src/runtime/emit/asof-scan.js +1 -1
  63. package/dist/src/runtime/emit/asof-scan.js.map +1 -1
  64. package/dist/src/runtime/emit/assertion-drop-guard.d.ts +26 -12
  65. package/dist/src/runtime/emit/assertion-drop-guard.d.ts.map +1 -1
  66. package/dist/src/runtime/emit/assertion-drop-guard.js +45 -26
  67. package/dist/src/runtime/emit/assertion-drop-guard.js.map +1 -1
  68. package/dist/src/runtime/emit/assertion-rename-helpers.d.ts +6 -6
  69. package/dist/src/runtime/emit/assertion-rename-helpers.d.ts.map +1 -1
  70. package/dist/src/runtime/emit/assertion-rename-helpers.js +18 -20
  71. package/dist/src/runtime/emit/assertion-rename-helpers.js.map +1 -1
  72. package/dist/src/runtime/emit/between.d.ts +2 -0
  73. package/dist/src/runtime/emit/between.d.ts.map +1 -1
  74. package/dist/src/runtime/emit/between.js +7 -8
  75. package/dist/src/runtime/emit/between.js.map +1 -1
  76. package/dist/src/runtime/emit/binary.d.ts +27 -5
  77. package/dist/src/runtime/emit/binary.d.ts.map +1 -1
  78. package/dist/src/runtime/emit/binary.js +278 -187
  79. package/dist/src/runtime/emit/binary.js.map +1 -1
  80. package/dist/src/runtime/emit/case.d.ts +34 -0
  81. package/dist/src/runtime/emit/case.d.ts.map +1 -1
  82. package/dist/src/runtime/emit/case.js +18 -11
  83. package/dist/src/runtime/emit/case.js.map +1 -1
  84. package/dist/src/runtime/emit/cast.d.ts +2 -0
  85. package/dist/src/runtime/emit/cast.d.ts.map +1 -1
  86. package/dist/src/runtime/emit/cast.js +7 -5
  87. package/dist/src/runtime/emit/cast.js.map +1 -1
  88. package/dist/src/runtime/emit/column-reference.d.ts +3 -1
  89. package/dist/src/runtime/emit/column-reference.d.ts.map +1 -1
  90. package/dist/src/runtime/emit/column-reference.js +6 -2
  91. package/dist/src/runtime/emit/column-reference.js.map +1 -1
  92. package/dist/src/runtime/emit/column-rename-cascade.d.ts +84 -0
  93. package/dist/src/runtime/emit/column-rename-cascade.d.ts.map +1 -0
  94. package/dist/src/runtime/emit/column-rename-cascade.js +134 -0
  95. package/dist/src/runtime/emit/column-rename-cascade.js.map +1 -0
  96. package/dist/src/runtime/emit/dml-executor.d.ts.map +1 -1
  97. package/dist/src/runtime/emit/dml-executor.js +21 -0
  98. package/dist/src/runtime/emit/dml-executor.js.map +1 -1
  99. package/dist/src/runtime/emit/drop-column-guards.d.ts +82 -53
  100. package/dist/src/runtime/emit/drop-column-guards.d.ts.map +1 -1
  101. package/dist/src/runtime/emit/drop-column-guards.js +155 -90
  102. package/dist/src/runtime/emit/drop-column-guards.js.map +1 -1
  103. package/dist/src/runtime/emit/drop-table.d.ts.map +1 -1
  104. package/dist/src/runtime/emit/drop-table.js +5 -0
  105. package/dist/src/runtime/emit/drop-table.js.map +1 -1
  106. package/dist/src/runtime/emit/drop-view.d.ts.map +1 -1
  107. package/dist/src/runtime/emit/drop-view.js +5 -0
  108. package/dist/src/runtime/emit/drop-view.js.map +1 -1
  109. package/dist/src/runtime/emit/expression-drop-guard.d.ts +57 -0
  110. package/dist/src/runtime/emit/expression-drop-guard.d.ts.map +1 -0
  111. package/dist/src/runtime/emit/expression-drop-guard.js +82 -0
  112. package/dist/src/runtime/emit/expression-drop-guard.js.map +1 -0
  113. package/dist/src/runtime/emit/filter.d.ts +1 -1
  114. package/dist/src/runtime/emit/filter.js +1 -1
  115. package/dist/src/runtime/emit/hash-aggregate.d.ts.map +1 -1
  116. package/dist/src/runtime/emit/hash-aggregate.js +18 -88
  117. package/dist/src/runtime/emit/hash-aggregate.js.map +1 -1
  118. package/dist/src/runtime/emit/literal.d.ts +14 -1
  119. package/dist/src/runtime/emit/literal.d.ts.map +1 -1
  120. package/dist/src/runtime/emit/literal.js +33 -7
  121. package/dist/src/runtime/emit/literal.js.map +1 -1
  122. package/dist/src/runtime/emit/materialized-view-helpers.d.ts +33 -10
  123. package/dist/src/runtime/emit/materialized-view-helpers.d.ts.map +1 -1
  124. package/dist/src/runtime/emit/materialized-view-helpers.js +158 -49
  125. package/dist/src/runtime/emit/materialized-view-helpers.js.map +1 -1
  126. package/dist/src/runtime/emit/materialized-view.d.ts.map +1 -1
  127. package/dist/src/runtime/emit/materialized-view.js +3 -0
  128. package/dist/src/runtime/emit/materialized-view.js.map +1 -1
  129. package/dist/src/runtime/emit/parameter.d.ts +3 -1
  130. package/dist/src/runtime/emit/parameter.d.ts.map +1 -1
  131. package/dist/src/runtime/emit/parameter.js +7 -2
  132. package/dist/src/runtime/emit/parameter.js.map +1 -1
  133. package/dist/src/runtime/emit/scalar-function.d.ts +29 -1
  134. package/dist/src/runtime/emit/scalar-function.d.ts.map +1 -1
  135. package/dist/src/runtime/emit/scalar-function.js +66 -16
  136. package/dist/src/runtime/emit/scalar-function.js.map +1 -1
  137. package/dist/src/runtime/emit/scalar-op.d.ts +63 -0
  138. package/dist/src/runtime/emit/scalar-op.d.ts.map +1 -0
  139. package/dist/src/runtime/emit/scalar-op.js +37 -0
  140. package/dist/src/runtime/emit/scalar-op.js.map +1 -0
  141. package/dist/src/runtime/emit/scan.d.ts.map +1 -1
  142. package/dist/src/runtime/emit/scan.js +19 -1
  143. package/dist/src/runtime/emit/scan.js.map +1 -1
  144. package/dist/src/runtime/emit/temporal-arithmetic.d.ts +18 -8
  145. package/dist/src/runtime/emit/temporal-arithmetic.d.ts.map +1 -1
  146. package/dist/src/runtime/emit/temporal-arithmetic.js +29 -311
  147. package/dist/src/runtime/emit/temporal-arithmetic.js.map +1 -1
  148. package/dist/src/runtime/emit/unary.d.ts +2 -0
  149. package/dist/src/runtime/emit/unary.d.ts.map +1 -1
  150. package/dist/src/runtime/emit/unary.js +125 -53
  151. package/dist/src/runtime/emit/unary.js.map +1 -1
  152. package/dist/src/runtime/emitters.d.ts +22 -0
  153. package/dist/src/runtime/emitters.d.ts.map +1 -1
  154. package/dist/src/runtime/emitters.js +29 -0
  155. package/dist/src/runtime/emitters.js.map +1 -1
  156. package/dist/src/runtime/scalar-fusion.d.ts +47 -0
  157. package/dist/src/runtime/scalar-fusion.d.ts.map +1 -0
  158. package/dist/src/runtime/scalar-fusion.js +275 -0
  159. package/dist/src/runtime/scalar-fusion.js.map +1 -0
  160. package/dist/src/runtime/strict-flags.d.ts +9 -0
  161. package/dist/src/runtime/strict-flags.d.ts.map +1 -1
  162. package/dist/src/runtime/strict-flags.js +9 -0
  163. package/dist/src/runtime/strict-flags.js.map +1 -1
  164. package/dist/src/runtime/strict-fork.js +2 -2
  165. package/dist/src/runtime/strict-fork.js.map +1 -1
  166. package/dist/src/runtime/strict-representation.d.ts +78 -0
  167. package/dist/src/runtime/strict-representation.d.ts.map +1 -0
  168. package/dist/src/runtime/strict-representation.js +159 -0
  169. package/dist/src/runtime/strict-representation.js.map +1 -0
  170. package/dist/src/schema/assertion.d.ts +58 -0
  171. package/dist/src/schema/assertion.d.ts.map +1 -1
  172. package/dist/src/schema/assertion.js +78 -0
  173. package/dist/src/schema/assertion.js.map +1 -1
  174. package/dist/src/schema/catalog-persistability.d.ts +11 -3
  175. package/dist/src/schema/catalog-persistability.d.ts.map +1 -1
  176. package/dist/src/schema/catalog-persistability.js +48 -29
  177. package/dist/src/schema/catalog-persistability.js.map +1 -1
  178. package/dist/src/schema/catalog.d.ts +22 -0
  179. package/dist/src/schema/catalog.d.ts.map +1 -1
  180. package/dist/src/schema/catalog.js +4 -1
  181. package/dist/src/schema/catalog.js.map +1 -1
  182. package/dist/src/schema/column-republication.d.ts +126 -0
  183. package/dist/src/schema/column-republication.d.ts.map +1 -0
  184. package/dist/src/schema/column-republication.js +121 -0
  185. package/dist/src/schema/column-republication.js.map +1 -0
  186. package/dist/src/schema/column-source-resolver.d.ts +29 -6
  187. package/dist/src/schema/column-source-resolver.d.ts.map +1 -1
  188. package/dist/src/schema/column-source-resolver.js +78 -9
  189. package/dist/src/schema/column-source-resolver.js.map +1 -1
  190. package/dist/src/schema/expression-dependents.d.ts +160 -0
  191. package/dist/src/schema/expression-dependents.d.ts.map +1 -0
  192. package/dist/src/schema/expression-dependents.js +228 -0
  193. package/dist/src/schema/expression-dependents.js.map +1 -0
  194. package/dist/src/schema/function.d.ts +15 -0
  195. package/dist/src/schema/function.d.ts.map +1 -1
  196. package/dist/src/schema/function.js.map +1 -1
  197. package/dist/src/schema/object-dependency-closure.d.ts +127 -0
  198. package/dist/src/schema/object-dependency-closure.d.ts.map +1 -0
  199. package/dist/src/schema/object-dependency-closure.js +117 -0
  200. package/dist/src/schema/object-dependency-closure.js.map +1 -0
  201. package/dist/src/schema/object-ref-resolver.d.ts +83 -0
  202. package/dist/src/schema/object-ref-resolver.d.ts.map +1 -0
  203. package/dist/src/schema/object-ref-resolver.js +135 -0
  204. package/dist/src/schema/object-ref-resolver.js.map +1 -0
  205. package/dist/src/schema/rename/column-rename.d.ts +228 -0
  206. package/dist/src/schema/rename/column-rename.d.ts.map +1 -0
  207. package/dist/src/schema/rename/column-rename.js +1225 -0
  208. package/dist/src/schema/rename/column-rename.js.map +1 -0
  209. package/dist/src/schema/rename/self-qualifier-strip.d.ts +29 -0
  210. package/dist/src/schema/rename/self-qualifier-strip.d.ts.map +1 -0
  211. package/dist/src/schema/rename/self-qualifier-strip.js +267 -0
  212. package/dist/src/schema/rename/self-qualifier-strip.js.map +1 -0
  213. package/dist/src/schema/rename/shared.d.ts +108 -0
  214. package/dist/src/schema/rename/shared.d.ts.map +1 -0
  215. package/dist/src/schema/rename/shared.js +49 -0
  216. package/dist/src/schema/rename/shared.js.map +1 -0
  217. package/dist/src/schema/rename/table-rename.d.ts +263 -0
  218. package/dist/src/schema/rename/table-rename.d.ts.map +1 -0
  219. package/dist/src/schema/rename/table-rename.js +860 -0
  220. package/dist/src/schema/rename/table-rename.js.map +1 -0
  221. package/dist/src/schema/rename-rewriter.d.ts +18 -278
  222. package/dist/src/schema/rename-rewriter.d.ts.map +1 -1
  223. package/dist/src/schema/rename-rewriter.js +17 -1506
  224. package/dist/src/schema/rename-rewriter.js.map +1 -1
  225. package/dist/src/schema/schema-differ.d.ts.map +1 -1
  226. package/dist/src/schema/schema-differ.js +228 -21
  227. package/dist/src/schema/schema-differ.js.map +1 -1
  228. package/dist/src/types/builtin-types.d.ts.map +1 -1
  229. package/dist/src/types/builtin-types.js +29 -36
  230. package/dist/src/types/builtin-types.js.map +1 -1
  231. package/dist/src/types/cast-semantics.d.ts +7 -5
  232. package/dist/src/types/cast-semantics.d.ts.map +1 -1
  233. package/dist/src/types/cast-semantics.js +20 -9
  234. package/dist/src/types/cast-semantics.js.map +1 -1
  235. package/dist/src/types/index.d.ts +1 -1
  236. package/dist/src/types/index.d.ts.map +1 -1
  237. package/dist/src/types/index.js +1 -1
  238. package/dist/src/types/index.js.map +1 -1
  239. package/dist/src/types/registry.d.ts.map +1 -1
  240. package/dist/src/types/registry.js +2 -1
  241. package/dist/src/types/registry.js.map +1 -1
  242. package/dist/src/types/temporal-ops.d.ts +119 -0
  243. package/dist/src/types/temporal-ops.d.ts.map +1 -0
  244. package/dist/src/types/temporal-ops.js +348 -0
  245. package/dist/src/types/temporal-ops.js.map +1 -0
  246. package/dist/src/types/temporal-types.d.ts +11 -0
  247. package/dist/src/types/temporal-types.d.ts.map +1 -1
  248. package/dist/src/types/temporal-types.js +87 -0
  249. package/dist/src/types/temporal-types.js.map +1 -1
  250. package/dist/src/util/affinity.d.ts +2 -1
  251. package/dist/src/util/affinity.d.ts.map +1 -1
  252. package/dist/src/util/affinity.js +16 -5
  253. package/dist/src/util/affinity.js.map +1 -1
  254. package/dist/src/util/ast-spine-clone.d.ts +2 -2
  255. package/dist/src/util/ast-spine-clone.js +2 -2
  256. package/dist/src/util/coercion.d.ts +22 -7
  257. package/dist/src/util/coercion.d.ts.map +1 -1
  258. package/dist/src/util/coercion.js +28 -15
  259. package/dist/src/util/coercion.js.map +1 -1
  260. package/dist/src/util/comparison.d.ts +25 -0
  261. package/dist/src/util/comparison.d.ts.map +1 -1
  262. package/dist/src/util/comparison.js +25 -0
  263. package/dist/src/util/comparison.js.map +1 -1
  264. package/dist/src/util/key-tuple-codec.d.ts +12 -3
  265. package/dist/src/util/key-tuple-codec.d.ts.map +1 -1
  266. package/dist/src/util/key-tuple-codec.js.map +1 -1
  267. package/dist/src/util/numeric-canonical.d.ts +26 -0
  268. package/dist/src/util/numeric-canonical.d.ts.map +1 -0
  269. package/dist/src/util/numeric-canonical.js +66 -0
  270. package/dist/src/util/numeric-canonical.js.map +1 -0
  271. package/dist/src/util/value-text.d.ts +48 -0
  272. package/dist/src/util/value-text.d.ts.map +1 -0
  273. package/dist/src/util/value-text.js +35 -0
  274. package/dist/src/util/value-text.js.map +1 -0
  275. package/dist/src/vtab/memory/layer/manager.d.ts.map +1 -1
  276. package/dist/src/vtab/memory/layer/manager.js +14 -5
  277. package/dist/src/vtab/memory/layer/manager.js.map +1 -1
  278. package/dist/src/vtab/module.d.ts +25 -0
  279. package/dist/src/vtab/module.d.ts.map +1 -1
  280. package/package.json +4 -3
@@ -0,0 +1,263 @@
1
+ import type * as AST from '../../parser/ast.js';
2
+ import { type ResolveObjectRef, type TableRenameTarget } from './shared.js';
3
+ /**
4
+ * Scope-aware, in-place table-reference walker: propagates
5
+ * `ALTER TABLE … RENAME` into dependent object ASTs (view bodies, CHECK
6
+ * expressions, assertion bodies, partial-index predicates, column DEFAULT /
7
+ * generated expressions) and answers the read-only "does this AST reference
8
+ * table X?" probe the DROP guards use.
9
+ *
10
+ * All three verbs are expressed over ONE traversal ({@link visitTableRefs}),
11
+ * which reports every REAL table reference — one not shadowed by a CTE, a FROM
12
+ * alias, or the `new.`/`old.` row image — to a sink. The rewrite sink renames
13
+ * matching references in place; the probe sink records a match and stops the
14
+ * walk; the collect sink ({@link collectTableRefsInAst}) keys every reference
15
+ * for the reachability closure the DROP guards follow through view chains. One
16
+ * traversal is the invariant, not an implementation detail: the DROP guards
17
+ * must refuse exactly the references a rename would rewrite.
18
+ *
19
+ * All name comparisons are case-insensitive to match the Quereus catalog
20
+ * rules. Walkers mutate the input AST and return whether anything changed, so
21
+ * callers can skip cloning when nothing matched.
22
+ */
23
+ /** Options for the table-reference walk, threaded from the entry points. */
24
+ export interface TableRenameOpts {
25
+ /**
26
+ * The walked expression is evaluated against a WRITTEN ROW — a CHECK
27
+ * constraint or a column DEFAULT / generated body — so a bare `new.` /
28
+ * `old.` column qualifier names the row image, never a table called `new`
29
+ * or `old`. Suppression is scope-aware: it applies only while no FROM/WITH
30
+ * frame rebinds the qualifier (a subquery selecting from a real table
31
+ * named `new` still counts as a table reference), and never to a
32
+ * schema-qualified `main.new.a`, which is a real three-part reference.
33
+ *
34
+ * Deliberately NOT set for partial-index predicates: a predicate describes
35
+ * rows already stored and has no written-row context, so `new.x` there IS
36
+ * a table reference. (The column walker records the same asymmetry by
37
+ * passing row-image mode `'none'` for predicates.)
38
+ *
39
+ * A boolean where the column walker's
40
+ * {@link import('./shared.js').RowImageContext} is three-valued, and
41
+ * COMPLETE at two: this walker never *matches* a row image, only
42
+ * suppresses one, so the column walker's `'own'`/`'foreign'` split
43
+ * collapses — `false` maps to `'none'`, `true` to `'foreign'`. Like the
44
+ * column walker, the flag is overridden (to `true`) over `with inverse` /
45
+ * `with defaults` subtrees regardless of the entry-point value, because
46
+ * written-row context there is a property of the position, not the walk.
47
+ */
48
+ rowImageContext?: boolean;
49
+ /**
50
+ * The walked expression is SCHEMA-AUTHORED — a CHECK constraint, a column
51
+ * DEFAULT / generated body, or a partial-index predicate — so it plans under
52
+ * `schemaAuthoredContext` (`planner/building/schema-authored-context.ts`):
53
+ * its owning schema and NOTHING else, never the session schema path. Set by
54
+ * the three collection helpers below; absent for the stored bodies that DO
55
+ * plan under the home schema path (view bodies, materialized-view bodies,
56
+ * assertion checks).
57
+ *
58
+ * Suppresses the untouched-reference arm of {@link renameTableInAst}, for
59
+ * two reasons that agree:
60
+ *
61
+ * - Nothing is lost. That arm fires only when an unqualified name resolves
62
+ * through to ANOTHER schema, which is precisely what this planning context
63
+ * rejects — so it could only ever fire on a body the planner already
64
+ * refuses to evaluate.
65
+ * - It keeps the walk IDEMPOTENT where idempotence is load-bearing. The
66
+ * renamed table's own CHECK / predicate / column expressions are walked
67
+ * more than once on purpose: `runRenameTable` rewrites them before the
68
+ * catalog swap, `propagateTableRename` walks every table again afterwards,
69
+ * and a persisting module rewrites the same shared ASTs inside its own
70
+ * `renameTable` hook. The rewrite arm is idempotent by construction (after
71
+ * it runs, nothing names `oldName`); the untouched arm is NOT, because a
72
+ * reference the rewrite already turned into `newName` is indistinguishable
73
+ * — to the resolvers — from one the new name captured. Confining that arm
74
+ * to the once-walked home-path bodies is what keeps the two facts from
75
+ * colliding.
76
+ */
77
+ schemaAuthoredBody?: boolean;
78
+ }
79
+ /**
80
+ * `target.resolve` and the derived `targetKey` (`objectRefKey(target.schemaName,
81
+ * target.oldName)`) decide matching for the rewrite and the probe below alike: a
82
+ * reference matches when `resolve(ref.schema, ref.name)` — the reference's
83
+ * planner-parity resolution under the WALKED BODY's home schema path — equals
84
+ * `targetKey`. The bare-name equality check in front is a pure short-circuit:
85
+ * the resolver echoes the name it is given into the key, so a reference spelled
86
+ * differently can never resolve to the target.
87
+ *
88
+ * The rewrite additionally enforces a POST-CONDITION the probe does not need,
89
+ * and it covers EVERY reference the walk reports — not only the ones it
90
+ * rewrites:
91
+ *
92
+ * > Walking a body for a rename, every reference must mean after the statement
93
+ * > exactly what it meant before.
94
+ *
95
+ * Both arms decide that the same way: re-resolve the reference under the same
96
+ * home schema path against the catalog AS IT WILL BE AFTER THE RENAME
97
+ * (`target.resolveAfter`) and compare with what it meant before.
98
+ *
99
+ * - A REWRITTEN reference must still yield the renamed object's key. When it
100
+ * would not — the bare new name is captured by an earlier schema on the
101
+ * body's home path — it is schema-qualified to the renamed schema via
102
+ * {@link TableRef.qualify}.
103
+ * - An UNTOUCHED reference must still yield its own before-answer. A rename
104
+ * also CREATES a name, and that new name can capture a reference the walk
105
+ * never matched: a `temp`-owned body reading bare `k` (falling through to
106
+ * `main.k`, because `temp` holds no `k`) silently re-binds to `temp.k` the
107
+ * moment `alter table temp.other rename to k` lands, without its text ever
108
+ * mentioning the renamed table. When the answer would change, the reference
109
+ * is qualified to the schema its BEFORE-answer named — recovered from that
110
+ * key by {@link import('./shared.js').objectRefKeySchema}. This arm applies
111
+ * to the stored bodies that plan under the home schema path and is walked
112
+ * ONCE per body; {@link TableRenameOpts.schemaAuthoredBody} turns it off for
113
+ * the schema-authored expressions, which need it neither for correctness nor
114
+ * for the re-walks they are deliberately subjected to — see that flag.
115
+ *
116
+ * The post-condition also covers the FROM-frame namespace, not just the
117
+ * catalog's: inside one body, the bare qualifier an unaliased FROM source
118
+ * exposes must keep binding that source. When the rename would give a source a
119
+ * name already visible as a qualifier where it sits ({@link
120
+ * TableRef.qualifierCollides}), the source pins its pre-rename spelling as an
121
+ * explicit alias ({@link TableRef.aliasAs}) and every column qualifier bound
122
+ * through it keeps the old spelling — `from t join u as t2` becomes
123
+ * `from t2 as t join u as t2` under `t → t2`, with `t.x` untouched. And when
124
+ * the new name is shadowed by a CTE in scope at the source ({@link
125
+ * TableRef.cteShadows}) — invisible to the catalog resolvers — the reference
126
+ * is schema-qualified so it cannot re-bind to the CTE.
127
+ *
128
+ * Qualification is conditional in both arms, never eager, so the common
129
+ * no-collision rename leaves body text (and a materialized view's `bodyHash`)
130
+ * exactly as before. A qualified reference resolves by passthrough, so its
131
+ * before- and after-answers are always equal and neither arm can fire on one;
132
+ * only unqualified references ever gain a qualifier. And only the NEW name can
133
+ * change meaning without being rewritten: removing the old name can only push a
134
+ * resolution later, and the references that resolved to the removed entry are
135
+ * exactly the ones the rewrite already matches — so there is no freed-name
136
+ * direction to handle.
137
+ *
138
+ * ALREADY-BROKEN BODIES: the resolver answers a total function — a name held by
139
+ * no schema on the path still gets a stable key, the home schema's — so a body
140
+ * naming an object that exists nowhere reads `before = <home>.<name>`, and a
141
+ * rename introducing that name in an earlier schema flips `after`. The
142
+ * untouched arm then qualifies the reference to the home schema, PINNING the
143
+ * pre-existing "no such table" failure rather than letting the body silently
144
+ * start reading the new arrival. That is the invariant-faithful answer, so no
145
+ * existence probe is added to dodge it (same reasoning as the seedless-qualifier
146
+ * emit site below: it only ever fires on an already-unevaluable body).
147
+ */
148
+ export declare function renameTableInAst(node: AST.AstNode | undefined, target: TableRenameTarget, opts?: TableRenameOpts): boolean;
149
+ /**
150
+ * Whether `node` refers to the table/view identified by `targetKey` (spelled
151
+ * `name`) — read-only, nothing is mutated.
152
+ *
153
+ * Deliberately the SAME traversal {@link renameTableInAst} uses — both are
154
+ * sinks over {@link visitTableRefs} — so "refers to" can never drift from
155
+ * "would have been rewritten by a rename". That equivalence is the whole
156
+ * point: the DROP guard refuses exactly the cases `ALTER TABLE … RENAME`
157
+ * would have followed. In particular, a body whose `with <name> as (…)`
158
+ * merely SHADOWS the probed name is not a reference — the walk skips it for
159
+ * both verbs. The probe's sink stops the walk at the first match.
160
+ *
161
+ * The column-level probes ({@link import('./column-rename.js').columnReferencedInAst},
162
+ * {@link import('./column-rename.js').columnReferencedInCheckExpression}) reach
163
+ * the same equivalence a different way — a real rename, to a sentinel name,
164
+ * over a throwaway clone — because the column walker has ~8 mutation points
165
+ * and a CTE-re-exposure branch that reads the new name; see their comments.
166
+ */
167
+ export declare function tableReferencedInAst(node: AST.AstNode | undefined, name: string, resolve: ResolveObjectRef, targetKey: string, opts?: TableRenameOpts): boolean;
168
+ /**
169
+ * Every real (non-shadowed) table / view reference in `node`, keyed the way
170
+ * {@link renameTableInAst} and {@link tableReferencedInAst} key their target:
171
+ * `resolve(ref.schema, ref.name)`, the reference's planner-parity resolution
172
+ * under the WALKED BODY's home schema path.
173
+ *
174
+ * The collect-all THIRD sink over the same {@link walkTableRefs} traversal, so
175
+ * it inherits the scope-awareness of the other two for free: a body whose
176
+ * `with t as (…)` merely SHADOWS the name contributes no `<schema>.t` key, a FROM
177
+ * alias contributes nothing, and a `new.` / `old.` row-image qualifier under
178
+ * {@link TableRenameOpts.rowImageContext} contributes nothing. That matters
179
+ * more here than anywhere else — a collect-everything walk is exactly where
180
+ * that property gets quietly lost, and the reachability closure built on this
181
+ * ({@link import('../object-dependency-closure.js').reachableObjects}) turns
182
+ * every key it yields into a refused DROP.
183
+ *
184
+ * The value is the object NAME the key was built from, lowercased. The
185
+ * resolver echoes the name it is given into the key, so this is always
186
+ * `ref.name.toLowerCase()`; it is returned rather than re-derived because a
187
+ * schema name may itself contain a dot, which makes splitting a key by
188
+ * separator scan wrong — see {@link import('./shared.js').objectRefKeySchema},
189
+ * whose whole job is that split and which needs exactly this.
190
+ */
191
+ export declare function collectTableRefsInAst(node: AST.AstNode | undefined, resolve: ResolveObjectRef, opts?: TableRenameOpts): Map<string, string>;
192
+ /**
193
+ * Rewrite the renamed table inside every partial-index predicate of `indexes`,
194
+ * in place. A predicate may carry a table-qualified self-reference
195
+ * (`create index ix on t (b) where t.b > 0`), which a table rename must follow.
196
+ *
197
+ * No {@link TableRenameOpts.rowImageContext}: a predicate describes rows
198
+ * already stored, so `new.x` there is a real table reference — see the flag's
199
+ * doc comment. {@link TableRenameOpts.schemaAuthoredBody} IS set: a predicate
200
+ * plans under its owning schema alone, and this AST is one of the several the
201
+ * rename walks more than once.
202
+ *
203
+ * Sharing and idempotence work exactly as in
204
+ * {@link import('./column-rename.js').renameColumnInIndexPredicates}: the
205
+ * predicate `Expression` is shared by reference with the catalog's
206
+ * `TableSchema` and with a unique partial index's `derivedFromIndex` UNIQUE
207
+ * constraint, so one in-place rewrite covers all of them, and a second call
208
+ * with the same pair finds nothing naming `oldName` and returns false.
209
+ */
210
+ export declare function renameTableInIndexPredicates(indexes: ReadonlyArray<{
211
+ readonly predicate?: AST.Expression;
212
+ }> | undefined, target: TableRenameTarget): boolean;
213
+ /**
214
+ * Rewrite the renamed table inside every CHECK constraint expression of `checks`,
215
+ * in place. A CHECK may carry a table-qualified self-reference (`check (t.b > 0)`)
216
+ * exactly as a partial-index predicate may, and a table rename must follow it.
217
+ *
218
+ * A CHECK is evaluated against a written row, so the walk runs with
219
+ * {@link TableRenameOpts.rowImageContext}: a bare `new.a` / `old.a` names the
220
+ * row image and survives even a rename of a table literally called `new`. It
221
+ * also runs with {@link TableRenameOpts.schemaAuthoredBody}, for the same
222
+ * reasons the predicate arm above does.
223
+ *
224
+ * Same sharing and idempotence story as {@link renameTableInIndexPredicates}: the
225
+ * `expr` is the very AST the catalog's `TableSchema` holds, so one rewrite covers
226
+ * every holder and a second call with the same pair is a no-op.
227
+ */
228
+ export declare function renameTableInCheckConstraints(checks: ReadonlyArray<{
229
+ readonly expr: AST.Expression;
230
+ }> | undefined, target: TableRenameTarget): boolean;
231
+ /**
232
+ * Rewrite the renamed table inside the two expressions a `ColumnSchema` can carry —
233
+ * a column DEFAULT (`w integer default ((select min(v) from u))`, however authored:
234
+ * inline, or via `ALTER TABLE … ALTER COLUMN … SET DEFAULT`, which writes the same
235
+ * field) and a generated column's body (`g integer generated always as ((select
236
+ * min(u.v) from u) + id)`) — in place.
237
+ *
238
+ * Both expressions evaluate against the row being written, so the walk runs
239
+ * with {@link TableRenameOpts.rowImageContext}: a default's `new.a` names the
240
+ * row image, not a table called `new`. It also runs with
241
+ * {@link TableRenameOpts.schemaAuthoredBody}, for the same reasons the two arms
242
+ * above do.
243
+ *
244
+ * Unlike the column-rename counterpart
245
+ * ({@link import('./column-rename.js').renameColumnInColumnExpressions}) there
246
+ * is no seeded/unseeded split: {@link renameTableInAst} resolves nothing against an
247
+ * implicit owning table, so the SAME entry point is correct for the renamed table's own
248
+ * columns (a self-referencing default, `default ((select count(*) from t))`) and for
249
+ * every other table's.
250
+ *
251
+ * Same sharing and idempotence story as {@link renameTableInCheckConstraints}: the
252
+ * `Expression` is the very AST the catalog's `TableSchema` holds, so one in-place
253
+ * rewrite reaches every holder and a second call with the same pair finds nothing
254
+ * naming `oldName` and returns false.
255
+ *
256
+ * The parameter is structurally typed rather than `ColumnSchema[]` so this module stays
257
+ * free of catalog imports; `ColumnSchema` satisfies it.
258
+ */
259
+ export declare function renameTableInColumnExpressions(columns: ReadonlyArray<{
260
+ readonly defaultValue?: AST.Expression | null;
261
+ readonly generatedExpr?: AST.Expression;
262
+ }> | undefined, target: TableRenameTarget): boolean;
263
+ //# sourceMappingURL=table-rename.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"table-rename.d.ts","sourceRoot":"","sources":["../../../../src/schema/rename/table-rename.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,GAAG,MAAM,qBAAqB,CAAC;AAChD,OAAO,EAAqD,KAAK,gBAAgB,EAAE,KAAK,iBAAiB,EAAE,MAAM,aAAa,CAAC;AAE/H;;;;;;;;;;;;;;;;;;;GAmBG;AAEH,4EAA4E;AAC5E,MAAM,WAAW,eAAe;IAC/B;;;;;;;;;;;;;;;;;;;;;;OAsBG;IACH,eAAe,CAAC,EAAE,OAAO,CAAC;IAC1B;;;;;;;;;;;;;;;;;;;;;;;;;;;OA2BG;IACH,kBAAkB,CAAC,EAAE,OAAO,CAAC;CAC7B;AA6GD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAoEG;AACH,wBAAgB,gBAAgB,CAC/B,IAAI,EAAE,GAAG,CAAC,OAAO,GAAG,SAAS,EAC7B,MAAM,EAAE,iBAAiB,EACzB,IAAI,CAAC,EAAE,eAAe,GACpB,OAAO,CAoET;AAED;;;;;;;;;;;;;;;;;GAiBG;AACH,wBAAgB,oBAAoB,CACnC,IAAI,EAAE,GAAG,CAAC,OAAO,GAAG,SAAS,EAC7B,IAAI,EAAE,MAAM,EACZ,OAAO,EAAE,gBAAgB,EACzB,SAAS,EAAE,MAAM,EACjB,IAAI,CAAC,EAAE,eAAe,GACpB,OAAO,CAUT;AAED;;;;;;;;;;;;;;;;;;;;;;GAsBG;AACH,wBAAgB,qBAAqB,CACpC,IAAI,EAAE,GAAG,CAAC,OAAO,GAAG,SAAS,EAC7B,OAAO,EAAE,gBAAgB,EACzB,IAAI,CAAC,EAAE,eAAe,GACpB,GAAG,CAAC,MAAM,EAAE,MAAM,CAAC,CAUrB;AAED;;;;;;;;;;;;;;;;;GAiBG;AACH,wBAAgB,4BAA4B,CAC3C,OAAO,EAAE,aAAa,CAAC;IAAE,QAAQ,CAAC,SAAS,CAAC,EAAE,GAAG,CAAC,UAAU,CAAA;CAAE,CAAC,GAAG,SAAS,EAC3E,MAAM,EAAE,iBAAiB,GACvB,OAAO,CAGT;AAED;;;;;;;;;;;;;;GAcG;AACH,wBAAgB,6BAA6B,CAC5C,MAAM,EAAE,aAAa,CAAC;IAAE,QAAQ,CAAC,IAAI,EAAE,GAAG,CAAC,UAAU,CAAA;CAAE,CAAC,GAAG,SAAS,EACpE,MAAM,EAAE,iBAAiB,GACvB,OAAO,CAGT;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2BG;AACH,wBAAgB,8BAA8B,CAC7C,OAAO,EAAE,aAAa,CAAC;IACtB,QAAQ,CAAC,YAAY,CAAC,EAAE,GAAG,CAAC,UAAU,GAAG,IAAI,CAAC;IAC9C,QAAQ,CAAC,aAAa,CAAC,EAAE,GAAG,CAAC,UAAU,CAAC;CACxC,CAAC,GAAG,SAAS,EACd,MAAM,EAAE,iBAAiB,GACvB,OAAO,CAOT"}