@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.
- package/dist/builder/{sub-builders → features}/chart-type/chart-type-builder.d.ts +1 -1
- package/dist/builder/{sub-builders → features}/dimensions/dim-builder.d.ts +1 -1
- package/dist/builder/{sub-builders → features}/dimensions/dim-node-builder.d.ts +1 -1
- package/dist/builder/{sub-builders/havingFilters → features/havingFilter}/having-builder.d.ts +13 -13
- package/dist/builder/{sub-builders/havingFilters → features/havingFilter}/having-group-builder.d.ts +4 -3
- package/dist/builder/{sub-builders/havingFilters → features/havingFilter}/having-node-builder.d.ts +2 -2
- package/dist/builder/features/havingFilter/having-utils.d.ts +9 -0
- package/dist/builder/features/havingFilter/index.d.ts +3 -0
- package/dist/builder/features/index.d.ts +9 -0
- package/dist/builder/features/limit/index.d.ts +1 -0
- package/dist/builder/features/limit/limit-builder.d.ts +31 -0
- package/dist/builder/features/locale/index.d.ts +1 -0
- package/dist/builder/features/locale/locale-builder.d.ts +31 -0
- package/dist/builder/{sub-builders → features}/measures/mea-builder.d.ts +1 -1
- package/dist/builder/{sub-builders → features}/measures/mea-node-builder.d.ts +1 -1
- package/dist/builder/features/theme/index.d.ts +1 -0
- package/dist/builder/features/theme/theme-builder.d.ts +31 -0
- package/dist/builder/features/undo-manager/index.d.ts +1 -0
- package/dist/builder/{sub-builders/whereFilters → features/whereFilter}/index.d.ts +1 -1
- package/dist/builder/{sub-builders/whereFilters → features/whereFilter}/where-builder.d.ts +11 -11
- package/dist/builder/{sub-builders/whereFilters → features/whereFilter}/where-group-builder.d.ts +2 -1
- package/dist/builder/{sub-builders/whereFilters → features/whereFilter}/where-node-builder.d.ts +6 -1
- package/dist/builder/features/whereFilter/where-utils.d.ts +9 -0
- package/dist/builder/index.d.ts +1 -2
- package/dist/builder/vbi-builder.d.ts +6 -11
- package/dist/builder/vbi.d.ts +2 -2
- package/dist/index.cjs +521 -334
- package/dist/index.d.ts +1 -1
- package/dist/index.js +498 -329
- package/dist/types/builder/VBIInterface.d.ts +6 -5
- package/dist/types/dsl/{havingFilters → havingFilter}/having.d.ts +10 -6
- package/dist/types/dsl/index.d.ts +4 -5
- package/dist/types/dsl/measures/measures.d.ts +16 -2
- package/dist/types/dsl/vbi/vbi.d.ts +40 -4
- package/dist/types/dsl/{whereFilters → whereFilter}/filters.d.ts +10 -6
- package/dist/utils/filter-guards.d.ts +5 -0
- package/dist/utils/index.d.ts +1 -0
- package/package.json +5 -5
- package/dist/builder/sub-builders/havingFilters/index.d.ts +0 -3
- package/dist/builder/sub-builders/index.d.ts +0 -5
- /package/dist/builder/{sub-builders → features}/chart-type/index.d.ts +0 -0
- /package/dist/builder/{sub-builders → features}/dimensions/index.d.ts +0 -0
- /package/dist/builder/{sub-builders → features}/measures/index.d.ts +0 -0
- /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
|
-
|
|
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
|
-
|
|
42
|
+
preorderTraverse: ()=>vseed_namespaceObject.preorderTraverse,
|
|
37
43
|
buildVQuery: ()=>buildVQuery,
|
|
38
|
-
|
|
39
|
-
|
|
44
|
+
LocaleBuilder: ()=>LocaleBuilder,
|
|
45
|
+
UndoManager: ()=>UndoManager
|
|
40
46
|
});
|
|
41
47
|
const external_yjs_namespaceObject = require("yjs");
|
|
42
|
-
class
|
|
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
|
-
|
|
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
|
|
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
|
|
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(
|
|
70
|
-
this.dsl.get('
|
|
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
|
|
91
|
+
const node = new MeasureNodeBuilder(yMap);
|
|
74
92
|
callback(node);
|
|
75
93
|
return this;
|
|
76
94
|
}
|
|
77
95
|
remove(field) {
|
|
78
|
-
const
|
|
79
|
-
const index =
|
|
80
|
-
if (-1 !== index) this.dsl.get('
|
|
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
|
|
85
|
-
const index =
|
|
86
|
-
if (-1 === index) throw new Error(`
|
|
87
|
-
const
|
|
88
|
-
const node = new
|
|
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
|
|
94
|
-
const index =
|
|
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
|
|
114
|
+
return new MeasureNodeBuilder(measures.get(index));
|
|
97
115
|
}
|
|
98
116
|
findAll() {
|
|
99
|
-
const
|
|
100
|
-
return
|
|
117
|
+
const measures = this.dsl.get('measures');
|
|
118
|
+
return measures.toArray().map((yMap)=>new MeasureNodeBuilder(yMap));
|
|
101
119
|
}
|
|
102
|
-
|
|
103
|
-
return this.dsl.get('
|
|
120
|
+
toJSON() {
|
|
121
|
+
return this.dsl.get('measures').toJSON();
|
|
104
122
|
}
|
|
105
123
|
observe(callback) {
|
|
106
|
-
this.dsl.get('
|
|
124
|
+
this.dsl.get('measures').observe(callback);
|
|
107
125
|
return ()=>{
|
|
108
|
-
this.dsl.get('
|
|
126
|
+
this.dsl.get('measures').unobserve(callback);
|
|
109
127
|
};
|
|
110
128
|
}
|
|
111
|
-
static
|
|
112
|
-
return '
|
|
129
|
+
static isMeasureNode(node) {
|
|
130
|
+
return 'encoding' in node || 'aggregate' in node;
|
|
113
131
|
}
|
|
114
|
-
static
|
|
132
|
+
static isMeasureGroup(node) {
|
|
115
133
|
return 'children' in node;
|
|
116
134
|
}
|
|
117
135
|
}
|
|
118
|
-
class
|
|
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
|
-
|
|
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
|
|
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
|
|
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(
|
|
158
|
-
this.dsl.get('
|
|
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
|
|
167
|
+
const node = new DimensionNodeBuilder(yMap);
|
|
162
168
|
callback(node);
|
|
163
169
|
return this;
|
|
164
170
|
}
|
|
165
171
|
remove(field) {
|
|
166
|
-
const
|
|
167
|
-
const index =
|
|
168
|
-
if (-1 !== index) this.dsl.get('
|
|
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
|
|
173
|
-
const index =
|
|
174
|
-
if (-1 === index) throw new Error(`
|
|
175
|
-
const
|
|
176
|
-
const node = new
|
|
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
|
|
182
|
-
const index =
|
|
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
|
|
190
|
+
return new DimensionNodeBuilder(dimensions.get(index));
|
|
185
191
|
}
|
|
186
192
|
findAll() {
|
|
187
|
-
const
|
|
188
|
-
return
|
|
193
|
+
const dimensions = this.dsl.get('dimensions');
|
|
194
|
+
return dimensions.toArray().map((yMap)=>new DimensionNodeBuilder(yMap));
|
|
189
195
|
}
|
|
190
|
-
|
|
191
|
-
return this.dsl.get('
|
|
196
|
+
toJSON() {
|
|
197
|
+
return this.dsl.get('dimensions').toJSON();
|
|
192
198
|
}
|
|
193
199
|
observe(callback) {
|
|
194
|
-
this.dsl.get('
|
|
200
|
+
this.dsl.get('dimensions').observe(callback);
|
|
195
201
|
return ()=>{
|
|
196
|
-
this.dsl.get('
|
|
202
|
+
this.dsl.get('dimensions').unobserve(callback);
|
|
197
203
|
};
|
|
198
204
|
}
|
|
199
|
-
static
|
|
200
|
-
return '
|
|
205
|
+
static isDimensionNode(node) {
|
|
206
|
+
return 'alias' in node && !('children' in node);
|
|
201
207
|
}
|
|
202
|
-
static
|
|
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
|
-
|
|
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
|
-
|
|
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
|
|
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
|
-
|
|
257
|
-
conditions.push([
|
|
356
|
+
this.getConditions().push([
|
|
258
357
|
yMap
|
|
259
358
|
]);
|
|
260
|
-
const node = new
|
|
359
|
+
const node = new WhereFilterNodeBuilder(yMap);
|
|
261
360
|
callback(node);
|
|
262
361
|
return this;
|
|
263
362
|
}
|
|
264
363
|
addGroup(op, callback) {
|
|
265
|
-
const yMap =
|
|
266
|
-
|
|
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
|
|
368
|
+
const group = new WhereGroupBuilder(yMap);
|
|
274
369
|
callback(group);
|
|
275
370
|
return this;
|
|
276
371
|
}
|
|
277
372
|
remove(idOrIndex) {
|
|
278
|
-
const conditions = this.
|
|
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.
|
|
383
|
+
const conditions = this.getConditions();
|
|
289
384
|
conditions.delete(0, conditions.length);
|
|
290
385
|
return this;
|
|
291
386
|
}
|
|
292
|
-
|
|
387
|
+
toJSON() {
|
|
293
388
|
return this.yMap.toJSON();
|
|
294
389
|
}
|
|
295
390
|
}
|
|
296
|
-
class
|
|
297
|
-
|
|
298
|
-
doc;
|
|
391
|
+
class WhereFilterBuilder {
|
|
392
|
+
whereFilter;
|
|
299
393
|
constructor(doc, dsl){
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
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.
|
|
413
|
+
this.getConditions().push([
|
|
311
414
|
yMap
|
|
312
415
|
]);
|
|
313
|
-
const node = new
|
|
416
|
+
const node = new WhereFilterNodeBuilder(yMap);
|
|
314
417
|
callback(node);
|
|
315
418
|
return this;
|
|
316
419
|
}
|
|
317
420
|
addGroup(op, callback) {
|
|
318
|
-
const yMap =
|
|
319
|
-
|
|
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
|
|
425
|
+
const group = new WhereGroupBuilder(yMap);
|
|
326
426
|
callback(group);
|
|
327
427
|
return this;
|
|
328
428
|
}
|
|
329
429
|
update(id, callback) {
|
|
330
|
-
const
|
|
331
|
-
const
|
|
332
|
-
if (
|
|
333
|
-
|
|
334
|
-
const
|
|
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
|
|
340
|
-
const
|
|
341
|
-
if (
|
|
342
|
-
const yMap =
|
|
343
|
-
if (!
|
|
344
|
-
const group = new
|
|
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
|
|
450
|
+
const conditions = this.getConditions();
|
|
350
451
|
if ('number' == typeof idOrIndex) {
|
|
351
|
-
if (idOrIndex >= 0 && idOrIndex <
|
|
452
|
+
if (idOrIndex >= 0 && idOrIndex < conditions.length) conditions.delete(idOrIndex, 1);
|
|
352
453
|
} else {
|
|
353
|
-
const
|
|
354
|
-
if (
|
|
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
|
|
360
|
-
const
|
|
460
|
+
const conditions = this.getConditions();
|
|
461
|
+
const match = findEntry(conditions, id);
|
|
462
|
+
const yMap = match?.item;
|
|
361
463
|
if (!yMap) return;
|
|
362
|
-
if (
|
|
363
|
-
return new
|
|
464
|
+
if (WhereFilterBuilder.isGroup(yMap)) return new WhereGroupBuilder(yMap);
|
|
465
|
+
return new WhereFilterNodeBuilder(yMap);
|
|
364
466
|
}
|
|
365
467
|
clear() {
|
|
366
|
-
const
|
|
367
|
-
|
|
468
|
+
const conditions = this.getConditions();
|
|
469
|
+
conditions.delete(0, conditions.length);
|
|
368
470
|
return this;
|
|
369
471
|
}
|
|
370
|
-
|
|
371
|
-
return this.
|
|
472
|
+
toJSON() {
|
|
473
|
+
return this.whereFilter.toJSON();
|
|
372
474
|
}
|
|
373
475
|
observe(callback) {
|
|
374
|
-
this.
|
|
476
|
+
this.whereFilter.observeDeep(callback);
|
|
375
477
|
return ()=>{
|
|
376
|
-
this.
|
|
478
|
+
this.whereFilter.unobserveDeep(callback);
|
|
377
479
|
};
|
|
378
480
|
}
|
|
379
481
|
static isGroup(yMap) {
|
|
380
|
-
return
|
|
482
|
+
return isWhereGroup(yMap);
|
|
381
483
|
}
|
|
382
484
|
static isNode(yMap) {
|
|
383
485
|
return void 0 !== yMap.get('field');
|
|
384
486
|
}
|
|
385
487
|
}
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
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
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
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
|
|
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
|
-
|
|
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
|
|
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
|
-
|
|
481
|
-
conditions.push([
|
|
562
|
+
this.getConditions().push([
|
|
482
563
|
yMap
|
|
483
564
|
]);
|
|
484
|
-
const node = new
|
|
565
|
+
const node = new HavingFilterNodeBuilder(yMap);
|
|
485
566
|
callback(node);
|
|
486
567
|
return this;
|
|
487
568
|
}
|
|
488
569
|
addGroup(op, callback) {
|
|
489
|
-
const yMap =
|
|
490
|
-
|
|
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
|
|
574
|
+
const group = new HavingGroupBuilder(yMap);
|
|
498
575
|
callback(group);
|
|
499
576
|
return this;
|
|
500
577
|
}
|
|
501
578
|
remove(idOrIndex) {
|
|
502
|
-
const conditions = this.
|
|
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.
|
|
589
|
+
const conditions = this.getConditions();
|
|
513
590
|
conditions.delete(0, conditions.length);
|
|
514
591
|
return this;
|
|
515
592
|
}
|
|
516
|
-
|
|
593
|
+
toJSON() {
|
|
517
594
|
return this.yMap.toJSON();
|
|
518
595
|
}
|
|
519
596
|
}
|
|
520
|
-
class
|
|
521
|
-
|
|
522
|
-
doc;
|
|
597
|
+
class HavingFilterBuilder {
|
|
598
|
+
havingFilter;
|
|
523
599
|
constructor(doc, dsl){
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
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.
|
|
619
|
+
this.getConditions().push([
|
|
535
620
|
yMap
|
|
536
621
|
]);
|
|
537
|
-
const node = new
|
|
622
|
+
const node = new HavingFilterNodeBuilder(yMap);
|
|
538
623
|
callback(node);
|
|
539
624
|
return this;
|
|
540
625
|
}
|
|
541
626
|
addGroup(op, callback) {
|
|
542
|
-
const yMap =
|
|
543
|
-
|
|
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
|
|
631
|
+
const group = new HavingGroupBuilder(yMap);
|
|
550
632
|
callback(group);
|
|
551
633
|
return this;
|
|
552
634
|
}
|
|
553
635
|
update(id, callback) {
|
|
554
|
-
const
|
|
555
|
-
const
|
|
556
|
-
if (
|
|
557
|
-
|
|
558
|
-
const
|
|
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
|
|
564
|
-
const
|
|
565
|
-
if (
|
|
566
|
-
const yMap =
|
|
567
|
-
if (!
|
|
568
|
-
const group = new
|
|
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
|
|
656
|
+
const conditions = this.getConditions();
|
|
574
657
|
if ('number' == typeof idOrIndex) {
|
|
575
|
-
if (idOrIndex >= 0 && idOrIndex <
|
|
658
|
+
if (idOrIndex >= 0 && idOrIndex < conditions.length) conditions.delete(idOrIndex, 1);
|
|
576
659
|
} else {
|
|
577
|
-
const
|
|
578
|
-
if (
|
|
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
|
|
584
|
-
const
|
|
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 (
|
|
587
|
-
return new
|
|
670
|
+
if (HavingFilterBuilder.isGroup(yMap)) return new HavingGroupBuilder(yMap);
|
|
671
|
+
return new HavingFilterNodeBuilder(yMap);
|
|
588
672
|
}
|
|
589
673
|
clear() {
|
|
590
|
-
const
|
|
591
|
-
|
|
674
|
+
const conditions = this.getConditions();
|
|
675
|
+
conditions.delete(0, conditions.length);
|
|
592
676
|
return this;
|
|
593
677
|
}
|
|
594
|
-
|
|
595
|
-
return this.
|
|
678
|
+
toJSON() {
|
|
679
|
+
return this.havingFilter.toJSON();
|
|
596
680
|
}
|
|
597
681
|
observe(callback) {
|
|
598
|
-
this.
|
|
682
|
+
this.havingFilter.observeDeep(callback);
|
|
599
683
|
return ()=>{
|
|
600
|
-
this.
|
|
684
|
+
this.havingFilter.unobserveDeep(callback);
|
|
601
685
|
};
|
|
602
686
|
}
|
|
603
687
|
static isGroup(yMap) {
|
|
604
|
-
return
|
|
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
|
|
666
|
-
if (0 ===
|
|
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
|
|
829
|
+
function buildWhere_isWhereGroup(clause) {
|
|
677
830
|
return 'op' in clause && 'conditions' in clause;
|
|
678
831
|
}
|
|
679
832
|
function mapClauseToCondition(clause) {
|
|
680
|
-
if (
|
|
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
|
|
697
|
-
const
|
|
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
|
-
|
|
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
|
-
|
|
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
|
|
728
|
-
if (0 ===
|
|
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:
|
|
734
|
-
conditions:
|
|
925
|
+
op: havingFilter.op,
|
|
926
|
+
conditions: havingFilter.conditions.flatMap(buildHaving_mapClauseToCondition)
|
|
735
927
|
};
|
|
736
928
|
return result;
|
|
737
929
|
};
|
|
738
|
-
function
|
|
930
|
+
function buildHaving_isHavingGroup(clause) {
|
|
739
931
|
return 'op' in clause && 'conditions' in clause;
|
|
740
932
|
}
|
|
741
933
|
function buildHaving_mapClauseToCondition(clause) {
|
|
742
|
-
if (
|
|
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
|
-
|
|
796
|
-
|
|
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.
|
|
805
|
-
this.
|
|
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
|
-
|
|
865
|
-
|
|
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
|
-
|
|
918
|
-
|
|
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",
|