@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.
- package/dist/src/core/database.d.ts +6 -0
- package/dist/src/core/database.d.ts.map +1 -1
- package/dist/src/core/database.js +45 -5
- package/dist/src/core/database.js.map +1 -1
- package/dist/src/core/statement.d.ts.map +1 -1
- package/dist/src/core/statement.js +74 -15
- package/dist/src/core/statement.js.map +1 -1
- package/dist/src/func/builtins/aggregate.d.ts.map +1 -1
- package/dist/src/func/builtins/aggregate.js +88 -35
- package/dist/src/func/builtins/aggregate.js.map +1 -1
- package/dist/src/func/builtins/conversion.d.ts +5 -0
- package/dist/src/func/builtins/conversion.d.ts.map +1 -1
- package/dist/src/func/builtins/conversion.js +16 -2
- package/dist/src/func/builtins/conversion.js.map +1 -1
- package/dist/src/func/builtins/explain.d.ts.map +1 -1
- package/dist/src/func/builtins/explain.js +9 -2
- package/dist/src/func/builtins/explain.js.map +1 -1
- package/dist/src/func/builtins/index.d.ts.map +1 -1
- package/dist/src/func/builtins/index.js +5 -2
- package/dist/src/func/builtins/index.js.map +1 -1
- package/dist/src/func/builtins/scalar.d.ts.map +1 -1
- package/dist/src/func/builtins/scalar.js +4 -2
- package/dist/src/func/builtins/scalar.js.map +1 -1
- package/dist/src/func/builtins/string.d.ts +2 -0
- package/dist/src/func/builtins/string.d.ts.map +1 -1
- package/dist/src/func/builtins/string.js +60 -4
- package/dist/src/func/builtins/string.js.map +1 -1
- package/dist/src/func/registration.d.ts +6 -0
- package/dist/src/func/registration.d.ts.map +1 -1
- package/dist/src/func/registration.js +1 -0
- package/dist/src/func/registration.js.map +1 -1
- package/dist/src/index.d.ts +7 -3
- package/dist/src/index.d.ts.map +1 -1
- package/dist/src/index.js +21 -2
- package/dist/src/index.js.map +1 -1
- package/dist/src/planner/building/constraint-builder.js +1 -1
- package/dist/src/planner/building/constraint-builder.js.map +1 -1
- package/dist/src/planner/nodes/scalar.d.ts.map +1 -1
- package/dist/src/planner/nodes/scalar.js +13 -1
- package/dist/src/planner/nodes/scalar.js.map +1 -1
- package/dist/src/planner/rules/retrieve/rule-grow-retrieve.d.ts.map +1 -1
- package/dist/src/planner/rules/retrieve/rule-grow-retrieve.js +121 -51
- package/dist/src/planner/rules/retrieve/rule-grow-retrieve.js.map +1 -1
- package/dist/src/planner/rules/shared/index-style-context.d.ts +14 -4
- package/dist/src/planner/rules/shared/index-style-context.d.ts.map +1 -1
- package/dist/src/planner/rules/shared/index-style-context.js +14 -4
- package/dist/src/planner/rules/shared/index-style-context.js.map +1 -1
- package/dist/src/runtime/emission-context.d.ts +14 -1
- package/dist/src/runtime/emission-context.d.ts.map +1 -1
- package/dist/src/runtime/emission-context.js +17 -5
- package/dist/src/runtime/emission-context.js.map +1 -1
- package/dist/src/runtime/emit/aggregate-setup.d.ts +44 -8
- package/dist/src/runtime/emit/aggregate-setup.d.ts.map +1 -1
- package/dist/src/runtime/emit/aggregate-setup.js +79 -15
- package/dist/src/runtime/emit/aggregate-setup.js.map +1 -1
- package/dist/src/runtime/emit/aggregate.d.ts.map +1 -1
- package/dist/src/runtime/emit/aggregate.js +21 -106
- package/dist/src/runtime/emit/aggregate.js.map +1 -1
- package/dist/src/runtime/emit/alter-table.d.ts.map +1 -1
- package/dist/src/runtime/emit/alter-table.js +212 -155
- package/dist/src/runtime/emit/alter-table.js.map +1 -1
- package/dist/src/runtime/emit/asof-scan.js +1 -1
- package/dist/src/runtime/emit/asof-scan.js.map +1 -1
- package/dist/src/runtime/emit/assertion-drop-guard.d.ts +26 -12
- package/dist/src/runtime/emit/assertion-drop-guard.d.ts.map +1 -1
- package/dist/src/runtime/emit/assertion-drop-guard.js +45 -26
- package/dist/src/runtime/emit/assertion-drop-guard.js.map +1 -1
- package/dist/src/runtime/emit/assertion-rename-helpers.d.ts +6 -6
- package/dist/src/runtime/emit/assertion-rename-helpers.d.ts.map +1 -1
- package/dist/src/runtime/emit/assertion-rename-helpers.js +18 -20
- package/dist/src/runtime/emit/assertion-rename-helpers.js.map +1 -1
- package/dist/src/runtime/emit/between.d.ts +2 -0
- package/dist/src/runtime/emit/between.d.ts.map +1 -1
- package/dist/src/runtime/emit/between.js +7 -8
- package/dist/src/runtime/emit/between.js.map +1 -1
- package/dist/src/runtime/emit/binary.d.ts +27 -5
- package/dist/src/runtime/emit/binary.d.ts.map +1 -1
- package/dist/src/runtime/emit/binary.js +278 -187
- package/dist/src/runtime/emit/binary.js.map +1 -1
- package/dist/src/runtime/emit/case.d.ts +34 -0
- package/dist/src/runtime/emit/case.d.ts.map +1 -1
- package/dist/src/runtime/emit/case.js +18 -11
- package/dist/src/runtime/emit/case.js.map +1 -1
- package/dist/src/runtime/emit/cast.d.ts +2 -0
- package/dist/src/runtime/emit/cast.d.ts.map +1 -1
- package/dist/src/runtime/emit/cast.js +7 -5
- package/dist/src/runtime/emit/cast.js.map +1 -1
- package/dist/src/runtime/emit/column-reference.d.ts +3 -1
- package/dist/src/runtime/emit/column-reference.d.ts.map +1 -1
- package/dist/src/runtime/emit/column-reference.js +6 -2
- package/dist/src/runtime/emit/column-reference.js.map +1 -1
- package/dist/src/runtime/emit/column-rename-cascade.d.ts +84 -0
- package/dist/src/runtime/emit/column-rename-cascade.d.ts.map +1 -0
- package/dist/src/runtime/emit/column-rename-cascade.js +134 -0
- package/dist/src/runtime/emit/column-rename-cascade.js.map +1 -0
- package/dist/src/runtime/emit/dml-executor.d.ts.map +1 -1
- package/dist/src/runtime/emit/dml-executor.js +21 -0
- package/dist/src/runtime/emit/dml-executor.js.map +1 -1
- package/dist/src/runtime/emit/drop-column-guards.d.ts +82 -53
- package/dist/src/runtime/emit/drop-column-guards.d.ts.map +1 -1
- package/dist/src/runtime/emit/drop-column-guards.js +155 -90
- package/dist/src/runtime/emit/drop-column-guards.js.map +1 -1
- package/dist/src/runtime/emit/drop-table.d.ts.map +1 -1
- package/dist/src/runtime/emit/drop-table.js +5 -0
- package/dist/src/runtime/emit/drop-table.js.map +1 -1
- package/dist/src/runtime/emit/drop-view.d.ts.map +1 -1
- package/dist/src/runtime/emit/drop-view.js +5 -0
- package/dist/src/runtime/emit/drop-view.js.map +1 -1
- package/dist/src/runtime/emit/expression-drop-guard.d.ts +57 -0
- package/dist/src/runtime/emit/expression-drop-guard.d.ts.map +1 -0
- package/dist/src/runtime/emit/expression-drop-guard.js +82 -0
- package/dist/src/runtime/emit/expression-drop-guard.js.map +1 -0
- package/dist/src/runtime/emit/filter.d.ts +1 -1
- package/dist/src/runtime/emit/filter.js +1 -1
- package/dist/src/runtime/emit/hash-aggregate.d.ts.map +1 -1
- package/dist/src/runtime/emit/hash-aggregate.js +18 -88
- package/dist/src/runtime/emit/hash-aggregate.js.map +1 -1
- package/dist/src/runtime/emit/literal.d.ts +14 -1
- package/dist/src/runtime/emit/literal.d.ts.map +1 -1
- package/dist/src/runtime/emit/literal.js +33 -7
- package/dist/src/runtime/emit/literal.js.map +1 -1
- package/dist/src/runtime/emit/materialized-view-helpers.d.ts +33 -10
- package/dist/src/runtime/emit/materialized-view-helpers.d.ts.map +1 -1
- package/dist/src/runtime/emit/materialized-view-helpers.js +158 -49
- package/dist/src/runtime/emit/materialized-view-helpers.js.map +1 -1
- package/dist/src/runtime/emit/materialized-view.d.ts.map +1 -1
- package/dist/src/runtime/emit/materialized-view.js +3 -0
- package/dist/src/runtime/emit/materialized-view.js.map +1 -1
- package/dist/src/runtime/emit/parameter.d.ts +3 -1
- package/dist/src/runtime/emit/parameter.d.ts.map +1 -1
- package/dist/src/runtime/emit/parameter.js +7 -2
- package/dist/src/runtime/emit/parameter.js.map +1 -1
- package/dist/src/runtime/emit/scalar-function.d.ts +29 -1
- package/dist/src/runtime/emit/scalar-function.d.ts.map +1 -1
- package/dist/src/runtime/emit/scalar-function.js +66 -16
- package/dist/src/runtime/emit/scalar-function.js.map +1 -1
- package/dist/src/runtime/emit/scalar-op.d.ts +63 -0
- package/dist/src/runtime/emit/scalar-op.d.ts.map +1 -0
- package/dist/src/runtime/emit/scalar-op.js +37 -0
- package/dist/src/runtime/emit/scalar-op.js.map +1 -0
- package/dist/src/runtime/emit/scan.d.ts.map +1 -1
- package/dist/src/runtime/emit/scan.js +19 -1
- package/dist/src/runtime/emit/scan.js.map +1 -1
- package/dist/src/runtime/emit/temporal-arithmetic.d.ts +18 -8
- package/dist/src/runtime/emit/temporal-arithmetic.d.ts.map +1 -1
- package/dist/src/runtime/emit/temporal-arithmetic.js +29 -311
- package/dist/src/runtime/emit/temporal-arithmetic.js.map +1 -1
- package/dist/src/runtime/emit/unary.d.ts +2 -0
- package/dist/src/runtime/emit/unary.d.ts.map +1 -1
- package/dist/src/runtime/emit/unary.js +125 -53
- package/dist/src/runtime/emit/unary.js.map +1 -1
- package/dist/src/runtime/emitters.d.ts +22 -0
- package/dist/src/runtime/emitters.d.ts.map +1 -1
- package/dist/src/runtime/emitters.js +29 -0
- package/dist/src/runtime/emitters.js.map +1 -1
- package/dist/src/runtime/scalar-fusion.d.ts +47 -0
- package/dist/src/runtime/scalar-fusion.d.ts.map +1 -0
- package/dist/src/runtime/scalar-fusion.js +275 -0
- package/dist/src/runtime/scalar-fusion.js.map +1 -0
- package/dist/src/runtime/strict-flags.d.ts +9 -0
- package/dist/src/runtime/strict-flags.d.ts.map +1 -1
- package/dist/src/runtime/strict-flags.js +9 -0
- package/dist/src/runtime/strict-flags.js.map +1 -1
- package/dist/src/runtime/strict-fork.js +2 -2
- package/dist/src/runtime/strict-fork.js.map +1 -1
- package/dist/src/runtime/strict-representation.d.ts +78 -0
- package/dist/src/runtime/strict-representation.d.ts.map +1 -0
- package/dist/src/runtime/strict-representation.js +159 -0
- package/dist/src/runtime/strict-representation.js.map +1 -0
- package/dist/src/schema/assertion.d.ts +58 -0
- package/dist/src/schema/assertion.d.ts.map +1 -1
- package/dist/src/schema/assertion.js +78 -0
- package/dist/src/schema/assertion.js.map +1 -1
- package/dist/src/schema/catalog-persistability.d.ts +11 -3
- package/dist/src/schema/catalog-persistability.d.ts.map +1 -1
- package/dist/src/schema/catalog-persistability.js +48 -29
- package/dist/src/schema/catalog-persistability.js.map +1 -1
- package/dist/src/schema/catalog.d.ts +22 -0
- package/dist/src/schema/catalog.d.ts.map +1 -1
- package/dist/src/schema/catalog.js +4 -1
- package/dist/src/schema/catalog.js.map +1 -1
- package/dist/src/schema/column-republication.d.ts +126 -0
- package/dist/src/schema/column-republication.d.ts.map +1 -0
- package/dist/src/schema/column-republication.js +121 -0
- package/dist/src/schema/column-republication.js.map +1 -0
- package/dist/src/schema/column-source-resolver.d.ts +29 -6
- package/dist/src/schema/column-source-resolver.d.ts.map +1 -1
- package/dist/src/schema/column-source-resolver.js +78 -9
- package/dist/src/schema/column-source-resolver.js.map +1 -1
- package/dist/src/schema/expression-dependents.d.ts +160 -0
- package/dist/src/schema/expression-dependents.d.ts.map +1 -0
- package/dist/src/schema/expression-dependents.js +228 -0
- package/dist/src/schema/expression-dependents.js.map +1 -0
- package/dist/src/schema/function.d.ts +15 -0
- package/dist/src/schema/function.d.ts.map +1 -1
- package/dist/src/schema/function.js.map +1 -1
- package/dist/src/schema/object-dependency-closure.d.ts +127 -0
- package/dist/src/schema/object-dependency-closure.d.ts.map +1 -0
- package/dist/src/schema/object-dependency-closure.js +117 -0
- package/dist/src/schema/object-dependency-closure.js.map +1 -0
- package/dist/src/schema/object-ref-resolver.d.ts +83 -0
- package/dist/src/schema/object-ref-resolver.d.ts.map +1 -0
- package/dist/src/schema/object-ref-resolver.js +135 -0
- package/dist/src/schema/object-ref-resolver.js.map +1 -0
- package/dist/src/schema/rename/column-rename.d.ts +228 -0
- package/dist/src/schema/rename/column-rename.d.ts.map +1 -0
- package/dist/src/schema/rename/column-rename.js +1225 -0
- package/dist/src/schema/rename/column-rename.js.map +1 -0
- package/dist/src/schema/rename/self-qualifier-strip.d.ts +29 -0
- package/dist/src/schema/rename/self-qualifier-strip.d.ts.map +1 -0
- package/dist/src/schema/rename/self-qualifier-strip.js +267 -0
- package/dist/src/schema/rename/self-qualifier-strip.js.map +1 -0
- package/dist/src/schema/rename/shared.d.ts +108 -0
- package/dist/src/schema/rename/shared.d.ts.map +1 -0
- package/dist/src/schema/rename/shared.js +49 -0
- package/dist/src/schema/rename/shared.js.map +1 -0
- package/dist/src/schema/rename/table-rename.d.ts +263 -0
- package/dist/src/schema/rename/table-rename.d.ts.map +1 -0
- package/dist/src/schema/rename/table-rename.js +860 -0
- package/dist/src/schema/rename/table-rename.js.map +1 -0
- package/dist/src/schema/rename-rewriter.d.ts +18 -278
- package/dist/src/schema/rename-rewriter.d.ts.map +1 -1
- package/dist/src/schema/rename-rewriter.js +17 -1506
- package/dist/src/schema/rename-rewriter.js.map +1 -1
- package/dist/src/schema/schema-differ.d.ts.map +1 -1
- package/dist/src/schema/schema-differ.js +228 -21
- package/dist/src/schema/schema-differ.js.map +1 -1
- package/dist/src/types/builtin-types.d.ts.map +1 -1
- package/dist/src/types/builtin-types.js +29 -36
- package/dist/src/types/builtin-types.js.map +1 -1
- package/dist/src/types/cast-semantics.d.ts +7 -5
- package/dist/src/types/cast-semantics.d.ts.map +1 -1
- package/dist/src/types/cast-semantics.js +20 -9
- package/dist/src/types/cast-semantics.js.map +1 -1
- package/dist/src/types/index.d.ts +1 -1
- package/dist/src/types/index.d.ts.map +1 -1
- package/dist/src/types/index.js +1 -1
- package/dist/src/types/index.js.map +1 -1
- package/dist/src/types/registry.d.ts.map +1 -1
- package/dist/src/types/registry.js +2 -1
- package/dist/src/types/registry.js.map +1 -1
- package/dist/src/types/temporal-ops.d.ts +119 -0
- package/dist/src/types/temporal-ops.d.ts.map +1 -0
- package/dist/src/types/temporal-ops.js +348 -0
- package/dist/src/types/temporal-ops.js.map +1 -0
- package/dist/src/types/temporal-types.d.ts +11 -0
- package/dist/src/types/temporal-types.d.ts.map +1 -1
- package/dist/src/types/temporal-types.js +87 -0
- package/dist/src/types/temporal-types.js.map +1 -1
- package/dist/src/util/affinity.d.ts +2 -1
- package/dist/src/util/affinity.d.ts.map +1 -1
- package/dist/src/util/affinity.js +16 -5
- package/dist/src/util/affinity.js.map +1 -1
- package/dist/src/util/ast-spine-clone.d.ts +2 -2
- package/dist/src/util/ast-spine-clone.js +2 -2
- package/dist/src/util/coercion.d.ts +22 -7
- package/dist/src/util/coercion.d.ts.map +1 -1
- package/dist/src/util/coercion.js +28 -15
- package/dist/src/util/coercion.js.map +1 -1
- package/dist/src/util/comparison.d.ts +25 -0
- package/dist/src/util/comparison.d.ts.map +1 -1
- package/dist/src/util/comparison.js +25 -0
- package/dist/src/util/comparison.js.map +1 -1
- package/dist/src/util/key-tuple-codec.d.ts +12 -3
- package/dist/src/util/key-tuple-codec.d.ts.map +1 -1
- package/dist/src/util/key-tuple-codec.js.map +1 -1
- package/dist/src/util/numeric-canonical.d.ts +26 -0
- package/dist/src/util/numeric-canonical.d.ts.map +1 -0
- package/dist/src/util/numeric-canonical.js +66 -0
- package/dist/src/util/numeric-canonical.js.map +1 -0
- package/dist/src/util/value-text.d.ts +48 -0
- package/dist/src/util/value-text.d.ts.map +1 -0
- package/dist/src/util/value-text.js +35 -0
- package/dist/src/util/value-text.js.map +1 -0
- package/dist/src/vtab/memory/layer/manager.d.ts.map +1 -1
- package/dist/src/vtab/memory/layer/manager.js +14 -5
- package/dist/src/vtab/memory/layer/manager.js.map +1 -1
- package/dist/src/vtab/module.d.ts +25 -0
- package/dist/src/vtab/module.d.ts.map +1 -1
- package/package.json +4 -3
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"object-ref-resolver.d.ts","sourceRoot":"","sources":["../../../src/schema/object-ref-resolver.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,qBAAqB,CAAC;AACpD,OAAO,EAAgB,KAAK,gBAAgB,EAAE,KAAK,iBAAiB,EAAE,MAAM,sBAAsB,CAAC;AAEnG;;;;;GAKG;AACH,MAAM,WAAW,kBAAkB;IAClC,oFAAoF;IACpF,aAAa,CAAC,cAAc,EAAE,MAAM,GAAG,gBAAgB,CAAC;IACxD;;;;;;;OAOG;IACH,gBAAgB,CAAC,UAAU,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,GAAG,kBAAkB,CAAC;CAC3F;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA0CG;AACH,wBAAgB,0BAA0B,CAAC,EAAE,EAAE,QAAQ,GAAG,kBAAkB,CAa3E;AAqCD;;;;;;;;GAQG;AACH,wBAAgB,qBAAqB,CACpC,SAAS,EAAE,kBAAkB,EAC7B,UAAU,EAAE,MAAM,EAClB,OAAO,EAAE,MAAM,EACf,OAAO,EAAE,MAAM,GACb,CAAC,cAAc,EAAE,MAAM,KAAK,iBAAiB,CAiB/C;AAED;;;;;GAKG;AACH,wBAAgB,sBAAsB,CAAC,EAAE,EAAE,QAAQ,EAAE,cAAc,EAAE,MAAM,GAAG,gBAAgB,CAE7F"}
|
|
@@ -0,0 +1,135 @@
|
|
|
1
|
+
import { objectRefKey } from './rename-rewriter.js';
|
|
2
|
+
/**
|
|
3
|
+
* The catalog-backed {@link ResolveObjectRef} the rename walkers consult to decide
|
|
4
|
+
* whether a table/view reference written in a stored body denotes the object being
|
|
5
|
+
* renamed / probed. It answers the way the PLANNER answers for that body — against
|
|
6
|
+
* the owning object's home schema path ({@link Database._homeSchemaPath}:
|
|
7
|
+
* `[homeSchema, ...session default path]`) — not against a single "default schema".
|
|
8
|
+
*
|
|
9
|
+
* Resolution rules:
|
|
10
|
+
* - **Qualified** (`schema` present) → `objectRefKey(schema, name)`, no catalog
|
|
11
|
+
* lookup. A qualified name means what it says even when the object does not
|
|
12
|
+
* exist (it may be the one about to be created, or the one just renamed away).
|
|
13
|
+
* - **Unqualified** → the first schema in the home path holding a table or view
|
|
14
|
+
* (a materialized view is a table) of that name.
|
|
15
|
+
* - **Miss in every schema** → the home schema's key, so a body naming an object
|
|
16
|
+
* that does not exist still gets a stable key rather than `undefined` —
|
|
17
|
+
* `undefined` is reserved for "no resolver could be consulted at all".
|
|
18
|
+
*
|
|
19
|
+
* NOTE: "the way the planner answers" is exact for the body kinds that plan under
|
|
20
|
+
* {@link Database._homeSchemaPath} — view bodies, materialized-view bodies, and
|
|
21
|
+
* assertion checks (`planner/stored-body-context.ts`). A CHECK constraint or a
|
|
22
|
+
* column DEFAULT / generated expression is stricter still: it plans under
|
|
23
|
+
* `schemaAuthoredContext` (`planner/building/schema-authored-context.ts`), the
|
|
24
|
+
* owning schema and NOTHING else, so an unqualified name the owning schema does
|
|
25
|
+
* not hold is an error there rather than a fallthrough down the session path.
|
|
26
|
+
* This resolver applies the looser home-path rule to all of them, which is
|
|
27
|
+
* deliberately safe rather than exact: the two rules can only disagree when the
|
|
28
|
+
* home schema lacks the name, and such a CHECK / DEFAULT cannot be evaluated at
|
|
29
|
+
* all — so no VALID body is ever matched (or missed) differently. Tighten to a
|
|
30
|
+
* per-body-kind path only if a rename ever needs to be right about a body the
|
|
31
|
+
* planner itself rejects.
|
|
32
|
+
*
|
|
33
|
+
* SNAPSHOT DISCIPLINE — the single most likely way to get this wrong: build the
|
|
34
|
+
* snapshot (`snapshotObjectRefResolvers` / `buildObjectRefResolver`) BEFORE the
|
|
35
|
+
* statement's first catalog mutation, and pass the same instance through the whole
|
|
36
|
+
* statement. Name-set lookups answer from the snapshot, NOT the live catalog, and
|
|
37
|
+
* that is load-bearing: rename propagation runs after the catalog swap, when the
|
|
38
|
+
* old name is gone — a live lookup of a bare `t` under `[main, temp]` after
|
|
39
|
+
* `main.t` was renamed would fall through to `temp.t` and silently match (or miss)
|
|
40
|
+
* the wrong object. The pre-mutation snapshot resolves every reference the way the
|
|
41
|
+
* body planned before the statement started, which is the question the rename is
|
|
42
|
+
* asking. (The session `schema_path` option is read at resolver-derivation time;
|
|
43
|
+
* it cannot change mid-statement.)
|
|
44
|
+
*/
|
|
45
|
+
export function snapshotObjectRefResolvers(db) {
|
|
46
|
+
// NOTE: snapshots every schema's table+view name set on each DDL statement, and
|
|
47
|
+
// resolves per reference after that; both are Map/Set work over handfuls of
|
|
48
|
+
// names. If a schema-heavy workload ever shows this hot, snapshot lazily per
|
|
49
|
+
// schema actually consulted.
|
|
50
|
+
const bySchema = new Map();
|
|
51
|
+
for (const schema of db.schemaManager._getAllSchemas()) {
|
|
52
|
+
const names = new Set();
|
|
53
|
+
for (const table of schema.getAllTables())
|
|
54
|
+
names.add(table.name.toLowerCase());
|
|
55
|
+
for (const view of schema.getAllViews())
|
|
56
|
+
names.add(view.name.toLowerCase());
|
|
57
|
+
bySchema.set(schema.name.toLowerCase(), names);
|
|
58
|
+
}
|
|
59
|
+
return buildResolvers(db, bySchema);
|
|
60
|
+
}
|
|
61
|
+
/** The shared builder over `(db, bySchema)`, so a {@link ObjectRefResolvers.withTableRenamed}
|
|
62
|
+
* sibling reuses the base snapshot's resolution logic over its own name-set map. */
|
|
63
|
+
function buildResolvers(db, bySchema) {
|
|
64
|
+
const cache = new Map();
|
|
65
|
+
return {
|
|
66
|
+
forHomeSchema(homeSchemaName) {
|
|
67
|
+
const homeLower = homeSchemaName.toLowerCase();
|
|
68
|
+
const cached = cache.get(homeLower);
|
|
69
|
+
if (cached)
|
|
70
|
+
return cached;
|
|
71
|
+
const path = db._homeSchemaPath(homeSchemaName).map(s => s.toLowerCase());
|
|
72
|
+
const resolve = (schema, name) => {
|
|
73
|
+
if (schema !== undefined)
|
|
74
|
+
return objectRefKey(schema, name);
|
|
75
|
+
const nameLower = name.toLowerCase();
|
|
76
|
+
for (const schemaLower of path) {
|
|
77
|
+
if (bySchema.get(schemaLower)?.has(nameLower))
|
|
78
|
+
return `${schemaLower}.${nameLower}`;
|
|
79
|
+
}
|
|
80
|
+
return `${homeLower}.${nameLower}`;
|
|
81
|
+
};
|
|
82
|
+
cache.set(homeLower, resolve);
|
|
83
|
+
return resolve;
|
|
84
|
+
},
|
|
85
|
+
withTableRenamed(schemaName, oldName, newName) {
|
|
86
|
+
// Copy the affected schema's Set and the outer Map shallowly — the base
|
|
87
|
+
// snapshot must keep answering pre-rename.
|
|
88
|
+
const schemaLower = schemaName.toLowerCase();
|
|
89
|
+
const sibling = new Map(bySchema);
|
|
90
|
+
const names = new Set(bySchema.get(schemaLower) ?? []);
|
|
91
|
+
names.delete(oldName.toLowerCase());
|
|
92
|
+
names.add(newName.toLowerCase());
|
|
93
|
+
sibling.set(schemaLower, names);
|
|
94
|
+
return buildResolvers(db, sibling);
|
|
95
|
+
},
|
|
96
|
+
};
|
|
97
|
+
}
|
|
98
|
+
/**
|
|
99
|
+
* Per-home-schema {@link TableRenameTarget} factory for one `ALTER TABLE … RENAME TO`
|
|
100
|
+
* statement: binds the renamed object's identity to a pre-mutation `resolve` and a
|
|
101
|
+
* post-rename `resolveAfter` (the {@link ObjectRefResolvers.withTableRenamed} sibling),
|
|
102
|
+
* both derived per body-owning home schema. One statement builds this once and hands
|
|
103
|
+
* every walk the target for the walked body's owner, which is what lets the rewrite
|
|
104
|
+
* enforce its post-condition — a rewritten reference must still resolve to the renamed
|
|
105
|
+
* object — at the sink.
|
|
106
|
+
*/
|
|
107
|
+
export function tableRenameTargetsFor(resolvers, schemaName, oldName, newName) {
|
|
108
|
+
const after = resolvers.withTableRenamed(schemaName, oldName, newName);
|
|
109
|
+
const cache = new Map();
|
|
110
|
+
return homeSchemaName => {
|
|
111
|
+
const homeLower = homeSchemaName.toLowerCase();
|
|
112
|
+
const cached = cache.get(homeLower);
|
|
113
|
+
if (cached)
|
|
114
|
+
return cached;
|
|
115
|
+
const target = {
|
|
116
|
+
oldName,
|
|
117
|
+
newName,
|
|
118
|
+
schemaName,
|
|
119
|
+
resolve: resolvers.forHomeSchema(homeSchemaName),
|
|
120
|
+
resolveAfter: after.forHomeSchema(homeSchemaName),
|
|
121
|
+
};
|
|
122
|
+
cache.set(homeLower, target);
|
|
123
|
+
return target;
|
|
124
|
+
};
|
|
125
|
+
}
|
|
126
|
+
/**
|
|
127
|
+
* Single-home convenience over {@link snapshotObjectRefResolvers}, for callers
|
|
128
|
+
* that walk bodies of one owning schema only (the DROP guards, a store module's
|
|
129
|
+
* own-table rewrite). Same snapshot discipline: build before the statement's
|
|
130
|
+
* first catalog mutation.
|
|
131
|
+
*/
|
|
132
|
+
export function buildObjectRefResolver(db, homeSchemaName) {
|
|
133
|
+
return snapshotObjectRefResolvers(db).forHomeSchema(homeSchemaName);
|
|
134
|
+
}
|
|
135
|
+
//# sourceMappingURL=object-ref-resolver.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"object-ref-resolver.js","sourceRoot":"","sources":["../../../src/schema/object-ref-resolver.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,YAAY,EAAiD,MAAM,sBAAsB,CAAC;AAsBnG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA0CG;AACH,MAAM,UAAU,0BAA0B,CAAC,EAAY;IACtD,gFAAgF;IAChF,4EAA4E;IAC5E,6EAA6E;IAC7E,6BAA6B;IAC7B,MAAM,QAAQ,GAAG,IAAI,GAAG,EAAuB,CAAC;IAChD,KAAK,MAAM,MAAM,IAAI,EAAE,CAAC,aAAa,CAAC,cAAc,EAAE,EAAE,CAAC;QACxD,MAAM,KAAK,GAAG,IAAI,GAAG,EAAU,CAAC;QAChC,KAAK,MAAM,KAAK,IAAI,MAAM,CAAC,YAAY,EAAE;YAAE,KAAK,CAAC,GAAG,CAAC,KAAK,CAAC,IAAI,CAAC,WAAW,EAAE,CAAC,CAAC;QAC/E,KAAK,MAAM,IAAI,IAAI,MAAM,CAAC,WAAW,EAAE;YAAE,KAAK,CAAC,GAAG,CAAC,IAAI,CAAC,IAAI,CAAC,WAAW,EAAE,CAAC,CAAC;QAC5E,QAAQ,CAAC,GAAG,CAAC,MAAM,CAAC,IAAI,CAAC,WAAW,EAAE,EAAE,KAAK,CAAC,CAAC;IAChD,CAAC;IACD,OAAO,cAAc,CAAC,EAAE,EAAE,QAAQ,CAAC,CAAC;AACrC,CAAC;AAED;qFACqF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0,0 +1,228 @@
|
|
|
1
|
+
import type * as AST from '../../parser/ast.js';
|
|
2
|
+
import { type ResolveColumnInSource, type ResolveObjectRef, type RowImageContext } from './shared.js';
|
|
3
|
+
/**
|
|
4
|
+
* Rewrite column references inside a full statement/expression AST, resolving
|
|
5
|
+
* unqualified refs against the FROM scopes the walk descends (no implicit seed,
|
|
6
|
+
* unlike {@link renameColumnInCheckExpression}). The walk descends a select
|
|
7
|
+
* body's trailing `with defaults (…)` clause ({@link AST.SelectStmt.defaults}),
|
|
8
|
+
* whose entry exprs evaluate in the body's FROM scope.
|
|
9
|
+
*
|
|
10
|
+
* `rowImage` says what a bare, unbound `new.` / `old.` qualifier means in the
|
|
11
|
+
* walked expression — independent of the (absent) seed; see
|
|
12
|
+
* {@link RowImageContext} and {@link matchesRowImage}. A view / assertion body
|
|
13
|
+
* is `'none'` (no written-row context — `new.x` is an ordinary table
|
|
14
|
+
* reference); another table's CHECK / DEFAULT / generated body is `'foreign'`
|
|
15
|
+
* (written-row context whose image belongs to that table, so the qualifier
|
|
16
|
+
* names nothing this walk cares about).
|
|
17
|
+
*
|
|
18
|
+
* When `resolveColumnInSource` is supplied, the scope walk consults it at each
|
|
19
|
+
* inner FROM frame so an unqualified ref that legitimately binds to a like-named
|
|
20
|
+
* column on a subquery's own FROM source is NOT false-captured by an enclosing
|
|
21
|
+
* binding (e.g. a `with defaults` expr `cap + (select max(cap) from lim)` under
|
|
22
|
+
* a `t.cap` rename must leave the inner `lim.cap` untouched). The same callback
|
|
23
|
+
* infrastructure backs {@link renameColumnInCheckExpression}; both the forward
|
|
24
|
+
* propagation (live schema lookup) and the differ's inverse reconcile
|
|
25
|
+
* (declared-side resolver) pass it so the two stay in parity.
|
|
26
|
+
*/
|
|
27
|
+
export declare function renameColumnInAst(node: AST.AstNode | undefined, tableName: string, oldColName: string, newColName: string, resolve: ResolveObjectRef, targetKey: string, rowImage: RowImageContext, resolveColumnInSource?: ResolveColumnInSource): boolean;
|
|
28
|
+
/**
|
|
29
|
+
* Rewrite a column reference inside a CHECK expression. Unlike
|
|
30
|
+
* `renameColumnInAst`, this entry point seeds the scope stack with an
|
|
31
|
+
* implicit unaliased binding to `tableName` so top-level unqualified
|
|
32
|
+
* `ColumnExpr` nodes resolve to the owning table. CHECK expressions
|
|
33
|
+
* cannot reference other tables at top level, so the implicit binding
|
|
34
|
+
* is safe there.
|
|
35
|
+
*
|
|
36
|
+
* When `resolveColumnInSource` is supplied, the scope walk consults it at
|
|
37
|
+
* each inner FROM frame: if any real-table source in that frame exposes
|
|
38
|
+
* `oldColName`, the unqualified ref binds inside the subquery and the
|
|
39
|
+
* walk stops before reaching the seed. This stops the rewriter from
|
|
40
|
+
* false-positively rewriting an inner unqualified ref that legitimately
|
|
41
|
+
* binds to a like-named column on the subquery's FROM (e.g.
|
|
42
|
+
* `check ((select min(v) from u) > 0)` when `u` also has a `v` column).
|
|
43
|
+
*
|
|
44
|
+
* Limitation: subquery / function-source inner sources are not asked (the
|
|
45
|
+
* rewriter would need recursive column-set inference on their bodies), so an
|
|
46
|
+
* unqualified ref binding only through one of those falls through to the seed.
|
|
47
|
+
* An ALIASED real source is asked like any other — an alias adds a qualifier,
|
|
48
|
+
* it does not take the source's columns out of scope. `renameColumnInAst`
|
|
49
|
+
* shares the same callback (passed by the view-body callers) and the same
|
|
50
|
+
* residual.
|
|
51
|
+
*
|
|
52
|
+
* The seed and the `new.` / `old.` **row-image** namespace are INDEPENDENT: the
|
|
53
|
+
* seed answers how *unqualified* refs bind, while the explicit `rowImage`
|
|
54
|
+
* argument answers what a bare, unbound `new.` / `old.` qualifier names (see
|
|
55
|
+
* {@link RowImageContext}). A CHECK / DEFAULT / generated body of the renamed
|
|
56
|
+
* table itself passes `'own'` — those expressions evaluate against the row
|
|
57
|
+
* being written, so `check (new.a > 0)` (`docs/sql-ddl.md` § CHECK Constraints)
|
|
58
|
+
* names the owning table's row image and matches. A partial-index predicate is
|
|
59
|
+
* seeded too but passes `'none'`: it describes rows already stored, with no
|
|
60
|
+
* written-row context.
|
|
61
|
+
*
|
|
62
|
+
* The `'own'` match is scope-**aware**, not depth-blind, because `new` and `old`
|
|
63
|
+
* are not reserved words in this parser: `create table "new" (…)` is legal, so a
|
|
64
|
+
* CHECK may legitimately contain `(select max("new".a) from "new")`. The match
|
|
65
|
+
* therefore requires that no FROM/WITH frame above the seed rebind the
|
|
66
|
+
* qualifier — see `matchesRowImage`.
|
|
67
|
+
*/
|
|
68
|
+
export declare function renameColumnInCheckExpression(expr: AST.AstNode | undefined, tableName: string, oldColName: string, newColName: string, resolve: ResolveObjectRef, targetKey: string, rowImage: RowImageContext, resolveColumnInSource?: ResolveColumnInSource): boolean;
|
|
69
|
+
/**
|
|
70
|
+
* Sentinel rename target for the read-only column probes: the two below, and
|
|
71
|
+
* the drop verb's republication fixpoint
|
|
72
|
+
* (`schema/column-republication.ts`), which probes exposure the same way. No
|
|
73
|
+
* user column can hold this name, and the probe rewrites *to* it, so it can
|
|
74
|
+
* never collide with anything the walk is looking for.
|
|
75
|
+
*/
|
|
76
|
+
export declare const PROBE_COLUMN_NAME = "__quereus_column_probe__";
|
|
77
|
+
/**
|
|
78
|
+
* Whether `node` refers to `tableName`.`columnName` — read-only with respect to
|
|
79
|
+
* the caller's AST; a throwaway {@link spineCloneAst} copy is what gets
|
|
80
|
+
* rewritten.
|
|
81
|
+
*
|
|
82
|
+
* Same equivalence {@link tableReferencedInAst} establishes for the table verb,
|
|
83
|
+
* and for the same reason: "refers to" must mean "would have been rewritten by
|
|
84
|
+
* `ALTER TABLE … RENAME COLUMN`", or a DROP guard built on it refuses a
|
|
85
|
+
* different set of cases than the rename follows. See that function's comment
|
|
86
|
+
* for why the column verb reaches it by clone+sentinel rather than by `dryRun`.
|
|
87
|
+
*
|
|
88
|
+
* `resolveColumnInSource` is **not optional in practice**: without it the walk
|
|
89
|
+
* has no way to tell that an unqualified ref inside a subquery binds to a
|
|
90
|
+
* like-named column on the subquery's own FROM source, and a caller asking
|
|
91
|
+
* "does this body name `t.v`?" gets `true` for a body whose only `v` is
|
|
92
|
+
* another table's. Every caller should pass the catalog-backed resolver
|
|
93
|
+
* (`buildColumnSourceResolver`).
|
|
94
|
+
*
|
|
95
|
+
* NOTE: one spine clone plus one walk per probe, and the DROP COLUMN guard probes every
|
|
96
|
+
* live assertion. Trivial at the handful-of-assertions scale schemas have today, and it
|
|
97
|
+
* only runs on DDL; if a schema ever carries assertions by the hundred, filter by
|
|
98
|
+
* `tableReferencedInAst` (no clone) before paying for the column probe.
|
|
99
|
+
*/
|
|
100
|
+
export declare function columnReferencedInAst(node: AST.AstNode | undefined, tableName: string, columnName: string, resolve: ResolveObjectRef, targetKey: string, rowImage: RowImageContext, resolveColumnInSource?: ResolveColumnInSource): boolean;
|
|
101
|
+
/**
|
|
102
|
+
* {@link columnReferencedInAst} for an expression that resolves unqualified refs
|
|
103
|
+
* against an implicit binding to `tableName` — a CHECK expression or a
|
|
104
|
+
* partial-index predicate. Uses {@link renameColumnInCheckExpression}'s seeded
|
|
105
|
+
* entry point so the probe answers for exactly the scope that expression is
|
|
106
|
+
* planned in.
|
|
107
|
+
*/
|
|
108
|
+
export declare function columnReferencedInCheckExpression(expr: AST.AstNode | undefined, tableName: string, columnName: string, resolve: ResolveObjectRef, targetKey: string, rowImage: RowImageContext, resolveColumnInSource?: ResolveColumnInSource): boolean;
|
|
109
|
+
/**
|
|
110
|
+
* Rewrite the renamed column inside every partial-index predicate of `indexes`,
|
|
111
|
+
* in place. A predicate resolves unqualified refs against the indexed table
|
|
112
|
+
* itself — the same implicit seed a CHECK expression uses — so
|
|
113
|
+
* {@link renameColumnInCheckExpression} is the correct entry point here, not
|
|
114
|
+
* {@link renameColumnInAst}.
|
|
115
|
+
*
|
|
116
|
+
* The predicate `Expression` is shared by reference between the catalog's
|
|
117
|
+
* `TableSchema`, any module-local copy of it, and — for a unique partial index —
|
|
118
|
+
* the `derivedFromIndex` UNIQUE constraint that carries the same predicate.
|
|
119
|
+
* Rewriting in place keeps all of them in step; cloning would strand the derived
|
|
120
|
+
* constraint on the old AST.
|
|
121
|
+
*
|
|
122
|
+
* Idempotent: once rewritten, nothing names `oldColName` any more, so a second
|
|
123
|
+
* call with the same pair returns false without touching the AST.
|
|
124
|
+
*
|
|
125
|
+
* The parameter is structurally typed rather than `IndexSchema[]` so this module
|
|
126
|
+
* stays free of catalog imports; `IndexSchema` satisfies it.
|
|
127
|
+
*
|
|
128
|
+
* Row-image mode is `'none'`: a partial-index predicate describes rows already
|
|
129
|
+
* stored, so it has no written-row context and a bare `new.` / `old.` qualifier
|
|
130
|
+
* there is an ordinary table reference — the same asymmetry
|
|
131
|
+
* {@link import('./table-rename.js').renameTableInIndexPredicates} records by
|
|
132
|
+
* passing no `rowImageContext`. (An indexed table literally named `new` still
|
|
133
|
+
* matches through the seed binding, so this changes no answer for the case
|
|
134
|
+
* that plans.)
|
|
135
|
+
*/
|
|
136
|
+
export declare function renameColumnInIndexPredicates(indexes: ReadonlyArray<{
|
|
137
|
+
readonly predicate?: AST.Expression;
|
|
138
|
+
}> | undefined, tableName: string, oldColName: string, newColName: string, resolve: ResolveObjectRef, targetKey: string, resolveColumnInSource?: ResolveColumnInSource): boolean;
|
|
139
|
+
/**
|
|
140
|
+
* Rewrite the renamed column inside every CHECK constraint expression of `checks`
|
|
141
|
+
* belonging to the renamed table itself, in place. The seeded-scope entry point
|
|
142
|
+
* applies for the same reason it does for a partial-index predicate: a CHECK
|
|
143
|
+
* resolves unqualified refs against its owning table.
|
|
144
|
+
*
|
|
145
|
+
* Only pass the renamed table's OWN checks — a CHECK on a *different* table that
|
|
146
|
+
* happens to reference the renamed table needs {@link renameColumnInAst}, whose
|
|
147
|
+
* walk has no implicit seed. That own-table contract is also why the row-image
|
|
148
|
+
* mode is hardcoded `'own'` here: a CHECK evaluates against the row being
|
|
149
|
+
* written, whose image IS the renamed table's.
|
|
150
|
+
*/
|
|
151
|
+
export declare function renameColumnInCheckConstraints(checks: ReadonlyArray<{
|
|
152
|
+
readonly expr: AST.Expression;
|
|
153
|
+
}> | undefined, tableName: string, oldColName: string, newColName: string, resolve: ResolveObjectRef, targetKey: string, resolveColumnInSource?: ResolveColumnInSource): boolean;
|
|
154
|
+
/**
|
|
155
|
+
* Rewrite the renamed column inside the two expressions a `ColumnSchema` can carry —
|
|
156
|
+
* a column DEFAULT (`b integer default (new.a + 1)`, however authored: inline, or via
|
|
157
|
+
* `ALTER TABLE … ALTER COLUMN … SET DEFAULT`, which writes the same field) and a
|
|
158
|
+
* generated column's body (`g integer generated always as (a + 1)`) — in place, for
|
|
159
|
+
* every column of the renamed table itself.
|
|
160
|
+
*
|
|
161
|
+
* The seeded {@link renameColumnInCheckExpression} entry point with row-image mode
|
|
162
|
+
* `'own'` is correct for both:
|
|
163
|
+
*
|
|
164
|
+
* - The implicit unaliased binding to the owning table is what makes a generated
|
|
165
|
+
* column's **bare** `a` resolve — it has no FROM clause to bind against, exactly like
|
|
166
|
+
* a CHECK.
|
|
167
|
+
* - The `'own'` mode is what makes a default's `new.a` resolve. A default is evaluated
|
|
168
|
+
* against the row being written, so that qualifier names this table's row image, not
|
|
169
|
+
* anything a FROM binds.
|
|
170
|
+
*
|
|
171
|
+
* Case folding (`NEW.A`) and the shadowing edge (a real table literally named `new`,
|
|
172
|
+
* reached from a subquery inside the expression) therefore behave exactly as they do for
|
|
173
|
+
* a CHECK, because the same walk decides all three.
|
|
174
|
+
*
|
|
175
|
+
* Only pass the renamed table's OWN columns. A default on a *different* table can reach
|
|
176
|
+
* this table only through a subquery, so an unqualified ref there must bind inside that
|
|
177
|
+
* subquery's FROM — that caller wants {@link renameColumnInAst}, whose walk has no seed.
|
|
178
|
+
*
|
|
179
|
+
* Same sharing and idempotence story as {@link renameColumnInCheckConstraints}: a
|
|
180
|
+
* module's rename hook rebuilds only the renamed column's `ColumnSchema` and keeps every
|
|
181
|
+
* other one by reference, and even the rebuilt one carries the SAME expression nodes
|
|
182
|
+
* (`buildConstraintsFromColumn` passes them into the reconstructed `ColumnDef` by
|
|
183
|
+
* reference and `columnDefToSchema` assigns them straight back), so one in-place rewrite
|
|
184
|
+
* reaches every holder and a second call with the same pair is a no-op.
|
|
185
|
+
*
|
|
186
|
+
* The parameter is structurally typed rather than `ColumnSchema[]` so this module stays
|
|
187
|
+
* free of catalog imports; `ColumnSchema` satisfies it.
|
|
188
|
+
*/
|
|
189
|
+
export declare function renameColumnInColumnExpressions(columns: ReadonlyArray<{
|
|
190
|
+
readonly defaultValue?: AST.Expression | null;
|
|
191
|
+
readonly generatedExpr?: AST.Expression;
|
|
192
|
+
}> | undefined, tableName: string, oldColName: string, newColName: string, resolve: ResolveObjectRef, targetKey: string, resolveColumnInSource?: ResolveColumnInSource): boolean;
|
|
193
|
+
/**
|
|
194
|
+
* Whether `body`'s top-level result columns publish the renamed column under
|
|
195
|
+
* `newColName` — i.e. whether rewriting this body shifted the name its readers
|
|
196
|
+
* see. Call AFTER the body rewrite: the predicate compares against the NEW
|
|
197
|
+
* name, exactly as the CTE exposure analysis it shares its internals with
|
|
198
|
+
* ({@link cteExposesRenamedColumn} / `isResultColumnExposure`). An explicit
|
|
199
|
+
* result-column alias suppresses exposure; a bare projection of the renamed
|
|
200
|
+
* column, or a `*` / `t.*` / `a.*` whose frame binds the target, exposes it —
|
|
201
|
+
* a FROM alias is no obstacle, since it only changes which qualifier names the
|
|
202
|
+
* source.
|
|
203
|
+
*
|
|
204
|
+
* An explicit view / materialized-view column list pins the published names
|
|
205
|
+
* regardless of the body — that guard belongs at the call site
|
|
206
|
+
* (`ViewSchema.columns` / `TableDerivation.columns` play the role
|
|
207
|
+
* `cte.columns` plays inside the CTE analysis; this predicate never sees them).
|
|
208
|
+
*/
|
|
209
|
+
export declare function bodyExposesRenamedColumn(body: AST.QueryExpr | undefined, tableName: string, oldColName: string, newColName: string, resolve: ResolveObjectRef, targetKey: string, resolveColumnInSource?: ResolveColumnInSource): boolean;
|
|
210
|
+
/**
|
|
211
|
+
* Whether `body`'s top-level result columns publish a column named
|
|
212
|
+
* `columnName`, from ANY origin: an explicit alias, an unaliased bare
|
|
213
|
+
* projection of a column so named (wherever it binds), or a `*` / `t.*` whose
|
|
214
|
+
* bound real-table source exposes it (asked through `resolveColumnInSource`).
|
|
215
|
+
*
|
|
216
|
+
* The collision half of the rename-cascade pre-flight
|
|
217
|
+
* (`runtime/emit/column-rename-cascade.ts`): run against the PRISTINE
|
|
218
|
+
* (pre-rewrite) body with `columnName = newCol` — the rename target cannot
|
|
219
|
+
* publish `newCol` before the rename, so anything found is necessarily a
|
|
220
|
+
* DIFFERENT column the shifted name would collide with.
|
|
221
|
+
*
|
|
222
|
+
* Shares the walker's scope residual: a `*` over a subquery or function source
|
|
223
|
+
* has no askable column set, so a publication arriving only that way is not
|
|
224
|
+
* seen. A `*` over an aliased REAL source is seen — the alias binds like any
|
|
225
|
+
* other qualifier.
|
|
226
|
+
*/
|
|
227
|
+
export declare function bodyPublishesColumnNamed(body: AST.QueryExpr | undefined, columnName: string, resolve: ResolveObjectRef, resolveColumnInSource?: ResolveColumnInSource): boolean;
|
|
228
|
+
//# sourceMappingURL=column-rename.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"column-rename.d.ts","sourceRoot":"","sources":["../../../../src/schema/rename/column-rename.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,GAAG,MAAM,qBAAqB,CAAC;AAEhD,OAAO,EAAuC,KAAK,qBAAqB,EAAE,KAAK,gBAAgB,EAAE,KAAK,eAAe,EAAE,MAAM,aAAa,CAAC;AAqD3I;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AACH,wBAAgB,iBAAiB,CAChC,IAAI,EAAE,GAAG,CAAC,OAAO,GAAG,SAAS,EAC7B,SAAS,EAAE,MAAM,EACjB,UAAU,EAAE,MAAM,EAClB,UAAU,EAAE,MAAM,EAClB,OAAO,EAAE,gBAAgB,EACzB,SAAS,EAAE,MAAM,EACjB,QAAQ,EAAE,eAAe,EACzB,qBAAqB,CAAC,E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