rawsql-ts 0.26.1 → 0.28.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 (34) hide show
  1. package/dist/esm/index.d.ts +1 -0
  2. package/dist/esm/index.js.map +1 -1
  3. package/dist/esm/index.min.js +1 -1
  4. package/dist/esm/index.min.js.map +3 -3
  5. package/dist/esm/transformers/ConditionOptimization.d.ts +5 -0
  6. package/dist/esm/transformers/ConditionOptimization.js +125 -67
  7. package/dist/esm/transformers/ConditionOptimization.js.map +1 -1
  8. package/dist/esm/transformers/ParameterConditionPlacementOptimizer.d.ts +26 -7
  9. package/dist/esm/transformers/ParameterConditionPlacementOptimizer.js +408 -138
  10. package/dist/esm/transformers/ParameterConditionPlacementOptimizer.js.map +1 -1
  11. package/dist/esm/transformers/SqlComponentFormatter.d.ts +9 -1
  12. package/dist/esm/transformers/SqlComponentFormatter.js +10 -1
  13. package/dist/esm/transformers/SqlComponentFormatter.js.map +1 -1
  14. package/dist/esm/transformers/StaticPredicatePlacementOptimizer.d.ts +22 -4
  15. package/dist/esm/transformers/StaticPredicatePlacementOptimizer.js +332 -95
  16. package/dist/esm/transformers/StaticPredicatePlacementOptimizer.js.map +1 -1
  17. package/dist/index.js.map +1 -1
  18. package/dist/index.min.js +1 -1
  19. package/dist/index.min.js.map +3 -3
  20. package/dist/src/index.d.ts +1 -0
  21. package/dist/src/transformers/ConditionOptimization.d.ts +5 -0
  22. package/dist/src/transformers/ParameterConditionPlacementOptimizer.d.ts +26 -7
  23. package/dist/src/transformers/SqlComponentFormatter.d.ts +9 -1
  24. package/dist/src/transformers/StaticPredicatePlacementOptimizer.d.ts +22 -4
  25. package/dist/transformers/ConditionOptimization.js +135 -62
  26. package/dist/transformers/ConditionOptimization.js.map +1 -1
  27. package/dist/transformers/ParameterConditionPlacementOptimizer.js +406 -136
  28. package/dist/transformers/ParameterConditionPlacementOptimizer.js.map +1 -1
  29. package/dist/transformers/SqlComponentFormatter.js +12 -2
  30. package/dist/transformers/SqlComponentFormatter.js.map +1 -1
  31. package/dist/transformers/StaticPredicatePlacementOptimizer.js +330 -93
  32. package/dist/transformers/StaticPredicatePlacementOptimizer.js.map +1 -1
  33. package/dist/tsconfig.browser.tsbuildinfo +1 -1
  34. package/package.json +1 -1
@@ -19,6 +19,7 @@ export interface ConditionOptimizationPhaseSummary {
19
19
  warningCount: number;
20
20
  errorCount: number;
21
21
  }
