@object-ui/core 3.1.5 → 3.3.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 (110) hide show
  1. package/CHANGELOG.md +18 -0
  2. package/README.md +20 -1
  3. package/dist/actions/ActionRunner.d.ts +9 -0
  4. package/dist/actions/ActionRunner.js +41 -4
  5. package/dist/adapters/ValueDataSource.d.ts +5 -1
  6. package/dist/adapters/ValueDataSource.js +30 -1
  7. package/dist/errors/index.js +2 -3
  8. package/dist/evaluator/ExpressionCache.d.ts +9 -10
  9. package/dist/evaluator/ExpressionCache.js +29 -8
  10. package/dist/evaluator/SafeExpressionParser.d.ts +131 -0
  11. package/dist/evaluator/SafeExpressionParser.js +851 -0
  12. package/dist/evaluator/index.d.ts +1 -0
  13. package/dist/evaluator/index.js +1 -0
  14. package/dist/protocols/DndProtocol.js +2 -14
  15. package/dist/protocols/KeyboardProtocol.js +1 -4
  16. package/dist/protocols/NotificationProtocol.js +3 -13
  17. package/dist/utils/debug.js +2 -1
  18. package/dist/utils/filter-converter.js +25 -5
  19. package/package.json +33 -9
  20. package/.turbo/turbo-build.log +0 -4
  21. package/src/__benchmarks__/core.bench.ts +0 -64
  22. package/src/__tests__/protocols/DndProtocol.test.ts +0 -186
  23. package/src/__tests__/protocols/KeyboardProtocol.test.ts +0 -177
  24. package/src/__tests__/protocols/NotificationProtocol.test.ts +0 -142
  25. package/src/__tests__/protocols/ResponsiveProtocol.test.ts +0 -176
  26. package/src/__tests__/protocols/SharingProtocol.test.ts +0 -188
  27. package/src/actions/ActionEngine.ts +0 -268
  28. package/src/actions/ActionRunner.ts +0 -717
  29. package/src/actions/TransactionManager.ts +0 -521
  30. package/src/actions/UndoManager.ts +0 -215
  31. package/src/actions/__tests__/ActionEngine.test.ts +0 -206
  32. package/src/actions/__tests__/ActionRunner.params.test.ts +0 -134
  33. package/src/actions/__tests__/ActionRunner.test.ts +0 -711
  34. package/src/actions/__tests__/TransactionManager.test.ts +0 -447
  35. package/src/actions/__tests__/UndoManager.test.ts +0 -320
  36. package/src/actions/index.ts +0 -12
  37. package/src/adapters/ApiDataSource.ts +0 -376
  38. package/src/adapters/README.md +0 -180
  39. package/src/adapters/ValueDataSource.ts +0 -438
  40. package/src/adapters/__tests__/ApiDataSource.test.ts +0 -418
  41. package/src/adapters/__tests__/ValueDataSource.test.ts +0 -472
  42. package/src/adapters/__tests__/resolveDataSource.test.ts +0 -144
  43. package/src/adapters/index.ts +0 -15
  44. package/src/adapters/resolveDataSource.ts +0 -79
  45. package/src/builder/__tests__/schema-builder.test.ts +0 -235
  46. package/src/builder/schema-builder.ts +0 -584
  47. package/src/data-scope/DataScopeManager.ts +0 -269
  48. package/src/data-scope/ViewDataProvider.ts +0 -282
  49. package/src/data-scope/__tests__/DataScopeManager.test.ts +0 -211
  50. package/src/data-scope/__tests__/ViewDataProvider.test.ts +0 -270
  51. package/src/data-scope/index.ts +0 -24
  52. package/src/errors/__tests__/errors.test.ts +0 -292
  53. package/src/errors/index.ts +0 -270
  54. package/src/evaluator/ExpressionCache.ts +0 -192
  55. package/src/evaluator/ExpressionContext.ts +0 -118
  56. package/src/evaluator/ExpressionEvaluator.ts +0 -315
  57. package/src/evaluator/FormulaFunctions.ts +0 -398
  58. package/src/evaluator/__tests__/ExpressionCache.test.ts +0 -135
  59. package/src/evaluator/__tests__/ExpressionContext.test.ts +0 -110
  60. package/src/evaluator/__tests__/ExpressionEvaluator.test.ts +0 -131
  61. package/src/evaluator/__tests__/FormulaFunctions.test.ts +0 -447
  62. package/src/evaluator/index.ts +0 -12
  63. package/src/index.ts +0 -38
  64. package/src/protocols/DndProtocol.ts +0 -184
  65. package/src/protocols/KeyboardProtocol.ts +0 -185
  66. package/src/protocols/NotificationProtocol.ts +0 -159
  67. package/src/protocols/ResponsiveProtocol.ts +0 -210
  68. package/src/protocols/SharingProtocol.ts +0 -185
  69. package/src/protocols/index.ts +0 -13
  70. package/src/query/__tests__/query-ast.test.ts +0 -211
  71. package/src/query/__tests__/window-functions.test.ts +0 -275
  72. package/src/query/index.ts +0 -7
  73. package/src/query/query-ast.ts +0 -341
  74. package/src/registry/PluginScopeImpl.ts +0 -259
  75. package/src/registry/PluginSystem.ts +0 -206
  76. package/src/registry/Registry.ts +0 -219
  77. package/src/registry/WidgetRegistry.ts +0 -316
  78. package/src/registry/__tests__/PluginSystem.test.ts +0 -309
  79. package/src/registry/__tests__/Registry.test.ts +0 -293
  80. package/src/registry/__tests__/WidgetRegistry.test.ts +0 -321
  81. package/src/registry/__tests__/plugin-scope-integration.test.ts +0 -283
  82. package/src/theme/ThemeEngine.ts +0 -530
  83. package/src/theme/__tests__/ThemeEngine.test.ts +0 -668
  84. package/src/theme/index.ts +0 -24
  85. package/src/types/index.ts +0 -21
  86. package/src/utils/__tests__/debug-collector.test.ts +0 -102
  87. package/src/utils/__tests__/debug.test.ts +0 -134
  88. package/src/utils/__tests__/expand-fields.test.ts +0 -120
  89. package/src/utils/__tests__/extract-records.test.ts +0 -50
  90. package/src/utils/__tests__/filter-converter.test.ts +0 -118
  91. package/src/utils/__tests__/merge-views-into-objects.test.ts +0 -110
  92. package/src/utils/__tests__/normalize-quick-filter.test.ts +0 -123
  93. package/src/utils/debug-collector.ts +0 -100
  94. package/src/utils/debug.ts +0 -147
  95. package/src/utils/expand-fields.ts +0 -76
  96. package/src/utils/extract-records.ts +0 -33
  97. package/src/utils/filter-converter.ts +0 -133
  98. package/src/utils/merge-views-into-objects.ts +0 -36
  99. package/src/utils/normalize-quick-filter.ts +0 -78
  100. package/src/validation/__tests__/object-validation-engine.test.ts +0 -567
  101. package/src/validation/__tests__/schema-validator.test.ts +0 -118
  102. package/src/validation/__tests__/validation-engine.test.ts +0 -102
  103. package/src/validation/index.ts +0 -10
  104. package/src/validation/schema-validator.ts +0 -344
  105. package/src/validation/validation-engine.ts +0 -528
  106. package/src/validation/validators/index.ts +0 -25
  107. package/src/validation/validators/object-validation-engine.ts +0 -722
  108. package/tsconfig.json +0 -15
  109. package/tsconfig.tsbuildinfo +0 -1
  110. package/vitest.config.ts +0 -2
