@quereus/quereus 0.6.2 → 0.6.4

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 (89) hide show
  1. package/README.md +1 -1
  2. package/dist/src/index.d.ts +4 -6
  3. package/dist/src/index.d.ts.map +1 -1
  4. package/dist/src/index.js +2 -4
  5. package/dist/src/index.js.map +1 -1
  6. package/dist/src/runtime/emit/schema-declarative.js +1 -1
  7. package/dist/src/runtime/emit/schema-declarative.js.map +1 -1
  8. package/dist/src/schema/schema-hasher.d.ts +3 -3
  9. package/dist/src/schema/schema-hasher.d.ts.map +1 -1
  10. package/dist/src/schema/schema-hasher.js +9 -27
  11. package/dist/src/schema/schema-hasher.js.map +1 -1
  12. package/dist/src/util/hash.d.ts +19 -0
  13. package/dist/src/util/hash.d.ts.map +1 -0
  14. package/dist/src/util/hash.js +76 -0
  15. package/dist/src/util/hash.js.map +1 -0
  16. package/dist/src/util/plugin-helper.d.ts +45 -0
  17. package/dist/src/util/plugin-helper.d.ts.map +1 -0
  18. package/dist/src/util/plugin-helper.js +85 -0
  19. package/dist/src/util/plugin-helper.js.map +1 -0
  20. package/package.json +4 -2
  21. package/src/index.ts +10 -16
  22. package/src/planner/building/delete.ts +214 -214
  23. package/src/planner/building/insert.ts +428 -428
  24. package/src/planner/building/update.ts +319 -319
  25. package/src/runtime/emit/schema-declarative.ts +1 -1
  26. package/src/schema/schema-hasher.ts +9 -27
  27. package/src/util/ast-stringify.ts +864 -864
  28. package/src/util/hash.ts +90 -0
  29. package/src/util/plugin-helper.ts +110 -0
  30. package/src/vtab/memory/table.ts +256 -256
  31. package/src/vtab/table.ts +162 -162
  32. package/dist/src/config/loader.d.ts +0 -41
  33. package/dist/src/config/loader.d.ts.map +0 -1
  34. package/dist/src/config/loader.js +0 -102
  35. package/dist/src/config/loader.js.map +0 -1
  36. package/dist/src/planner/nodes/physical-access-nodes.d.ts +0 -83
  37. package/dist/src/planner/nodes/physical-access-nodes.d.ts.map +0 -1
  38. package/dist/src/planner/nodes/physical-access-nodes.js +0 -226
  39. package/dist/src/planner/nodes/physical-access-nodes.js.map +0 -1
  40. package/dist/src/planner/nodes/scan.d.ts +0 -27
  41. package/dist/src/planner/nodes/scan.d.ts.map +0 -1
  42. package/dist/src/planner/nodes/scan.js +0 -78
  43. package/dist/src/planner/nodes/scan.js.map +0 -1
  44. package/dist/src/planner/nodes/update-executor-node.d.ts +0 -24
  45. package/dist/src/planner/nodes/update-executor-node.d.ts.map +0 -1
  46. package/dist/src/planner/nodes/update-executor-node.js +0 -57
  47. package/dist/src/planner/nodes/update-executor-node.js.map +0 -1
  48. package/dist/src/planner/physical-utils.d.ts +0 -36
  49. package/dist/src/planner/physical-utils.d.ts.map +0 -1
  50. package/dist/src/planner/physical-utils.js +0 -122
  51. package/dist/src/planner/physical-utils.js.map +0 -1
  52. package/dist/src/planner/rules/physical/rule-filter-optimization.d.ts +0 -11
  53. package/dist/src/planner/rules/physical/rule-filter-optimization.d.ts.map +0 -1
  54. package/dist/src/planner/rules/physical/rule-filter-optimization.js +0 -49
  55. package/dist/src/planner/rules/physical/rule-filter-optimization.js.map +0 -1
  56. package/dist/src/planner/rules/physical/rule-mark-physical.d.ts +0 -11
  57. package/dist/src/planner/rules/physical/rule-mark-physical.d.ts.map +0 -1
  58. package/dist/src/planner/rules/physical/rule-mark-physical.js +0 -29
  59. package/dist/src/planner/rules/physical/rule-mark-physical.js.map +0 -1
  60. package/dist/src/planner/rules/physical/rule-project-optimization.d.ts +0 -11
  61. package/dist/src/planner/rules/physical/rule-project-optimization.d.ts.map +0 -1
  62. package/dist/src/planner/rules/physical/rule-project-optimization.js +0 -44
  63. package/dist/src/planner/rules/physical/rule-project-optimization.js.map +0 -1
  64. package/dist/src/planner/rules/physical/rule-sort-optimization.d.ts +0 -11
  65. package/dist/src/planner/rules/physical/rule-sort-optimization.d.ts.map +0 -1
  66. package/dist/src/planner/rules/physical/rule-sort-optimization.js +0 -53
  67. package/dist/src/planner/rules/physical/rule-sort-optimization.js.map +0 -1
  68. package/dist/src/planner/rules/rewrite/rule-constant-folding.d.ts +0 -11
  69. package/dist/src/planner/rules/rewrite/rule-constant-folding.d.ts.map +0 -1
  70. package/dist/src/planner/rules/rewrite/rule-constant-folding.js +0 -59
  71. package/dist/src/planner/rules/rewrite/rule-constant-folding.js.map +0 -1
  72. package/dist/src/planner/util/deferred-constraint.d.ts +0 -14
  73. package/dist/src/planner/util/deferred-constraint.d.ts.map +0 -1
  74. package/dist/src/planner/util/deferred-constraint.js +0 -85
  75. package/dist/src/planner/util/deferred-constraint.js.map +0 -1
  76. package/dist/src/runtime/emit/table-reference.d.ts +0 -5
  77. package/dist/src/runtime/emit/table-reference.d.ts.map +0 -1
  78. package/dist/src/runtime/emit/table-reference.js +0 -67
  79. package/dist/src/runtime/emit/table-reference.js.map +0 -1
  80. package/dist/src/runtime/emit/update-executor.d.ts +0 -5
  81. package/dist/src/runtime/emit/update-executor.d.ts.map +0 -1
  82. package/dist/src/runtime/emit/update-executor.js +0 -54
  83. package/dist/src/runtime/emit/update-executor.js.map +0 -1
  84. package/dist/src/util/plugin-loader.d.ts +0 -52
  85. package/dist/src/util/plugin-loader.d.ts.map +0 -1
  86. package/dist/src/util/plugin-loader.js +0 -307
  87. package/dist/src/util/plugin-loader.js.map +0 -1
  88. package/src/config/loader.ts +0 -140
  89. package/src/util/plugin-loader.ts +0 -387
