rawsql-ts 0.25.0 → 0.26.1

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 (42) hide show
  1. package/dist/esm/index.d.ts +3 -0
  2. package/dist/esm/index.js +3 -0
  3. package/dist/esm/index.js.map +1 -1
  4. package/dist/esm/index.min.js +2 -2
  5. package/dist/esm/index.min.js.map +4 -4
  6. package/dist/esm/transformers/ConditionOptimization.d.ts +75 -0
  7. package/dist/esm/transformers/ConditionOptimization.js +310 -0
  8. package/dist/esm/transformers/ConditionOptimization.js.map +1 -0
  9. package/dist/esm/transformers/ParameterConditionPlacementOptimizer.d.ts +85 -0
  10. package/dist/esm/transformers/ParameterConditionPlacementOptimizer.js +939 -0
  11. package/dist/esm/transformers/ParameterConditionPlacementOptimizer.js.map +1 -0
  12. package/dist/esm/transformers/SSSQLFilterBuilder.d.ts +6 -0
  13. package/dist/esm/transformers/SSSQLFilterBuilder.js +84 -8
  14. package/dist/esm/transformers/SSSQLFilterBuilder.js.map +1 -1
  15. package/dist/esm/transformers/SqlComponentFormatter.d.ts +3 -0
  16. package/dist/esm/transformers/SqlComponentFormatter.js +7 -0
  17. package/dist/esm/transformers/SqlComponentFormatter.js.map +1 -0
  18. package/dist/esm/transformers/StaticPredicatePlacementOptimizer.d.ts +85 -0
  19. package/dist/esm/transformers/StaticPredicatePlacementOptimizer.js +1198 -0
  20. package/dist/esm/transformers/StaticPredicatePlacementOptimizer.js.map +1 -0
  21. package/dist/index.js +3 -0
  22. package/dist/index.js.map +1 -1
  23. package/dist/index.min.js +2 -2
  24. package/dist/index.min.js.map +4 -4
  25. package/dist/src/index.d.ts +3 -0
  26. package/dist/src/transformers/ConditionOptimization.d.ts +75 -0
  27. package/dist/src/transformers/ParameterConditionPlacementOptimizer.d.ts +85 -0
  28. package/dist/src/transformers/SSSQLFilterBuilder.d.ts +6 -0
  29. package/dist/src/transformers/SqlComponentFormatter.d.ts +3 -0
  30. package/dist/src/transformers/StaticPredicatePlacementOptimizer.d.ts +85 -0
  31. package/dist/transformers/ConditionOptimization.js +339 -0
  32. package/dist/transformers/ConditionOptimization.js.map +1 -0
  33. package/dist/transformers/ParameterConditionPlacementOptimizer.js +949 -0
  34. package/dist/transformers/ParameterConditionPlacementOptimizer.js.map +1 -0
  35. package/dist/transformers/SSSQLFilterBuilder.js +92 -16
  36. package/dist/transformers/SSSQLFilterBuilder.js.map +1 -1
  37. package/dist/transformers/SqlComponentFormatter.js +11 -0
  38. package/dist/transformers/SqlComponentFormatter.js.map +1 -0
  39. package/dist/transformers/StaticPredicatePlacementOptimizer.js +1208 -0
  40. package/dist/transformers/StaticPredicatePlacementOptimizer.js.map +1 -0
  41. package/dist/tsconfig.browser.tsbuildinfo +1 -1
  42. package/package.json +1 -1
@@ -77,6 +77,9 @@ export * from './transformers/FilterableItemCollector';
77
77
  export { FixtureCteBuilder, FixtureTableDefinition, FixtureColumnDefinition } from './transformers/FixtureCteBuilder';
78
78
  export * from './transformers/DynamicQueryBuilder';
79
79
  export * from './transformers/SSSQLFilterBuilder';
80
+ export * from './transformers/ConditionOptimization';
81
+ export * from './transformers/ParameterConditionPlacementOptimizer';
82
+ export * from './transformers/StaticPredicatePlacementOptimizer';
80
83
  export * from './transformers/PruneOptionalConditionBranches';
81
84
  export { SchemaInfo, optimizeUnusedLeftJoins, optimizeUnusedLeftJoinsToFixedPoint, optimizeUnusedCtes, optimizeUnusedCtesToFixedPoint } from './transformers/OptimizeUnusedLeftJoins';
82
85
  export * from './transformers/TableColumnResolver';