@@ -1,275 +0,0 @@
1
- /**
2
- * ObjectUI
3
- * Copyright (c) 2024-present ObjectStack Inc.
4
- *
5
- * This source code is licensed under the MIT license found in the
6
- * LICENSE file in the root directory of this source tree.
7
- */
8
-
9
- /**
10
- * @object-ui/core - Window Function Tests
11
- *
12
- * Tests for ObjectStack Spec v2.0.1 window function support
13
- */
14
-
15
- import { describe, it, expect } from 'vitest';
16
- import { QueryASTBuilder } from '../query-ast';
17
- import type { WindowNode, WindowFunction } from '@object-ui/types';
18
-
19
- describe('QueryASTBuilder - Window Functions', () => {
20
- const builder = new QueryASTBuilder();
21
-
22
- describe('buildWindow', () => {
23
- it('should build a simple row_number window function', () => {
24
- const config = {
25
- function: 'row_number' as WindowFunction,
26
- alias: 'row_num',
27
- partitionBy: ['department'],
28
- orderBy: [{ field: 'salary', direction: 'desc' as const }],
29
- };
30
-
31
- // @ts-expect-error - testing private method
32
- const result: WindowNode = builder.buildWindow(config);
33
-
34
- expect(result).toMatchObject({
35
- type: 'window',
36
- function: 'row_number',
37
- alias: 'row_num',
38
- });
39
-
40
- expect(result.partitionBy).toHaveLength(1);
41
- expect(result.partitionBy![0]).toMatchObject({
42
- type: 'field',
43
- name: 'department',
44
- });
45
-
46
- expect(result.orderBy).toHaveLength(1);
47
- expect(result.orderBy![0]).toMatchObject({
48
- field: { type: 'field', name: 'salary' },
49
- direction: 'desc',
50
- });
51
- });
52
-
53
- it('should build a rank window function with multiple partition fields', () => {
54
- const config = {
55
- function: 'rank' as WindowFunction,
56
- alias: 'rank_val',
57
- partitionBy: ['department', 'location'],
58
- orderBy: [
59
- { field: 'performance_score', direction: 'desc' as const },
60
- { field: 'tenure_years', direction: 'desc' as const },
61
- ],
62
- };
63
-
64
- // @ts-expect-error - testing private method
65
- const result: WindowNode = builder.buildWindow(config);
66
-
67
- expect(result).toMatchObject({
68
- type: 'window',
69
- function: 'rank',
70
- alias: 'rank_val',
71
- });
72
-
73
- expect(result.partitionBy).toHaveLength(2);
74
- expect(result.orderBy).toHaveLength(2);
75
- });
76
-
77
- it('should build a lag window function with offset and default value', () => {
78
- const config = {
79
- function: 'lag' as WindowFunction,
80
- field: 'revenue',
81
- alias: 'prev_month_revenue',
82
- partitionBy: ['product_id'],
83
- orderBy: [{ field: 'month', direction: 'asc' as const }],
84
- offset: 1,
85
- defaultValue: 0,
86
- };
87
-
88
- // @ts-expect-error - testing private method
89
- const result: WindowNode = builder.buildWindow(config);
90
-
91
- expect(result).toMatchObject({
92
- type: 'window',
93
- function: 'lag',
94
- alias: 'prev_month_revenue',
95
- offset: 1,
96
- });
97
-
98
- expect(result.field).toMatchObject({
99
- type: 'field',
100
- name: 'revenue',
101
- });
102
-
103
- expect(result.defaultValue).toMatchObject({
104
- type: 'literal',
105
- value: 0,
106
- data_type: 'number',
107
- });
108
- });
109
-
110
- it('should build a lead window function', () => {
111
- const config = {
112
- function: 'lead' as WindowFunction,
113
- field: 'sales',
114
- alias: 'next_day_sales',
115
- orderBy: [{ field: 'date', direction: 'asc' as const }],
116
- offset: 1,
117
- };
118
-
119
- // @ts-expect-error - testing private method
120
- const result: WindowNode = builder.buildWindow(config);
121
-
122
- expect(result).toMatchObject({
123
- type: 'window',
124
- function: 'lead',
125
- alias: 'next_day_sales',
126
- offset: 1,
127
- });
128
- });
129
-
130
- it('should build aggregate window functions (sum, avg, count)', () => {
131
- const sumConfig = {
132
- function: 'sum' as WindowFunction,
133
- field: 'amount',
134
- alias: 'running_total',
135
- orderBy: [{ field: 'date', direction: 'asc' as const }],
136
- frame: {
137
- unit: 'rows' as const,
138
- start: 'unbounded_preceding' as const,
139
- end: 'current_row' as const,
140
- },
141
- };
142
-
143
- // @ts-expect-error - testing private method
144
- const result: WindowNode = builder.buildWindow(sumConfig);
145
-
146
- expect(result).toMatchObject({
147
- type: 'window',
148
- function: 'sum',
149
- alias: 'running_total',
150
- });
151
-
152
- expect(result.field).toMatchObject({
153
- type: 'field',
154
- name: 'amount',
155
- });
156
-
157
- expect(result.frame).toEqual({
158
- unit: 'rows',
159
- start: 'unbounded_preceding',
160
- end: 'current_row',
161
- });
162
- });
163
-
164
- it('should build first_value window function', () => {
165
- const config = {
166
- function: 'first_value' as WindowFunction,
167
- field: 'price',
168
- alias: 'first_price',
169
- partitionBy: ['product_category'],
170
- orderBy: [{ field: 'created_at', direction: 'asc' as const }],
171
- };
172
-
173
- // @ts-expect-error - testing private method
174
- const result: WindowNode = builder.buildWindow(config);
175
-
176
- expect(result).toMatchObject({
177
- type: 'window',
178
- function: 'first_value',
179
- alias: 'first_price',
180
- });
181
- });
182
-
183
- it('should build last_value window function', () => {
184
- const config = {
185
- function: 'last_value' as WindowFunction,
186
- field: 'status',
187
- alias: 'latest_status',
188
- partitionBy: ['customer_id'],
189
- orderBy: [{ field: 'updated_at', direction: 'desc' as const }],
190
- };
191
-
192
- // @ts-expect-error - testing private method
193
- const result: WindowNode = builder.buildWindow(config);
194
-
195
- expect(result).toMatchObject({
196
- type: 'window',
197
- function: 'last_value',
198
- alias: 'latest_status',
199
- });
200
- });
201
-
202
- it('should handle window function without partition by', () => {
203
- const config = {
204
- function: 'row_number' as WindowFunction,
205
- alias: 'global_row_num',
206
- orderBy: [{ field: 'created_at', direction: 'asc' as const }],
207
- };
208
-
209
- // @ts-expect-error - testing private method
210
- const result: WindowNode = builder.buildWindow(config);
211
-
212
- expect(result.partitionBy).toBeUndefined();
213
- expect(result.orderBy).toBeDefined();
214
- });
215
-
216
- it('should handle window function with frame specification', () => {
217
- const config = {
218
- function: 'avg' as WindowFunction,
219
- field: 'temperature',
220
- alias: 'moving_avg_3days',
221
- orderBy: [{ field: 'date', direction: 'asc' as const }],
222
- frame: {
223
- unit: 'rows' as const,
224
- start: { type: 'preceding' as const, offset: 2 },
225
- end: 'current_row' as const,
226
- },
227
- };
228
-
229
- // @ts-expect-error - testing private method
230
- const result: WindowNode = builder.buildWindow(config);
231
-
232
- expect(result.frame).toEqual({
233
- unit: 'rows',
234
- start: { type: 'preceding', offset: 2 },
235
- end: 'current_row',
236
- });
237
- });
238
-
239
- it('should build dense_rank window function', () => {
240
- const config = {
241
- function: 'dense_rank' as WindowFunction,
242
- alias: 'dense_rank_val',
243
- partitionBy: ['team'],
244
- orderBy: [{ field: 'score', direction: 'desc' as const }],
245
- };
246
-
247
- // @ts-expect-error - testing private method
248
- const result: WindowNode = builder.buildWindow(config);
249
-
250
- expect(result).toMatchObject({
251
- type: 'window',
252
- function: 'dense_rank',
253
- alias: 'dense_rank_val',
254
- });
255
- });
256
-
257
- it('should build percent_rank window function', () => {
258
- const config = {
259
- function: 'percent_rank' as WindowFunction,
260
- alias: 'percentile',
261
- partitionBy: ['class'],
262
- orderBy: [{ field: 'exam_score', direction: 'desc' as const }],
263
- };
264
-
265
- // @ts-expect-error - testing private method
266
- const result: WindowNode = builder.buildWindow(config);
267
-
268
- expect(result).toMatchObject({
269
- type: 'window',
270
- function: 'percent_rank',
271
- alias: 'percentile',
272
- });
273
- });
274
- });
275
- });
@@ -1,7 +0,0 @@
1
- /**
2
- * @object-ui/core - Query Module
3
- *
4
- * Phase 3.3: Query AST builder and utilities
5
- */
6
-
7
- export * from './query-ast.js';
@@ -1,341 +0,0 @@
1
- /**
2
- * ObjectUI - Query AST Builder
3
- * Phase 3.3: QuerySchema AST implementation
4
- * ObjectStack Spec v2.0.1: Window functions support
5
- */
6
-
7
- import type {
8
- QueryAST,
9
- QuerySchema,
10
- SelectNode,
11
- FromNode,
12
- WhereNode,
13
- JoinNode,
14
- GroupByNode,
15
- OrderByNode,
16
- LimitNode,
17
- OffsetNode,
18
- AggregateNode,
19
- WindowNode,
20
- WindowFunction,
21
- WindowFrame,
22
- WindowConfig,
23
- FieldNode,
24
- LiteralNode,
25
- OperatorNode,
26
- LogicalOperator,
27
- AdvancedFilterSchema,
28
- AdvancedFilterCondition,
29
- QuerySortConfig,
30
- JoinConfig,
31
- AggregationConfig,
32
- } from '@object-ui/types';
33
-
34
- /**
35
- * Query AST Builder - Converts QuerySchema to AST
36
- */
37
- export class QueryASTBuilder {
38
- build(query: QuerySchema): QueryAST {
39
- const ast: QueryAST = {
40
- select: this.buildSelect(query),
41
- from: this.buildFrom(query),
42
- };
43
-
44
- if (query.filter) {
45
- ast.where = this.buildWhere(query.filter);
46
- }
47
-
48
- if (query.joins && query.joins.length > 0) {
49
- ast.joins = query.joins.map(join => this.buildJoin(join));
50
- }
51
-
52
- if (query.group_by && query.group_by.length > 0) {
53
- ast.group_by = this.buildGroupBy(query.group_by);
54
- }
55
-
56
- if (query.sort && query.sort.length > 0) {
57
- ast.order_by = this.buildOrderBy(query.sort);
58
- }
59
-
60
- if (query.limit !== undefined) {
61
- ast.limit = this.buildLimit(query.limit);
62
- }
63
-
64
- if (query.offset !== undefined) {
65
- ast.offset = this.buildOffset(query.offset);
66
- }
67
-
68
- return ast;
69
- }
70
-
71
- private buildSelect(query: QuerySchema): SelectNode {
72
- const fields: (FieldNode | AggregateNode | WindowNode)[] = [];
73
-
74
- if (query.fields && query.fields.length > 0) {
75
- fields.push(...query.fields.map(field => this.buildField(field)));
76
- } else if (!query.aggregations || query.aggregations.length === 0) {
77
- // Only add '*' if there are no aggregations
78
- fields.push(this.buildField('*'));
79
- }
80
-
81
- if (query.aggregations && query.aggregations.length > 0) {
82
- fields.push(...query.aggregations.map(agg => this.buildAggregation(agg)));
83
- }
84
-
85
- // Add window functions (ObjectStack Spec v2.0.1)
86
- if (query.windows && query.windows.length > 0) {
87
- fields.push(...query.windows.map(win => this.buildWindow(win)));
88
- }
89
-
90
- return {
91
- type: 'select',
92
- fields,
93
- distinct: false,
94
- };
95
- }
96
-
97
- private buildFrom(query: QuerySchema): FromNode {
98
- return {
99
- type: 'from',
100
- table: query.object,
101
- };
102
- }
103
-
104
- private buildWhere(filter: AdvancedFilterSchema): WhereNode {
105
- return {
106
- type: 'where',
107
- condition: this.buildFilterCondition(filter),
108
- };
109
- }
110
-
111
- private buildFilterCondition(filter: AdvancedFilterSchema): OperatorNode {
112
- const operator = filter.operator || 'and';
113
- const operands: (OperatorNode | FieldNode | LiteralNode)[] = [];
114
-
115
- if (filter.conditions && filter.conditions.length > 0) {
116
- operands.push(...filter.conditions.map(cond => this.buildCondition(cond)));
117
- }
118
-
119
- if (filter.groups && filter.groups.length > 0) {
120
- operands.push(...filter.groups.map(group => this.buildFilterCondition(group)));
121
- }
122
-
123
- return {
124
- type: 'operator',
125
- operator: operator as LogicalOperator,
126
- operands,
127
- };
128
- }
129
-
130
- private buildCondition(condition: AdvancedFilterCondition): OperatorNode {
131
- const field = this.buildField(condition.field);
132
-
133
- // Map filter operators to comparison operators
134
- const operatorMap: Record<string, string> = {
135
- 'equals': '=',
136
- 'not_equals': '!=',
137
- 'greater_than': '>',
138
- 'greater_than_or_equal': '>=',
139
- 'less_than': '<',
140
- 'less_than_or_equal': '<=',
141
- 'contains': 'contains',
142
- 'not_contains': 'contains',
143
- 'starts_with': 'starts_with',
144
- 'ends_with': 'ends_with',
145
- 'like': 'like',
146
- 'ilike': 'ilike',
147
- 'in': 'in',
148
- 'not_in': 'not_in',
149
- 'is_null': 'is_null',
150
- 'is_not_null': 'is_not_null',
151
- 'between': 'between',
152
- };
153
-
154
- const operator = operatorMap[condition.operator] || '=';
155
-
156
- // Handle special operators
157
- if (operator === 'between' && condition.values && condition.values.length === 2) {
158
- return {
159
- type: 'operator',
160
- operator: 'between' as any,
161
- operands: [
162
- field,
163
- this.buildLiteral(condition.values[0]),
164
- this.buildLiteral(condition.values[1])
165
- ],
166
- };
167
- }
168
-
169
- if ((operator === 'in' || operator === 'not_in') && condition.values) {
170
- return {
171
- type: 'operator',
172
- operator: operator as any,
173
- operands: [field, ...condition.values.map(v => this.buildLiteral(v))],
174
- };
175
- }
176
-
177
- if (operator === 'is_null' || operator === 'is_not_null') {
178
- return {
179
- type: 'operator',
180
- operator: operator as any,
181
- operands: [field],
182
- };
183
- }
184
-
185
- // Standard binary operator
186
- const value = this.buildLiteral(condition.value);
187
- return {
188
- type: 'operator',
189
- operator: operator as any,
190
- operands: [field, value],
191
- };
192
- }
193
-
194
- private buildJoin(join: JoinConfig): JoinNode {
195
- const onCondition: OperatorNode = {
196
- type: 'operator',
197
- operator: '=',
198
- operands: [
199
- this.buildField(join.on.local_field),
200
- this.buildField(join.on.foreign_field, join.alias || join.object),
201
- ],
202
- };
203
-
204
- return {
205
- type: 'join',
206
- join_type: join.type,
207
- table: join.object,
208
- alias: join.alias,
209
- on: onCondition,
210
- };
211
- }
212
-
213
- private buildGroupBy(fields: string[]): GroupByNode {
214
- return {
215
- type: 'group_by',
216
- fields: fields.map(field => this.buildField(field)),
217
- };
218
- }
219
-
220
- private buildOrderBy(sorts: QuerySortConfig[]): OrderByNode {
221
- return {
222
- type: 'order_by',
223
- fields: sorts.map(sort => ({
224
- field: this.buildField(sort.field),
225
- direction: sort.order,
226
- })),
227
- };
228
- }
229
-
230
- private buildLimit(limit: number): LimitNode {
231
- return {
232
- type: 'limit',
233
- value: limit,
234
- };
235
- }
236
-
237
- private buildOffset(offset: number): OffsetNode {
238
- return {
239
- type: 'offset',
240
- value: offset,
241
- };
242
- }
243
-
244
- private buildField(field: string, table?: string): FieldNode {
245
- const parts = field.split('.');
246
-
247
- if (parts.length === 2) {
248
- return {
249
- type: 'field',
250
- table: parts[0],
251
- name: parts[1],
252
- };
253
- }
254
-
255
- return {
256
- type: 'field',
257
- table,
258
- name: field,
259
- };
260
- }
261
-
262
- private buildLiteral(value: any): LiteralNode {
263
- let dataType: 'string' | 'number' | 'boolean' | 'date' | 'null' = 'string';
264
-
265
- if (value === null || value === undefined) {
266
- dataType = 'null';
267
- } else if (typeof value === 'number') {
268
- dataType = 'number';
269
- } else if (typeof value === 'boolean') {
270
- dataType = 'boolean';
271
- } else if (value instanceof Date) {
272
- dataType = 'date';
273
- }
274
-
275
- return {
276
- type: 'literal',
277
- value,
278
- data_type: dataType,
279
- };
280
- }
281
-
282
- private buildAggregation(agg: AggregationConfig): AggregateNode {
283
- return {
284
- type: 'aggregate',
285
- function: agg.function,
286
- field: agg.field ? this.buildField(agg.field) : undefined,
287
- alias: agg.alias,
288
- distinct: agg.distinct,
289
- };
290
- }
291
-
292
- /**
293
- * Build window function node (ObjectStack Spec v2.0.1)
294
- */
295
- private buildWindow(config: WindowConfig): WindowNode {
296
- const node: WindowNode = {
297
- type: 'window',
298
- function: config.function,
299
- alias: config.alias,
300
- };
301
-
302
- if (config.field) {
303
- node.field = this.buildField(config.field);
304
- }
305
-
306
- if (config.partitionBy && config.partitionBy.length > 0) {
307
- node.partitionBy = config.partitionBy.map(field => this.buildField(field));
308
- }
309
-
310
- if (config.orderBy && config.orderBy.length > 0) {
311
- node.orderBy = config.orderBy.map(sort => ({
312
- field: this.buildField(sort.field),
313
- direction: sort.direction,
314
- }));
315
- }
316
-
317
- if (config.frame) {
318
- node.frame = config.frame;
319
- }
320
-
321
- if (config.offset !== undefined) {
322
- node.offset = config.offset;
323
- }
324
-
325
- if (config.defaultValue !== undefined) {
326
- node.defaultValue = this.buildLiteral(config.defaultValue);
327
- }
328
-
329
- return node;
330
- }
331
-
332
- optimize(ast: QueryAST): QueryAST {
333
- return ast;
334
- }
335
- }
336
-
337
- export const defaultQueryASTBuilder = new QueryASTBuilder();
338
-
339
- export function buildQueryAST(query: QuerySchema): QueryAST {
340
- return defaultQueryASTBuilder.build(query);
341
- }