@@ -1,49 +0,0 @@
1
- /**
2
- * Rule: Filter Optimization
3
- *
4
- * Transforms: FilterNode → FilterNode (optimized)
5
- * Conditions: When filter node's source needs optimization
6
- * Benefits: Ensures filter nodes have optimized sources and proper physical properties
7
- */
8
- import { createLogger } from '../../../common/logger.js';
9
- import { FilterNode } from '../../nodes/filter.js';
10
- import { PlanNode as BasePlanNode } from '../../nodes/plan-node.js';
11
- const log = createLogger('optimizer:rule:filter-optimization');
12
- export function ruleFilterOptimization(node, context) {
13
- // Guard: only apply to FilterNode
14
- if (!(node instanceof FilterNode)) {
15
- return null;
16
- }
17
- log('Optimizing FilterNode %s', node.id);
18
- // Optimize the source
19
- const optimizedSource = context.optimizer.optimizeNode(node.source, context);
20
- // If source didn't change, just ensure physical properties are set
21
- if (optimizedSource === node.source) {
22
- if (!node.physical) {
23
- // Filter preserves most properties but may reduce row count
24
- const sourceRows = optimizedSource.estimatedRows;
25
- const filteredRows = sourceRows ? Math.ceil(sourceRows * 0.3) : undefined; // Assume 30% selectivity
26
- BasePlanNode.setDefaultPhysical(node, {
27
- estimatedRows: filteredRows,
28
- deterministic: true,
29
- readonly: true
30
- });
31
- log('Set physical properties on existing FilterNode');
32
- return node;
33
- }
34
- return null; // No change needed
35
- }
36
- // Source changed - create new filter node with optimized source
37
- const result = new FilterNode(node.scope, optimizedSource, node.predicate);
38
- // Set physical properties
39
- const sourceRows = optimizedSource.estimatedRows;
40
- const filteredRows = sourceRows ? Math.ceil(sourceRows * 0.3) : undefined; // Assume 30% selectivity
41
- BasePlanNode.setDefaultPhysical(result, {
42
- estimatedRows: filteredRows,
43
- deterministic: true,
44
- readonly: true
45
- });
46
- log('Created optimized FilterNode with new source');
47
- return result;
48
- }
49
- //# sourceMappingURL=rule-filter-optimization.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"rule-filter-optimization.js","sourceRoot":"","sources":["../../../../../src/planner/rules/physical/rule-filter-optimization.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,EAAE,YAAY,EAAE,MAAM,2BAA2B,CAAC;AAGzD,OAAO,EAAE,UAAU,EAAE,MAAM,uBAAuB,CAAC;AACnD,OAAO,EAAE,QAAQ,IAAI,YAAY,EAAE,MAAM,0BAA0B,CAAC;AAEpE,MAAM,GAAG,GAAG,YAAY,CAAC,oCAAoC,CAAC,CAAC;AAE/D,MAAM,UAAU,sBAAsB,CAAC,IAAc,EAAE,OAAmB;IACzE,kCAAkC;IAClC,IAAI,CAAC,CAAC,IAAI,YAAY,UAAU,CAAC,EAAE,CAAC;QACnC,OAAO,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AAI;KACd,CAAC,CAAC;IAEH,GAAG,CAAC,8CAA8C,CAAC,CAAC;IACpD,OAAO,MAAM,CAAC;AACf,CAAC"}
@@ -1,11 +0,0 @@
1
- /**
2
- * Rule: Mark Physical (Fallback)
3
- *
4
- * Transforms: Any logical node → Same node (marked as physical)
5
- * Conditions: When no other rule has made the node physical
6
- * Benefits: Ensures all nodes become physical even if no specific transformation is needed
7
- */
8
- import type { PlanNode } from '../../nodes/plan-node.js';
9
- import type { OptContext } from '../../framework/context.js';
10
- export declare function ruleMarkPhysical(node: PlanNode, _context: OptContext): PlanNode | null;
11
- //# sourceMappingURL=rule-mark-physical.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"rule-mark-physical.d.ts","sourceRoot":"","sources":["../../../../../src/planner/rules/physical/rule-mark-physical.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAGH,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,0BAA0B,CAAC;AACzD,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,4BAA4B,CAAC;AAI7D,wBAAgB,gBAAgB,CAAC,IAAI,EAAE,QAAQ,EAAE,QAAQ,EAAE,UAAU,GAAG,QAAQ,GAAG,IAAI,CAsBtF"}
@@ -1,29 +0,0 @@
1
- /**
2
- * Rule: Mark Physical (Fallback)
3
- *
4
- * Transforms: Any logical node → Same node (marked as physical)
5
- * Conditions: When no other rule has made the node physical
6
- * Benefits: Ensures all nodes become physical even if no specific transformation is needed
7
- */
8
- import { createLogger } from '../../../common/logger.js';
9
- const log = createLogger('optimizer:rule:mark-physical');
10
- export function ruleMarkPhysical(node, _context) {
11
- // This is a fallback rule - only apply if the node is not already physical
12
- if (node.physical) {
13
- return null; // Already physical
14
- }
15
- // Some node types cannot be made physical directly (like AggregateNode)
16
- // These should have been handled by specific transformation rules
17
- const cannotBePhysical = new Set([
18
- 'Aggregate', // Should be transformed to StreamAggregate/HashAggregate
19
- ]);
20
- if (cannotBePhysical.has(node.nodeType)) {
21
- log('Cannot mark %s as physical - requires transformation', node.nodeType);
22
- return null; // Let the optimizer handle this as an error
23
- }
24
- log('Marking %s as physical (fallback rule)', node.nodeType);
25
- // Return the node - framework will set physical properties via markPhysical()
26
- // Don't hardcode properties, let the framework compute them from children
27
- return node;
28
- }
29
- //# sourceMappingURL=rule-mark-physical.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"rule-mark-physical.js","sourceRoot":"","sources":["../../../../../src/planner/rules/physical/rule-mark-physical.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,EAAE,YAAY,EAAE,MAAM,2BAA2B,CAAC;AAIzD,MAAM,GAAG,GAAG,YAAY,CAAC,8BAA8B,CAAC,CAAC;AAEzD,MAAM,UAAU,gBAAgB,CAAC,IAAc,EAAE,QAAoB;IACpE,2EAA2E;IAC3E,IAAI,IAAI,CAAC,QAAQ,EAAE,CAAC;QACnB,OAAO,IAAI,CAAC,CAAC,mBAAmB;IACjC,CAAC;IAED,wEAAwE;IACxE,kEAAkE;IAClE,MAAM,gBAAgB,GAAG,IAAI,GAAG,CAAC;QAChC,WAAW,EAAE,yDAAyD;KACtE,CAAC,CAAC;IAEH,IAAI,gBAAgB,CAAC,GAAG,CAAC,IAAI,CAAC,QAAQ,CAAC,EAAE,CAAC;QACzC,GAAG,CAAC,sDAAsD,EAAE,IAAI,CAAC,QAAQ,CAAC,CAAC;QAC3E,OAAO,IAAI,CAAC,CAAC,4CAA4C;IAC1D,CAAC;IAED,GAAG,CAAC,wCAAwC,EAAE,IAAI,CAAC,QAAQ,CAAC,CAAC;IAE7D,8EAA8E;IAC9E,0EAA0E;IAC1E,OAAO,IAAI,CAAC;AACb,CAAC"}
@@ -1,11 +0,0 @@
1
- /**
2
- * Rule: Project Optimization
3
- *
4
- * Transforms: ProjectNode → ProjectNode (optimized)
5
- * Conditions: When project node's source needs optimization
6
- * Benefits: Ensures project nodes have optimized sources and proper physical properties
7
- */
8
- import type { PlanNode } from '../../nodes/plan-node.js';
9
- import type { OptContext } from '../../framework/context.js';
10
- export declare function ruleProjectOptimization(node: PlanNode, context: OptContext): PlanNode | null;
11
- //# sourceMappingURL=rule-project-optimization.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"rule-project-optimization.d.ts","sourceRoot":"","sources":["../../../../../src/planner/rules/physical/rule-project-optimization.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAGH,OAAO,KAAK,EAAE,QAAQ,EAAsB,MAAM,0BAA0B,CAAC;AAC7E,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,4BAA4B,CAAC;AAM7D,wBAAgB,uBAAuB,CAAC,IAAI,EAAE,QAAQ,EAAE,OAAO,EAAE,UAAU,GAAG,QAAQ,GAAG,IAAI,CAqC5F"}
@@ -1,44 +0,0 @@
1
- /**
2
- * Rule: Project Optimization
3
- *
4
- * Transforms: ProjectNode → ProjectNode (optimized)
5
- * Conditions: When project node's source needs optimization
6
- * Benefits: Ensures project nodes have optimized sources and proper physical properties
7
- */
8
- import { createLogger } from '../../../common/logger.js';
9
- import { ProjectNode } from '../../nodes/project-node.js';
10
- import { PlanNode as BasePlanNode } from '../../nodes/plan-node.js';
11
- const log = createLogger('optimizer:rule:project-optimization');
12
- export function ruleProjectOptimization(node, context) {
13
- // Guard: only apply to ProjectNode
14
- if (!(node instanceof ProjectNode)) {
15
- return null;
16
- }
17
- log('Optimizing ProjectNode %s', node.id);
18
- // Optimize the source
19
- const optimizedSource = context.optimizer.optimizeNode(node.source, context);
20
- // If source didn't change, just ensure physical properties are set
21
- if (optimizedSource === node.source) {
22
- if (!node.physical) {
23
- BasePlanNode.setDefaultPhysical(node, {
24
- estimatedRows: optimizedSource.estimatedRows,
25
- deterministic: true,
26
- readonly: true
27
- });
28
- log('Set physical properties on existing ProjectNode');
29
- return node;
30
- }
31
- return null; // No change needed
32
- }
33
- // Source changed - create new project node with optimized source
34
- const result = new ProjectNode(node.scope, optimizedSource, node.projections);
35
- // Set physical properties
36
- BasePlanNode.setDefaultPhysical(result, {
37
- estimatedRows: optimizedSource.estimatedRows,
38
- deterministic: true,
39
- readonly: true
40
- });
41
- log('Created optimized ProjectNode with new source');
42
- return result;
43
- }
44
- //# sourceMappingURL=rule-project-optimization.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"rule-project-optimization.js","sourceRoot":"","sources":["../../../../../src/planner/rules/physical/rule-project-optimization.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,EAAE,YAAY,EAAE,MAAM,2BAA2B,CAAC;AAGzD,OAAO,EAAE,WAAW,EAAE,MAAM,6BAA6B,CAAC;AAC1D,OAAO,EAAE,QAAQ,IAAI,YAAY,EAAE,MAAM,0BAA0B,CAAC;AAEpE,MAAM,GAAG,GAAG,YAAY,CAAC,qCAAqC,CAAC,CAAC;AAEhE,MAAM,UAAU,uBAAuB,CAAC,IAAc,EAAE,OAAmB;IAC1E,mCAAmC;IACnC,IAAI,CAAC,CAAC,IAAI,YAAY,WAAW,CAAC,EAAE,CAAC;QACpC,OAAO,IAAI,CAAC;IACb,CAAC;IAED,GAAG,CAAC,2BAA2B,EAAE,IAAI,CAAC,EAAE,CAAC,CAAC;IAE1C,sBAAsB;IACtB,MAAM,eAAe,GAAG,OAAO,CAAC,SAAS,CAAC,YAAY,CAAC,IAAI,CAAC,MAAM,EAAE,OAAO,CAAuB,CAAC;IAEnG,mEAAmE;IACnE,IAAI,eAAe,KAAK,IAAI,CAAC,MAAM,EAAE,CAAC;QACrC,IAAI,CAAC,IAAI,CAAC,QAAQ,EAAE,CAAC;YACpB,YAAY,CAAC,kBAAkB,CAAC,IAAI,EAAE;gBACrC,aAAa,EAAE,eAAe,CAAC,aAAa;gBAC5C,aAAa,EAAE,IAAI;gBACnB,QAAQ,EAAE,IAAI;aACd,CAAC,CAAC;YACH,GAAG,CAAC,iDAAiD,CAAC,CAAC;YACvD,OAAO,IAAI,CAAC;QACb,CAAC;QACD,OAAO,IAAI,CAAC,CAAC,mBAAmB;IACjC,CAAC;IAED,iEAAiE;IACjE,MAAM,MAAM,GAAG,IAAI,WAAW,CAAC,IAAI,CAAC,KAAK,EAAE,eAAe,EAAE,IAAI,CAAC,WAAW,CAAC,CAAC;IAE9E,0BAA0B;IAC1B,YAAY,CAAC,kBAAkB,CAAC,MAAM,EAAE;QACvC,aAAa,EAAE,eAAe,CAAC,aAAa;QAC5C,aAAa,EAAE,IAAI;QACnB,QAAQ,EAAE,IAAI;KACd,CAAC,CAAC;IAEH,GAAG,CAAC,+CAA+C,CAAC,CAAC;IACrD,OAAO,MAAM,CAAC;AACf,CAAC"}
@@ -1,11 +0,0 @@
1
- /**
2
- * Rule: Sort Optimization
3
- *
4
- * Transforms: SortNode → SortNode (optimized)
5
- * Conditions: When sort node needs optimization or source changes
6
- * Benefits: Ensures proper physical properties and optimizes child nodes
7
- */
8
- import type { PlanNode } from '../../nodes/plan-node.js';
9
- import type { OptContext } from '../../framework/context.js';
10
- export declare function ruleSortOptimization(node: PlanNode, context: OptContext): PlanNode | null;
11
- //# sourceMappingURL=rule-sort-optimization.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"rule-sort-optimization.d.ts","sourceRoot":"","sources":["../../../../../src/planner/rules/physical/rule-sort-optimization.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAGH,OAAO,KAAK,EAAE,QAAQ,EAAsB,MAAM,0BAA0B,CAAC;AAC7E,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,4BAA4B,CAAC;AAM7D,wBAAgB,oBAAoB,CAAC,IAAI,EAAE,QAAQ,EAAE,OAAO,EAAE,UAAU,GAAG,QAAQ,GAAG,IAAI,CA6CzF"}
@@ -1,53 +0,0 @@
1
- /**
2
- * Rule: Sort Optimization
3
- *
4
- * Transforms: SortNode → SortNode (optimized)
5
- * Conditions: When sort node needs optimization or source changes
6
- * Benefits: Ensures proper physical properties and optimizes child nodes
7
- */
8
- import { createLogger } from '../../../common/logger.js';
9
- import { SortNode } from '../../nodes/sort.js';
10
- import { PlanNode as BasePlanNode } from '../../nodes/plan-node.js';
11
- const log = createLogger('optimizer:rule:sort-optimization');
12
- export function ruleSortOptimization(node, context) {
13
- // Guard: only apply to SortNode
14
- if (!(node instanceof SortNode)) {
15
- return null;
16
- }
17
- log('Optimizing SortNode %s', node.id);
18
- // Sort is already a physical node in our current design
19
- // Just optimize its source
20
- const optimizedSource = context.optimizer.optimizeNode(node.source, context);
21
- if (optimizedSource === node.source) {
22
- // No change in source, but still need to ensure physical properties are set
23
- if (!node.physical) {
24
- BasePlanNode.setDefaultPhysical(node, {
25
- ordering: node.sortKeys.map((key, idx) => ({
26
- column: idx,
27
- desc: key.direction === 'desc'
28
- })),
29
- estimatedRows: optimizedSource.estimatedRows,
30
- deterministic: true,
31
- readonly: true
32
- });
33
- log('Set physical properties on existing SortNode');
34
- return node;
35
- }
36
- return null; // No change
37
- }
38
- // Source changed - create new sort node
39
- const newSort = new SortNode(node.scope, optimizedSource, node.sortKeys);
40
- // Set physical properties
41
- BasePlanNode.setDefaultPhysical(newSort, {
42
- ordering: node.sortKeys.map((key, idx) => ({
43
- column: idx,
44
- desc: key.direction === 'desc'
45
- })),
46
- estimatedRows: optimizedSource.estimatedRows,
47
- deterministic: true,
48
- readonly: true
49
- });
50
- log('Created optimized SortNode with new source');
51
- return newSort;
52
- }
53
- //# sourceMappingURL=rule-sort-optimization.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"rule-sort-optimization.js","sourceRoot":"","sources":["../../../../../src/planner/rules/physical/rule-sort-optimization.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,EAAE,YAAY,EAAE,MAAM,2BAA2B,CAAC;AAGzD,OAAO,EAAE,QAAQ,EAAE,MAAM,qBAAqB,CAAC;AAC/C,OAAO,EAAE,QAAQ,IAAI,YAAY,EAAE,MAAM,0BAA0B,CAAC;AAEpE,MAAM,GAAG,GAAG,YAAY,CAAC,kCAAkC,CAAC,CAAC;AAE7D,MAAM,UAAU,oBAAoB,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GAAG;YACX,IAAI,EAAE,GAAG,CAAC,SAAS,KAAK,MAAM;SAC9B,CAAC,CAAC;QACH,aAAa,EAAE,eAAe,CAAC,aAAa;QAC5C,aAAa,EAAE,IAAI;QACnB,QAAQ,EAAE,IAAI;KACd,CAAC,CAAC;IAEH,GAAG,CAAC,4CAA4C,CAAC,CAAC;IAClD,OAAO,OAAO,CAAC;AAChB,CAAC"}
@@ -1,11 +0,0 @@
1
- /**
2
- * Rule: Constant Folding
3
- *
4
- * Transforms: Relational nodes with constant scalar expressions → Same node with literals
5
- * Conditions: When relational nodes contain scalar expressions that can be folded
6
- * Benefits: Reduces runtime computation by evaluating constants at plan time
7
- */
8
- import type { PlanNode } from '../../nodes/plan-node.js';
9
- import type { OptContext } from '../../framework/context.js';
10
- export declare function ruleConstantFolding(node: PlanNode, context: OptContext): PlanNode | null;
11
- //# sourceMappingURL=rule-constant-folding.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"rule-constant-folding.d.ts","sourceRoot":"","sources":["../../../../../src/planner/rules/rewrite/rule-constant-folding.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAGH,OAAO,KAAK,EAAE,QAAQ,EAAsB,MAAM,0BAA0B,CAAC;AAC7E,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,4BAA4B,CAAC;AAM7D,wBAAgB,mBAAmB,CAAC,IAAI,EAAE,QAAQ,EAAE,OAAO,EAAE,UAAU,GAAG,QAAQ,GAAG,IAAI,CA4BxF"}
@@ -1,59 +0,0 @@
1
- /**
2
- * Rule: Constant Folding
3
- *
4
- * Transforms: Relational nodes with constant scalar expressions → Same node with literals
5
- * Conditions: When relational nodes contain scalar expressions that can be folded
6
- * Benefits: Reduces runtime computation by evaluating constants at plan time
7
- */
8
- import { createLogger } from '../../../common/logger.js';
9
- import { classifyConstants, applyConstPropagation, createConstFoldingContext } from '../../analysis/const-pass.js';
10
- import { createRuntimeExpressionEvaluator } from '../../analysis/const-evaluator.js';
11
- const log = createLogger('optimizer:rule:constant-folding');
12
- export function ruleConstantFolding(node, context) {
13
- // Only apply to relational nodes that can have scalar expressions
14
- if (node.getType().typeClass !== 'relation') {
15
- return null;
16
- }
17
- const relationalNode = node;
18
- // Skip if this node doesn't have any scalar expressions to fold
19
- // We'll target nodes that commonly have expressions: Project, Filter, etc.
20
- const targetNodeTypes = new Set([
21
- 'Project', // Projection expressions
22
- 'Filter', // Predicate expressions
23
- 'Window', // Window function expressions
24
- 'Aggregate', // Aggregate expressions
25
- 'Sort', // Sort key expressions
26
- 'Values', // Literal values in VALUES clauses
27
- 'Join' // Join condition expressions
28
- ]);
29
- if (!targetNodeTypes.has(node.nodeType)) {
30
- return null;
31
- }
32
- log('Applying constant folding to %s node %s', node.nodeType, node.id);
33
- // Apply constant folding using the full const-pass infrastructure
34
- return applyConstantFoldingToNode(relationalNode, context);
35
- }
36
- /**
37
- * Apply constant folding to a relational node using the const-pass infrastructure
38
- */
39
- function applyConstantFoldingToNode(node, context) {
40
- try {
41
- // Create runtime expression evaluator
42
- const evaluator = createRuntimeExpressionEvaluator(context.db);
43
- const foldingContext = createConstFoldingContext(evaluator);
44
- // Classify constants in the tree
45
- classifyConstants(node, foldingContext);
46
- // Apply propagation
47
- const result = applyConstPropagation(node, foldingContext);
48
- if (result !== node) {
49
- log('Constant folding transformed node %s', node.nodeType);
50
- return result;
51
- }
52
- return null; // No changes
53
- }
54
- catch (error) {
55
- log('Failed to apply constant folding to node %s: %s', node.id, error);
56
- return null;
57
- }
58
- }
59
- //# sourceMappingURL=rule-constant-folding.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"rule-constant-folding.js","sourceRoot":"","sources":["../../../../../src/planner/rules/rewrite/rule-constant-folding.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,EAAE,YAAY,EAAE,MAAM,2BAA2B,CAAC;AAGzD,OAAO,EAAE,iBAAiB,EAAE,qBAAqB,EAAE,yBAAyB,EAAE,MAAM,8BAA8B,CAAC;AACn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AAE,cAAc,CAAC,CAAC;QAE3D,IAAI,MAAM,KAAK,IAAI,EAAE,CAAC;YACrB,GAAG,CAAC,sCAAsC,EAAE,IAAI,CAAC,QAAQ,CAAC,CAAC;YAC3D,OAAO,MAAM,CAAC;QACf,CAAC;QAED,OAAO,IAAI,CAAC,CAAC,aAAa;IAE3B,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QAChB,GAAG,CAAC,iDAAiD,EAAE,IAAI,CAAC,EAAE,EAAE,KAAK,CAAC,CAAC;QACvE,OAAO,IAAI,CAAC;IACb,CAAC;AACF,CAAC"}
@@ -1,14 +0,0 @@
1
- import type { Database } from '../../core/database.js';
2
- import type { TableSchema } from '../../schema/table.js';
3
- import type * as AST from '../../parser/ast.js';
4
- import { TableReferenceNode } from '../nodes/reference.js';
5
- import type { PlanningContext } from '../planning-context.js';
6
- export interface DeferredConstraintSetup {
7
- tableRef: TableReferenceNode;
8
- context: PlanningContext;
9
- }
10
- export declare function createDeferredConstraintSetup(db: Database, table: TableSchema, options?: {
11
- bindOld?: boolean;
12
- }): DeferredConstraintSetup;
13
- export declare function constraintPlanContainsSubquery(_db: Database, _table: TableSchema, expr: AST.Expression): boolean;
14
- //# sourceMappingURL=deferred-constraint.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"deferred-constraint.d.ts","sourceRoot":"","sources":["../../../../src/planner/util/deferred-constraint.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,wBAAwB,CAAC;AACvD,OAAO,KAAK,EAAE,WAAW,EAAuB,MAAM,uBAAuB,CAAC;AAC9E,OAAO,KAAK,KAAK,GAAG,MAAM,qBAAqB,CAAC;AAGhD,OAAO,EAAE,kBAAkB,EAAuB,MAAM,uBAAuB,CAAC;AAGhF,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,wBAAwB,CAAC;AAU9D,MAAM,WAAW,uBAAuB;IACvC,QAAQ,EAAE,kBAAkB,CAAC;IAC7B,OAAO,EAAE,eAAe,CAAC;CACzB;AAED,wBAAgB,6BAA6B,CAAC,EAAE,EAAE,QAAQ,EAAE,KAAK,EAAE,WAAW,EAAE,OAAO,CAAC,EAAE;IAAE,OAAO,CAAC,EAAE,OAAO,CAAA;CAAE,GAAG,uBAAuB,CAwCxI;AAED,wBAAgB,8BAA8B,CAAC,GAAG,EAAE,QAAQ,EAAE,MAAM,EAAE,WAAW,EAAE,IAAI,EAAE,GAAG,CAAC,UAAU,GAAG,OAAO,CAuChH"}
@@ -1,85 +0,0 @@
1
- import { GlobalScope } from '../scopes/global.js';
2
- import { RegisteredScope } from '../scopes/registered.js';
3
- import { TableReferenceNode, ColumnReferenceNode } from '../nodes/reference.js';
4
- import { LiteralNode } from '../nodes/scalar.js';
5
- import { BuildTimeDependencyTracker } from '../planning-context.js';
6
- export function createDeferredConstraintSetup(db, table, options) {
7
- const globalScope = new GlobalScope(db.schemaManager);
8
- const tableRef = new TableReferenceNode(globalScope, table, table.vtabModule, table.vtabAuxData);
9
- const registered = new RegisteredScope(tableRef.scope);
10
- const attrs = tableRef.getAttributes();
11
- const lowerTableName = table.name.toLowerCase();
12
- const makeColumnFactory = (attr, colIndex) => {
13
- return (exp, s) => new ColumnReferenceNode(s, exp, attr.type, attr.id, colIndex);
14
- };
15
- table.columns.forEach((col, colIndex) => {
16
- const attr = attrs[colIndex];
17
- const lowerName = col.name.toLowerCase();
18
- const columnFactory = makeColumnFactory(attr, colIndex);
19
- registered.subscribeFactory(lowerName, columnFactory);
20
- registered.subscribeFactory(`new.${lowerName}`, columnFactory);
21
- registered.subscribeFactory(`${lowerTableName}.${lowerName}`, columnFactory);
22
- if (options?.bindOld) {
23
- const literalNull = { type: 'literal', value: null };
24
- registered.subscribeFactory(`old.${lowerName}`, (exp, s) => new LiteralNode(s, literalNull));
25
- }
26
- });
27
- const context = {
28
- db: db,
29
- schemaManager: db.schemaManager,
30
- parameters: {},
31
- scope: registered,
32
- cteNodes: new Map(),
33
- schemaDependencies: new BuildTimeDependencyTracker(),
34
- schemaCache: new Map(),
35
- cteReferenceCache: new Map(),
36
- outputScopes: new Map()
37
- };
38
- return { tableRef, context };
39
- }
40
- export function constraintPlanContainsSubquery(_db, _table, expr) {
41
- // Check AST directly without building a plan to avoid schema resolution issues
42
- const stack = [expr];
43
- while (stack.length) {
44
- const node = stack.pop();
45
- if (node.type === 'subquery' || node.type === 'exists') {
46
- return true;
47
- }
48
- if (node.type === 'in' && node.subquery) {
49
- return true;
50
- }
51
- // Check for table references in scalar contexts (e.g., correlated subqueries)
52
- if (node.type === 'column' && node.table) {
53
- const colExpr = node;
54
- // If column references a different table, it likely involves a subquery or join
55
- if (colExpr.table && colExpr.table.toLowerCase() !== _table.name.toLowerCase()) {
56
- return true;
57
- }
58
- }
59
- // Recursively check children
60
- if (node.type === 'binary') {
61
- const bin = node;
62
- stack.push(bin.left, bin.right);
63
- }
64
- else if (node.type === 'unary') {
65
- const un = node;
66
- stack.push(un.expr);
67
- }
68
- else if (node.type === 'function') {
69
- const fn = node;
70
- stack.push(...fn.args);
71
- }
72
- else if (node.type === 'case') {
73
- const cs = node;
74
- if (cs.baseExpr)
75
- stack.push(cs.baseExpr);
76
- cs.whenThenClauses.forEach(w => {
77
- stack.push(w.when, w.then);
78
- });
79
- if (cs.elseExpr)
80
- stack.push(cs.elseExpr);
81
- }
82
- }
83
- return false;
84
- }
85
- //# sourceMappingURL=deferred-constraint.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"deferred-constraint.js","sourceRoot":"","sources":["../../../../src/planner/util/deferred-constraint.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,WAAW,EAAE,MAAM,qBAAqB,CAAC;AAClD,OAAO,EAAE,eAAe,EAAE,MAAM,yBAAyB,CAAC;AAC1D,OAAO,EAAE,kBAAkB,EAAE,mBAAmB,EAAE,MAAM,uBAAuB,CAAC;AAEhF,OAAO,EAAE,WAAW,EAA6B,MAAM,oBAAoB,CAAC;AAE5E,OAAO,EAAE,0BAA0B,E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,EAAE,CAAC,QAAQ,CAAC,CAAC;QAC1C,CAAC;IACF,CAAC;IACD,OAAO,KAAK,CAAC;AACd,CAAC"}
@@ -1,5 +0,0 @@
1
- import type { TableReferenceNode } from '../../planner/nodes/reference.js';
2
- import type { Instruction } from '../types.js';
3
- import type { EmissionContext } from '../emission-context.js';
4
- export declare function emitTableReference(plan: TableReferenceNode, ctx: EmissionContext): Instruction;
5
- //# sourceMappingURL=table-reference.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"table-reference.d.ts","sourceRoot":"","sources":["../../../../src/runtime/emit/table-reference.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,kCAAkC,CAAC;AAC3E,OAAO,KAAK,EAAE,WAAW,EAAkB,MAAM,aAAa,CAAC;AAC/D,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,wBAAwB,CAAC;AAU9D,wBAAgB,kBAAkB,CAAC,IAAI,EAAE,kBAAkB,EAAE,GAAG,EAAE,eAAe,GAAG,WAAW,CA+E9F"}
@@ -1,67 +0,0 @@
1
- import { disconnectVTable } from '../utils.js';
2
- import { createValidatedInstruction } from '../emitters.js';
3
- import { QuereusError } from '../../common/errors.js';
4
- import { StatusCode } from '../../common/types.js';
5
- import { buildRowDescriptor } from '../../util/row-descriptor.js';
6
- export function emitTableReference(plan, ctx) {
7
- // Create row descriptor for output attributes
8
- const rowDescriptor = buildRowDescriptor(plan.getAttributes());
9
- async function* run(rctx) {
10
- // Get the table schema and pre-resolved vtab module
11
- const tableSchema = plan.tableSchema;
12
- const vtabModule = plan.vtabModule;
13
- const vtabAuxData = plan.vtabAuxData;
14
- // Create vtab instance using pre-resolved module
15
- if (typeof vtabModule.xConnect !== 'function') {
16
- throw new QuereusError(`Virtual table module '${tableSchema.vtabModuleName}' does not implement xConnect`, StatusCode.MISUSE);
17
- }
18
- const vtabArgs = tableSchema.vtabArgs || {};
19
- const vtab = vtabModule.xConnect(rctx.db, vtabAuxData, tableSchema.vtabModuleName, tableSchema.schemaName, tableSchema.name, vtabArgs);
20
- try {
21
- // Set up context for each row using row descriptor
22
- let row;
23
- rctx.context.set(rowDescriptor, () => row);
24
- // Check if the virtual table supports xQuery
25
- if (typeof vtab.xQuery === 'function') {
26
- // Create a minimal FilterInfo for full table scan
27
- const defaultIndexInfo = {
28
- nConstraint: 0,
29
- aConstraint: [],
30
- nOrderBy: 0,
31
- aOrderBy: [],
32
- aConstraintUsage: [],
33
- idxNum: 0,
34
- idxStr: 'fullscan',
35
- orderByConsumed: false,
36
- estimatedCost: 1000,
37
- estimatedRows: BigInt(100),
38
- idxFlags: 0,
39
- colUsed: 0n,
40
- };
41
- const filterInfo = {
42
- idxNum: 0,
43
- idxStr: 'fullscan',
44
- constraints: [],
45
- args: [],
46
- indexInfoOutput: defaultIndexInfo,
47
- };
48
- // Use xQuery with the filter info
49
- const asyncRowIterable = vtab.xQuery(filterInfo);
50
- for await (row of asyncRowIterable) {
51
- yield row;
52
- }
53
- }
54
- else {
55
- throw new QuereusError(`Virtual table '${tableSchema.name}' does not support xQuery.`, StatusCode.UNSUPPORTED);
56
- }
57
- // Clean up context
58
- rctx.context.delete(rowDescriptor);
59
- }
60
- finally {
61
- // Properly disconnect the VirtualTable instance
62
- await disconnectVTable(rctx, vtab);
63
- }
64
- }
65
- return createValidatedInstruction([], run, ctx, `table_ref(${plan.tableSchema.schemaName}.${plan.tableSchema.name})`);
66
- }
67
- //# sourceMappingURL=table-reference.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"table-reference.js","sourceRoot":"","sources":["../../../../src/runtime/emit/table-reference.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,gBAAgB,EAAE,MAAM,aAAa,CAAC;AAC/C,OAAO,EAAE,0BAA0B,EAAE,MAAM,gBAAgB,CAAC;AAG5D,OAAO,EAAE,YAAY,EAAE,MAAM,wBAAwB,CAAC;AACtD,OAAO,EAAE,UAAU,EAAE,MAAM,uBAAuB,CAAC;AACnD,OA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AAM,EAAE,CAAC;oBACT,MAAM,EAAE,UAAU;oBAClB,eAAe,EAAE,KAAK;oBACtB,aAAa,EAAE,IAAI;oBACnB,aAAa,EAAE,MAAM,CAAC,GAAG,CAAC;oBAC1B,QAAQ,EAAE,CAAC;oBACX,OAAO,EAAE,EAAE;iBACX,CAAC;gBAEF,MAAM,UAAU,GAAe;oBAC9B,MAAM,EAAE,CAAC;oBACT,MAAM,EAAE,UAAU;oBAClB,WAAW,EAAE,EAAE;oBACf,IAAI,EAAE,EAAE;oBACR,eAAe,EAAE,gBAAgB;iBACjC,CAAC;gBAEF,kCAAkC;gBAClC,MAAM,gBAAgB,GAAG,IAAI,CAAC,MAAM,CAAC,UAAU,CAAC,CAAC;gBACjD,IAAI,KAAK,EAAE,GAAG,IAAI,gBAAgB,EAAE,CAAC;oBACpC,MAAM,GAAG,CAAC;gBACX,CAAC;YACF,CAAC;iBAAM,CAAC;gBACP,MAAM,IAAI,YAAY,CAAC,kBAAkB,WAAW,CAAC,IAAI,4BAA4B,EAAE,UAAU,CAAC,WAAW,CAAC,CAAC;YAChH,CAAC;YAED,mBAAmB;YACnB,IAAI,CAAC,OAAO,CAAC,MAAM,CAAC,aAAa,CAAC,CAAC;QACpC,CAAC;gBAAS,CAAC;YACV,gDAAgD;YAChD,MAAM,gBAAgB,CAAC,IAAI,EAAE,IAAI,CAAC,CAAC;QACpC,CAAC;IACF,CAAC;IAED,OAAO,0BAA0B,CAChC,EAAE,EACF,GAAG,EACH,GAAG,EACH,aAAa,IAAI,CAAC,WAAW,CAAC,UAAU,IAAI,IAAI,CAAC,WAAW,CAAC,IAAI,GAAG,CACpE,CAAC;AACH,CAAC"}
@@ -1,5 +0,0 @@
1
- import type { UpdateExecutorNode } from '../../planner/nodes/update-executor-node.js';
2
- import type { Instruction } from '../types.js';
3
- import type { EmissionContext } from '../emission-context.js';
4
- export declare function emitUpdateExecutor(plan: UpdateExecutorNode, ctx: EmissionContext): Instruction;
5
- //# sourceMappingURL=update-executor.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"update-executor.d.ts","sourceRoot":"","sources":["../../../../src/runtime/emit/update-executor.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,6CAA6C,CAAC;AACtF,OAAO,KAAK,EAAE,WAAW,EAAkC,MAAM,aAAa,CAAC;AAK/E,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,wBAAwB,CAAC;AAM9D,wBAAgB,kBAAkB,CAAC,IAAI,EAAE,kBAAkB,EAAE,GAAG,EAAE,eAAe,GAAG,WAAW,CAqD9F"}
@@ -1,54 +0,0 @@
1
- import { emitPlanNode } from '../emitters.js';
2
- import { QuereusError } from '../../common/errors.js';
3
- import { StatusCode } from '../../common/types.js';
4
- import { getVTable } from '../utils.js';
5
- import { createLogger } from '../../common/logger.js';
6
- const log = createLogger('runtime:emit:update-executor');
7
- const errorLog = log.extend('error');
8
- export function emitUpdateExecutor(plan, ctx) {
9
- const tableSchema = plan.table.tableSchema;
10
- // Pre-calculate primary key column indices from schema
11
- const pkColumnIndicesInSchema = tableSchema.primaryKeyDefinition.map(pkColDef => pkColDef.index);
12
- async function executeUpdate(vtab, updatedRow) {
13
- // For UPDATE operations, we need the OLD row's primary key values to identify which row to update
14
- // The NEW row values are what we're updating TO
15
- const oldRowKeyValues = updatedRow.__oldRowKeyValues;
16
- if (!oldRowKeyValues) {
17
- throw new QuereusError(`Missing OLD row key values for UPDATE on '${tableSchema.name}'. Expected from ConstraintCheck.`, StatusCode.INTERNAL);
18
- }
19
- // Extract primary key values from the OLD row (these identify which row to update)
20
- const keyValues = [];
21
- for (const pkColIdx of pkColumnIndicesInSchema) {
22
- if (pkColIdx >= oldRowKeyValues.length) {
23
- throw new QuereusError(`PK column index ${pkColIdx} out of bounds for OLD row length ${oldRowKeyValues.length} in UPDATE on '${tableSchema.name}'.`, StatusCode.INTERNAL);
24
- }
25
- keyValues.push(oldRowKeyValues[pkColIdx]);
26
- }
27
- // Perform the actual update via xUpdate: update the row identified by keyValues to have the values in updatedRow
28
- await vtab.xUpdate('update', updatedRow, keyValues);
29
- }
30
- // Always yield the updated rows - consumers decide if they want them
31
- async function* run(ctx, updatedRowsIterable) {
32
- const vtab = await getVTable(ctx, tableSchema);
33
- try {
34
- for await (const updatedRow of updatedRowsIterable) {
35
- await executeUpdate(vtab, updatedRow);
36
- // Yield the updated row (strip metadata)
37
- const cleanRow = updatedRow.slice();
38
- delete cleanRow.__oldRowKeyValues;
39
- delete cleanRow.__updateRowData;
40
- yield cleanRow;
41
- }
42
- }
43
- finally {
44
- await vtab.xDisconnect().catch((e) => errorLog(`Error during xDisconnect for ${tableSchema.name}: ${e}`));
45
- }
46
- }
47
- const sourceInstruction = emitPlanNode(plan.source, ctx);
48
- return {
49
- params: [sourceInstruction],
50
- run: run,
51
- note: `executeUpdate(${plan.table.tableSchema.name})`
52
- };
53
- }
54
- //# sourceMappingURL=update-executor.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"update-executor.js","sourceRoot":"","sources":["../../../../src/runtime/emit/update-executor.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC;AAC9C,OAAO,EAAE,YAAY,EAAE,MAAM,wBAAwB,CAAC;AACtD,OAAO,EAAE,UAAU,EAA2B,MAAM,uBAAuB,CAAC;AAC5E,OAAO,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AAExC,OAAO,EAAE,YAAY,EAAE,MAAM,wBAAwB,CAAC;AAEtD,MAAM,GAAG,GAAG,YAAY,CAAC,8BAA8B,CAAC,CAAC;AACzD,MAAM,QAAQ,GAAG,GAAG,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC;AAErC,MAAM,UAAU,kBAAkB,CAAC,IAAwB,EAAE,GAAoB;IAChF,MAAM,WAAW,GAAG,IAAI,CAAC,KAAK,CAAC,WAAW,CAAC;IAE3C,uDAAuD;IACvD,MAAM,uBAAuB,GAAG,WAAW,CAAC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