@visactor/vbi 0.4.15 → 0.4.16

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 (44) hide show
  1. package/dist/builder/{sub-builders → features}/chart-type/chart-type-builder.d.ts +1 -1
  2. package/dist/builder/{sub-builders → features}/dimensions/dim-builder.d.ts +1 -1
  3. package/dist/builder/{sub-builders → features}/dimensions/dim-node-builder.d.ts +1 -1
  4. package/dist/builder/{sub-builders/havingFilters → features/havingFilter}/having-builder.d.ts +13 -13
  5. package/dist/builder/{sub-builders/havingFilters → features/havingFilter}/having-group-builder.d.ts +4 -3
  6. package/dist/builder/{sub-builders/havingFilters → features/havingFilter}/having-node-builder.d.ts +2 -2
  7. package/dist/builder/features/havingFilter/having-utils.d.ts +9 -0
  8. package/dist/builder/features/havingFilter/index.d.ts +3 -0
  9. package/dist/builder/features/index.d.ts +9 -0
  10. package/dist/builder/features/limit/index.d.ts +1 -0
  11. package/dist/builder/features/limit/limit-builder.d.ts +31 -0
  12. package/dist/builder/features/locale/index.d.ts +1 -0
  13. package/dist/builder/features/locale/locale-builder.d.ts +31 -0
  14. package/dist/builder/{sub-builders → features}/measures/mea-builder.d.ts +1 -1
  15. package/dist/builder/{sub-builders → features}/measures/mea-node-builder.d.ts +1 -1
  16. package/dist/builder/features/theme/index.d.ts +1 -0
  17. package/dist/builder/features/theme/theme-builder.d.ts +31 -0
  18. package/dist/builder/features/undo-manager/index.d.ts +1 -0
  19. package/dist/builder/{sub-builders/whereFilters → features/whereFilter}/index.d.ts +1 -1
  20. package/dist/builder/{sub-builders/whereFilters → features/whereFilter}/where-builder.d.ts +11 -11
  21. package/dist/builder/{sub-builders/whereFilters → features/whereFilter}/where-group-builder.d.ts +2 -1
  22. package/dist/builder/{sub-builders/whereFilters → features/whereFilter}/where-node-builder.d.ts +6 -1
  23. package/dist/builder/features/whereFilter/where-utils.d.ts +9 -0
  24. package/dist/builder/index.d.ts +1 -2
  25. package/dist/builder/vbi-builder.d.ts +6 -11
  26. package/dist/builder/vbi.d.ts +2 -2
  27. package/dist/index.cjs +521 -334
  28. package/dist/index.d.ts +1 -1
  29. package/dist/index.js +498 -329
  30. package/dist/types/builder/VBIInterface.d.ts +6 -5
  31. package/dist/types/dsl/{havingFilters → havingFilter}/having.d.ts +10 -6
  32. package/dist/types/dsl/index.d.ts +4 -5
  33. package/dist/types/dsl/measures/measures.d.ts +16 -2
  34. package/dist/types/dsl/vbi/vbi.d.ts +40 -4
  35. package/dist/types/dsl/{whereFilters → whereFilter}/filters.d.ts +10 -6
  36. package/dist/utils/filter-guards.d.ts +5 -0
  37. package/dist/utils/index.d.ts +1 -0
  38. package/package.json +5 -5
  39. package/dist/builder/sub-builders/havingFilters/index.d.ts +0 -3
  40. package/dist/builder/sub-builders/index.d.ts +0 -5
  41. /package/dist/builder/{sub-builders → features}/chart-type/index.d.ts +0 -0
  42. /package/dist/builder/{sub-builders → features}/dimensions/index.d.ts +0 -0
  43. /package/dist/builder/{sub-builders → features}/measures/index.d.ts +0 -0
  44. /package/dist/builder/{undo-manager.d.ts → features/undo-manager/undo-manager.d.ts} +0 -0
package/dist/index.cjs CHANGED
@@ -24,22 +24,28 @@ var __webpack_require__ = {};
24
24
  var __webpack_exports__ = {};
25
25
  __webpack_require__.r(__webpack_exports__);
26
26
  __webpack_require__.d(__webpack_exports__, {
27
- preorderTraverse: ()=>vseed_namespaceObject.preorderTraverse,
27
+ HavingFilterBuilder: ()=>HavingFilterBuilder,
28
+ WhereFilterBuilder: ()=>WhereFilterBuilder,
28
29
  isVBIHavingGroup: ()=>isVBIHavingGroup,
30
+ VBIBuilder: ()=>VBIBuilder,
31
+ VBI: ()=>VBI,
32
+ isVBIHavingFilter: ()=>isVBIHavingFilter,
33
+ findTreeNodesBy: ()=>vseed_namespaceObject.findTreeNodesBy,
34
+ ThemeBuilder: ()=>ThemeBuilder,
35
+ id: ()=>id_id,
29
36
  MeasuresBuilder: ()=>MeasuresBuilder,
37
+ LimitBuilder: ()=>LimitBuilder,
30
38
  DimensionsBuilder: ()=>DimensionsBuilder,
31
- VBIBuilder: ()=>VBIBuilder,
32
39
  ChartTypeBuilder: ()=>ChartTypeBuilder,
33
40
  isVBIFilter: ()=>isVBIFilter,
34
- VBI: ()=>VBI,
35
41
  isVBIWhereGroup: ()=>isVBIWhereGroup,
36
- isVBIHavingFilter: ()=>isVBIHavingFilter,
42
+ preorderTraverse: ()=>vseed_namespaceObject.preorderTraverse,
37
43
  buildVQuery: ()=>buildVQuery,
38
- findTreeNodesBy: ()=>vseed_namespaceObject.findTreeNodesBy,
39
- id: ()=>id_id
44
+ LocaleBuilder: ()=>LocaleBuilder,
45
+ UndoManager: ()=>UndoManager
40
46
  });
41
47
  const external_yjs_namespaceObject = require("yjs");