@@ -0,0 +1,75 @@
1
+ import { SelectQuery, SimpleSelectQuery } from "../models/SelectQuery";
2
+ import { ParameterConditionMove, ParameterConditionOptimizationError, ParameterConditionOptimizationOptions, ParameterConditionOptimizationWarning, ParameterConditionSkipped } from "./ParameterConditionPlacementOptimizer";
3
+ import { StaticPredicateMove, StaticPredicatePlacementError, StaticPredicatePlacementWarning, StaticPredicateSkipped } from "./StaticPredicatePlacementOptimizer";
4
+ import { OptionalConditionPruningParameters } from "./PruneOptionalConditionBranches";
5
+ export type ConditionOptimizationInput = string | SelectQuery | SimpleSelectQuery;
6
+ export type ConditionOptimizationPhaseKind = "sssql_optional_condition" | "parameter_condition_placement" | "static_predicate_placement";
7
+ export interface ConditionOptimizationOptions extends ParameterConditionOptimizationOptions {
8
+ /**
9
+ * Explicit opt-in values for SSSQL optional branch pruning.
10
+ * Only listed parameter names are considered, and only null/undefined values
11
+ * are pruned by the safe-only SSSQL phase.
12
+ */
13
+ optionalConditionParameters?: OptionalConditionPruningParameters;
14
+ }
15
+ export interface ConditionOptimizationPhaseSummary {
16
+ kind: ConditionOptimizationPhaseKind;
17
+ appliedCount: number;
18
+ skippedCount: number;
19
+ warningCount: number;
20
+ errorCount: number;
21
+ }
22
+ export interface SssqlOptionalConditionApplied {
23
+ phaseKind: "sssql_optional_condition";
24
+ kind: "prune_optional_branch" | "refresh_optional_branch";
25
+ conditionSql: string;
26
+ parameterName: string;
27
+ reason: string;
28
+ previousConditionSql?: string;
29
+ }
30
+ export interface SssqlOptionalConditionSkipped {
31
+ phaseKind: "sssql_optional_condition";
32
+ kind: "optional_branch_skipped";
33
+ conditionSql: string;
34
+ parameterName: string;
35
+ code: string;
36
+ reason: string;
37
+ }
38
+ export type ConditionOptimizationApplied = SssqlOptionalConditionApplied | (ParameterConditionMove & {
39
+ phaseKind: "parameter_condition_placement";
40
+ }) | (StaticPredicateMove & {
41
+ phaseKind: "static_predicate_placement";
42
+ });
43
+ export type ConditionOptimizationSkipped = SssqlOptionalConditionSkipped | (ParameterConditionSkipped & {
44
+ phaseKind: "parameter_condition_placement";
45
+ }) | (StaticPredicateSkipped & {
46
+ phaseKind: "static_predicate_placement";
47
+ });
48
+ export type ConditionOptimizationWarning = (ParameterConditionOptimizationWarning & {
49
+ phaseKind: ConditionOptimizationPhaseKind;
50
+ }) | (StaticPredicatePlacementWarning & {
51
+ phaseKind: ConditionOptimizationPhaseKind;
52
+ });
53
+ export type ConditionOptimizationError = (ParameterConditionOptimizationError & {
54
+ phaseKind: ConditionOptimizationPhaseKind;
55
+ }) | (StaticPredicatePlacementError & {
56
+ phaseKind: ConditionOptimizationPhaseKind;
57
+ });
58
+ export interface ConditionOptimizationSafety {
59
+ mode: "safe_only";
60
+ unsafeRewriteApplied: false;
61
+ dryRun: boolean;
62
+ formatterGeneratedSource: boolean;
63
+ }
64
+ export interface ConditionOptimizationResult {
65
+ ok: boolean;
66
+ sql: string;
67
+ phases: readonly ConditionOptimizationPhaseSummary[];
68
+ applied: readonly ConditionOptimizationApplied[];
69
+ skipped: readonly ConditionOptimizationSkipped[];
70
+ warnings: readonly ConditionOptimizationWarning[];
71
+ errors: readonly ConditionOptimizationError[];
72
+ safety: ConditionOptimizationSafety;
73
+ }
74
+ export declare const planConditionOptimization: (input: ConditionOptimizationInput, options?: ConditionOptimizationOptions) => ConditionOptimizationResult;
75
+ export declare const optimizeConditions: (input: ConditionOptimizationInput, options?: ConditionOptimizationOptions) => ConditionOptimizationResult;
@@ -0,0 +1,85 @@
1
+ import { SelectQuery, SimpleSelectQuery } from "../models/SelectQuery";
2
+ export type ParameterConditionOptimizationInput = string | SelectQuery | SimpleSelectQuery;
3
+ /**
4
+ * First-phase safe-only placement for ordinary parameter predicates.
5
+ *
6
+ * The optimizer intentionally handles only root top-level AND predicates and one
7
+ * CTE/derived-table hop where the destination output is a direct column reference.
8
+ * Unsupported boundaries such as OR, UNION, DISTINCT, GROUP BY, WINDOW, OUTER
9
+ * JOIN, expression outputs, and function predicates are reported as skipped.
10
+ */
11
+ export interface ParameterConditionOptimizationOptions {
12
+ dryRun?: boolean;
13
+ }
14
+ export interface ParameterConditionOptimizationWarning {
15
+ code: string;
16
+ message: string;
17
+ detail?: unknown;
18
+ }
19
+ export interface ParameterConditionOptimizationError {
20
+ code: string;
21
+ message: string;
22
+ detail?: unknown;
23
+ }
24
+ export interface ParameterConditionMove {
25
+ kind: "move_condition";
26
+ conditionSql: string;
27
+ fromScopeId: string;
28
+ toScopeId: string;
29
+ reason: string;
30
+ parameterNames: readonly string[];
31
+ columnReferences: readonly string[];
32
+ }
33
+ export interface ParameterConditionSkipped {
34
+ conditionSql: string;
35
+ scopeId: string;
36
+ reason: string;
37
+ code: string;
38
+ }
39
+ export interface ParameterConditionOptimizationSafety {
40
+ mode: "safe_only";
41
+ unsafeRewriteApplied: false;
42
+ dryRun: boolean;
43
+ formatterGeneratedSource: boolean;
44
+ }
45
+ export interface ParameterConditionOptimizationResult {
46
+ ok: boolean;
47
+ sql: string;
48
+ applied: readonly ParameterConditionMove[];
49
+ skipped: readonly ParameterConditionSkipped[];
50
+ warnings: readonly ParameterConditionOptimizationWarning[];
51
+ errors: readonly ParameterConditionOptimizationError[];
52
+ safety: ParameterConditionOptimizationSafety;
53
+ conditionMoves: readonly ParameterConditionMove[];
54
+ }
55
+ export declare class ParameterConditionPlacementOptimizer {
56
+ plan(input: ParameterConditionOptimizationInput, options?: ParameterConditionOptimizationOptions): ParameterConditionOptimizationResult;
57
+ optimize(input: ParameterConditionOptimizationInput, options?: ParameterConditionOptimizationOptions): ParameterConditionOptimizationResult;
58
+ private parseInput;
59
+ private analyzeCandidate;
60
+ private findUnsupportedExpression;
61
+ private isSupportedInPredicate;
62
+ private resolveTarget;
63
+ private findCurrentQueryBoundary;
64
+ private findTargetQueryBoundary;
65
+ private resolveSourceBinding;
66
+ private resolveUpstreamQuery;
67
+ private resolveTargetColumn;
68
+ private verifyColumnResolvableInQuery;
69
+ private rebaseCondition;
70
+ private getSourceBindings;
71
+ private findNullableSideBoundary;
72
+ private hasOuterJoin;
73
+ private getOutputColumnMatchCount;
74
+ private resolveSourceQueryForColumns;
75
+ private getSelectItemOutputName;
76
+ private findCte;
77
+ private countTableSourceReferences;
78
+ private hasWindowUsage;
79
+ private collectColumnReferences;
80
+ private collectParameterNames;
81
+ private makeSkipped;
82
+ private buildResult;
83
+ }
84
+ export declare const planParameterConditionOptimization: (input: ParameterConditionOptimizationInput, options?: ParameterConditionOptimizationOptions) => ParameterConditionOptimizationResult;
85
+ export declare const optimizeParameterConditionPlacement: (input: ParameterConditionOptimizationInput, options?: ParameterConditionOptimizationOptions) => ParameterConditionOptimizationResult;
@@ -136,6 +136,12 @@ export declare class SSSQLFilterBuilder {
136
136
  private resolveSourceExpressionToUpstreamQuery;
137
137
  private resolveAnchorTargetInQuery;
138
138
  private getSourceAlias;
139
+ private buildScalarRefreshPlan;
140
+ private resolveScalarTargetInQuery;
141
+ private isNullableBranchColumn;
142
+ private hasLaterJoinThatNullsPriorSources;
143
+ private isPriorSourcesNullableJoin;
144
+ private isJoinedSourceNullable;
139
145
  private rebaseMovedBranch;
140
146
  private rebaseMovedBranchByAlias;
141
147
  }