22
+ export type ConditionOptimizationSkipDisposition = "blocked" | "unchanged" | "ignored";
22
23
  export interface SssqlOptionalConditionApplied {
23
24
  phaseKind: "sssql_optional_condition";
24
25
  kind: "prune_optional_branch" | "refresh_optional_branch";
@@ -34,6 +35,7 @@ export interface SssqlOptionalConditionSkipped {
34
35
  parameterName: string;
35
36
  code: string;
36
37
  reason: string;
38
+ skipDisposition: ConditionOptimizationSkipDisposition;
37
39
  }
38
40
  export type ConditionOptimizationApplied = SssqlOptionalConditionApplied | (ParameterConditionMove & {
39
41
  phaseKind: "parameter_condition_placement";
@@ -42,8 +44,10 @@ export type ConditionOptimizationApplied = SssqlOptionalConditionApplied | (Para
42
44
  });
43
45
  export type ConditionOptimizationSkipped = SssqlOptionalConditionSkipped | (ParameterConditionSkipped & {
44
46
  phaseKind: "parameter_condition_placement";
47
+ skipDisposition: ConditionOptimizationSkipDisposition;
45
48
  }) | (StaticPredicateSkipped & {
46
49
  phaseKind: "static_predicate_placement";
50
+ skipDisposition: ConditionOptimizationSkipDisposition;
47
51
  });
48
52
  export type ConditionOptimizationWarning = (ParameterConditionOptimizationWarning & {
49
53
  phaseKind: ConditionOptimizationPhaseKind;
@@ -64,6 +68,7 @@ export interface ConditionOptimizationSafety {
64
68
  export interface ConditionOptimizationResult {
65
69
  ok: boolean;
66
70
  sql: string;
71
+ query: SelectQuery | null;
67
72
  phases: readonly ConditionOptimizationPhaseSummary[];
68
73
  applied: readonly ConditionOptimizationApplied[];
69
74
  skipped: readonly ConditionOptimizationSkipped[];
@@ -1,16 +1,25 @@
1
1
  import { SelectQueryParser } from "../parsers/SelectQueryParser";
2
- import { optimizeParameterConditionPlacement, planParameterConditionOptimization } from "./ParameterConditionPlacementOptimizer";
3
- import { optimizeStaticPredicatePlacement, planStaticPredicatePlacement } from "./StaticPredicatePlacementOptimizer";
2
+ import { ParameterConditionPlacementOptimizer } from "./ParameterConditionPlacementOptimizer";
3
+ import { StaticPredicatePlacementOptimizer } from "./StaticPredicatePlacementOptimizer";
4
4
  import { collectSupportedOptionalConditionBranches, pruneOptionalConditionBranches } from "./PruneOptionalConditionBranches";
5
5
  import { SSSQLFilterBuilder } from "./SSSQLFilterBuilder";
6
- import { formatSqlComponent } from "./SqlComponentFormatter";
6
+ import { formatSqlComponent, hasSqlComponentFormatOverride } from "./SqlComponentFormatter";
7
7
  const hasOwnParameter = (parameters, parameterName) => Object.prototype.hasOwnProperty.call(parameters, parameterName);
8
8
  const isAbsentOptionalValue = (parameters, parameterName) => parameters[parameterName] === null || parameters[parameterName] === undefined;
9
- const parseConditionOptimizationInput = (input) => {
9
+ const parseConditionOptimizationInput = (input, options) => {
10
10
  const warnings = [];
11
11
  const errors = [];
12
- const sourceSql = typeof input === "string" ? input : formatSqlComponent(input);
12
+ const sourceSql = typeof input === "string" ? input : formatSqlComponent(input, options);
13
13
  const formatterGeneratedSource = typeof input !== "string";
14
+ if (typeof input !== "string" && options.cloneInput === false) {
15
+ return {
16
+ query: input,
17
+ sql: sourceSql,
18
+ formatterGeneratedSource: false,
19
+ warnings,
20
+ errors
21
+ };
22
+ }
14
23
  if (formatterGeneratedSource) {
15
24
  warnings.push({
16
25
  phaseKind: "sssql_optional_condition",
@@ -43,48 +52,50 @@ const parseConditionOptimizationInput = (input) => {
43
52
  };
44
53
  }
45
54
  };
46
- const buildSssqlApplied = (branch) => {
55
+ const buildSssqlApplied = (branch, options) => {
47
56
  return {
48
57
  phaseKind: "sssql_optional_condition",
49
58
  kind: "prune_optional_branch",
50
- conditionSql: formatSqlComponent(branch.expression),
59
+ conditionSql: formatSqlComponent(branch.expression, options),
51
60
  parameterName: branch.parameterName,
52
61
  reason: "The optional branch parameter is explicitly absent, so the safe-only SSSQL phase pruned the branch."
53
62
  };
54
63
  };
55
- const buildSssqlRefreshApplied = (branch, previousConditionSql) => {
64
+ const buildSssqlRefreshApplied = (branch, previousConditionSql, options) => {
56
65
  return {
57
66
  phaseKind: "sssql_optional_condition",
58
67
  kind: "refresh_optional_branch",
59
- conditionSql: formatSqlComponent(branch.expression),
68
+ conditionSql: formatSqlComponent(branch.expression, options),
60
69
  previousConditionSql,
61
70
  parameterName: branch.parameterName,
62
71
  reason: "The safe-only SSSQL phase refreshed the optional branch placement before ordinary parameter placement."
63
72
  };
64
73
  };
65
- const buildSssqlSkipped = (branch, parameters) => {
74
+ const buildSssqlSkipped = (branch, parameters, options) => {
66
75
  const parameterProvided = hasOwnParameter(parameters, branch.parameterName);
67
76
  return {
68
77
  phaseKind: "sssql_optional_condition",
69
78
  kind: "optional_branch_skipped",
70
- conditionSql: formatSqlComponent(branch.expression),
79
+ conditionSql: formatSqlComponent(branch.expression, options),
71
80
  parameterName: branch.parameterName,
72
81
  code: parameterProvided
73
82
  ? "SSSQL_OPTIONAL_PARAMETER_PRESENT"
74
83
  : "SSSQL_OPTIONAL_PARAMETER_NOT_PROVIDED",
75
84
  reason: parameterProvided
76
85
  ? "The optional branch parameter is present, so the branch remains active."
77
- : "No optional branch parameter value was provided, so the branch remains unchanged."
86
+ : "No optional branch parameter value was provided, so the branch remains unchanged.",
87
+ skipDisposition: parameterProvided ? "unchanged" : "ignored"
78
88
  };
79
89
  };
80
- const buildSssqlRefreshSkipped = (branch, code, reason) => {
90
+ const buildSssqlRefreshSkipped = (branch, code, reason, skipDisposition, options) => {
81
91
  return {
82
92
  phaseKind: "sssql_optional_condition",
83
93
  kind: "optional_branch_skipped",
84
- conditionSql: formatSqlComponent(branch.expression),
94
+ conditionSql: formatSqlComponent(branch.expression, options),
85
95
  parameterName: branch.parameterName,
86
96
  code,
87
- reason
97
+ reason,
98
+ skipDisposition
88
99
  };
89
100
  };
90
101
  const buildSssqlRefreshFilters = (branches, parameters) => {
@@ -96,78 +107,105 @@ const buildSssqlRefreshFilters = (branches, parameters) => {
96
107
  }
97
108
  return filters;
98
109
  };
99
- const refreshRemainingSssqlBranches = (sql, parameters) => {
100
- const parsed = parseConditionOptimizationInput(sql);
110
+ const refreshRemainingSssqlBranches = (query, fallbackSql, parameters, options) => {
111
+ var _a, _b;
101
112
  const applied = [];
102
113
  const skipped = [];
103
- if (!parsed.query) {
104
- return {
105
- sql: parsed.sql,
106
- applied,
107
- skipped,
108
- warnings: parsed.warnings,
109
- errors: parsed.errors,
110
- formatterGeneratedSource: parsed.formatterGeneratedSource
111
- };
112
- }
113
- const beforeBranches = collectSupportedOptionalConditionBranches(parsed.query);
114
+ const beforeBranches = collectSupportedOptionalConditionBranches(query);
114
115
  if (beforeBranches.length === 0) {
115
116
  return {
116
- sql: parsed.sql,
117
+ query,
118
+ sql: fallbackSql,
117
119
  applied,
118
120
  skipped,
119
- warnings: parsed.warnings,
120
- errors: parsed.errors,
121
- formatterGeneratedSource: parsed.formatterGeneratedSource
121
+ warnings: [],
122
+ errors: [],
123
+ formatterGeneratedSource: false
122
124
  };
123
125
  }
124
126
  const beforeBranchSql = new WeakMap();
125
127
  const beforeBranchQuery = new WeakMap();
128
+ const parameterCounts = new Map();
126
129
  for (const branch of beforeBranches) {
127
- beforeBranchSql.set(branch.expression, formatSqlComponent(branch.expression));
130
+ beforeBranchSql.set(branch.expression, formatSqlComponent(branch.expression, options));
128
131
  beforeBranchQuery.set(branch.expression, branch.query);
132
+ parameterCounts.set(branch.parameterName, ((_a = parameterCounts.get(branch.parameterName)) !== null && _a !== void 0 ? _a : 0) + 1);
129
133
  }
130
- try {
131
- new SSSQLFilterBuilder().refresh(parsed.query, buildSssqlRefreshFilters(beforeBranches, parameters));
134
+ const alreadyReportedExpressions = new WeakSet();
135
+ const refreshableBranches = [];
136
+ for (const branch of beforeBranches) {
137
+ if (((_b = parameterCounts.get(branch.parameterName)) !== null && _b !== void 0 ? _b : 0) > 1) {
138
+ skipped.push(buildSssqlRefreshSkipped(branch, "SSSQL_OPTIONAL_REFRESH_DUPLICATE_PARAMETER_UNCHANGED", "SSSQL optional branch refresh left this duplicate parameter branch unchanged so each query scope can keep its existing local predicate.", "unchanged", options));
139
+ alreadyReportedExpressions.add(branch.expression);
140
+ continue;
141
+ }
142
+ refreshableBranches.push(branch);
132
143
  }
133
- catch (error) {
134
- const detail = error instanceof Error ? error.message : String(error);
135
- return {
136
- sql,
137
- applied,
138
- skipped: beforeBranches.map(branch => buildSssqlRefreshSkipped(branch, "SSSQL_OPTIONAL_REFRESH_UNSUPPORTED", `SSSQL optional branch refresh was skipped because safe refresh could not be proven: ${detail}`)),
139
- warnings: parsed.warnings,
140
- errors: parsed.errors,
141
- formatterGeneratedSource: parsed.formatterGeneratedSource
142
- };
144
+ for (const branch of refreshableBranches) {
145
+ try {
146
+ new SSSQLFilterBuilder().refresh(query, buildSssqlRefreshFilters([branch], parameters));
147
+ }
148
+ catch (error) {
149
+ const detail = error instanceof Error ? error.message : String(error);
150
+ skipped.push(buildSssqlRefreshSkipped(branch, "SSSQL_OPTIONAL_REFRESH_UNSUPPORTED", `SSSQL optional branch refresh was skipped because safe refresh could not be proven: ${detail}`, "blocked", options));
151
+ alreadyReportedExpressions.add(branch.expression);
152
+ }
143
153
  }
144
- const afterBranches = collectSupportedOptionalConditionBranches(parsed.query);
154
+ const afterBranches = collectSupportedOptionalConditionBranches(query);
145
155
  for (const branch of afterBranches) {
156
+ if (alreadyReportedExpressions.has(branch.expression)) {
157
+ continue;
158
+ }
146
159
  const previousSql = beforeBranchSql.get(branch.expression);
147
160
  const previousQuery = beforeBranchQuery.get(branch.expression);
148
161
  if (!previousSql || !previousQuery) {
149
- skipped.push(buildSssqlRefreshSkipped(branch, "SSSQL_OPTIONAL_REFRESH_UNSUPPORTED", "SSSQL optional branch refresh left an untracked branch unchanged."));
162
+ skipped.push(buildSssqlRefreshSkipped(branch, "SSSQL_OPTIONAL_REFRESH_UNSUPPORTED", "SSSQL optional branch refresh left an untracked branch unchanged.", "blocked", options));
150
163
  continue;
151
164
  }
152
- const refreshedSql = formatSqlComponent(branch.expression);
165
+ const refreshedSql = formatSqlComponent(branch.expression, options);
153
166
  if (previousQuery !== branch.query || previousSql !== refreshedSql) {
154
- applied.push(buildSssqlRefreshApplied(branch, previousSql));
167
+ applied.push(buildSssqlRefreshApplied(branch, previousSql, options));
155
168
  continue;
156
169
  }
157
- skipped.push(buildSssqlRefreshSkipped(branch, "SSSQL_OPTIONAL_REFRESH_NOOP", "SSSQL optional branch refresh found no safe placement change to apply."));
170
+ const parameterProvided = hasOwnParameter(parameters, branch.parameterName);
171
+ skipped.push(buildSssqlRefreshSkipped(branch, parameterProvided
172
+ ? "SSSQL_OPTIONAL_REFRESH_NOOP"
173
+ : "SSSQL_OPTIONAL_PARAMETER_NOT_PROVIDED", parameterProvided
174
+ ? "SSSQL optional branch refresh found no safe placement change to apply."
175
+ : "No optional branch parameter value was provided, so the branch was not a refresh target.", parameterProvided ? "unchanged" : "ignored", options));
158
176
  }
159
177
  return {
160
- sql: applied.length > 0 ? formatSqlComponent(parsed.query) : sql,
178
+ query,
179
+ sql: applied.length > 0 || hasSqlComponentFormatOverride(options)
180
+ ? formatSqlComponent(query, options)
181
+ : fallbackSql,
161
182
  applied,
162
183
  skipped,
163
- warnings: parsed.warnings,
164
- errors: parsed.errors,
165
- formatterGeneratedSource: parsed.formatterGeneratedSource
184
+ warnings: [],
185
+ errors: [],
186
+ formatterGeneratedSource: false
166
187
  };
167
188
  };
189
+ const refreshRemainingSssqlBranchesFromSql = (sql, parameters, options) => {
190
+ const parsed = parseConditionOptimizationInput(sql, options);
191
+ if (!parsed.query) {
192
+ return {
193
+ query: null,
194
+ sql: parsed.sql,
195
+ applied: [],
196
+ skipped: [],
197
+ warnings: parsed.warnings,
198
+ errors: parsed.errors,
199
+ formatterGeneratedSource: parsed.formatterGeneratedSource
200
+ };
201
+ }
202
+ const refreshed = refreshRemainingSssqlBranches(parsed.query, sql, parameters, options);
203
+ return Object.assign(Object.assign({}, refreshed), { warnings: [...parsed.warnings, ...refreshed.warnings], errors: [...parsed.errors, ...refreshed.errors], formatterGeneratedSource: parsed.formatterGeneratedSource || refreshed.formatterGeneratedSource });
204
+ };
168
205
  const runSssqlOptionalConditionPhase = (input, options) => {
169
206
  var _a;
170
- const parsed = parseConditionOptimizationInput(input);
207
+ const reuseOwnedModel = options.cloneInput === false && typeof input !== "string";
208
+ const parsed = parseConditionOptimizationInput(input, options);
171
209
  const warnings = [...parsed.warnings];
172
210
  let errors = [...parsed.errors];
173
211
  const applied = [];
@@ -175,6 +213,7 @@ const runSssqlOptionalConditionPhase = (input, options) => {
175
213
  const optionalConditionParameters = (_a = options.optionalConditionParameters) !== null && _a !== void 0 ? _a : {};
176
214
  if (!parsed.query) {
177
215
  return {
216
+ query: null,
178
217
  sql: parsed.sql,
179
218
  applied,
180
219
  skipped,
@@ -184,14 +223,16 @@ const runSssqlOptionalConditionPhase = (input, options) => {
184
223
  };
185
224
  }
186
225
  let currentSql = parsed.sql;
226
+ let currentQuery = parsed.query;
227
+ let formatterGeneratedSource = parsed.formatterGeneratedSource;
187
228
  const branches = collectSupportedOptionalConditionBranches(parsed.query);
188
229
  const pruneBranches = branches.filter(branch => hasOwnParameter(optionalConditionParameters, branch.parameterName)
189
230
  && isAbsentOptionalValue(optionalConditionParameters, branch.parameterName));
190
231
  if (pruneBranches.length > 0) {
191
232
  try {
192
233
  pruneOptionalConditionBranches(parsed.query, optionalConditionParameters);
193
- currentSql = formatSqlComponent(parsed.query);
194
- applied.push(...pruneBranches.map(buildSssqlApplied));
234
+ currentSql = formatSqlComponent(parsed.query, options);
235
+ applied.push(...pruneBranches.map(branch => buildSssqlApplied(branch, options)));
195
236
  }
196
237
  catch (error) {
197
238
  errors = [...errors, {
@@ -203,38 +244,43 @@ const runSssqlOptionalConditionPhase = (input, options) => {
203
244
  }
204
245
  }
205
246
  if (errors.length === 0) {
206
- const refreshPhase = refreshRemainingSssqlBranches(currentSql, optionalConditionParameters);
247
+ const refreshPhase = reuseOwnedModel
248
+ ? refreshRemainingSssqlBranches(parsed.query, currentSql, optionalConditionParameters, options)
249
+ : refreshRemainingSssqlBranchesFromSql(currentSql, optionalConditionParameters, options);
207
250
  applied.push(...refreshPhase.applied);
208
251
  skipped.push(...refreshPhase.skipped);
209
252
  warnings.push(...refreshPhase.warnings);
210
253
  errors.push(...refreshPhase.errors);
211
254
  currentSql = refreshPhase.sql;
255
+ currentQuery = refreshPhase.query;
256
+ formatterGeneratedSource = formatterGeneratedSource || refreshPhase.formatterGeneratedSource;
212
257
  }
213
258
  else {
214
259
  for (const branch of branches) {
215
260
  if (pruneBranches.includes(branch)) {
216
261
  continue;
217
262
  }
218
- skipped.push(buildSssqlSkipped(branch, optionalConditionParameters));
263
+ skipped.push(buildSssqlSkipped(branch, optionalConditionParameters, options));
219
264
  }
220
265
  }
221
266
  return {
267
+ query: errors.length === 0 ? currentQuery : null,
222
268
  sql: errors.length === 0 ? currentSql : parsed.sql,
223
269
  applied,
224
270
  skipped,
225
271
  warnings,
226
272
  errors,
227
- formatterGeneratedSource: parsed.formatterGeneratedSource
273
+ formatterGeneratedSource
228
274
  };
229
275
  };
230
276
  const mapParameterWarnings = (warnings) => warnings.map(warning => (Object.assign({ phaseKind: "parameter_condition_placement" }, warning)));
231
277
  const mapParameterErrors = (errors) => errors.map(error => (Object.assign({ phaseKind: "parameter_condition_placement" }, error)));
232
278
  const mapParameterApplied = (applied) => applied.map(item => (Object.assign({ phaseKind: "parameter_condition_placement" }, item)));
233
- const mapParameterSkipped = (skipped) => skipped.map(item => (Object.assign({ phaseKind: "parameter_condition_placement" }, item)));
279
+ const mapParameterSkipped = (skipped) => skipped.map(item => (Object.assign({ phaseKind: "parameter_condition_placement", skipDisposition: "blocked" }, item)));
234
280
  const mapStaticWarnings = (warnings) => warnings.map(warning => (Object.assign({ phaseKind: "static_predicate_placement" }, warning)));
235
281
  const mapStaticErrors = (errors) => errors.map(error => (Object.assign({ phaseKind: "static_predicate_placement" }, error)));
236
282
  const mapStaticApplied = (applied) => applied.map(item => (Object.assign({ phaseKind: "static_predicate_placement" }, item)));
237
- const mapStaticSkipped = (skipped) => skipped.map(item => (Object.assign({ phaseKind: "static_predicate_placement" }, item)));
283
+ const mapStaticSkipped = (skipped) => skipped.map(item => (Object.assign({ phaseKind: "static_predicate_placement", skipDisposition: "blocked" }, item)));
238
284
  const makePhaseSummary = (kind, counts) => ({
239
285
  kind,
240
286
  appliedCount: counts.appliedCount,
@@ -243,21 +289,32 @@ const makePhaseSummary = (kind, counts) => ({
243
289
  errorCount: counts.errorCount
244
290
  });
245
291
  const runConditionOptimization = (input, options, defaultDryRun) => {
246
- var _a;
292
+ var _a, _b, _c;
247
293
  const dryRun = (_a = options.dryRun) !== null && _a !== void 0 ? _a : defaultDryRun;
294
+ const reuseOwnedModel = options.cloneInput === false && typeof input !== "string";
248
295
  // Run semantic SSSQL handling before generic placement phases so optional
249
296
  // branches remain owned by SSSQL even if later phases grow broader support.
250
297
  const sssqlPhase = runSssqlOptionalConditionPhase(input, Object.assign(Object.assign({}, options), { dryRun }));
298
+ const parameterOptimizer = new ParameterConditionPlacementOptimizer();
299
+ const parameterInput = reuseOwnedModel
300
+ ? (_b = sssqlPhase.query) !== null && _b !== void 0 ? _b : sssqlPhase.sql
301
+ : sssqlPhase.sql;
302
+ const parameterOptions = Object.assign(Object.assign({}, options), { dryRun, cloneInput: reuseOwnedModel && sssqlPhase.query ? false : options.cloneInput });
251
303
  const parameterPhase = dryRun
252
- ? planParameterConditionOptimization(sssqlPhase.sql, { dryRun })
253
- : optimizeParameterConditionPlacement(sssqlPhase.sql, { dryRun });
304
+ ? parameterOptimizer.plan(parameterInput, parameterOptions)
305
+ : parameterOptimizer.optimize(parameterInput, parameterOptions);
254
306
  const parameterWarnings = mapParameterWarnings(parameterPhase.warnings);
255
307
  const parameterErrors = mapParameterErrors(parameterPhase.errors);
256
308
  const parameterApplied = mapParameterApplied(parameterPhase.applied);
257
309
  const parameterSkipped = mapParameterSkipped(parameterPhase.skipped);
310
+ const staticOptimizer = new StaticPredicatePlacementOptimizer();
311
+ const staticInput = reuseOwnedModel
312
+ ? (_c = parameterPhase.query) !== null && _c !== void 0 ? _c : parameterPhase.sql
313
+ : parameterPhase.sql;
314
+ const staticOptions = Object.assign(Object.assign({}, options), { dryRun, cloneInput: reuseOwnedModel && parameterPhase.query ? false : options.cloneInput });
258
315
  const staticPhase = dryRun
259
- ? planStaticPredicatePlacement(parameterPhase.sql, { dryRun })
260
- : optimizeStaticPredicatePlacement(parameterPhase.sql, { dryRun });
316
+ ? staticOptimizer.plan(staticInput, staticOptions)
317
+ : staticOptimizer.optimize(staticInput, staticOptions);
261
318
  const staticWarnings = mapStaticWarnings(staticPhase.warnings);
262
319
  const staticErrors = mapStaticErrors(staticPhase.errors);
263
320
  const staticApplied = mapStaticApplied(staticPhase.applied);
@@ -267,6 +324,7 @@ const runConditionOptimization = (input, options, defaultDryRun) => {
267
324
  return {
268
325
  ok: errors.length === 0,
269
326
  sql: staticPhase.sql,
327
+ query: staticPhase.query,
270
328
  phases: [
271
329
  makePhaseSummary("sssql_optional_condition", {
272
330
  appliedCount: sssqlPhase.applied.length,
@@ -1 +1 @@
1
- {"version":3,"file":"ConditionOptimization.js","sourceRoot":"","sources":["../../../src/transformers/ConditionOptimization.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,iBAAiB,EAAE,MAAM,8BAA8B,CAAC;AACjE,OAAO,EACH,mCAAmC,EAMnC,kCAAkC,EACrC,MAAM,wCAAwC,CAAC;AAChD,OAAO,EACH,gCAAgC,EAChC,4BAA4B,EAK/B,MAAM,qCAAqC,CAAC;AAC7C,OAAO,EACH,yCAAyC,EAEzC,8BAA8B,EAEjC,MAAM,kCAAkC,CAAC;AAC1C,OAAO,EAAE,kBAAkB,EAAE,MAAM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,GAAG,aAAa,CAAC;QACvE,OAAO,EAAE,CAAC,GAAG,UAAU,CAAC,OAAO,EAAE,GAAG,gBAAgB,EAAE,GAAG,aAAa,CAAC;QACvE,QAAQ;QACR,MAAM;QACN,MAAM,EAAE;YACJ,IAAI,EAAE,WAAW;YACjB,oBAAoB,EAAE,KAAK;YAC3B,MAAM;YACN,wBAAwB,EAAE,UAAU,CAAC,wBAAwB;mBACtD,cAAc,CAAC,MAAM,CAAC,wBAAwB;mBAC9C,WAAW,CAAC,MAAM,CAAC,wBAAwB;SACrD;KACJ,CAAC;AACN,CAAC,CAAC;AAEF,MAAM,CAAC,MAAM,yBAAyB,GAAG,CACrC,KAAiC,EACjC,UAAwC,EAAE,EACf,EAAE;IAC7B,OAAO,wBAAwB,CAAC,KAAK,EAAE,OAAO,EAAE,IAAI,CAAC,CAAC;AAC1D,CAAC,CAAC;AAEF,MAAM,CAAC,MAAM,kBAAkB,GAAG,CAC9B,KAAiC,EACjC,UAAwC,EAAE,EACf,EAAE;IAC7B,OAAO,wBAAwB,CAAC,KAAK,EAAE,OAAO,EAAE,KAAK,CAAC,CAAC;AAC3D,CAAC,CAAC"}
1
+ {"version":3,"file":"ConditionOptimization.js","sourceRoot":"","sources":["../../../src/transformers/ConditionOptimization.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,iBAAiB,EAAE,MAAM,8BAA8B,CAAC;AACjE,OAAO,EACH,oCAAoC,EAMvC,MAAM,wCAAwC,CAAC;AAChD,OAAO,EACH,iCAAiC,EAKpC,MAAM,qCAAqC,CAAC;AAC7C,OAAO,EACH,yCAAyC,EAEzC,8BAA8B,EAEjC,MAAM,kCAAkC,CAAC;AAC1C,OAAO,EAAE,kBAAkB,EAAE,MAAM,sBAAsB,CAAC;AAC1D,OAAO,EACH,kBAAkB,EAClB,6BAA6B,EAEhC,MAAM,yBAAyB,CAAC;AA8GjC,MAAM,eAAe,GAAG,CACpB,UAA8C,EAC9C,aAAqB,EACd,EAAE,CAAC,MAAM,C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,CAAC;AAEF,MAAM,CAAC,MAAM,yBAAyB,GAAG,CACrC,KAAiC,EACjC,UAAwC,EAAE,EACf,EAAE;IAC7B,OAAO,wBAAwB,CAAC,KAAK,EAAE,OAAO,EAAE,IAAI,CAAC,CAAC;AAC1D,CAAC,CAAC;AAEF,MAAM,CAAC,MAAM,kBAAkB,GAAG,CAC9B,KAAiC,EACjC,UAAwC,EAAE,EACf,EAAE;IAC7B,OAAO,wBAAwB,CAAC,KAAK,EAAE,OAAO,EAAE,KAAK,CAAC,CAAC;AAC3D,CAAC,CAAC"}
@@ -1,15 +1,22 @@
1
1
  import { SelectQuery, SimpleSelectQuery } from "../models/SelectQuery";
2
+ import { SqlComponentFormatOptions } from "./SqlComponentFormatter";
2
3
  export type ParameterConditionOptimizationInput = string | SelectQuery | SimpleSelectQuery;
3
4
  /**
4
5
  * First-phase safe-only placement for ordinary parameter predicates.
5
6
  *
6
7
  * The optimizer intentionally handles only root top-level AND predicates and one
7
8
  * 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.
9
+ * Unsupported boundaries such as OR, DISTINCT ON, WINDOW, OUTER JOIN,
10
+ * expression outputs, and function predicates are reported as skipped.
10
11
  */
11
- export interface ParameterConditionOptimizationOptions {
12
+ export interface ParameterConditionOptimizationOptions extends SqlComponentFormatOptions {
12
13
  dryRun?: boolean;
14
+ /**
15
+ * Whether AST/model inputs should be cloned before optimization.
16
+ * Defaults to true for public-call safety. Internal pipelines can pass false
17
+ * when they own the model and want to avoid AST -> SQL -> AST round trips.
18
+ */
19
+ cloneInput?: boolean;
13
20
  }
14
21
  export interface ParameterConditionOptimizationWarning {
15
22
  code: string;
@@ -45,6 +52,7 @@ export interface ParameterConditionOptimizationSafety {
45
52
  export interface ParameterConditionOptimizationResult {
46
53
  ok: boolean;
47
54
  sql: string;
55
+ query: SelectQuery | null;
48
56
  applied: readonly ParameterConditionMove[];
49
57
  skipped: readonly ParameterConditionSkipped[];
50
58
  warnings: readonly ParameterConditionOptimizationWarning[];
@@ -58,21 +66,32 @@ export declare class ParameterConditionPlacementOptimizer {
58
66
  private parseInput;
59
67
  private analyzeCandidate;
60
68
  private findUnsupportedExpression;
69
+ private findUnsupportedParameterPredicateShape;
61
70
  private isSupportedInPredicate;
62
71
  private resolveTarget;
63
- private findCurrentQueryBoundary;
64
- private findTargetQueryBoundary;
72
+ private findRootQueryBoundary;
73
+ private resolveTargetPlacement;
65
74
  private resolveSourceBinding;
66
75
  private resolveUpstreamQuery;
67
- private resolveTargetColumn;
76
+ private resolveUnionTarget;
77
+ private resolveTargetColumns;
78
+ private resolveTargetColumnByOutputIndex;
79
+ private resolveDeepestBranchTarget;
68
80
  private verifyColumnResolvableInQuery;
81
+ private isGroupKeyColumn;
82
+ private sameResolvableColumnInQuery;
83
+ private resolveColumnSourceAlias;
69
84
  private rebaseCondition;
70
85
  private getSourceBindings;
71
86
  private findNullableSideBoundary;
72
87
  private hasOuterJoin;
88
+ private hasDistinctOnBoundary;
89
+ private hasOrdinaryDistinct;
73
90
  private getOutputColumnMatchCount;
91
+ private collectUnionBranches;
92
+ private resolveUnionOutputIndex;
93
+ private collectSelectOutputs;
74
94
  private resolveSourceQueryForColumns;
75
- private getSelectItemOutputName;
76
95
  private findCte;
77
96
  private countTableSourceReferences;
78
97
  private hasWindowUsage;