42
- class DimensionNodeBuilder {
48
+ class MeasureNodeBuilder {
43
49
  yMap;
44
50
  constructor(yMap){
45
51
  this.yMap = yMap;
@@ -51,71 +57,83 @@ class DimensionNodeBuilder {
51
57
  this.yMap.set('alias', alias);
52
58
  return this;
53
59
  }
54
- toJson() {
60
+ setEncoding(encoding) {
61
+ this.yMap.set('encoding', encoding);
62
+ return this;
63
+ }
64
+ setAggregate(aggregate) {
65
+ this.yMap.set('aggregate', aggregate);
66
+ return this;
67
+ }
68
+ toJSON() {
55
69
  return this.yMap.toJSON();
56
70
  }
57
71
  }
58
- class DimensionsBuilder {
72
+ class MeasuresBuilder {
59
73
  dsl;
60
74
  constructor(_doc, dsl){
61
75
  this.dsl = dsl;
62
76
  }
63
77
  add(field, callback) {
64
- const dimension = {
78
+ const measure = {
65
79
  alias: field,
66
- field
80
+ field,
81
+ encoding: 'yAxis',
82
+ aggregate: {
83
+ func: 'sum'
84
+ }
67
85
  };
68
86
  const yMap = new external_yjs_namespaceObject.Map();
69
- for (const [key, value] of Object.entries(dimension))yMap.set(key, value);
70
- this.dsl.get('dimensions').push([
87
+ for (const [key, value] of Object.entries(measure))yMap.set(key, value);
88
+ this.dsl.get('measures').push([
71
89
  yMap
72
90
  ]);
73
- const node = new DimensionNodeBuilder(yMap);
91
+ const node = new MeasureNodeBuilder(yMap);
74
92
  callback(node);
75
93
  return this;
76
94
  }
77
95
  remove(field) {
78
- const dimensions = this.dsl.get('dimensions');
79
- const index = dimensions.toArray().findIndex((item)=>item.get('field') === field);
80
- if (-1 !== index) this.dsl.get('dimensions').delete(index, 1);
96
+ const measures = this.dsl.get('measures');
97
+ const index = measures.toArray().findIndex((item)=>item.get('field') === field);
98
+ if (-1 !== index) this.dsl.get('measures').delete(index, 1);
81
99
  return this;
82
100
  }
83
101
  update(field, callback) {
84
- const dimensions = this.dsl.get('dimensions');
85
- const index = dimensions.toArray().findIndex((item)=>item.get('field') === field);
86
- if (-1 === index) throw new Error(`Dimension with field "${field}" not found`);
87
- const dimensionYMap = dimensions.get(index);
88
- const node = new DimensionNodeBuilder(dimensionYMap);
102
+ const measures = this.dsl.get('measures');
103
+ const index = measures.toArray().findIndex((item)=>item.get('field') === field);
104
+ if (-1 === index) throw new Error(`Measure with field "${field}" not found`);
105
+ const measureYMap = measures.get(index);
106
+ const node = new MeasureNodeBuilder(measureYMap);
89
107
  callback(node);
90
108
  return this;
91
109
  }
92
110
  find(field) {
93
- const dimensions = this.dsl.get('dimensions');
94
- const index = dimensions.toArray().findIndex((item)=>item.get('field') === field);
111
+ const measures = this.dsl.get('measures');
112
+ const index = measures.toArray().findIndex((item)=>item.get('field') === field);
95
113
  if (-1 === index) return;
96
- return new DimensionNodeBuilder(dimensions.get(index));
114
+ return new MeasureNodeBuilder(measures.get(index));
97
115
  }
98
116
  findAll() {
99
- const dimensions = this.dsl.get('dimensions');
100
- return dimensions.toArray().map((yMap)=>new DimensionNodeBuilder(yMap));
117
+ const measures = this.dsl.get('measures');
118
+ return measures.toArray().map((yMap)=>new MeasureNodeBuilder(yMap));
101
119
  }
102
- toJson() {
103
- return this.dsl.get('dimensions').toJSON();
120
+ toJSON() {
121
+ return this.dsl.get('measures').toJSON();
104
122
  }
105
123
  observe(callback) {
106
- this.dsl.get('dimensions').observe(callback);
124
+ this.dsl.get('measures').observe(callback);
107
125
  return ()=>{
108
- this.dsl.get('dimensions').unobserve(callback);
126
+ this.dsl.get('measures').unobserve(callback);
109
127
  };
110
128
  }
111
- static isDimensionNode(node) {
112
- return 'alias' in node && !('children' in node);
129
+ static isMeasureNode(node) {
130
+ return 'encoding' in node || 'aggregate' in node;
113
131
  }
114
- static isDimensionGroup(node) {
132
+ static isMeasureGroup(node) {
115
133
  return 'children' in node;
116
134
  }
117
135
  }
118
- class MeasureNodeBuilder {
136
+ class DimensionNodeBuilder {
119
137
  yMap;
120
138
  constructor(yMap){
121
139
  this.yMap = yMap;
@@ -127,88 +145,163 @@ class MeasureNodeBuilder {
127
145
  this.yMap.set('alias', alias);
128
146
  return this;
129
147
  }
130
- setEncoding(encoding) {
131
- this.yMap.set('encoding', encoding);
132
- return this;
133
- }
134
- setAggregate(aggregate) {
135
- this.yMap.set('aggregate', aggregate);
136
- return this;
137
- }
138
- toJson() {
148
+ toJSON() {
139
149
  return this.yMap.toJSON();
140
150
  }
141
151
  }
142
- class MeasuresBuilder {
152
+ class DimensionsBuilder {
143
153
  dsl;
144
154
  constructor(_doc, dsl){
145
155
  this.dsl = dsl;
146
156
  }
147
157
  add(field, callback) {
148
- const measure = {
158
+ const dimension = {
149
159
  alias: field,
150
- field,
151
- encoding: 'yAxis',
152
- aggregate: {
153
- func: 'sum'
154
- }
160
+ field
155
161
  };
156
162
  const yMap = new external_yjs_namespaceObject.Map();
157
- for (const [key, value] of Object.entries(measure))yMap.set(key, value);
158
- this.dsl.get('measures').push([
163
+ for (const [key, value] of Object.entries(dimension))yMap.set(key, value);
164
+ this.dsl.get('dimensions').push([
159
165
  yMap
160
166
  ]);
161
- const node = new MeasureNodeBuilder(yMap);
167
+ const node = new DimensionNodeBuilder(yMap);
162
168
  callback(node);
163
169
  return this;
164
170
  }
165
171
  remove(field) {
166
- const measures = this.dsl.get('measures');
167
- const index = measures.toArray().findIndex((item)=>item.get('field') === field);
168
- if (-1 !== index) this.dsl.get('measures').delete(index, 1);
172
+ const dimensions = this.dsl.get('dimensions');
173
+ const index = dimensions.toArray().findIndex((item)=>item.get('field') === field);
174
+ if (-1 !== index) this.dsl.get('dimensions').delete(index, 1);
169
175
  return this;
170
176
  }
171
177
  update(field, callback) {
172
- const measures = this.dsl.get('measures');
173
- const index = measures.toArray().findIndex((item)=>item.get('field') === field);
174
- if (-1 === index) throw new Error(`Measure with field "${field}" not found`);
175
- const measureYMap = measures.get(index);
176
- const node = new MeasureNodeBuilder(measureYMap);
178
+ const dimensions = this.dsl.get('dimensions');
179
+ const index = dimensions.toArray().findIndex((item)=>item.get('field') === field);
180
+ if (-1 === index) throw new Error(`Dimension with field "${field}" not found`);
181
+ const dimensionYMap = dimensions.get(index);
182
+ const node = new DimensionNodeBuilder(dimensionYMap);
177
183
  callback(node);
178
184
  return this;
179
185
  }
180
186
  find(field) {
181
- const measures = this.dsl.get('measures');
182
- const index = measures.toArray().findIndex((item)=>item.get('field') === field);
187
+ const dimensions = this.dsl.get('dimensions');
188
+ const index = dimensions.toArray().findIndex((item)=>item.get('field') === field);
183
189
  if (-1 === index) return;
184
- return new MeasureNodeBuilder(measures.get(index));
190
+ return new DimensionNodeBuilder(dimensions.get(index));
185
191
  }
186
192
  findAll() {
187
- const measures = this.dsl.get('measures');
188
- return measures.toArray().map((yMap)=>new MeasureNodeBuilder(yMap));
193
+ const dimensions = this.dsl.get('dimensions');
194
+ return dimensions.toArray().map((yMap)=>new DimensionNodeBuilder(yMap));
189
195
  }
190
- toJson() {
191
- return this.dsl.get('measures').toJSON();
196
+ toJSON() {
197
+ return this.dsl.get('dimensions').toJSON();
192
198
  }
193
199
  observe(callback) {
194
- this.dsl.get('measures').observe(callback);
200
+ this.dsl.get('dimensions').observe(callback);
195
201
  return ()=>{
196
- this.dsl.get('measures').unobserve(callback);
202
+ this.dsl.get('dimensions').unobserve(callback);
197
203
  };
198
204
  }
199
- static isMeasureNode(node) {
200
- return 'encoding' in node || 'aggregate' in node;
205
+ static isDimensionNode(node) {
206
+ return 'alias' in node && !('children' in node);
201
207
  }
202
- static isMeasureGroup(node) {
208
+ static isDimensionGroup(node) {
203
209
  return 'children' in node;
204
210
  }
205
211
  }
206
212
  const vseed_namespaceObject = require("@visactor/vseed");
213
+ class ChartTypeBuilder {
214
+ dsl;
215
+ constructor(_doc, dsl){
216
+ this.dsl = dsl;
217
+ }
218
+ observe(callback) {
219
+ const wrapper = (e, trans)=>{
220
+ if (e.keysChanged.has('chartType')) callback(e, trans);
221
+ };
222
+ this.dsl.observe(wrapper);
223
+ return ()=>{
224
+ this.dsl.unobserve(wrapper);
225
+ };
226
+ }
227
+ changeChartType(chartType) {
228
+ this.dsl.set('chartType', chartType);
229
+ }
230
+ getChartType() {
231
+ return this.dsl.get('chartType') || 'table';
232
+ }
233
+ toJSON() {
234
+ return this.dsl.get('chartType') || 'table';
235
+ }
236
+ getAvailableChartTypes() {
237
+ return [
238
+ vseed_namespaceObject.ChartTypeEnum.Table,
239
+ vseed_namespaceObject.ChartTypeEnum.PivotTable,
240
+ vseed_namespaceObject.ChartTypeEnum.Line,
241
+ vseed_namespaceObject.ChartTypeEnum.Column,
242
+ vseed_namespaceObject.ChartTypeEnum.ColumnPercent,
243
+ vseed_namespaceObject.ChartTypeEnum.ColumnParallel,
244
+ vseed_namespaceObject.ChartTypeEnum.BarPercent,
245
+ vseed_namespaceObject.ChartTypeEnum.BarParallel,
246
+ vseed_namespaceObject.ChartTypeEnum.Area,
247
+ vseed_namespaceObject.ChartTypeEnum.AreaPercent,
248
+ vseed_namespaceObject.ChartTypeEnum.DualAxis,
249
+ vseed_namespaceObject.ChartTypeEnum.Scatter,
250
+ vseed_namespaceObject.ChartTypeEnum.Rose,
251
+ vseed_namespaceObject.ChartTypeEnum.RoseParallel,
252
+ vseed_namespaceObject.ChartTypeEnum.Pie,
253
+ vseed_namespaceObject.ChartTypeEnum.Donut,
254
+ vseed_namespaceObject.ChartTypeEnum.Radar,
255
+ vseed_namespaceObject.ChartTypeEnum.Funnel,
256
+ vseed_namespaceObject.ChartTypeEnum.Heatmap,
257
+ vseed_namespaceObject.ChartTypeEnum.Boxplot,
258
+ vseed_namespaceObject.ChartTypeEnum.Histogram
259
+ ];
260
+ }
261
+ }
207
262
  const external_uuid_namespaceObject = require("uuid");
208
263
  const id_id = {
209
264
  uuid: ()=>(0, external_uuid_namespaceObject.v4)()
210
265
  };
211
- class HavingFiltersNodeBuilder {
266
+ function isVBIFilter(clause) {
267
+ return 'field' in clause;
268
+ }
269
+ function isVBIWhereGroup(clause) {
270
+ return 'conditions' in clause;
271
+ }
272
+ function isVBIHavingFilter(clause) {
273
+ return 'field' in clause;
274
+ }
275
+ function isVBIHavingGroup(clause) {
276
+ return 'conditions' in clause;
277
+ }
278
+ function createWhereGroup(op = 'and', groupId = 'root') {
279
+ const yMap = new external_yjs_namespaceObject.Map();
280
+ yMap.set('id', groupId);
281
+ yMap.set('op', op);
282
+ yMap.set('conditions', new external_yjs_namespaceObject.Array());
283
+ return yMap;
284
+ }
285
+ function isWhereGroup(yMap) {
286
+ return void 0 !== yMap.get('op') && void 0 !== yMap.get('conditions');
287
+ }
288
+ function findEntry(collection, entryId) {
289
+ const items = collection.toArray();
290
+ for(let index = 0; index < items.length; index++){
291
+ const item = items[index];
292
+ if (item.get('id') === entryId) return {
293
+ collection,
294
+ index,
295
+ item
296
+ };
297
+ if (isWhereGroup(item)) {
298
+ const nestedCollection = item.get('conditions');
299
+ const nestedMatch = findEntry(nestedCollection, entryId);
300
+ if (nestedMatch) return nestedMatch;
301
+ }
302
+ }
303
+ }
304
+ class WhereFilterNodeBuilder {
212
305
  yMap;
213
306
  constructor(yMap){
214
307
  this.yMap = yMap;
@@ -219,26 +312,33 @@ class HavingFiltersNodeBuilder {
219
312
  getField() {
220
313
  return this.yMap.get('field');
221
314
  }
315
+ setField(field) {
316
+ this.yMap.set('field', field);
317
+ return this;
318
+ }
222
319
  getOperator() {
223
320
  return this.yMap.get('op');
224
321
  }
225
- setValue(value) {
226
- this.yMap.set('value', value);
227
- return this;
228
- }
229
322
  setOperator(operator) {
230
323
  this.yMap.set('op', operator);
231
324
  return this;
232
325
  }
233
- toJson() {
326
+ setValue(value) {
327
+ this.yMap.set('value', value);
328
+ return this;
329
+ }
330
+ toJSON() {
234
331
  return this.yMap.toJSON();
235
332
  }
236
333
  }
237
- class HavingGroupBuilder {
334
+ class WhereGroupBuilder {
238
335
  yMap;
239
336
  constructor(yMap){
240
337
  this.yMap = yMap;
241
338
  }
339
+ getConditions() {
340
+ return this.yMap.get('conditions');
341
+ }
242
342
  getId() {
243
343
  return this.yMap.get('id');
244
344
  }
@@ -253,29 +353,24 @@ class HavingGroupBuilder {
253
353
  const yMap = new external_yjs_namespaceObject.Map();
254
354
  yMap.set('id', id_id.uuid());
255
355
  yMap.set('field', field);
256
- const conditions = this.yMap.get('conditions');
257
- conditions.push([
356
+ this.getConditions().push([
258
357
  yMap
259
358
  ]);
260
- const node = new HavingFiltersNodeBuilder(yMap);
359
+ const node = new WhereFilterNodeBuilder(yMap);
261
360
  callback(node);
262
361
  return this;
263
362
  }
264
363
  addGroup(op, callback) {
265
- const yMap = new external_yjs_namespaceObject.Map();
266
- yMap.set('id', id_id.uuid());
267
- yMap.set('op', op);
268
- yMap.set('conditions', new external_yjs_namespaceObject.Array());
269
- const conditions = this.yMap.get('conditions');
270
- conditions.push([
364
+ const yMap = createWhereGroup(op, id_id.uuid());
365
+ this.getConditions().push([
271
366
  yMap
272
367
  ]);
273
- const group = new HavingGroupBuilder(yMap);
368
+ const group = new WhereGroupBuilder(yMap);
274
369
  callback(group);
275
370
  return this;
276
371
  }
277
372
  remove(idOrIndex) {
278
- const conditions = this.yMap.get('conditions');
373
+ const conditions = this.getConditions();
279
374
  if ('number' == typeof idOrIndex) {
280
375
  if (idOrIndex >= 0 && idOrIndex < conditions.length) conditions.delete(idOrIndex, 1);
281
376
  } else {
@@ -285,154 +380,138 @@ class HavingGroupBuilder {
285
380
  return this;
286
381
  }
287
382
  clear() {
288
- const conditions = this.yMap.get('conditions');
383
+ const conditions = this.getConditions();
289
384
  conditions.delete(0, conditions.length);
290
385
  return this;
291
386
  }
292
- toJson() {
387
+ toJSON() {
293
388
  return this.yMap.toJSON();
294
389
  }
295
390
  }
296
- class HavingFiltersBuilder {
297
- dsl;
298
- doc;
391
+ class WhereFilterBuilder {
392
+ whereFilter;
299
393
  constructor(doc, dsl){
300
- this.doc = doc;
301
- this.dsl = dsl;
302
- if (!this.dsl.get('havingFilters')) this.doc.transact(()=>{
303
- this.dsl.set('havingFilters', new external_yjs_namespaceObject.Array());
394
+ doc.transact(()=>{
395
+ const existingWhereFilter = dsl.get('whereFilter');
396
+ if (existingWhereFilter instanceof external_yjs_namespaceObject.Map) this.whereFilter = existingWhereFilter;
397
+ else {
398
+ this.whereFilter = createWhereGroup();
399
+ dsl.set('whereFilter', this.whereFilter);
400
+ }
401
+ if (!(this.whereFilter.get('conditions') instanceof external_yjs_namespaceObject.Array)) this.whereFilter.set('conditions', new external_yjs_namespaceObject.Array());
402
+ if (!this.whereFilter.get('id')) this.whereFilter.set('id', 'root');
403
+ if (!this.whereFilter.get('op')) this.whereFilter.set('op', 'and');
304
404
  });
305
405
  }
406
+ getConditions() {
407
+ return this.whereFilter.get('conditions');
408
+ }
306
409
  add(field, callback) {
307
410
  const yMap = new external_yjs_namespaceObject.Map();
308
411
  yMap.set('id', id_id.uuid());
309
412
  yMap.set('field', field);
310
- this.dsl.get('havingFilters').push([
413
+ this.getConditions().push([
311
414
  yMap
312
415
  ]);
313
- const node = new HavingFiltersNodeBuilder(yMap);
416
+ const node = new WhereFilterNodeBuilder(yMap);
314
417
  callback(node);
315
418
  return this;
316
419
  }
317
420
  addGroup(op, callback) {
318
- const yMap = new external_yjs_namespaceObject.Map();
319
- yMap.set('id', id_id.uuid());
320
- yMap.set('op', op);
321
- yMap.set('conditions', new external_yjs_namespaceObject.Array());
322
- this.dsl.get('havingFilters').push([
421
+ const yMap = createWhereGroup(op, id_id.uuid());
422
+ this.getConditions().push([
323
423
  yMap
324
424
  ]);
325
- const group = new HavingGroupBuilder(yMap);
425
+ const group = new WhereGroupBuilder(yMap);
326
426
  callback(group);
327
427
  return this;
328
428
  }
329
429
  update(id, callback) {
330
- const havingFilters = this.dsl.get('havingFilters');
331
- const index = havingFilters.toArray().findIndex((item)=>item.get('id') === id);
332
- if (-1 === index) throw new Error(`Having filter with id ${id} not found`);
333
- const filterYMap = havingFilters.get(index);
334
- const node = new HavingFiltersNodeBuilder(filterYMap);
430
+ const conditions = this.getConditions();
431
+ const match = findEntry(conditions, id);
432
+ if (!match) throw new Error(`Where filter with id ${id} not found`);
433
+ if (!WhereFilterBuilder.isNode(match.item)) throw new Error(`Item with id ${id} is not a filter`);
434
+ const filterYMap = match.item;
435
+ const node = new WhereFilterNodeBuilder(filterYMap);
335
436
  callback(node);
336
437
  return this;
337
438
  }
338
439
  updateGroup(id, callback) {
339
- const havingFilters = this.dsl.get('havingFilters');
340
- const index = havingFilters.toArray().findIndex((item)=>item.get('id') === id);
341
- if (-1 === index) throw new Error(`Having group with id ${id} not found`);
342
- const yMap = havingFilters.get(index);
343
- if (!HavingFiltersBuilder.isGroup(yMap)) throw new Error(`Item with id ${id} is not a group`);
344
- const group = new HavingGroupBuilder(yMap);
440
+ const conditions = this.getConditions();
441
+ const match = findEntry(conditions, id);
442
+ if (!match) throw new Error(`Where group with id ${id} not found`);
443
+ const yMap = match.item;
444
+ if (!WhereFilterBuilder.isGroup(yMap)) throw new Error(`Item with id ${id} is not a group`);
445
+ const group = new WhereGroupBuilder(yMap);
345
446
  callback(group);
346
447
  return this;
347
448
  }
348
449
  remove(idOrIndex) {
349
- const havingFilters = this.dsl.get('havingFilters');
450
+ const conditions = this.getConditions();
350
451
  if ('number' == typeof idOrIndex) {
351
- if (idOrIndex >= 0 && idOrIndex < havingFilters.length) havingFilters.delete(idOrIndex, 1);
452
+ if (idOrIndex >= 0 && idOrIndex < conditions.length) conditions.delete(idOrIndex, 1);
352
453
  } else {
353
- const index = havingFilters.toArray().findIndex((item)=>item.get('id') === idOrIndex);
354
- if (-1 !== index) havingFilters.delete(index, 1);
454
+ const match = findEntry(conditions, idOrIndex);
455
+ if (match) match.collection.delete(match.index, 1);
355
456
  }
356
457
  return this;
357
458
  }
358
459
  find(id) {
359
- const havingFilters = this.dsl.get('havingFilters');
360
- const yMap = havingFilters.toArray().find((item)=>item.get('id') === id);
460
+ const conditions = this.getConditions();
461
+ const match = findEntry(conditions, id);
462
+ const yMap = match?.item;
361
463
  if (!yMap) return;
362
- if (HavingFiltersBuilder.isGroup(yMap)) return new HavingGroupBuilder(yMap);
363
- return new HavingFiltersNodeBuilder(yMap);
464
+ if (WhereFilterBuilder.isGroup(yMap)) return new WhereGroupBuilder(yMap);
465
+ return new WhereFilterNodeBuilder(yMap);
364
466
  }
365
467
  clear() {
366
- const havingFilters = this.dsl.get('havingFilters');
367
- havingFilters.delete(0, havingFilters.length);
468
+ const conditions = this.getConditions();
469
+ conditions.delete(0, conditions.length);
368
470
  return this;
369
471
  }
370
- toJson() {
371
- return this.dsl.get('havingFilters').toJSON();
472
+ toJSON() {
473
+ return this.whereFilter.toJSON();
372
474
  }
373
475
  observe(callback) {
374
- this.dsl.get('havingFilters').observe(callback);
476
+ this.whereFilter.observeDeep(callback);
375
477
  return ()=>{
376
- this.dsl.get('havingFilters').unobserve(callback);
478
+ this.whereFilter.unobserveDeep(callback);
377
479
  };
378
480
  }
379
481
  static isGroup(yMap) {
380
- return void 0 !== yMap.get('op') && void 0 !== yMap.get('conditions');
482
+ return isWhereGroup(yMap);
381
483
  }
382
484
  static isNode(yMap) {
383
485
  return void 0 !== yMap.get('field');
384
486
  }
385
487
  }
386
- class ChartTypeBuilder {
387
- dsl;
388
- constructor(_doc, dsl){
389
- this.dsl = dsl;
390
- }
391
- observe(callback) {
392
- const wrapper = (e, trans)=>{
393
- if (e.keysChanged.has('chartType')) callback(e, trans);
394
- };
395
- this.dsl.observe(wrapper);
396
- return ()=>{
397
- this.dsl.unobserve(wrapper);
488
+ function createHavingGroup(op = 'and', groupId = 'root') {
489
+ const yMap = new external_yjs_namespaceObject.Map();
490
+ yMap.set('id', groupId);
491
+ yMap.set('op', op);
492
+ yMap.set('conditions', new external_yjs_namespaceObject.Array());
493
+ return yMap;
494
+ }
495
+ function isHavingGroup(yMap) {
496
+ return void 0 !== yMap.get('op') && void 0 !== yMap.get('conditions');
497
+ }
498
+ function having_utils_findEntry(collection, entryId) {
499
+ const items = collection.toArray();
500
+ for(let index = 0; index < items.length; index++){
501
+ const item = items[index];
502
+ if (item.get('id') === entryId) return {
503
+ collection,
504
+ index,
505
+ item
398
506
  };
399
- }
400
- changeChartType(chartType) {
401
- this.dsl.set('chartType', chartType);
402
- }
403
- getChartType() {
404
- return this.dsl.get('chartType') || 'table';
405
- }
406
- toJson() {
407
- return this.dsl.get('chartType') || 'table';
408
- }
409
- getAvailableChartTypes() {
410
- return [
411
- vseed_namespaceObject.ChartTypeEnum.Table,
412
- vseed_namespaceObject.ChartTypeEnum.PivotTable,
413
- vseed_namespaceObject.ChartTypeEnum.Line,
414
- vseed_namespaceObject.ChartTypeEnum.Column,
415
- vseed_namespaceObject.ChartTypeEnum.ColumnPercent,
416
- vseed_namespaceObject.ChartTypeEnum.ColumnParallel,
417
- vseed_namespaceObject.ChartTypeEnum.BarPercent,
418
- vseed_namespaceObject.ChartTypeEnum.BarParallel,
419
- vseed_namespaceObject.ChartTypeEnum.Area,
420
- vseed_namespaceObject.ChartTypeEnum.AreaPercent,
421
- vseed_namespaceObject.ChartTypeEnum.DualAxis,
422
- vseed_namespaceObject.ChartTypeEnum.Scatter,
423
- vseed_namespaceObject.ChartTypeEnum.Rose,
424
- vseed_namespaceObject.ChartTypeEnum.RoseParallel,
425
- vseed_namespaceObject.ChartTypeEnum.Pie,
426
- vseed_namespaceObject.ChartTypeEnum.Donut,
427
- vseed_namespaceObject.ChartTypeEnum.Radar,
428
- vseed_namespaceObject.ChartTypeEnum.Funnel,
429
- vseed_namespaceObject.ChartTypeEnum.Heatmap,
430
- vseed_namespaceObject.ChartTypeEnum.Boxplot,
431
- vseed_namespaceObject.ChartTypeEnum.Histogram
432
- ];
507
+ if (isHavingGroup(item)) {
508
+ const nestedCollection = item.get('conditions');
509
+ const nestedMatch = having_utils_findEntry(nestedCollection, entryId);
510
+ if (nestedMatch) return nestedMatch;
511
+ }
433
512
  }
434
513
  }
435
- class WhereFilterNodeBuilder {
514
+ class HavingFilterNodeBuilder {
436
515
  yMap;
437
516
  constructor(yMap){
438
517
  this.yMap = yMap;
@@ -446,23 +525,26 @@ class WhereFilterNodeBuilder {
446
525
  getOperator() {
447
526
  return this.yMap.get('op');
448
527
  }
449
- setOperator(operator) {
450
- this.yMap.set('op', operator);
451
- return this;
452
- }
453
528
  setValue(value) {
454
529
  this.yMap.set('value', value);
455
530
  return this;
456
531
  }
457
- toJson() {
532
+ setOperator(operator) {
533
+ this.yMap.set('op', operator);
534
+ return this;
535
+ }
536
+ toJSON() {
458
537
  return this.yMap.toJSON();
459
538
  }
460
539
  }
461
- class WhereGroupBuilder {
540
+ class HavingGroupBuilder {
462
541
  yMap;
463
542
  constructor(yMap){
464
543
  this.yMap = yMap;
465
544
  }
545
+ getConditions() {
546
+ return this.yMap.get('conditions');
547
+ }
466
548
  getId() {
467
549
  return this.yMap.get('id');
468
550
  }
@@ -477,29 +559,24 @@ class WhereGroupBuilder {
477
559
  const yMap = new external_yjs_namespaceObject.Map();
478
560
  yMap.set('id', id_id.uuid());
479
561
  yMap.set('field', field);
480
- const conditions = this.yMap.get('conditions');
481
- conditions.push([
562
+ this.getConditions().push([
482
563
  yMap
483
564
  ]);
484
- const node = new WhereFilterNodeBuilder(yMap);
565
+ const node = new HavingFilterNodeBuilder(yMap);
485
566
  callback(node);
486
567
  return this;
487
568
  }
488
569
  addGroup(op, callback) {
489
- const yMap = new external_yjs_namespaceObject.Map();
490
- yMap.set('id', id_id.uuid());
491
- yMap.set('op', op);
492
- yMap.set('conditions', new external_yjs_namespaceObject.Array());
493
- const conditions = this.yMap.get('conditions');
494
- conditions.push([
570
+ const yMap = createHavingGroup(op, id_id.uuid());
571
+ this.getConditions().push([
495
572
  yMap
496
573
  ]);
497
- const group = new WhereGroupBuilder(yMap);
574
+ const group = new HavingGroupBuilder(yMap);
498
575
  callback(group);
499
576
  return this;
500
577
  }
501
578
  remove(idOrIndex) {
502
- const conditions = this.yMap.get('conditions');
579
+ const conditions = this.getConditions();
503
580
  if ('number' == typeof idOrIndex) {
504
581
  if (idOrIndex >= 0 && idOrIndex < conditions.length) conditions.delete(idOrIndex, 1);
505
582
  } else {
@@ -509,104 +586,183 @@ class WhereGroupBuilder {
509
586
  return this;
510
587
  }
511
588
  clear() {
512
- const conditions = this.yMap.get('conditions');
589
+ const conditions = this.getConditions();
513
590
  conditions.delete(0, conditions.length);
514
591
  return this;
515
592
  }
516
- toJson() {
593
+ toJSON() {
517
594
  return this.yMap.toJSON();
518
595
  }
519
596
  }
520
- class WhereFiltersBuilder {
521
- dsl;
522
- doc;
597
+ class HavingFilterBuilder {
598
+ havingFilter;
523
599
  constructor(doc, dsl){
524
- this.doc = doc;
525
- this.dsl = dsl;
526
- if (!this.dsl.get('whereFilters')) this.doc.transact(()=>{
527
- this.dsl.set('whereFilters', new external_yjs_namespaceObject.Array());
600
+ doc.transact(()=>{
601
+ const existingHavingFilter = dsl.get('havingFilter');
602
+ if (existingHavingFilter instanceof external_yjs_namespaceObject.Map) this.havingFilter = existingHavingFilter;
603
+ else {
604
+ this.havingFilter = createHavingGroup();
605
+ dsl.set('havingFilter', this.havingFilter);
606
+ }
607
+ if (!(this.havingFilter.get('conditions') instanceof external_yjs_namespaceObject.Array)) this.havingFilter.set('conditions', new external_yjs_namespaceObject.Array());
608
+ if (!this.havingFilter.get('id')) this.havingFilter.set('id', 'root');
609
+ if (!this.havingFilter.get('op')) this.havingFilter.set('op', 'and');
528
610
  });
529
611
  }
612
+ getConditions() {
613
+ return this.havingFilter.get('conditions');
614
+ }
530
615
  add(field, callback) {
531
616
  const yMap = new external_yjs_namespaceObject.Map();
532
617
  yMap.set('id', id_id.uuid());
533
618
  yMap.set('field', field);
534
- this.dsl.get('whereFilters').push([
619
+ this.getConditions().push([
535
620
  yMap
536
621
  ]);
537
- const node = new WhereFilterNodeBuilder(yMap);
622
+ const node = new HavingFilterNodeBuilder(yMap);
538
623
  callback(node);
539
624
  return this;
540
625
  }
541
626
  addGroup(op, callback) {
542
- const yMap = new external_yjs_namespaceObject.Map();
543
- yMap.set('id', id_id.uuid());
544
- yMap.set('op', op);
545
- yMap.set('conditions', new external_yjs_namespaceObject.Array());
546
- this.dsl.get('whereFilters').push([
627
+ const yMap = createHavingGroup(op, id_id.uuid());
628
+ this.getConditions().push([
547
629
  yMap
548
630
  ]);
549
- const group = new WhereGroupBuilder(yMap);
631
+ const group = new HavingGroupBuilder(yMap);
550
632
  callback(group);
551
633
  return this;
552
634
  }
553
635
  update(id, callback) {
554
- const whereFilters = this.dsl.get('whereFilters');
555
- const index = whereFilters.toArray().findIndex((item)=>item.get('id') === id);
556
- if (-1 === index) throw new Error(`Where filter with id ${id} not found`);
557
- const filterYMap = whereFilters.get(index);
558
- const node = new WhereFilterNodeBuilder(filterYMap);
636
+ const conditions = this.getConditions();
637
+ const match = having_utils_findEntry(conditions, id);
638
+ if (!match) throw new Error(`Having filter with id ${id} not found`);
639
+ if (!HavingFilterBuilder.isNode(match.item)) throw new Error(`Item with id ${id} is not a filter`);
640
+ const filterYMap = match.item;
641
+ const node = new HavingFilterNodeBuilder(filterYMap);
559
642
  callback(node);
560
643
  return this;
561
644
  }
562
645
  updateGroup(id, callback) {
563
- const whereFilters = this.dsl.get('whereFilters');
564
- const index = whereFilters.toArray().findIndex((item)=>item.get('id') === id);
565
- if (-1 === index) throw new Error(`Where group with id ${id} not found`);
566
- const yMap = whereFilters.get(index);
567
- if (!WhereFiltersBuilder.isGroup(yMap)) throw new Error(`Item with id ${id} is not a group`);
568
- const group = new WhereGroupBuilder(yMap);
646
+ const conditions = this.getConditions();
647
+ const match = having_utils_findEntry(conditions, id);
648
+ if (!match) throw new Error(`Having group with id ${id} not found`);
649
+ const yMap = match.item;
650
+ if (!HavingFilterBuilder.isGroup(yMap)) throw new Error(`Item with id ${id} is not a group`);
651
+ const group = new HavingGroupBuilder(yMap);
569
652
  callback(group);
570
653
  return this;
571
654
  }
572
655
  remove(idOrIndex) {
573
- const whereFilters = this.dsl.get('whereFilters');
656
+ const conditions = this.getConditions();
574
657
  if ('number' == typeof idOrIndex) {
575
- if (idOrIndex >= 0 && idOrIndex < whereFilters.length) whereFilters.delete(idOrIndex, 1);
658
+ if (idOrIndex >= 0 && idOrIndex < conditions.length) conditions.delete(idOrIndex, 1);
576
659
  } else {
577
- const index = whereFilters.toArray().findIndex((item)=>item.get('id') === idOrIndex);
578
- if (-1 !== index) whereFilters.delete(index, 1);
660
+ const match = having_utils_findEntry(conditions, idOrIndex);
661
+ if (match) match.collection.delete(match.index, 1);
579
662
  }
580
663
  return this;
581
664
  }
582
665
  find(id) {
583
- const whereFilters = this.dsl.get('whereFilters');
584
- const yMap = whereFilters.toArray().find((item)=>item.get('id') === id);
666
+ const conditions = this.getConditions();
667
+ const match = having_utils_findEntry(conditions, id);
668
+ const yMap = match?.item;
585
669
  if (!yMap) return;
586
- if (WhereFiltersBuilder.isGroup(yMap)) return new WhereGroupBuilder(yMap);
587
- return new WhereFilterNodeBuilder(yMap);
670
+ if (HavingFilterBuilder.isGroup(yMap)) return new HavingGroupBuilder(yMap);
671
+ return new HavingFilterNodeBuilder(yMap);
588
672
  }
589
673
  clear() {
590
- const whereFilters = this.dsl.get('whereFilters');
591
- whereFilters.delete(0, whereFilters.length);
674
+ const conditions = this.getConditions();
675
+ conditions.delete(0, conditions.length);
592
676
  return this;
593
677
  }
594
- toJson() {
595
- return this.dsl.get('whereFilters').toJSON();
678
+ toJSON() {
679
+ return this.havingFilter.toJSON();
596
680
  }
597
681
  observe(callback) {
598
- this.dsl.get('whereFilters').observe(callback);
682
+ this.havingFilter.observeDeep(callback);
599
683
  return ()=>{
600
- this.dsl.get('whereFilters').unobserve(callback);
684
+ this.havingFilter.unobserveDeep(callback);
601
685
  };
602
686
  }
603
687
  static isGroup(yMap) {
604
- return void 0 !== yMap.get('op') && void 0 !== yMap.get('conditions');
688
+ return isHavingGroup(yMap);
605
689
  }
606
690
  static isNode(yMap) {
607
691
  return void 0 !== yMap.get('field');
608
692
  }
609
693
  }
694
+ class ThemeBuilder {
695
+ dsl;
696
+ constructor(_doc, dsl){
697
+ this.dsl = dsl;
698
+ }
699
+ observe(callback) {
700
+ const wrapper = (e, trans)=>{
701
+ if (e.keysChanged.has('theme')) callback(e, trans);
702
+ };
703
+ this.dsl.observe(wrapper);
704
+ return ()=>{
705
+ this.dsl.unobserve(wrapper);
706
+ };
707
+ }
708
+ setTheme(theme) {
709
+ this.dsl.set('theme', theme);
710
+ }
711
+ getTheme() {
712
+ return this.dsl.get('theme') || 'light';
713
+ }
714
+ toJSON() {
715
+ return this.getTheme();
716
+ }
717
+ }
718
+ class LocaleBuilder {
719
+ dsl;
720
+ constructor(_doc, dsl){
721
+ this.dsl = dsl;
722
+ }
723
+ observe(callback) {
724
+ const wrapper = (e, trans)=>{
725
+ if (e.keysChanged.has('locale')) callback(e, trans);
726
+ };
727
+ this.dsl.observe(wrapper);
728
+ return ()=>{
729
+ this.dsl.unobserve(wrapper);
730
+ };
731
+ }
732
+ setLocale(locale) {
733
+ this.dsl.set('locale', locale);
734
+ }
735
+ getLocale() {
736
+ return this.dsl.get('locale') || 'zh-CN';
737
+ }
738
+ toJSON() {
739
+ return this.getLocale();
740
+ }
741
+ }
742
+ class LimitBuilder {
743
+ dsl;
744
+ constructor(_doc, dsl){
745
+ this.dsl = dsl;
746
+ }
747
+ observe(callback) {
748
+ const wrapper = (e, trans)=>{
749
+ if (e.keysChanged.has('limit')) callback(e, trans);
750
+ };
751
+ this.dsl.observe(wrapper);
752
+ return ()=>{
753
+ this.dsl.unobserve(wrapper);
754
+ };
755
+ }
756
+ setLimit(limit) {
757
+ this.dsl.set('limit', limit);
758
+ }
759
+ getLimit() {
760
+ return this.dsl.get('limit');
761
+ }
762
+ toJSON() {
763
+ return this.getLimit();
764
+ }
765
+ }
610
766
  class UndoManager {
611
767
  manager;
612
768
  constructor(scope){
@@ -662,22 +818,19 @@ const buildGroupBy = (queryDSL, context)=>{
662
818
  };
663
819
  const buildWhere = (queryDSL, context)=>{
664
820
  const { vbiDSL } = context;
665
- const whereFilters = vbiDSL.whereFilters || [];
666
- if (0 === whereFilters.length) return queryDSL;
821
+ const whereFilter = vbiDSL.whereFilter;
822
+ if (!whereFilter || 0 === whereFilter.conditions.length) return queryDSL;
667
823
  const result = {
668
824
  ...queryDSL
669
825
  };
670
- result.where = {
671
- op: 'and',
672
- conditions: whereFilters.flatMap(mapClauseToCondition)
673
- };
826
+ result.where = mapGroupToCondition(whereFilter);
674
827
  return result;
675
828
  };
676
- function isWhereGroup(clause) {
829
+ function buildWhere_isWhereGroup(clause) {
677
830
  return 'op' in clause && 'conditions' in clause;
678
831
  }
679
832
  function mapClauseToCondition(clause) {
680
- if (isWhereGroup(clause)) return [
833
+ if (buildWhere_isWhereGroup(clause)) return [
681
834
  mapGroupToCondition(clause)
682
835
  ];
683
836
  return mapFilterToCondition(clause);
@@ -689,23 +842,62 @@ function mapGroupToCondition(group) {
689
842
  };
690
843
  }
691
844
  function mapFilterToCondition(filter) {
692
- if ('between' === filter.op) return handleBetweenFilter(filter);
845
+ if ('between' === filter.op || 'not between' === filter.op) return handleBetweenFilter(filter);
693
846
  return handleSimpleFilter(filter);
694
847
  }
695
848
  function handleBetweenFilter(filter) {
696
- const conditions = [];
697
- const value = filter.value;
698
- if (void 0 !== value.min && null !== value.min && '' !== value.min) conditions.push({
849
+ const value = normalizeBetweenValue(filter.value);
850
+ const lowerCondition = void 0 !== value.min && null !== value.min && '' !== value.min ? {
699
851
  field: filter.field,
700
852
  op: '<' === value.leftOp ? '>' : '>=',
701
853
  value: value.min
702
- });
703
- if (void 0 !== value.max && null !== value.max && '' !== value.max) conditions.push({
854
+ } : void 0;
855
+ const upperCondition = void 0 !== value.max && null !== value.max && '' !== value.max ? {
704
856
  field: filter.field,
705
857
  op: '<' === value.rightOp ? '<' : '<=',
706
858
  value: value.max
707
- });
708
- return conditions;
859
+ } : void 0;
860
+ if ('not between' === filter.op) {
861
+ const outsideConditions = [
862
+ lowerCondition && invertLowerBound(lowerCondition),
863
+ upperCondition && invertUpperBound(upperCondition)
864
+ ].filter(Boolean);
865
+ if (outsideConditions.length <= 1) return outsideConditions;
866
+ return [
867
+ {
868
+ op: 'or',
869
+ conditions: outsideConditions
870
+ }
871
+ ];
872
+ }
873
+ return [
874
+ lowerCondition,
875
+ upperCondition
876
+ ].filter(Boolean);
877
+ }
878
+ function normalizeBetweenValue(value) {
879
+ if (Array.isArray(value)) return {
880
+ min: value[0],
881
+ max: value[1],
882
+ leftOp: '<=',
883
+ rightOp: '<='
884
+ };
885
+ if ('object' == typeof value && null !== value) return value;
886
+ return {};
887
+ }
888
+ function invertLowerBound(condition) {
889
+ return {
890
+ field: condition.field,
891
+ op: '>' === condition.op ? '<=' : '<',
892
+ value: condition.value
893
+ };
894
+ }
895
+ function invertUpperBound(condition) {
896
+ return {
897
+ field: condition.field,
898
+ op: '<' === condition.op ? '>=' : '>',
899
+ value: condition.value
900
+ };
709
901
  }
710
902
  function handleSimpleFilter(filter) {
711
903
  let mappedOp = filter.op ?? '=';
@@ -724,22 +916,22 @@ function handleSimpleFilter(filter) {
724
916
  }
725
917
  const buildHaving = (queryDSL, context)=>{
726
918
  const { vbiDSL } = context;
727
- const havingFilters = vbiDSL.havingFilters || [];
728
- if (0 === havingFilters.length) return queryDSL;
919
+ const havingFilter = vbiDSL.havingFilter;
920
+ if (!havingFilter || 0 === havingFilter.conditions.length) return queryDSL;
729
921
  const result = {
730
922
  ...queryDSL
731
923
  };
732
924
  result.having = {
733
- op: 'and',
734
- conditions: havingFilters.flatMap(buildHaving_mapClauseToCondition)
925
+ op: havingFilter.op,
926
+ conditions: havingFilter.conditions.flatMap(buildHaving_mapClauseToCondition)
735
927
  };
736
928
  return result;
737
929
  };
738
- function isHavingGroup(clause) {
930
+ function buildHaving_isHavingGroup(clause) {
739
931
  return 'op' in clause && 'conditions' in clause;
740
932
  }
741
933
  function buildHaving_mapClauseToCondition(clause) {
742
- if (isHavingGroup(clause)) return [
934
+ if (buildHaving_isHavingGroup(clause)) return [
743
935
  buildHaving_mapGroupToCondition(clause)
744
936
  ];
745
937
  return buildHaving_mapFilterToCondition(clause);
@@ -792,8 +984,11 @@ class VBIBuilder {
792
984
  chartType;
793
985
  measures;
794
986
  dimensions;
795
- havingFilters;
796
- whereFilters;
987
+ havingFilter;
988
+ whereFilter;
989
+ theme;
990
+ locale;
991
+ limit;
797
992
  constructor(doc){
798
993
  this.doc = doc;
799
994
  this.dsl = doc.getMap('dsl');
@@ -801,8 +996,11 @@ class VBIBuilder {
801
996
  this.chartType = new ChartTypeBuilder(doc, this.dsl);
802
997
  this.measures = new MeasuresBuilder(doc, this.dsl);
803
998
  this.dimensions = new DimensionsBuilder(doc, this.dsl);
804
- this.havingFilters = new HavingFiltersBuilder(doc, this.dsl);
805
- this.whereFilters = new WhereFiltersBuilder(doc, this.dsl);
999
+ this.havingFilter = new HavingFilterBuilder(doc, this.dsl);
1000
+ this.whereFilter = new WhereFilterBuilder(doc, this.dsl);
1001
+ this.theme = new ThemeBuilder(doc, this.dsl);
1002
+ this.locale = new LocaleBuilder(doc, this.dsl);
1003
+ this.limit = new LimitBuilder(doc, this.dsl);
806
1004
  }
807
1005
  applyUpdate(update) {
808
1006
  external_yjs_namespaceObject.applyUpdate(this.doc, update);
@@ -839,18 +1037,6 @@ class VBIBuilder {
839
1037
  const result = await con.discoverSchema();
840
1038
  return result;
841
1039
  };
842
- setLimit(limit) {
843
- this.dsl.set('limit', limit);
844
- return this;
845
- }
846
- setLocale(locale) {
847
- this.dsl.set('locale', locale);
848
- return this;
849
- }
850
- setTheme(theme) {
851
- this.dsl.set('theme', theme);
852
- return this;
853
- }
854
1040
  }
855
1041
  const createVBI = ()=>({
856
1042
  connectorMap: connectorMap,
@@ -861,8 +1047,16 @@ const createVBI = ()=>({
861
1047
  chartType: 'table',
862
1048
  measures: [],
863
1049
  dimensions: [],
864
- whereFilters: [],
865
- havingFilters: [],
1050
+ whereFilter: {
1051
+ id: 'root',
1052
+ op: 'and',
1053
+ conditions: []
1054
+ },
1055
+ havingFilter: {
1056
+ id: 'root',
1057
+ op: 'and',
1058
+ conditions: []
1059
+ },
866
1060
  theme: 'light',
867
1061
  locale: 'zh-CN',
868
1062
  version: 0
@@ -876,7 +1070,7 @@ const createVBI = ()=>({
876
1070
  if (vbi.theme) dsl.set('theme', vbi.theme);
877
1071
  if (vbi.limit) dsl.set('limit', vbi.limit);
878
1072
  if (vbi.locale) dsl.set('locale', vbi.locale);
879
- if (vbi.version) dsl.set('version', vbi.version);
1073
+ if (void 0 !== vbi.version) dsl.set('version', vbi.version);
880
1074
  const toYMap = (obj, ensureId = false)=>{
881
1075
  const yMap = new external_yjs_namespaceObject.Map();
882
1076
  if (ensureId && !obj.id) yMap.set('id', id_id.uuid());
@@ -914,8 +1108,38 @@ const createVBI = ()=>({
914
1108
  });
915
1109
  return yArr;
916
1110
  };
917
- dsl.set('whereFilters', ensureYArray(vbi.whereFilters, true));
918
- dsl.set('havingFilters', ensureYArray(vbi.havingFilters, true));
1111
+ const whereFilter = vbi.whereFilter ?? {
1112
+ id: 'root',
1113
+ op: 'and',
1114
+ conditions: []
1115
+ };
1116
+ const whereGroup = whereFilter instanceof external_yjs_namespaceObject.Map ? whereFilter : createWhereGroup();
1117
+ if (whereFilter instanceof external_yjs_namespaceObject.Map) {
1118
+ if (!(whereGroup.get('conditions') instanceof external_yjs_namespaceObject.Array)) whereGroup.set('conditions', new external_yjs_namespaceObject.Array());
1119
+ if (!whereGroup.get('id')) whereGroup.set('id', 'root');
1120
+ if (!whereGroup.get('op')) whereGroup.set('op', 'and');
1121
+ } else {
1122
+ whereGroup.set('id', whereFilter.id ?? 'root');
1123
+ whereGroup.set('op', whereFilter.op ?? 'and');
1124
+ whereGroup.set('conditions', ensureYArray(whereFilter.conditions, true));
1125
+ }
1126
+ dsl.set('whereFilter', whereGroup);
1127
+ const havingFilter = vbi.havingFilter ?? {
1128
+ id: 'root',
1129
+ op: 'and',
1130
+ conditions: []
1131
+ };
1132
+ const havingGroup = havingFilter instanceof external_yjs_namespaceObject.Map ? havingFilter : createHavingGroup();
1133
+ if (havingFilter instanceof external_yjs_namespaceObject.Map) {
1134
+ if (!(havingGroup.get('conditions') instanceof external_yjs_namespaceObject.Array)) havingGroup.set('conditions', new external_yjs_namespaceObject.Array());
1135
+ if (!havingGroup.get('id')) havingGroup.set('id', 'root');
1136
+ if (!havingGroup.get('op')) havingGroup.set('op', 'and');
1137
+ } else {
1138
+ havingGroup.set('id', havingFilter.id ?? 'root');
1139
+ havingGroup.set('op', havingFilter.op ?? 'and');
1140
+ havingGroup.set('conditions', ensureYArray(havingFilter.conditions, true));
1141
+ }
1142
+ dsl.set('havingFilter', havingGroup);
919
1143
  dsl.set('measures', ensureYArray(vbi.measures));
920
1144
  dsl.set('dimensions', ensureYArray(vbi.dimensions));
921
1145
  });
@@ -923,60 +1147,17 @@ const createVBI = ()=>({
923
1147
  }
924
1148
  });
925
1149
  const VBI = createVBI();
926
- const external_zod_namespaceObject = require("zod");
927
- const zVBIFilter = external_zod_namespaceObject.z.object({
928
- id: external_zod_namespaceObject.z.string(),
929
- field: external_zod_namespaceObject.z.string(),
930
- op: external_zod_namespaceObject.z.string().optional(),
931
- value: external_zod_namespaceObject.z.any().optional()
932
- });
933
- const zVBIWhereGroup = external_zod_namespaceObject.z.lazy(()=>external_zod_namespaceObject.z.object({
934
- id: external_zod_namespaceObject.z.string(),
935
- op: external_zod_namespaceObject.z["enum"]([
936
- 'and',
937
- 'or'
938
- ]),
939
- conditions: external_zod_namespaceObject.z.array(zVBIWhereClause)
940
- }));
941
- const zVBIWhereClause = external_zod_namespaceObject.z.lazy(()=>external_zod_namespaceObject.z.union([
942
- zVBIFilter,
943
- zVBIWhereGroup
944
- ]));
945
- function isVBIFilter(clause) {
946
- return 'field' in clause;
947
- }
948
- function isVBIWhereGroup(clause) {
949
- return 'conditions' in clause;
950
- }
951
- const zVBIHavingFilter = external_zod_namespaceObject.z.object({
952
- id: external_zod_namespaceObject.z.string(),
953
- field: external_zod_namespaceObject.z.string(),
954
- op: external_zod_namespaceObject.z.string().optional(),
955
- value: external_zod_namespaceObject.z.any().optional()
956
- });
957
- const zVBIHavingGroup = external_zod_namespaceObject.z.lazy(()=>external_zod_namespaceObject.z.object({
958
- id: external_zod_namespaceObject.z.string(),
959
- op: external_zod_namespaceObject.z["enum"]([
960
- 'and',
961
- 'or'
962
- ]),
963
- conditions: external_zod_namespaceObject.z.array(zVBIHavingClause)
964
- }));
965
- const zVBIHavingClause = external_zod_namespaceObject.z.lazy(()=>external_zod_namespaceObject.z.union([
966
- zVBIHavingFilter,
967
- zVBIHavingGroup
968
- ]));
969
- function isVBIHavingFilter(clause) {
970
- return 'field' in clause;
971
- }
972
- function isVBIHavingGroup(clause) {
973
- return 'conditions' in clause;
974
- }
975
1150
  exports.ChartTypeBuilder = __webpack_exports__.ChartTypeBuilder;
976
1151
  exports.DimensionsBuilder = __webpack_exports__.DimensionsBuilder;
1152
+ exports.HavingFilterBuilder = __webpack_exports__.HavingFilterBuilder;
1153
+ exports.LimitBuilder = __webpack_exports__.LimitBuilder;
1154
+ exports.LocaleBuilder = __webpack_exports__.LocaleBuilder;
977
1155
  exports.MeasuresBuilder = __webpack_exports__.MeasuresBuilder;
1156
+ exports.ThemeBuilder = __webpack_exports__.ThemeBuilder;
1157
+ exports.UndoManager = __webpack_exports__.UndoManager;
978
1158
  exports.VBI = __webpack_exports__.VBI;
979
1159
  exports.VBIBuilder = __webpack_exports__.VBIBuilder;
1160
+ exports.WhereFilterBuilder = __webpack_exports__.WhereFilterBuilder;
980
1161
  exports.buildVQuery = __webpack_exports__.buildVQuery;
981
1162
  exports.findTreeNodesBy = __webpack_exports__.findTreeNodesBy;
982
1163
  exports.id = __webpack_exports__.id;
@@ -988,9 +1169,15 @@ exports.preorderTraverse = __webpack_exports__.preorderTraverse;
988
1169
  for(var __webpack_i__ in __webpack_exports__)if (-1 === [
989
1170
  "ChartTypeBuilder",
990
1171
  "DimensionsBuilder",
1172
+ "HavingFilterBuilder",
1173
+ "LimitBuilder",
1174
+ "LocaleBuilder",
991
1175
  "MeasuresBuilder",
1176
+ "ThemeBuilder",
1177
+ "UndoManager",
992
1178
  "VBI",
993
1179
  "VBIBuilder",
1180
+ "WhereFilterBuilder",
994
1181
  "buildVQuery",
995
1182
  "findTreeNodesBy",
996
1183
  "id",