@object-ui/core 3.3.0 → 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 (99) hide show
  1. package/CHANGELOG.md +6 -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.js +3 -1
  6. package/dist/utils/filter-converter.js +25 -5
  7. package/package.json +32 -8
  8. package/.turbo/turbo-build.log +0 -4
  9. package/src/__benchmarks__/core.bench.ts +0 -64
  10. package/src/__tests__/protocols/DndProtocol.test.ts +0 -186
  11. package/src/__tests__/protocols/KeyboardProtocol.test.ts +0 -177
  12. package/src/__tests__/protocols/NotificationProtocol.test.ts +0 -142
  13. package/src/__tests__/protocols/ResponsiveProtocol.test.ts +0 -176
  14. package/src/__tests__/protocols/SharingProtocol.test.ts +0 -188
  15. package/src/actions/ActionEngine.ts +0 -268
  16. package/src/actions/ActionRunner.ts +0 -717
  17. package/src/actions/TransactionManager.ts +0 -521
  18. package/src/actions/UndoManager.ts +0 -215
  19. package/src/actions/__tests__/ActionEngine.test.ts +0 -206
  20. package/src/actions/__tests__/ActionRunner.params.test.ts +0 -134
  21. package/src/actions/__tests__/ActionRunner.test.ts +0 -711
  22. package/src/actions/__tests__/TransactionManager.test.ts +0 -447
  23. package/src/actions/__tests__/UndoManager.test.ts +0 -320
  24. package/src/actions/index.ts +0 -12
  25. package/src/adapters/ApiDataSource.ts +0 -376
  26. package/src/adapters/README.md +0 -180
  27. package/src/adapters/ValueDataSource.ts +0 -459
  28. package/src/adapters/__tests__/ApiDataSource.test.ts +0 -418
  29. package/src/adapters/__tests__/ValueDataSource.test.ts +0 -571
  30. package/src/adapters/__tests__/resolveDataSource.test.ts +0 -144
  31. package/src/adapters/index.ts +0 -15
  32. package/src/adapters/resolveDataSource.ts +0 -79
  33. package/src/builder/__tests__/schema-builder.test.ts +0 -235
  34. package/src/builder/schema-builder.ts +0 -584
  35. package/src/data-scope/DataScopeManager.ts +0 -269
  36. package/src/data-scope/ViewDataProvider.ts +0 -282
  37. package/src/data-scope/__tests__/DataScopeManager.test.ts +0 -211
  38. package/src/data-scope/__tests__/ViewDataProvider.test.ts +0 -270
  39. package/src/data-scope/index.ts +0 -24
  40. package/src/errors/__tests__/errors.test.ts +0 -292
  41. package/src/errors/index.ts +0 -269
  42. package/src/evaluator/ExpressionCache.ts +0 -206
  43. package/src/evaluator/ExpressionContext.ts +0 -118
  44. package/src/evaluator/ExpressionEvaluator.ts +0 -315
  45. package/src/evaluator/FormulaFunctions.ts +0 -398
  46. package/src/evaluator/SafeExpressionParser.ts +0 -893
  47. package/src/evaluator/__tests__/ExpressionCache.test.ts +0 -135
  48. package/src/evaluator/__tests__/ExpressionContext.test.ts +0 -110
  49. package/src/evaluator/__tests__/ExpressionEvaluator.test.ts +0 -558
  50. package/src/evaluator/__tests__/FormulaFunctions.test.ts +0 -447
  51. package/src/evaluator/index.ts +0 -13
  52. package/src/index.ts +0 -38
  53. package/src/protocols/DndProtocol.ts +0 -168
  54. package/src/protocols/KeyboardProtocol.ts +0 -181
  55. package/src/protocols/NotificationProtocol.ts +0 -150
  56. package/src/protocols/ResponsiveProtocol.ts +0 -210
  57. package/src/protocols/SharingProtocol.ts +0 -185
  58. package/src/protocols/index.ts +0 -13
  59. package/src/query/__tests__/query-ast.test.ts +0 -211
  60. package/src/query/__tests__/window-functions.test.ts +0 -275
  61. package/src/query/index.ts +0 -7
  62. package/src/query/query-ast.ts +0 -341
  63. package/src/registry/PluginScopeImpl.ts +0 -259
  64. package/src/registry/PluginSystem.ts +0 -206
  65. package/src/registry/Registry.ts +0 -219
  66. package/src/registry/WidgetRegistry.ts +0 -316
  67. package/src/registry/__tests__/PluginSystem.test.ts +0 -309
  68. package/src/registry/__tests__/Registry.test.ts +0 -293
  69. package/src/registry/__tests__/WidgetRegistry.test.ts +0 -321
  70. package/src/registry/__tests__/plugin-scope-integration.test.ts +0 -283
  71. package/src/theme/ThemeEngine.ts +0 -530
  72. package/src/theme/__tests__/ThemeEngine.test.ts +0 -668
  73. package/src/theme/index.ts +0 -24
  74. package/src/types/index.ts +0 -21
  75. package/src/utils/__tests__/debug-collector.test.ts +0 -102
  76. package/src/utils/__tests__/debug.test.ts +0 -134
  77. package/src/utils/__tests__/expand-fields.test.ts +0 -120
  78. package/src/utils/__tests__/extract-records.test.ts +0 -50
  79. package/src/utils/__tests__/filter-converter.test.ts +0 -118
  80. package/src/utils/__tests__/merge-views-into-objects.test.ts +0 -110
  81. package/src/utils/__tests__/normalize-quick-filter.test.ts +0 -123
  82. package/src/utils/debug-collector.ts +0 -100
  83. package/src/utils/debug.ts +0 -148
  84. package/src/utils/expand-fields.ts +0 -76
  85. package/src/utils/extract-records.ts +0 -33
  86. package/src/utils/filter-converter.ts +0 -133
  87. package/src/utils/merge-views-into-objects.ts +0 -36
  88. package/src/utils/normalize-quick-filter.ts +0 -78
  89. package/src/validation/__tests__/object-validation-engine.test.ts +0 -567
  90. package/src/validation/__tests__/schema-validator.test.ts +0 -118
  91. package/src/validation/__tests__/validation-engine.test.ts +0 -102
  92. package/src/validation/index.ts +0 -10
  93. package/src/validation/schema-validator.ts +0 -344
  94. package/src/validation/validation-engine.ts +0 -528
  95. package/src/validation/validators/index.ts +0 -25
  96. package/src/validation/validators/object-validation-engine.ts +0 -722
  97. package/tsconfig.json +0 -15
  98. package/tsconfig.tsbuildinfo +0 -1
  99. package/vitest.config.ts +0 -2