@@ -0,0 +1,3 @@
1
+ import { SelectQuery, SimpleSelectQuery } from "../models/SelectQuery";
2
+ import { ValueComponent } from "../models/ValueComponent";
3
+ export declare const formatSqlComponent: (component: SelectQuery | SimpleSelectQuery | ValueComponent) => string;
@@ -0,0 +1,85 @@
1
+ import { SelectQuery, SimpleSelectQuery } from "../models/SelectQuery";
2
+ export type StaticPredicatePlacementInput = string | SelectQuery | SimpleSelectQuery;
3
+ /**
4
+ * Safe-only placement for parameter-free static predicates.
5
+ *
6
+ * The optimizer only moves top-level AND terms whose outer column references can
7
+ * be mechanically rebased to direct outputs of a single-use simple CTE or
8
+ * derived table. Unsupported or ambiguous predicates stay in place.
9
+ */
10
+ export interface StaticPredicatePlacementOptions {
11
+ dryRun?: boolean;
12
+ }
13
+ export interface StaticPredicatePlacementWarning {
14
+ code: string;
15
+ message: string;
16
+ detail?: unknown;
17
+ }
18
+ export interface StaticPredicatePlacementError {
19
+ code: string;
20
+ message: string;
21
+ detail?: unknown;
22
+ }
23
+ export interface StaticPredicateMove {
24
+ kind: "move_static_predicate";
25
+ predicateSql: string;
26
+ fromScopeId: string;
27
+ toScopeId: string;
28
+ reason: string;
29
+ columnReferences: readonly string[];
30
+ }
31
+ export interface StaticPredicateSkipped {
32
+ predicateSql: string;
33
+ scopeId: string;
34
+ reason: string;
35
+ code: string;
36
+ }
37
+ export interface StaticPredicatePlacementSafety {
38
+ mode: "safe_only";
39
+ unsafeRewriteApplied: false;
40
+ dryRun: boolean;
41
+ formatterGeneratedSource: boolean;
42
+ }
43
+ export interface StaticPredicatePlacementResult {
44
+ ok: boolean;
45
+ sql: string;
46
+ applied: readonly StaticPredicateMove[];
47
+ skipped: readonly StaticPredicateSkipped[];
48
+ warnings: readonly StaticPredicatePlacementWarning[];
49
+ errors: readonly StaticPredicatePlacementError[];
50
+ safety: StaticPredicatePlacementSafety;
51
+ staticPredicateMoves: readonly StaticPredicateMove[];
52
+ }
53
+ export declare class StaticPredicatePlacementOptimizer {
54
+ plan(input: StaticPredicatePlacementInput, options?: StaticPredicatePlacementOptions): StaticPredicatePlacementResult;
55
+ optimize(input: StaticPredicatePlacementInput, options?: StaticPredicatePlacementOptions): StaticPredicatePlacementResult;
56
+ private parseInput;
57
+ private analyzeCandidate;
58
+ private isExistsPredicate;
59
+ private findUnsupportedExpression;
60
+ private resolveTarget;
61
+ private findCurrentQueryBoundary;
62
+ private findTargetQueryBoundary;
63
+ private resolveSourceBinding;
64
+ private resolveUpstreamQuery;
65
+ private resolveTargetColumns;
66
+ private verifyColumnResolvableInQuery;
67
+ private rebasePredicate;
68
+ private getSourceBindings;
69
+ private findNullableSideBoundary;
70
+ private hasLaterJoinThatNullsPriorSources;
71
+ private hasOuterJoin;
72
+ private getOutputColumnMatchCount;
73
+ private resolveSourceQueryForColumns;
74
+ private getSelectItemOutputName;
75
+ private findCte;
76
+ private countTableSourceReferences;
77
+ private collectSourceAliases;
78
+ private collectRootColumnReferences;
79
+ private hasWindowUsage;
80
+ private collectParameterNames;
81
+ private makeSkipped;
82
+ private buildResult;
83
+ }
84
+ export declare const planStaticPredicatePlacement: (input: StaticPredicatePlacementInput, options?: StaticPredicatePlacementOptions) => StaticPredicatePlacementResult;
85
+ export declare const optimizeStaticPredicatePlacement: (input: StaticPredicatePlacementInput, options?: StaticPredicatePlacementOptions) => StaticPredicatePlacementResult;
@@ -0,0 +1,339 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.optimizeConditions = exports.planConditionOptimization = void 0;
4
+ const SelectQueryParser_1 = require("../parsers/SelectQueryParser");
5
+ const ParameterConditionPlacementOptimizer_1 = require("./ParameterConditionPlacementOptimizer");
6
+ const StaticPredicatePlacementOptimizer_1 = require("./StaticPredicatePlacementOptimizer");
7
+ const PruneOptionalConditionBranches_1 = require("./PruneOptionalConditionBranches");
8
+ const SSSQLFilterBuilder_1 = require("./SSSQLFilterBuilder");
9
+ const SqlComponentFormatter_1 = require("./SqlComponentFormatter");
10
+ const hasOwnParameter = (parameters, parameterName) => Object.prototype.hasOwnProperty.call(parameters, parameterName);
11
+ const isAbsentOptionalValue = (parameters, parameterName) => parameters[parameterName] === null || parameters[parameterName] === undefined;
12
+ const parseConditionOptimizationInput = (input) => {
13
+ const warnings = [];
14
+ const errors = [];
15
+ const sourceSql = typeof input === "string" ? input : (0, SqlComponentFormatter_1.formatSqlComponent)(input);
16
+ const formatterGeneratedSource = typeof input !== "string";
17
+ if (formatterGeneratedSource) {
18
+ warnings.push({
19
+ phaseKind: "sssql_optional_condition",
20
+ code: "AST_INPUT_FORMATTED",
21
+ message: "AST input is cloned through formatter output so the caller-owned query is not mutated."
22
+ });
23
+ }
24
+ try {
25
+ return {
26
+ query: SelectQueryParser_1.SelectQueryParser.parse(sourceSql),
27
+ sql: sourceSql,
28
+ formatterGeneratedSource,
29
+ warnings,
30
+ errors
31
+ };
32
+ }
33
+ catch (error) {
34
+ errors.push({
35
+ phaseKind: "sssql_optional_condition",
36
+ code: "PARSE_FAILED",
37
+ message: "SSSQL optional condition optimization could not parse the input SQL.",
38
+ detail: error instanceof Error ? error.message : String(error)
39
+ });
40
+ return {
41
+ query: null,
42
+ sql: sourceSql,
43
+ formatterGeneratedSource,
44
+ warnings,
45
+ errors
46
+ };
47
+ }
48
+ };
49
+ const buildSssqlApplied = (branch) => {
50
+ return {
51
+ phaseKind: "sssql_optional_condition",
52
+ kind: "prune_optional_branch",
53
+ conditionSql: (0, SqlComponentFormatter_1.formatSqlComponent)(branch.expression),
54
+ parameterName: branch.parameterName,
55
+ reason: "The optional branch parameter is explicitly absent, so the safe-only SSSQL phase pruned the branch."
56
+ };
57
+ };
58
+ const buildSssqlRefreshApplied = (branch, previousConditionSql) => {
59
+ return {
60
+ phaseKind: "sssql_optional_condition",
61
+ kind: "refresh_optional_branch",
62
+ conditionSql: (0, SqlComponentFormatter_1.formatSqlComponent)(branch.expression),
63
+ previousConditionSql,
64
+ parameterName: branch.parameterName,
65
+ reason: "The safe-only SSSQL phase refreshed the optional branch placement before ordinary parameter placement."
66
+ };
67
+ };
68
+ const buildSssqlSkipped = (branch, parameters) => {
69
+ const parameterProvided = hasOwnParameter(parameters, branch.parameterName);
70
+ return {
71
+ phaseKind: "sssql_optional_condition",
72
+ kind: "optional_branch_skipped",
73
+ conditionSql: (0, SqlComponentFormatter_1.formatSqlComponent)(branch.expression),
74
+ parameterName: branch.parameterName,
75
+ code: parameterProvided
76
+ ? "SSSQL_OPTIONAL_PARAMETER_PRESENT"
77
+ : "SSSQL_OPTIONAL_PARAMETER_NOT_PROVIDED",
78
+ reason: parameterProvided
79
+ ? "The optional branch parameter is present, so the branch remains active."
80
+ : "No optional branch parameter value was provided, so the branch remains unchanged."
81
+ };
82
+ };
83
+ const buildSssqlRefreshSkipped = (branch, code, reason) => {
84
+ return {
85
+ phaseKind: "sssql_optional_condition",
86
+ kind: "optional_branch_skipped",
87
+ conditionSql: (0, SqlComponentFormatter_1.formatSqlComponent)(branch.expression),
88
+ parameterName: branch.parameterName,
89
+ code,
90
+ reason
91
+ };
92
+ };
93
+ const buildSssqlRefreshFilters = (branches, parameters) => {
94
+ const filters = {};
95
+ for (const branch of branches) {
96
+ filters[branch.parameterName] = hasOwnParameter(parameters, branch.parameterName)
97
+ ? parameters[branch.parameterName]
98
+ : null;
99
+ }
100
+ return filters;
101
+ };
102
+ const refreshRemainingSssqlBranches = (sql, parameters) => {
103
+ const parsed = parseConditionOptimizationInput(sql);
104
+ const applied = [];
105
+ const skipped = [];
106
+ if (!parsed.query) {
107
+ return {
108
+ sql: parsed.sql,
109
+ applied,
110
+ skipped,
111
+ warnings: parsed.warnings,
112
+ errors: parsed.errors,
113
+ formatterGeneratedSource: parsed.formatterGeneratedSource
114
+ };
115
+ }
116
+ const beforeBranches = (0, PruneOptionalConditionBranches_1.collectSupportedOptionalConditionBranches)(parsed.query);
117
+ if (beforeBranches.length === 0) {
118
+ return {
119
+ sql: parsed.sql,
120
+ applied,
121
+ skipped,
122
+ warnings: parsed.warnings,
123
+ errors: parsed.errors,
124
+ formatterGeneratedSource: parsed.formatterGeneratedSource
125
+ };
126
+ }
127
+ const beforeBranchSql = new WeakMap();
128
+ const beforeBranchQuery = new WeakMap();
129
+ for (const branch of beforeBranches) {
130
+ beforeBranchSql.set(branch.expression, (0, SqlComponentFormatter_1.formatSqlComponent)(branch.expression));
131
+ beforeBranchQuery.set(branch.expression, branch.query);
132
+ }
133
+ try {
134
+ new SSSQLFilterBuilder_1.SSSQLFilterBuilder().refresh(parsed.query, buildSssqlRefreshFilters(beforeBranches, parameters));
135
+ }
136
+ catch (error) {
137
+ const detail = error instanceof Error ? error.message : String(error);
138
+ return {
139
+ sql,
140
+ applied,
141
+ skipped: beforeBranches.map(branch => buildSssqlRefreshSkipped(branch, "SSSQL_OPTIONAL_REFRESH_UNSUPPORTED", `SSSQL optional branch refresh was skipped because safe refresh could not be proven: ${detail}`)),
142
+ warnings: parsed.warnings,
143
+ errors: parsed.errors,
144
+ formatterGeneratedSource: parsed.formatterGeneratedSource
145
+ };
146
+ }
147
+ const afterBranches = (0, PruneOptionalConditionBranches_1.collectSupportedOptionalConditionBranches)(parsed.query);
148
+ for (const branch of afterBranches) {
149
+ const previousSql = beforeBranchSql.get(branch.expression);
150
+ const previousQuery = beforeBranchQuery.get(branch.expression);
151
+ if (!previousSql || !previousQuery) {
152
+ skipped.push(buildSssqlRefreshSkipped(branch, "SSSQL_OPTIONAL_REFRESH_UNSUPPORTED", "SSSQL optional branch refresh left an untracked branch unchanged."));
153
+ continue;
154
+ }
155
+ const refreshedSql = (0, SqlComponentFormatter_1.formatSqlComponent)(branch.expression);
156
+ if (previousQuery !== branch.query || previousSql !== refreshedSql) {
157
+ applied.push(buildSssqlRefreshApplied(branch, previousSql));
158
+ continue;
159
+ }
160
+ skipped.push(buildSssqlRefreshSkipped(branch, "SSSQL_OPTIONAL_REFRESH_NOOP", "SSSQL optional branch refresh found no safe placement change to apply."));
161
+ }
162
+ return {
163
+ sql: applied.length > 0 ? (0, SqlComponentFormatter_1.formatSqlComponent)(parsed.query) : sql,
164
+ applied,
165
+ skipped,
166
+ warnings: parsed.warnings,
167
+ errors: parsed.errors,
168
+ formatterGeneratedSource: parsed.formatterGeneratedSource
169
+ };
170
+ };
171
+ const runSssqlOptionalConditionPhase = (input, options) => {
172
+ var _a;
173
+ const parsed = parseConditionOptimizationInput(input);
174
+ const warnings = [...parsed.warnings];
175
+ let errors = [...parsed.errors];
176
+ const applied = [];
177
+ const skipped = [];
178
+ const optionalConditionParameters = (_a = options.optionalConditionParameters) !== null && _a !== void 0 ? _a : {};
179
+ if (!parsed.query) {
180
+ return {
181
+ sql: parsed.sql,
182
+ applied,
183
+ skipped,
184
+ warnings,
185
+ errors,
186
+ formatterGeneratedSource: parsed.formatterGeneratedSource
187
+ };
188
+ }
189
+ let currentSql = parsed.sql;
190
+ const branches = (0, PruneOptionalConditionBranches_1.collectSupportedOptionalConditionBranches)(parsed.query);
191
+ const pruneBranches = branches.filter(branch => hasOwnParameter(optionalConditionParameters, branch.parameterName)
192
+ && isAbsentOptionalValue(optionalConditionParameters, branch.parameterName));
193
+ if (pruneBranches.length > 0) {
194
+ try {
195
+ (0, PruneOptionalConditionBranches_1.pruneOptionalConditionBranches)(parsed.query, optionalConditionParameters);
196
+ currentSql = (0, SqlComponentFormatter_1.formatSqlComponent)(parsed.query);
197
+ applied.push(...pruneBranches.map(buildSssqlApplied));
198
+ }
199
+ catch (error) {
200
+ errors = [...errors, {
201
+ phaseKind: "sssql_optional_condition",
202
+ code: "SSSQL_PRUNE_FAILED",
203
+ message: "SSSQL optional condition optimization could not prune optional branches.",
204
+ detail: error instanceof Error ? error.message : String(error)
205
+ }];
206
+ }
207
+ }
208
+ if (errors.length === 0) {
209
+ const refreshPhase = refreshRemainingSssqlBranches(currentSql, optionalConditionParameters);
210
+ applied.push(...refreshPhase.applied);
211
+ skipped.push(...refreshPhase.skipped);
212
+ warnings.push(...refreshPhase.warnings);
213
+ errors.push(...refreshPhase.errors);
214
+ currentSql = refreshPhase.sql;
215
+ }
216
+ else {
217
+ for (const branch of branches) {
218
+ if (pruneBranches.includes(branch)) {
219
+ continue;
220
+ }
221
+ skipped.push(buildSssqlSkipped(branch, optionalConditionParameters));
222
+ }
223
+ }
224
+ return {
225
+ sql: errors.length === 0 ? currentSql : parsed.sql,
226
+ applied,
227
+ skipped,
228
+ warnings,
229
+ errors,
230
+ formatterGeneratedSource: parsed.formatterGeneratedSource
231
+ };
232
+ };
233
+ const mapParameterWarnings = (warnings) => warnings.map(warning => ({
234
+ phaseKind: "parameter_condition_placement",
235
+ ...warning
236
+ }));
237
+ const mapParameterErrors = (errors) => errors.map(error => ({
238
+ phaseKind: "parameter_condition_placement",
239
+ ...error
240
+ }));
241
+ const mapParameterApplied = (applied) => applied.map(item => ({
242
+ phaseKind: "parameter_condition_placement",
243
+ ...item
244
+ }));
245
+ const mapParameterSkipped = (skipped) => skipped.map(item => ({
246
+ phaseKind: "parameter_condition_placement",
247
+ ...item
248
+ }));
249
+ const mapStaticWarnings = (warnings) => warnings.map(warning => ({
250
+ phaseKind: "static_predicate_placement",
251
+ ...warning
252
+ }));
253
+ const mapStaticErrors = (errors) => errors.map(error => ({
254
+ phaseKind: "static_predicate_placement",
255
+ ...error
256
+ }));
257
+ const mapStaticApplied = (applied) => applied.map(item => ({
258
+ phaseKind: "static_predicate_placement",
259
+ ...item
260
+ }));
261
+ const mapStaticSkipped = (skipped) => skipped.map(item => ({
262
+ phaseKind: "static_predicate_placement",
263
+ ...item
264
+ }));
265
+ const makePhaseSummary = (kind, counts) => ({
266
+ kind,
267
+ appliedCount: counts.appliedCount,
268
+ skippedCount: counts.skippedCount,
269
+ warningCount: counts.warningCount,
270
+ errorCount: counts.errorCount
271
+ });
272
+ const runConditionOptimization = (input, options, defaultDryRun) => {
273
+ var _a;
274
+ const dryRun = (_a = options.dryRun) !== null && _a !== void 0 ? _a : defaultDryRun;
275
+ // Run semantic SSSQL handling before generic placement phases so optional
276
+ // branches remain owned by SSSQL even if later phases grow broader support.
277
+ const sssqlPhase = runSssqlOptionalConditionPhase(input, { ...options, dryRun });
278
+ const parameterPhase = dryRun
279
+ ? (0, ParameterConditionPlacementOptimizer_1.planParameterConditionOptimization)(sssqlPhase.sql, { dryRun })
280
+ : (0, ParameterConditionPlacementOptimizer_1.optimizeParameterConditionPlacement)(sssqlPhase.sql, { dryRun });
281
+ const parameterWarnings = mapParameterWarnings(parameterPhase.warnings);
282
+ const parameterErrors = mapParameterErrors(parameterPhase.errors);
283
+ const parameterApplied = mapParameterApplied(parameterPhase.applied);
284
+ const parameterSkipped = mapParameterSkipped(parameterPhase.skipped);
285
+ const staticPhase = dryRun
286
+ ? (0, StaticPredicatePlacementOptimizer_1.planStaticPredicatePlacement)(parameterPhase.sql, { dryRun })
287
+ : (0, StaticPredicatePlacementOptimizer_1.optimizeStaticPredicatePlacement)(parameterPhase.sql, { dryRun });
288
+ const staticWarnings = mapStaticWarnings(staticPhase.warnings);
289
+ const staticErrors = mapStaticErrors(staticPhase.errors);
290
+ const staticApplied = mapStaticApplied(staticPhase.applied);
291
+ const staticSkipped = mapStaticSkipped(staticPhase.skipped);
292
+ const warnings = [...sssqlPhase.warnings, ...parameterWarnings, ...staticWarnings];
293
+ const errors = [...sssqlPhase.errors, ...parameterErrors, ...staticErrors];
294
+ return {
295
+ ok: errors.length === 0,
296
+ sql: staticPhase.sql,
297
+ phases: [
298
+ makePhaseSummary("sssql_optional_condition", {
299
+ appliedCount: sssqlPhase.applied.length,
300
+ skippedCount: sssqlPhase.skipped.length,
301
+ warningCount: sssqlPhase.warnings.length,
302
+ errorCount: sssqlPhase.errors.length
303
+ }),
304
+ makePhaseSummary("parameter_condition_placement", {
305
+ appliedCount: parameterApplied.length,
306
+ skippedCount: parameterSkipped.length,
307
+ warningCount: parameterWarnings.length,
308
+ errorCount: parameterErrors.length
309
+ }),
310
+ makePhaseSummary("static_predicate_placement", {
311
+ appliedCount: staticApplied.length,
312
+ skippedCount: staticSkipped.length,
313
+ warningCount: staticWarnings.length,
314
+ errorCount: staticErrors.length
315
+ })
316
+ ],
317
+ applied: [...sssqlPhase.applied, ...parameterApplied, ...staticApplied],
318
+ skipped: [...sssqlPhase.skipped, ...parameterSkipped, ...staticSkipped],
319
+ warnings,
320
+ errors,
321
+ safety: {
322
+ mode: "safe_only",
323
+ unsafeRewriteApplied: false,
324
+ dryRun,
325
+ formatterGeneratedSource: sssqlPhase.formatterGeneratedSource
326
+ || parameterPhase.safety.formatterGeneratedSource
327
+ || staticPhase.safety.formatterGeneratedSource
328
+ }
329
+ };
330
+ };
331
+ const planConditionOptimization = (input, options = {}) => {
332
+ return runConditionOptimization(input, options, true);
333
+ };
334
+ exports.planConditionOptimization = planConditionOptimization;
335
+ const optimizeConditions = (input, options = {}) => {
336
+ return runConditionOptimization(input, options, false);
337
+ };
338
+ exports.optimizeConditions = optimizeConditions;
339
+ //# sourceMappingURL=ConditionOptimization.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ConditionOptimization.js","sourceRoot":"","sources":["../../src/transformers/ConditionOptimization.ts"],"names":[],"mappings":";;;AAEA,oEAAiE;AACjE,iGAQgD;AAChD,2FAO6C;AAC7C,qFAK0C;AAC1C,6DAA0D;AAC1D,mEAA6D;AAgG7D,MAAM,eAAe,GAAG,CACpB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