@@ -1,185 +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 - Sharing Protocol Bridge
11
- *
12
- * Converts spec-aligned SharingConfig and EmbedConfig schemas into
13
- * runtime-usable configurations. Provides embed code generation and
14
- * configuration validation.
15
- *
16
- * @module protocols/SharingProtocol
17
- * @packageDocumentation
18
- */
19
-
20
- import type { SharingConfig, EmbedConfig } from '@object-ui/types';
21
-
22
- // ============================================================================
23
- // Resolved Types
24
- // ============================================================================
25
-
26
- /** Fully resolved sharing configuration. */
27
- export interface ResolvedSharingConfig {
28
- enabled: boolean;
29
- publicLink?: string;
30
- password?: string;
31
- allowedDomains: string[];
32
- expiresAt?: string;
33
- allowAnonymous: boolean;
34
- }
35
-
36
- /** Fully resolved embed configuration. */
37
- export interface ResolvedEmbedConfig {
38
- enabled: boolean;
39
- allowedOrigins: string[];
40
- width: string;
41
- height: string;
42
- showHeader: boolean;
43
- showNavigation: boolean;
44
- responsive: boolean;
45
- }
46
-
47
- /** Validation result for sharing configuration. */
48
- export interface SharingValidationResult {
49
- valid: boolean;
50
- errors: string[];
51
- }
52
-
53
- // ============================================================================
54
- // Sharing Config Resolution
55
- // ============================================================================
56
-
57
- /**
58
- * Resolve a sharing configuration by applying spec defaults.
59
- *
60
- * @param config - Partial SharingConfig from the spec
61
- * @returns Fully resolved sharing configuration
62
- */
63
- export function resolveSharingConfig(config: Partial<SharingConfig>): ResolvedSharingConfig {
64
- return {
65
- enabled: config.enabled ?? false,
66
- publicLink: config.publicLink,
67
- password: config.password,
68
- allowedDomains: config.allowedDomains ?? [],
69
- expiresAt: config.expiresAt,
70
- allowAnonymous: config.allowAnonymous ?? false,
71
- };
72
- }
73
-
74
- // ============================================================================
75
- // Embed Config Resolution
76
- // ============================================================================
77
-
78
- /**
79
- * Resolve an embed configuration by applying spec defaults.
80
- *
81
- * @param config - Partial EmbedConfig from the spec
82
- * @returns Fully resolved embed configuration
83
- */
84
- export function resolveEmbedConfig(config: Partial<EmbedConfig>): ResolvedEmbedConfig {
85
- return {
86
- enabled: config.enabled ?? false,
87
- allowedOrigins: config.allowedOrigins ?? [],
88
- width: config.width ?? '100%',
89
- height: config.height ?? '600px',
90
- showHeader: config.showHeader ?? true,
91
- showNavigation: config.showNavigation ?? false,
92
- responsive: config.responsive ?? true,
93
- };
94
- }
95
-
96
- // ============================================================================
97
- // Embed Code Generation
98
- // ============================================================================
99
-
100
- /**
101
- * Generate an HTML iframe embed snippet from an EmbedConfig and URL.
102
- *
103
- * @param config - EmbedConfig from the spec
104
- * @param url - The URL to embed
105
- * @returns HTML string containing an iframe element
106
- */
107
- export function generateEmbedCode(config: EmbedConfig, url: string): string {
108
- const resolved = resolveEmbedConfig(config);
109
- const sanitizedUrl = escapeHtmlAttr(url);
110
- const title = 'Embedded content';
111
-
112
- const parts = [
113
- `<iframe`,
114
- ` src="${sanitizedUrl}"`,
115
- ` width="${escapeHtmlAttr(resolved.width)}"`,
116
- ` height="${escapeHtmlAttr(resolved.height)}"`,
117
- ` title="${title}"`,
118
- ` frameborder="0"`,
119
- ` allowfullscreen`,
120
- ];
121
-
122
- if (resolved.responsive) {
123
- parts.push(` style="max-width: 100%; border: none;"`);
124
- } else {
125
- parts.push(` style="border: none;"`);
126
- }
127
-
128
- parts.push(`></iframe>`);
129
-
130
- return parts.join('\n');
131
- }
132
-
133
- /**
134
- * Escape a string for safe use in an HTML attribute value.
135
- */
136
- function escapeHtmlAttr(value: string): string {
137
- return value
138
- .replace(/&/g, '&amp;')
139
- .replace(/"/g, '&quot;')
140
- .replace(/</g, '&lt;')
141
- .replace(/>/g, '&gt;');
142
- }
143
-
144
- // ============================================================================
145
- // Sharing Config Validation
146
- // ============================================================================
147
-
148
- /**
149
- * Validate a sharing configuration and return any errors.
150
- *
151
- * @param config - SharingConfig to validate
152
- * @returns Validation result with `valid` flag and error messages
153
- */
154
- export function validateSharingConfig(config: SharingConfig): SharingValidationResult {
155
- const errors: string[] = [];
156
-
157
- if (config.enabled && !config.publicLink) {
158
- errors.push('A public link is required when sharing is enabled.');
159
- }
160
-
161
- if (config.expiresAt) {
162
- const expiryDate = new Date(config.expiresAt);
163
- if (isNaN(expiryDate.getTime())) {
164
- errors.push('expiresAt must be a valid ISO 8601 date string.');
165
- }
166
- }
167
-
168
- if (config.allowedDomains) {
169
- for (const domain of config.allowedDomains) {
170
- if (!domain || domain.trim().length === 0) {
171
- errors.push('allowedDomains contains an empty or whitespace-only entry.');
172
- break;
173
- }
174
- }
175
- }
176
-
177
- if (config.password !== undefined && config.password.length === 0) {
178
- errors.push('Password must not be an empty string when provided.');
179
- }
180
-
181
- return {
182
- valid: errors.length === 0,
183
- errors,
184
- };
185
- }
@@ -1,13 +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
- export * from './DndProtocol.js';
10
- export * from './KeyboardProtocol.js';
11
- export * from './NotificationProtocol.js';
12
- export * from './ResponsiveProtocol.js';
13
- export * from './SharingProtocol.js';
@@ -1,211 +0,0 @@
1
- /**
2
- * @object-ui/core - Query AST Builder Tests
3
- */
4
-
5
- import { describe, it, expect } from 'vitest';
6
- import { QueryASTBuilder } from '../query-ast';
7
- import type { QuerySchema } from '@object-ui/types';
8
-
9
- describe('QueryASTBuilder', () => {
10
- const builder = new QueryASTBuilder();
11
-
12
- describe('Basic Query Building', () => {
13
- it('should build simple SELECT query', () => {
14
- const query: QuerySchema = {
15
- object: 'users',
16
- fields: ['id', 'name', 'email'],
17
- };
18
-
19
- const ast = builder.build(query);
20
-
21
- expect(ast.select.type).toBe('select');
22
- expect(ast.select.fields).toHaveLength(3);
23
- expect(ast.from.table).toBe('users');
24
- });
25
-
26
- it('should build SELECT * when no fields specified', () => {
27
- const query: QuerySchema = {
28
- object: 'users',
29
- };
30
-
31
- const ast = builder.build(query);
32
-
33
- expect(ast.select.fields).toHaveLength(1);
34
- expect(ast.select.fields[0]).toMatchObject({
35
- type: 'field',
36
- name: '*',
37
- });
38
- });
39
-
40
- it('should build query with WHERE clause', () => {
41
- const query: QuerySchema = {
42
- object: 'users',
43
- fields: ['id', 'name'],
44
- filter: {
45
- conditions: [
46
- {
47
- field: 'status',
48
- operator: 'equals',
49
- value: 'active',
50
- },
51
- ],
52
- },
53
- };
54
-
55
- const ast = builder.build(query);
56
-
57
- expect(ast.where).toBeDefined();
58
- expect(ast.where?.type).toBe('where');
59
- expect(ast.where?.condition.type).toBe('operator');
60
- });
61
-
62
- it('should build query with ORDER BY', () => {
63
- const query: QuerySchema = {
64
- object: 'users',
65
- fields: ['id', 'name'],
66
- sort: [
67
- { field: 'created_at', order: 'desc' },
68
- { field: 'name', order: 'asc' },
69
- ],
70
- };
71
-
72
- const ast = builder.build(query);
73
-
74
- expect(ast.order_by).toBeDefined();
75
- expect(ast.order_by?.fields).toHaveLength(2);
76
- expect(ast.order_by?.fields[0].direction).toBe('desc');
77
- });
78
-
79
- it('should build query with LIMIT and OFFSET', () => {
80
- const query: QuerySchema = {
81
- object: 'users',
82
- fields: ['id', 'name'],
83
- limit: 10,
84
- offset: 20,
85
- };
86
-
87
- const ast = builder.build(query);
88
-
89
- expect(ast.limit).toBeDefined();
90
- expect(ast.limit?.value).toBe(10);
91
- expect(ast.offset).toBeDefined();
92
- expect(ast.offset?.value).toBe(20);
93
- });
94
- });
95
-
96
- describe('Advanced Query Building', () => {
97
- it('should build query with JOIN', () => {
98
- const query: QuerySchema = {
99
- object: 'users',
100
- fields: ['id', 'name', 'orders.total'],
101
- joins: [
102
- {
103
- type: 'left',
104
- object: 'orders',
105
- on: {
106
- local_field: 'id',
107
- foreign_field: 'user_id',
108
- },
109
- },
110
- ],
111
- };
112
-
113
- const ast = builder.build(query);
114
-
115
- expect(ast.joins).toBeDefined();
116
- expect(ast.joins).toHaveLength(1);
117
- expect(ast.joins?.[0].join_type).toBe('left');
118
- expect(ast.joins?.[0].table).toBe('orders');
119
- });
120
-
121
- it('should build query with aggregations', () => {
122
- const query: QuerySchema = {
123
- object: 'orders',
124
- aggregations: [
125
- {
126
- function: 'count',
127
- alias: 'total_count',
128
- },
129
- {
130
- function: 'sum',
131
- field: 'amount',
132
- alias: 'total_amount',
133
- },
134
- ],
135
- };
136
-
137
- const ast = builder.build(query);
138
-
139
- expect(ast.select.fields).toHaveLength(2);
140
- expect(ast.select.fields[0]).toMatchObject({
141
- type: 'aggregate',
142
- function: 'count',
143
- alias: 'total_count',
144
- });
145
- });
146
-
147
- it('should build query with GROUP BY', () => {
148
- const query: QuerySchema = {
149
- object: 'orders',
150
- fields: ['user_id'],
151
- group_by: ['user_id'],
152
- aggregations: [
153
- {
154
- function: 'count',
155
- alias: 'order_count',
156
- },
157
- ],
158
- };
159
-
160
- const ast = builder.build(query);
161
-
162
- expect(ast.group_by).toBeDefined();
163
- expect(ast.group_by?.fields).toHaveLength(1);
164
- expect(ast.group_by?.fields[0]).toMatchObject({
165
- type: 'field',
166
- name: 'user_id',
167
- });
168
- });
169
- });
170
-
171
- describe('Complex Filters', () => {
172
- it('should build query with nested AND/OR filters', () => {
173
- const query: QuerySchema = {
174
- object: 'users',
175
- filter: {
176
- operator: 'and',
177
- conditions: [
178
- {
179
- field: 'status',
180
- operator: 'equals',
181
- value: 'active',
182
- },
183
- ],
184
- groups: [
185
- {
186
- operator: 'or',
187
- conditions: [
188
- {
189
- field: 'role',
190
- operator: 'equals',
191
- value: 'admin',
192
- },
193
- {
194
- field: 'role',
195
- operator: 'equals',
196
- value: 'moderator',
197
- },
198
- ],
199
- },
200
- ],
201
- },
202
- };
203
-
204
- const ast = builder.build(query);
205
-
206
- expect(ast.where).toBeDefined();
207
- expect(ast.where?.condition.operator).toBe('and');
208
- expect(ast.where?.condition.operands.length).toBeGreaterThan(0);
209
- });
210
- });
211
- });
@@ -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';