3xpr 1.15.27 → 3.0.0
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/CHANGELOG.md +22 -0
- package/expression/application/expressions.d.ts +1 -0
- package/expression/application/expressions.d.ts.map +1 -0
- package/expression/application/expressions.js.map +1 -1
- package/expression/application/index.d.ts +1 -0
- package/expression/application/index.d.ts.map +1 -0
- package/expression/application/index.js.map +1 -1
- package/expression/application/useCases/convert.d.ts +1 -0
- package/expression/application/useCases/convert.d.ts.map +1 -0
- package/expression/application/useCases/convert.js.map +1 -1
- package/expression/application/useCases/executor.d.ts +1 -0
- package/expression/application/useCases/executor.d.ts.map +1 -0
- package/expression/application/useCases/executor.js.map +1 -1
- package/expression/application/useCases/executorObserveDecorator.d.ts +1 -0
- package/expression/application/useCases/executorObserveDecorator.d.ts.map +1 -0
- package/expression/application/useCases/executorObserveDecorator.js.map +1 -1
- package/expression/domain/expressions.d.ts +1 -0
- package/expression/domain/expressions.d.ts.map +1 -0
- package/expression/domain/expressions.js.map +1 -1
- package/expression/domain/index.d.ts +1 -0
- package/expression/domain/index.d.ts.map +1 -0
- package/expression/domain/index.js.map +1 -1
- package/expression/infrastructure/convertFrom/convertFromFunction.d.ts +1 -0
- package/expression/infrastructure/convertFrom/convertFromFunction.d.ts.map +1 -0
- package/expression/infrastructure/convertFrom/convertFromFunction.js.map +1 -1
- package/expression/infrastructure/convertFrom/convertFromGraphql.d.ts +1 -0
- package/expression/infrastructure/convertFrom/convertFromGraphql.d.ts.map +1 -0
- package/expression/infrastructure/convertFrom/convertFromGraphql.js.map +1 -1
- package/expression/infrastructure/expressionsBuilder.d.ts +1 -0
- package/expression/infrastructure/expressionsBuilder.d.ts.map +1 -0
- package/expression/infrastructure/expressionsBuilder.js.map +1 -1
- package/expression/infrastructure/helper.d.ts +1 -0
- package/expression/infrastructure/helper.d.ts.map +1 -0
- package/expression/infrastructure/helper.js.map +1 -1
- package/expression/infrastructure/index.d.ts +1 -0
- package/expression/infrastructure/index.d.ts.map +1 -0
- package/expression/infrastructure/index.js.map +1 -1
- package/expression/infrastructure/library.d.ts +6 -0
- package/expression/infrastructure/library.d.ts.map +1 -0
- package/expression/infrastructure/library.js +735 -613
- package/expression/infrastructure/library.js.map +1 -1
- package/index.d.ts +1 -0
- package/index.d.ts.map +1 -0
- package/index.js.map +1 -1
- package/jest-unit-config.json +1 -1
- package/model/application/index.d.ts +1 -0
- package/model/application/index.d.ts.map +1 -0
- package/model/application/index.js.map +1 -1
- package/model/application/modelService.d.ts +1 -0
- package/model/application/modelService.d.ts.map +1 -0
- package/model/application/modelService.js +1 -1
- package/model/application/modelService.js.map +1 -1
- package/model/domain/index.d.ts +1 -0
- package/model/domain/index.d.ts.map +1 -0
- package/model/domain/index.js.map +1 -1
- package/model/domain/library.d.ts +1 -0
- package/model/domain/library.d.ts.map +1 -0
- package/model/domain/library.js.map +1 -1
- package/model/domain/services.d.ts +1 -0
- package/model/domain/services.d.ts.map +1 -0
- package/model/domain/services.js.map +1 -1
- package/operand/application/facade.d.ts +1 -0
- package/operand/application/facade.d.ts.map +1 -0
- package/operand/application/facade.js.map +1 -1
- package/operand/application/index.d.ts +1 -0
- package/operand/application/index.d.ts.map +1 -0
- package/operand/application/index.js.map +1 -1
- package/operand/application/services/builder.d.ts +1 -0
- package/operand/application/services/builder.d.ts.map +1 -0
- package/operand/application/services/builder.js.map +1 -1
- package/operand/application/services/builderCacheDecorator.d.ts +1 -0
- package/operand/application/services/builderCacheDecorator.d.ts.map +1 -0
- package/operand/application/services/builderCacheDecorator.js.map +1 -1
- package/operand/application/services/factory.d.ts +1 -0
- package/operand/application/services/factory.d.ts.map +1 -0
- package/operand/application/services/factory.js.map +1 -1
- package/operand/application/services/normalizer.d.ts +1 -0
- package/operand/application/services/normalizer.d.ts.map +1 -0
- package/operand/application/services/normalizer.js +0 -4
- package/operand/application/services/normalizer.js.map +1 -1
- package/operand/application/services/parameterService.d.ts +1 -0
- package/operand/application/services/parameterService.d.ts.map +1 -0
- package/operand/application/services/parameterService.js +0 -1
- package/operand/application/services/parameterService.js.map +1 -1
- package/operand/application/services/parser.d.ts +1 -0
- package/operand/application/services/parser.d.ts.map +1 -0
- package/operand/application/services/parser.js.map +1 -1
- package/operand/application/services/serializer.d.ts +1 -0
- package/operand/application/services/serializer.d.ts.map +1 -0
- package/operand/application/services/serializer.js.map +1 -1
- package/operand/application/services/typeService.d.ts +1 -0
- package/operand/application/services/typeService.d.ts.map +1 -0
- package/operand/application/services/typeService.js.map +1 -1
- package/operand/application/useCases/build.d.ts +1 -0
- package/operand/application/useCases/build.d.ts.map +1 -0
- package/operand/application/useCases/build.js.map +1 -1
- package/operand/application/useCases/clone.d.ts +1 -0
- package/operand/application/useCases/clone.d.ts.map +1 -0
- package/operand/application/useCases/clone.js.map +1 -1
- package/operand/application/useCases/complete.d.ts +1 -0
- package/operand/application/useCases/complete.d.ts.map +1 -0
- package/operand/application/useCases/complete.js.map +1 -1
- package/operand/application/useCases/normalize.d.ts +1 -0
- package/operand/application/useCases/normalize.d.ts.map +1 -0
- package/operand/application/useCases/normalize.js.map +1 -1
- package/operand/application/useCases/reduce.d.ts +1 -0
- package/operand/application/useCases/reduce.d.ts.map +1 -0
- package/operand/application/useCases/reduce.js.map +1 -1
- package/operand/domain/constBuilder.d.ts +1 -0
- package/operand/domain/constBuilder.d.ts.map +1 -0
- package/operand/domain/constBuilder.js.map +1 -1
- package/operand/domain/entities.d.ts +2 -0
- package/operand/domain/entities.d.ts.map +1 -0
- package/operand/domain/entities.js +5 -0
- package/operand/domain/entities.js.map +1 -1
- package/operand/domain/index.d.ts +1 -0
- package/operand/domain/index.d.ts.map +1 -0
- package/operand/domain/index.js.map +1 -1
- package/operand/domain/services.d.ts +1 -0
- package/operand/domain/services.d.ts.map +1 -0
- package/operand/domain/services.js.map +1 -1
- package/operand/infrastructure/constBuilder.d.ts +1 -0
- package/operand/infrastructure/constBuilder.d.ts.map +1 -0
- package/operand/infrastructure/constBuilder.js.map +1 -1
- package/operand/infrastructure/executors/expression.d.ts +1 -0
- package/operand/infrastructure/executors/expression.d.ts.map +1 -0
- package/operand/infrastructure/executors/expression.js.map +1 -1
- package/operand/infrastructure/executors/task.d.ts +1 -0
- package/operand/infrastructure/executors/task.d.ts.map +1 -0
- package/operand/infrastructure/executors/task.js.map +1 -1
- package/operand/infrastructure/facadeBuilder.d.ts +1 -0
- package/operand/infrastructure/facadeBuilder.d.ts.map +1 -0
- package/operand/infrastructure/facadeBuilder.js.map +1 -1
- package/operand/infrastructure/helper.d.ts +1 -0
- package/operand/infrastructure/helper.d.ts.map +1 -0
- package/operand/infrastructure/helper.js.map +1 -1
- package/operand/infrastructure/index.d.ts +1 -0
- package/operand/infrastructure/index.d.ts.map +1 -0
- package/operand/infrastructure/index.js.map +1 -1
- package/package.json +11 -15
- package/shared/domain/base.d.ts +1 -0
- package/shared/domain/base.d.ts.map +1 -0
- package/shared/domain/base.js.map +1 -1
- package/shared/domain/context.d.ts +1 -0
- package/shared/domain/context.d.ts.map +1 -0
- package/shared/domain/context.js.map +1 -1
- package/shared/domain/index.d.ts +1 -0
- package/shared/domain/index.d.ts.map +1 -0
- package/shared/domain/index.js.map +1 -1
- package/shared/domain/observer.d.ts +1 -0
- package/shared/domain/observer.d.ts.map +1 -0
- package/shared/domain/observer.js.map +1 -1
- package/shared/domain/operand.d.ts +1 -0
- package/shared/domain/operand.d.ts.map +1 -0
- package/shared/domain/operand.js.map +1 -1
- package/shared/domain/signals.d.ts +1 -0
- package/shared/domain/signals.d.ts.map +1 -0
- package/shared/domain/signals.js.map +1 -1
- package/shared/infrastructure/helper.d.ts +1 -0
- package/shared/infrastructure/helper.d.ts.map +1 -0
- package/shared/infrastructure/helper.js.map +1 -1
- package/shared/infrastructure/index.d.ts +1 -0
- package/shared/infrastructure/index.d.ts.map +1 -0
- package/shared/infrastructure/index.js.map +1 -1
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.CoreLibrary = void 0;
|
|
4
|
+
const crypto_1 = require("crypto");
|
|
4
5
|
const domain_1 = require("../../shared/domain");
|
|
5
6
|
const domain_2 = require("../../operand/domain");
|
|
6
7
|
class CoreLibrary {
|
|
@@ -25,6 +26,11 @@ class CoreLibrary {
|
|
|
25
26
|
this.dateTimeFunctions(model);
|
|
26
27
|
this.conversionFunctions(model);
|
|
27
28
|
this.setsFunctions(model);
|
|
29
|
+
this.extAggregationFunctions(model);
|
|
30
|
+
this.windowFunctions(model);
|
|
31
|
+
this.jsonFunctions(model);
|
|
32
|
+
this.statisticalFunctions(model);
|
|
33
|
+
this.systemFunctions(model);
|
|
28
34
|
}
|
|
29
35
|
constants(model) {
|
|
30
36
|
model.addConstant('true', true);
|
|
@@ -67,7 +73,7 @@ class CoreLibrary {
|
|
|
67
73
|
model.addOperator('>(a:T,b:T):boolean', (a, b) => a > b, { priority: 4, description: 'Greater than' });
|
|
68
74
|
model.addOperator('<(a:T,b:T):boolean', (a, b) => a < b, { priority: 4, description: 'Less than' });
|
|
69
75
|
model.addOperator('>=(a:T,b:T):boolean', (a, b) => a >= b, { priority: 4, description: 'Greater than or equal' });
|
|
70
|
-
model.addOperator('<=(a:T,b:T):boolean', (a, b) => a <= b, { priority:
|
|
76
|
+
model.addOperator('<=(a:T,b:T):boolean', (a, b) => a <= b, { priority: 4, description: 'Less than or equal' });
|
|
71
77
|
model.addOperator('&&(a:boolean,b:boolean):boolean', new And(), { priority: 3, description: 'Logical AND' });
|
|
72
78
|
model.addOperator('||(a:boolean,b:boolean):boolean', new Or(), { priority: 3, description: 'Logical OR' });
|
|
73
79
|
model.addOperator('!(a:boolean):boolean', (a) => !a, { priority: 5, description: 'Logical NOT' });
|
|
@@ -76,18 +82,18 @@ class CoreLibrary {
|
|
|
76
82
|
model.addOperator('[](list:T[],index:any):T', (list, index) => list[index], { priority: 2, description: 'Index' });
|
|
77
83
|
model.addOperator('$(name:string):string', (name) => process.env[name], { priority: 9, description: 'Environment Variable' });
|
|
78
84
|
model.addOperator('=(a:T,b:T):T', new Assignment(), { priority: 1, description: 'Assignment' });
|
|
79
|
-
model.addOperator('+=(a:number,b:number):number', new
|
|
80
|
-
model.addOperator('-=(a:number,b:number):number', new
|
|
81
|
-
model.addOperator('*=(a:number,b:number):number', new
|
|
82
|
-
model.addOperator('/=(a:number,b:number):number', new
|
|
83
|
-
model.addOperator('**=(a:number,b:number):number', new
|
|
84
|
-
model.addOperator('//=(a:number,b:number):number', new
|
|
85
|
-
model.addOperator('%=(a:number,b:number):number', new
|
|
86
|
-
model.addOperator('&=(a:number,b:number):number', new
|
|
87
|
-
model.addOperator('|=(a:number,b:number):number', new
|
|
88
|
-
model.addOperator('^=(a:number,b:number):number', new
|
|
89
|
-
model.addOperator('<<=(a:number,b:number):number', new
|
|
90
|
-
model.addOperator('>>=(a:number,b:number):number', new
|
|
85
|
+
model.addOperator('+=(a:number,b:number):number', new AssignmentOp((a, b) => a + b), { priority: 1, description: 'Assignment Addition' });
|
|
86
|
+
model.addOperator('-=(a:number,b:number):number', new AssignmentOp((a, b) => a - b), { priority: 1, description: 'Assignment Subtraction' });
|
|
87
|
+
model.addOperator('*=(a:number,b:number):number', new AssignmentOp((a, b) => a * b), { priority: 1, description: 'Assignment Multiplication' });
|
|
88
|
+
model.addOperator('/=(a:number,b:number):number', new AssignmentOp((a, b) => a / b), { priority: 1, description: 'Assignment Division' });
|
|
89
|
+
model.addOperator('**=(a:number,b:number):number', new AssignmentOp((a, b) => a ** b), { priority: 1, description: 'Assignment Exponentiation' });
|
|
90
|
+
model.addOperator('//=(a:number,b:number):number', new AssignmentOp((a, b) => Math.floor(a / b)), { priority: 1, description: 'Assignment Floor Division' });
|
|
91
|
+
model.addOperator('%=(a:number,b:number):number', new AssignmentOp((a, b) => a % b), { priority: 1, description: 'Assignment Modulus' });
|
|
92
|
+
model.addOperator('&=(a:number,b:number):number', new AssignmentOp((a, b) => a & b), { priority: 1, description: 'Assignment Bitwise AND' });
|
|
93
|
+
model.addOperator('|=(a:number,b:number):number', new AssignmentOp((a, b) => a | b), { priority: 1, description: 'Assignment Bitwise OR' });
|
|
94
|
+
model.addOperator('^=(a:number,b:number):number', new AssignmentOp((a, b) => a ^ b), { priority: 1, description: 'Assignment Bitwise XOR' });
|
|
95
|
+
model.addOperator('<<=(a:number,b:number):number', new AssignmentOp((a, b) => a << b), { priority: 1, description: 'Assignment Bitwise Left Shift' });
|
|
96
|
+
model.addOperator('>>=(a:number,b:number):number', new AssignmentOp((a, b) => a >> b), { priority: 1, description: 'Assignment Bitwise Right Shift' });
|
|
91
97
|
}
|
|
92
98
|
generalFunctions(model) {
|
|
93
99
|
model.addFunction('sleep(ms?: number):void', async (ms = 0) => {
|
|
@@ -100,6 +106,7 @@ class CoreLibrary {
|
|
|
100
106
|
nullFunctions(model) {
|
|
101
107
|
model.addFunction('nvl(value:T, default:T):T', (value, _default) => this.helper.utils.nvl(value, _default), { description: 'Null value' });
|
|
102
108
|
model.addFunction('nvl2(value:any, a:T,b:T):T', (value, a, b) => this.helper.utils.nvl2(value, a, b), { description: 'Null value' });
|
|
109
|
+
model.addFunctionAlias('ifNull', 'nvl');
|
|
103
110
|
}
|
|
104
111
|
comparisonFunctions(model) {
|
|
105
112
|
model.addFunction('between(value:T,from:T,to:T):boolean', (value, from, to) => this.helper.val.between(value, from, to), { description: 'Between' });
|
|
@@ -109,7 +116,7 @@ class CoreLibrary {
|
|
|
109
116
|
if (source === undefined || values === undefined) {
|
|
110
117
|
return false;
|
|
111
118
|
}
|
|
112
|
-
if (values.length === 1 && Array.isArray(values)) {
|
|
119
|
+
if (values.length === 1 && Array.isArray(values[0])) {
|
|
113
120
|
return values[0].includes(source);
|
|
114
121
|
}
|
|
115
122
|
else {
|
|
@@ -138,13 +145,19 @@ class CoreLibrary {
|
|
|
138
145
|
model.addFunction('isDateFormat(value:string):boolean', (value) => this.helper.val.isDateFormat(value), { description: 'Check if value is date format' });
|
|
139
146
|
model.addFunction('isDateTimeFormat(value:string):boolean', (value) => this.helper.val.isDateTimeFormat(value), { description: 'Check if value is date time format' });
|
|
140
147
|
model.addFunction('isTimeFormat(value:string):boolean', (value) => this.helper.val.isTimeFormat(value), { description: 'Check if value is time format' });
|
|
148
|
+
model.addFunction('coalesce(...values:T):T', (...values) => { var _a; return (_a = values.find(v => v !== null && v !== undefined)) !== null && _a !== void 0 ? _a : null; }, { description: 'First non-null value' });
|
|
149
|
+
model.addFunction('nullIf(a:T,b:T):T', (a, b) => a === b ? null : a, { description: 'Null if two values are equal' });
|
|
150
|
+
model.addFunction('greatest(...values:T):T', (...values) => values.filter(v => v !== null && v !== undefined).reduce((m, v) => v > m ? v : m), { description: 'Greatest of values' });
|
|
151
|
+
model.addFunction('least(...values:T):T', (...values) => values.filter(v => v !== null && v !== undefined).reduce((m, v) => v < m ? v : m), { description: 'Least of values' });
|
|
152
|
+
model.addFunction('iif(condition:boolean,trueValue:T,falseValue:T):T', (condition, trueValue, falseValue) => condition ? trueValue : falseValue, { description: 'Inline if' });
|
|
153
|
+
model.addFunction('choose(index:integer,...values:T):T', (index, ...values) => index >= 1 && index <= values.length ? values[index - 1] : null, { description: 'Choose value by 1-based index' });
|
|
141
154
|
}
|
|
142
155
|
numberFunctions(model) {
|
|
143
156
|
model.addFunction('abs(x:number):number', Math.abs, { description: 'Absolute value' });
|
|
144
157
|
model.addFunction('acos(x:number):number', Math.acos, { description: 'Arc cosine' });
|
|
145
158
|
model.addFunction('asin(x:number):number', Math.asin, { description: 'Arc sine' });
|
|
146
159
|
model.addFunction('atan(x:number):number', Math.atan, { description: 'Arc tangent' });
|
|
147
|
-
model.addFunction('atan2(x:number):number', Math.atan2, { description: 'Arc tangent of two variables' });
|
|
160
|
+
model.addFunction('atan2(y:number,x:number):number', Math.atan2, { description: 'Arc tangent of two variables' });
|
|
148
161
|
model.addFunction('ceil(x:number):number', Math.ceil, { description: 'Ceiling' });
|
|
149
162
|
model.addFunction('cos(x:number):number', Math.cos, { description: 'Cosine' });
|
|
150
163
|
model.addFunction('cosh(x:number):number', Math.cosh, { description: 'Hyperbolic cosine' });
|
|
@@ -161,6 +174,14 @@ class CoreLibrary {
|
|
|
161
174
|
model.addFunction('tan(x:number):number', Math.tan, { description: 'Tangent' });
|
|
162
175
|
model.addFunction('tanh(x:number):number', Math.tanh, { description: 'Hyperbolic tangent' });
|
|
163
176
|
model.addFunction('trunc(x:number):number', Math.trunc, { description: 'Truncate' });
|
|
177
|
+
model.addFunctionAlias('mod', 'remainder');
|
|
178
|
+
model.addFunction('power(x:number,y:number):number', Math.pow, { description: 'Power' });
|
|
179
|
+
model.addFunction('sqrt(x:number):number', Math.sqrt, { description: 'Square root' });
|
|
180
|
+
model.addFunction('rand():number', Math.random, { deterministic: false, description: 'Random number between 0 and 1' });
|
|
181
|
+
model.addFunction('cot(x:number):number', (x) => 1 / Math.tan(x), { description: 'Cotangent' });
|
|
182
|
+
model.addFunction('degrees(x:number):number', (x) => x * (180 / Math.PI), { description: 'Radians to degrees' });
|
|
183
|
+
model.addFunction('radians(x:number):number', (x) => x * (Math.PI / 180), { description: 'Degrees to radians' });
|
|
184
|
+
model.addFunction('pi():number', () => Math.PI, { description: 'Pi constant' });
|
|
164
185
|
}
|
|
165
186
|
conversionFunctions(model) {
|
|
166
187
|
model.addFunction('toString(value:any):string', (value) => this.helper.str.toString(value), { description: 'Convert to string' });
|
|
@@ -191,7 +212,7 @@ class CoreLibrary {
|
|
|
191
212
|
model.addFunction('replace(value: string, source: string, target: string):string', (value, source, target) => this.helper.str.replace(value, source, target), { description: 'Replace' });
|
|
192
213
|
model.addFunction('rpad(value: string, len: number, pad: string):string', (value, len, pad) => value.padEnd(len, pad), { description: 'Right pad' });
|
|
193
214
|
model.addFunction('rtrim(value: string):string', (value) => value.trimEnd(), { description: 'Right trim' });
|
|
194
|
-
model.addFunction('substring(value: string, from: number,
|
|
215
|
+
model.addFunction('substring(value: string, from: number, end: number):string', (value, from, end) => value.substring(from, end), { description: 'Substring' });
|
|
195
216
|
model.addFunctionAlias('substr', 'substring');
|
|
196
217
|
model.addFunction('trim(value: string):string', (value) => value.trim(), { description: 'Trim' });
|
|
197
218
|
model.addFunction('upper(value: string):string', (value) => value.toUpperCase(), { description: 'Upper case' });
|
|
@@ -216,24 +237,81 @@ class CoreLibrary {
|
|
|
216
237
|
model.addFunction('split(value:string,separator:string=","):string[]', (value, separator = ',') => value.split(separator), { description: 'Split string' });
|
|
217
238
|
model.addFunction('startWith(value:string, sub:string, start:number):boolean', (value, sub, start) => value.startsWith(sub, start), { description: 'Starts with' });
|
|
218
239
|
model.addFunctionAlias('startsWith', 'startWith');
|
|
240
|
+
model.addFunction('left(value:string,n:integer):string', (value, n) => n > 0 ? value.substring(0, n) : '', { description: 'Left N characters' });
|
|
241
|
+
model.addFunction('right(value:string,n:integer):string', (value, n) => n > 0 ? value.substring(value.length - n) : '', { description: 'Right N characters' });
|
|
242
|
+
model.addFunction('concatWs(separator:string,...values:any):string', (separator, ...values) => values.filter(v => v !== null && v !== undefined).join(separator), { description: 'Concatenate with separator' });
|
|
243
|
+
model.addFunction('inStr(value:string,sub:string,start?:number):number', (value, sub, start = 0) => value.indexOf(sub, start), { description: 'Position of substring' });
|
|
244
|
+
model.addFunctionAlias('locate', 'inStr');
|
|
245
|
+
model.addFunctionAlias('charIndex', 'inStr');
|
|
246
|
+
model.addFunctionAlias('position', 'inStr');
|
|
247
|
+
model.addFunctionAlias('initCap', 'title');
|
|
248
|
+
model.addFunctionAlias('char', 'chr');
|
|
249
|
+
model.addFunction('repeat(value:string,n:integer):string', (value, n) => value.repeat(Math.max(0, n)), { description: 'Repeat string N times' });
|
|
250
|
+
model.addFunction('space(n:integer):string', (n) => ' '.repeat(Math.max(0, n)), { description: 'N space characters' });
|
|
251
|
+
model.addFunction('splitPart(value:string,delimiter:string,n:integer):string', (value, delimiter, n) => {
|
|
252
|
+
const parts = value.split(delimiter);
|
|
253
|
+
return n >= 1 && n <= parts.length ? parts[n - 1] : '';
|
|
254
|
+
}, { description: 'Nth part of split string (1-based)' });
|
|
255
|
+
model.addFunction('translate(value:string,from:string,to:string):string', (value, from, to) => {
|
|
256
|
+
let result = value;
|
|
257
|
+
for (let i = 0; i < from.length; i++) {
|
|
258
|
+
result = result.split(from[i]).join(i < to.length ? to[i] : '');
|
|
259
|
+
}
|
|
260
|
+
return result;
|
|
261
|
+
}, { description: 'Replace individual characters' });
|
|
262
|
+
model.addFunction('ascii(value:string):integer', (value) => value ? value.charCodeAt(0) : 0, { description: 'ASCII code of first character' });
|
|
263
|
+
model.addFunction('soundex(value:string):string', (value) => {
|
|
264
|
+
const map = { B: '1', F: '1', P: '1', V: '1', C: '2', G: '2', J: '2', K: '2', Q: '2', S: '2', X: '2', Z: '2', D: '3', T: '3', L: '4', M: '5', N: '5', R: '6' };
|
|
265
|
+
const s = value.toUpperCase().replace(/[^A-Z]/g, '');
|
|
266
|
+
if (!s)
|
|
267
|
+
return '0000';
|
|
268
|
+
let code = s[0];
|
|
269
|
+
let prev = map[s[0]] || '0';
|
|
270
|
+
for (let i = 1; i < s.length && code.length < 4; i++) {
|
|
271
|
+
const curr = map[s[i]] || '0';
|
|
272
|
+
if (curr !== '0' && curr !== prev)
|
|
273
|
+
code += curr;
|
|
274
|
+
prev = curr;
|
|
275
|
+
}
|
|
276
|
+
return code.padEnd(4, '0');
|
|
277
|
+
}, { description: 'Soundex phonetic code' });
|
|
278
|
+
model.addFunction('md5(value:string):string', (value) => (0, crypto_1.createHash)('md5').update(value).digest('hex'), { description: 'MD5 hash' });
|
|
279
|
+
model.addFunction('sha1(value:string):string', (value) => (0, crypto_1.createHash)('sha1').update(value).digest('hex'), { description: 'SHA1 hash' });
|
|
280
|
+
model.addFunction('sha2(value:string,bits?:number):string', (value, bits = 256) => (0, crypto_1.createHash)(`sha${bits}`).update(value).digest('hex'), { description: 'SHA2 hash' });
|
|
281
|
+
model.addFunction('regexpReplace(value:string,pattern:string,replacement:string):string', (value, pattern, replacement) => value.replace(new RegExp(pattern, 'g'), replacement), { description: 'Replace all regex matches' });
|
|
282
|
+
model.addFunctionAlias('regexpLike', 'test');
|
|
283
|
+
model.addFunction('regexpSubstr(value:string,pattern:string,n?:integer):string', (value, pattern, n = 1) => {
|
|
284
|
+
const matches = [...value.matchAll(new RegExp(pattern, 'g'))];
|
|
285
|
+
return n >= 1 && n <= matches.length ? matches[n - 1][0] : '';
|
|
286
|
+
}, { description: 'Extract Nth regex match' });
|
|
287
|
+
model.addFunction('regexpInstr(value:string,pattern:string,n?:integer):integer', (value, pattern, n = 1) => {
|
|
288
|
+
var _a;
|
|
289
|
+
const matches = [...value.matchAll(new RegExp(pattern, 'g'))];
|
|
290
|
+
return n >= 1 && n <= matches.length ? ((_a = matches[n - 1].index) !== null && _a !== void 0 ? _a : -1) + 1 : 0;
|
|
291
|
+
}, { description: 'Position of Nth regex match (1-based, 0 if not found)' });
|
|
292
|
+
model.addFunction('regexpCount(value:string,pattern:string):integer', (value, pattern) => (value.match(new RegExp(pattern, 'g')) || []).length, { description: 'Count regex matches' });
|
|
293
|
+
model.addFunction('reverseStr(value:string):string', (value) => value.split('').reverse().join(''), { description: 'Reverse string characters' });
|
|
294
|
+
model.addFunctionAlias('groupConcat', 'join');
|
|
295
|
+
model.addFunctionAlias('stringAgg', 'join');
|
|
296
|
+
model.addFunctionAlias('listAgg', 'join');
|
|
219
297
|
}
|
|
220
298
|
dateTimeFunctions(model) {
|
|
221
299
|
model.addFunction('curTime():time', () => {
|
|
222
|
-
const
|
|
223
|
-
return
|
|
300
|
+
const d = new Date();
|
|
301
|
+
return `${String(d.getHours()).padStart(2, '0')}:${String(d.getMinutes()).padStart(2, '0')}:${String(d.getSeconds()).padStart(2, '0')}`;
|
|
224
302
|
}, { description: 'Current time' });
|
|
225
303
|
model.addFunction('today():date', () => {
|
|
226
|
-
const
|
|
227
|
-
return
|
|
304
|
+
const d = new Date();
|
|
305
|
+
return `${d.getFullYear()}-${String(d.getMonth() + 1).padStart(2, '0')}-${String(d.getDate()).padStart(2, '0')}`;
|
|
228
306
|
}, { description: 'Current date' });
|
|
229
307
|
model.addFunction('now():dateTime', () => new Date().toISOString(), { description: 'Current date time' });
|
|
230
308
|
model.addFunction('time(value: string):time', (value) => {
|
|
231
|
-
const
|
|
232
|
-
return
|
|
309
|
+
const d = new Date(value);
|
|
310
|
+
return `${String(d.getHours()).padStart(2, '0')}:${String(d.getMinutes()).padStart(2, '0')}:${String(d.getSeconds()).padStart(2, '0')}`;
|
|
233
311
|
}, { description: 'Get time' });
|
|
234
312
|
model.addFunction('date(value: string):date', (value) => {
|
|
235
|
-
const
|
|
236
|
-
return
|
|
313
|
+
const d = new Date(value);
|
|
314
|
+
return `${d.getFullYear()}-${String(d.getMonth() + 1).padStart(2, '0')}-${String(d.getDate()).padStart(2, '0')}`;
|
|
237
315
|
}, { description: 'Get date' });
|
|
238
316
|
model.addFunction('dateTime(value: string):dateTime', (value) => new Date(value).toISOString(), { description: 'Get date time' });
|
|
239
317
|
model.addFunction('year(value: dateTime):integer', (value) => {
|
|
@@ -301,7 +379,7 @@ class CoreLibrary {
|
|
|
301
379
|
_date.setHours(_date.getHours() + _time.getHours());
|
|
302
380
|
_date.setMinutes(_date.getMinutes() + _time.getMinutes());
|
|
303
381
|
_date.setSeconds(_date.getSeconds() + _time.getSeconds());
|
|
304
|
-
_date.setMilliseconds(_date.
|
|
382
|
+
_date.setMilliseconds(_date.getMilliseconds() + _time.getMilliseconds());
|
|
305
383
|
return _date.toISOString();
|
|
306
384
|
}, { description: 'Add time' });
|
|
307
385
|
model.addFunction('subtractTime(date: dateTime, time: time):dateTime', (date, time) => {
|
|
@@ -310,33 +388,23 @@ class CoreLibrary {
|
|
|
310
388
|
_date.setHours(_date.getHours() - _time.getHours());
|
|
311
389
|
_date.setMinutes(_date.getMinutes() - _time.getMinutes());
|
|
312
390
|
_date.setSeconds(_date.getSeconds() - _time.getSeconds());
|
|
313
|
-
_date.setMilliseconds(_date.
|
|
391
|
+
_date.setMilliseconds(_date.getMilliseconds() - _time.getMilliseconds());
|
|
314
392
|
return _date.toISOString();
|
|
315
393
|
}, { description: 'Subtract time' });
|
|
316
394
|
model.addFunction('yearDiff(date1: dateTime, date2: dateTime):integer', (date1, date2) => {
|
|
317
|
-
|
|
318
|
-
const _date2 = new Date(date2);
|
|
319
|
-
return Math.abs(_date2.getFullYear() - _date1.getFullYear());
|
|
395
|
+
return Math.abs(new Date(date2).getFullYear() - new Date(date1).getFullYear());
|
|
320
396
|
}, { description: 'Year difference' });
|
|
321
397
|
model.addFunction('dayDiff(date1: dateTime, date2: dateTime):integer', (date1, date2) => {
|
|
322
|
-
|
|
323
|
-
const _date2 = new Date(date2);
|
|
324
|
-
return Math.floor((_date1.getTime() - _date2.getTime()) / (24 * 3600 * 1000));
|
|
398
|
+
return Math.abs(Math.floor((new Date(date1).getTime() - new Date(date2).getTime()) / (24 * 3600 * 1000)));
|
|
325
399
|
}, { description: 'Day difference' });
|
|
326
400
|
model.addFunction('hourDiff(date1: dateTime, date2: dateTime):integer', (date1, date2) => {
|
|
327
|
-
|
|
328
|
-
const _date2 = new Date(date2);
|
|
329
|
-
return Math.floor((_date1.getTime() - _date2.getTime()) / (3600 * 1000));
|
|
401
|
+
return Math.abs(Math.floor((new Date(date1).getTime() - new Date(date2).getTime()) / (3600 * 1000)));
|
|
330
402
|
}, { description: 'Hour difference' });
|
|
331
403
|
model.addFunction('secondDiff(date1: dateTime, date2: dateTime):integer', (date1, date2) => {
|
|
332
|
-
|
|
333
|
-
const _date2 = new Date(date2);
|
|
334
|
-
return Math.floor((_date1.getTime() - _date2.getTime()) / (1000));
|
|
404
|
+
return Math.abs(Math.floor((new Date(date1).getTime() - new Date(date2).getTime()) / 1000));
|
|
335
405
|
}, { description: 'Second difference' });
|
|
336
406
|
model.addFunction('millisecondDiff(date1: dateTime, date2: dateTime):integer', (date1, date2) => {
|
|
337
|
-
|
|
338
|
-
const _date2 = new Date(date2);
|
|
339
|
-
return Math.floor(_date1.getTime() - _date2.getTime());
|
|
407
|
+
return Math.floor(new Date(date1).getTime() - new Date(date2).getTime());
|
|
340
408
|
}, { description: 'Millisecond difference' });
|
|
341
409
|
model.addFunction('dayToDate(value: number):dateTime', (value) => {
|
|
342
410
|
return new Date(value * 24 * 3600 * 1000).toISOString();
|
|
@@ -350,9 +418,110 @@ class CoreLibrary {
|
|
|
350
418
|
model.addFunction('millisecondToDate(value: number):dateTime', (value) => {
|
|
351
419
|
return new Date(value).toISOString();
|
|
352
420
|
}, { description: 'Convert milliseconds to date time' });
|
|
421
|
+
model.addFunctionAlias('currentTimestamp', 'now');
|
|
422
|
+
model.addFunctionAlias('curDate', 'today');
|
|
423
|
+
model.addFunctionAlias('currentDate', 'today');
|
|
424
|
+
model.addFunctionAlias('currentTime', 'curTime');
|
|
425
|
+
model.addFunctionAlias('addMonths', 'addMonth');
|
|
426
|
+
model.addFunctionAlias('toDate', 'date');
|
|
427
|
+
model.addFunctionAlias('dateDiff', 'dayDiff');
|
|
428
|
+
model.addFunction('timeDiff(time1:time,time2:time):time', (time1, time2) => {
|
|
429
|
+
const t1 = new Date('2000-01-01T' + time1);
|
|
430
|
+
const t2 = new Date('2000-01-01T' + time2);
|
|
431
|
+
const totalSec = Math.abs(Math.floor((t1.getTime() - t2.getTime()) / 1000));
|
|
432
|
+
return `${String(Math.floor(totalSec / 3600)).padStart(2, '0')}:${String(Math.floor((totalSec % 3600) / 60)).padStart(2, '0')}:${String(totalSec % 60).padStart(2, '0')}`;
|
|
433
|
+
}, { description: 'Difference between two times' });
|
|
434
|
+
model.addFunction('monthsBetween(date1:dateTime,date2:dateTime):number', (date1, date2) => {
|
|
435
|
+
const d1 = new Date(date1);
|
|
436
|
+
const d2 = new Date(date2);
|
|
437
|
+
return Math.abs((d2.getFullYear() - d1.getFullYear()) * 12 + d2.getMonth() - d1.getMonth());
|
|
438
|
+
}, { description: 'Months between two dates' });
|
|
439
|
+
model.addFunction('extract(part:string,date:dateTime):integer', (part, date) => {
|
|
440
|
+
const d = new Date(date);
|
|
441
|
+
switch (part.toLowerCase()) {
|
|
442
|
+
case 'year': return d.getFullYear();
|
|
443
|
+
case 'month': return d.getMonth() + 1;
|
|
444
|
+
case 'day': return d.getDate();
|
|
445
|
+
case 'hour': return d.getHours();
|
|
446
|
+
case 'minute': return d.getMinutes();
|
|
447
|
+
case 'second': return d.getSeconds();
|
|
448
|
+
case 'millisecond': return d.getMilliseconds();
|
|
449
|
+
case 'weekday': return d.getDay();
|
|
450
|
+
case 'week': return Math.ceil(((d.getTime() - new Date(d.getFullYear(), 0, 1).getTime()) / 86400000 + new Date(d.getFullYear(), 0, 1).getDay() + 1) / 7);
|
|
451
|
+
case 'quarter': return Math.floor(d.getMonth() / 3) + 1;
|
|
452
|
+
default: return 0;
|
|
453
|
+
}
|
|
454
|
+
}, { description: 'Extract date part by name' });
|
|
455
|
+
model.addFunction('dateFormat(date:dateTime,format:string):string', (date, format) => {
|
|
456
|
+
const d = new Date(date);
|
|
457
|
+
return format
|
|
458
|
+
.replace('%Y', String(d.getFullYear()))
|
|
459
|
+
.replace('%y', String(d.getFullYear()).slice(2))
|
|
460
|
+
.replace('%m', String(d.getMonth() + 1).padStart(2, '0'))
|
|
461
|
+
.replace('%c', String(d.getMonth() + 1))
|
|
462
|
+
.replace('%d', String(d.getDate()).padStart(2, '0'))
|
|
463
|
+
.replace('%e', String(d.getDate()))
|
|
464
|
+
.replace('%H', String(d.getHours()).padStart(2, '0'))
|
|
465
|
+
.replace('%k', String(d.getHours()))
|
|
466
|
+
.replace('%i', String(d.getMinutes()).padStart(2, '0'))
|
|
467
|
+
.replace('%s', String(d.getSeconds()).padStart(2, '0'));
|
|
468
|
+
}, { description: 'Format date with pattern (%Y %m %d %H %i %s)' });
|
|
469
|
+
model.addFunctionAlias('toChar', 'dateFormat');
|
|
470
|
+
model.addFunction('lastDay(date:dateTime):date', (date) => {
|
|
471
|
+
const d = new Date(date);
|
|
472
|
+
d.setMonth(d.getMonth() + 1, 0);
|
|
473
|
+
return `${d.getFullYear()}-${String(d.getMonth() + 1).padStart(2, '0')}-${String(d.getDate()).padStart(2, '0')}`;
|
|
474
|
+
}, { description: 'Last day of month' });
|
|
475
|
+
model.addFunction('nextDay(date:dateTime,weekday:integer):date', (date, weekday) => {
|
|
476
|
+
const d = new Date(date);
|
|
477
|
+
const daysUntil = ((weekday - d.getDay() + 7) % 7) || 7;
|
|
478
|
+
d.setDate(d.getDate() + daysUntil);
|
|
479
|
+
return `${d.getFullYear()}-${String(d.getMonth() + 1).padStart(2, '0')}-${String(d.getDate()).padStart(2, '0')}`;
|
|
480
|
+
}, { description: 'Next occurrence of weekday (0=Sun,6=Sat)' });
|
|
481
|
+
model.addFunction('dayName(date:dateTime):string', (date) => ['Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday'][new Date(date).getDay()], { description: 'Name of weekday' });
|
|
482
|
+
model.addFunction('monthName(date:dateTime):string', (date) => ['January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December'][new Date(date).getMonth()], { description: 'Name of month' });
|
|
483
|
+
model.addFunction('week(date:dateTime):integer', (date) => {
|
|
484
|
+
const d = new Date(date);
|
|
485
|
+
const start = new Date(d.getFullYear(), 0, 1);
|
|
486
|
+
return Math.ceil(((d.getTime() - start.getTime()) / 86400000 + start.getDay() + 1) / 7);
|
|
487
|
+
}, { description: 'Week number of year' });
|
|
488
|
+
model.addFunction('quarter(date:dateTime):integer', (date) => Math.floor(new Date(date).getMonth() / 3) + 1, { description: 'Quarter of year (1-4)' });
|
|
489
|
+
model.addFunction('dateTrunc(date:dateTime,precision:string):dateTime', (date, precision) => {
|
|
490
|
+
const d = new Date(date);
|
|
491
|
+
switch (precision.toLowerCase()) {
|
|
492
|
+
case 'year': return new Date(Date.UTC(d.getUTCFullYear(), 0, 1)).toISOString();
|
|
493
|
+
case 'month': return new Date(Date.UTC(d.getUTCFullYear(), d.getUTCMonth(), 1)).toISOString();
|
|
494
|
+
case 'day': return new Date(Date.UTC(d.getUTCFullYear(), d.getUTCMonth(), d.getUTCDate())).toISOString();
|
|
495
|
+
case 'hour': return new Date(Date.UTC(d.getUTCFullYear(), d.getUTCMonth(), d.getUTCDate(), d.getUTCHours())).toISOString();
|
|
496
|
+
case 'minute': return new Date(Date.UTC(d.getUTCFullYear(), d.getUTCMonth(), d.getUTCDate(), d.getUTCHours(), d.getUTCMinutes())).toISOString();
|
|
497
|
+
default: return d.toISOString();
|
|
498
|
+
}
|
|
499
|
+
}, { description: 'Truncate date to precision (year/month/day/hour/minute), UTC-based' });
|
|
500
|
+
model.addFunction('makeDate(year:integer,dayOfYear:integer):date', (year, dayOfYear) => {
|
|
501
|
+
const d = new Date(year, 0, dayOfYear);
|
|
502
|
+
return `${d.getFullYear()}-${String(d.getMonth() + 1).padStart(2, '0')}-${String(d.getDate()).padStart(2, '0')}`;
|
|
503
|
+
}, { description: 'Create date from year and day-of-year' });
|
|
504
|
+
model.addFunction('unixTimestamp(date?:dateTime):integer', (date) => Math.floor((date ? new Date(date) : new Date()).getTime() / 1000), { description: 'Unix timestamp in seconds' });
|
|
505
|
+
model.addFunction('fromUnixTime(ts:integer):dateTime', (ts) => new Date(ts * 1000).toISOString(), { description: 'Date from Unix timestamp' });
|
|
506
|
+
model.addFunction('age(date1:dateTime,date2?:dateTime):string', (date1, date2) => {
|
|
507
|
+
const d1 = new Date(date1);
|
|
508
|
+
const d2 = date2 ? new Date(date2) : new Date();
|
|
509
|
+
let years = d2.getFullYear() - d1.getFullYear();
|
|
510
|
+
let months = d2.getMonth() - d1.getMonth();
|
|
511
|
+
let days = d2.getDate() - d1.getDate();
|
|
512
|
+
if (days < 0) {
|
|
513
|
+
months--;
|
|
514
|
+
days += 30;
|
|
515
|
+
}
|
|
516
|
+
if (months < 0) {
|
|
517
|
+
years--;
|
|
518
|
+
months += 12;
|
|
519
|
+
}
|
|
520
|
+
return `${years} years ${months} months ${days} days`;
|
|
521
|
+
}, { description: 'Age between two dates as text' });
|
|
353
522
|
}
|
|
354
523
|
arrayFunctions(model) {
|
|
355
|
-
model.addFunction('map(list: any[], predicate: T):T[]', new
|
|
524
|
+
model.addFunction('map(list: any[], predicate: T):T[]', new MapEval(this.builder, this.cloner, this.helper), { description: 'Map' });
|
|
356
525
|
model.addFunctionAlias('select', 'map');
|
|
357
526
|
model.addFunction('foreach(list: any[], predicate: any):void', new Foreach(), { description: 'Foreach' });
|
|
358
527
|
model.addFunctionAlias('each', 'foreach');
|
|
@@ -385,11 +554,10 @@ class CoreLibrary {
|
|
|
385
554
|
}
|
|
386
555
|
let to = from + records;
|
|
387
556
|
if (to > list.length) {
|
|
388
|
-
to = list.length
|
|
557
|
+
to = list.length;
|
|
389
558
|
}
|
|
390
559
|
return list.slice(from, to);
|
|
391
560
|
}, { description: 'Paging' });
|
|
392
|
-
// this.addFunction('update', ArrayFunctions.update, OperatorType.arrow, Update)
|
|
393
561
|
}
|
|
394
562
|
groupFunctions(model) {
|
|
395
563
|
model.addFunction('distinct(list: any[], predicate: any): any[]', new Distinct(this.helper), { description: 'Distinct' });
|
|
@@ -401,6 +569,191 @@ class CoreLibrary {
|
|
|
401
569
|
model.addFunction('avg(list: T[], value: number): number', new Avg(this.helper), { description: 'Average' });
|
|
402
570
|
model.addFunction('sum(list: T[], value: number): number', new Sum(this.helper), { description: 'Sum' });
|
|
403
571
|
}
|
|
572
|
+
extAggregationFunctions(model) {
|
|
573
|
+
model.addFunction('countDistinct(list:T[],predicate?:any):integer', new CountDistinct(), { description: 'Count distinct values' });
|
|
574
|
+
model.addFunction('sumDistinct(list:T[],predicate?:number):number', new SumDistinct(), { description: 'Sum of distinct values' });
|
|
575
|
+
model.addFunction('avgDistinct(list:T[],predicate?:number):number', new AvgDistinct(), { description: 'Average of distinct values' });
|
|
576
|
+
model.addFunction('median(list:T[],predicate?:number):number', new Median(), { description: 'Median value' });
|
|
577
|
+
model.addFunction('percentileCont(list:number[],p:number):number', (list, p) => {
|
|
578
|
+
if (!list.length)
|
|
579
|
+
return 0;
|
|
580
|
+
const sorted = [...list].sort((a, b) => a - b);
|
|
581
|
+
const pos = p * (sorted.length - 1);
|
|
582
|
+
const lo = Math.floor(pos);
|
|
583
|
+
const hi = Math.ceil(pos);
|
|
584
|
+
return lo === hi ? sorted[lo] : sorted[lo] + (sorted[hi] - sorted[lo]) * (pos - lo);
|
|
585
|
+
}, { description: 'Continuous percentile interpolation' });
|
|
586
|
+
model.addFunction('percentileDisc(list:number[],p:number):number', (list, p) => {
|
|
587
|
+
if (!list.length)
|
|
588
|
+
return 0;
|
|
589
|
+
const sorted = [...list].sort((a, b) => a - b);
|
|
590
|
+
return sorted[Math.min(Math.floor(p * sorted.length), sorted.length - 1)];
|
|
591
|
+
}, { description: 'Discrete percentile' });
|
|
592
|
+
model.addFunction('stdDev(list:T[],predicate?:number):number', new StdDevEval(false), { description: 'Sample standard deviation' });
|
|
593
|
+
model.addFunctionAlias('stdDevSamp', 'stdDev');
|
|
594
|
+
model.addFunction('stdDevPop(list:T[],predicate?:number):number', new StdDevEval(true), { description: 'Population standard deviation' });
|
|
595
|
+
model.addFunction('variance(list:T[],predicate?:number):number', new VarianceEval(false), { description: 'Sample variance' });
|
|
596
|
+
model.addFunctionAlias('varSamp', 'variance');
|
|
597
|
+
model.addFunction('varPop(list:T[],predicate?:number):number', new VarianceEval(true), { description: 'Population variance' });
|
|
598
|
+
model.addFunction('boolAnd(list:T[],predicate?:boolean):boolean', new BoolAndEval(), { description: 'True if all values are truthy' });
|
|
599
|
+
model.addFunctionAlias('every', 'boolAnd');
|
|
600
|
+
model.addFunction('boolOr(list:T[],predicate?:boolean):boolean', new BoolOrEval(), { description: 'True if any value is truthy' });
|
|
601
|
+
model.addFunction('bitAnd(list:T[],predicate?:number):number', new BitAndAgg(), { description: 'Bitwise AND of all values' });
|
|
602
|
+
model.addFunction('bitOr(list:T[],predicate?:number):number', new BitOrAgg(), { description: 'Bitwise OR of all values' });
|
|
603
|
+
}
|
|
604
|
+
windowFunctions(model) {
|
|
605
|
+
model.addFunction('rowNumber(list:T[]):number[]', (list) => list.map((_, i) => i + 1), { description: 'Row numbers 1..n' });
|
|
606
|
+
model.addFunction('rank(list:T[],predicate?:any):number[]', new RankEval(false), { description: 'Rank with gaps for ties' });
|
|
607
|
+
model.addFunction('denseRank(list:T[],predicate?:any):number[]', new RankEval(true), { description: 'Dense rank without gaps' });
|
|
608
|
+
model.addFunction('lag(list:T[],n?:integer):T[]', (list, n = 1) => list.map((_, i) => i >= n ? list[i - n] : null), { description: 'Values shifted N positions back' });
|
|
609
|
+
model.addFunction('lead(list:T[],n?:integer):T[]', (list, n = 1) => list.map((_, i) => i + n < list.length ? list[i + n] : null), { description: 'Values shifted N positions forward' });
|
|
610
|
+
model.addFunction('firstValue(list:T[]):T', (list) => list.length > 0 ? list[0] : null, { description: 'First value in list' });
|
|
611
|
+
model.addFunction('lastValue(list:T[]):T', (list) => list.length > 0 ? list[list.length - 1] : null, { description: 'Last value in list' });
|
|
612
|
+
model.addFunction('nthValue(list:T[],n:integer):T', (list, n) => n >= 1 && n <= list.length ? list[n - 1] : null, { description: 'Nth value in list (1-based)' });
|
|
613
|
+
model.addFunction('ntile(list:T[],n:integer):number[]', (list, n) => list.map((_, i) => Math.floor(i * n / list.length) + 1), { description: 'NTile bucket numbers' });
|
|
614
|
+
model.addFunction('cumeDist(list:T[]):number[]', (list) => { const len = list.length; return list.map((_, i) => (i + 1) / len); }, { description: 'Cumulative distribution 0..1' });
|
|
615
|
+
model.addFunction('percentRank(list:T[]):number[]', (list) => {
|
|
616
|
+
const len = list.length;
|
|
617
|
+
if (len <= 1)
|
|
618
|
+
return list.map(() => 0);
|
|
619
|
+
return list.map((_, i) => i / (len - 1));
|
|
620
|
+
}, { description: 'Percent rank 0..1' });
|
|
621
|
+
model.addFunction('sumOver(list:number[]):number[]', (list) => { let r = 0; return list.map(v => { r += v; return r; }); }, { description: 'Running sum' });
|
|
622
|
+
model.addFunction('avgOver(list:number[]):number[]', (list) => { let r = 0; return list.map((v, i) => { r += v; return r / (i + 1); }); }, { description: 'Running average' });
|
|
623
|
+
model.addFunction('countOver(list:T[]):number[]', (list) => list.map((_, i) => i + 1), { description: 'Running count' });
|
|
624
|
+
model.addFunction('minOver(list:number[]):number[]', (list) => { let m = Infinity; return list.map(v => { if (v < m)
|
|
625
|
+
m = v; return m; }); }, { description: 'Running minimum' });
|
|
626
|
+
model.addFunction('maxOver(list:number[]):number[]', (list) => { let m = -Infinity; return list.map(v => { if (v > m)
|
|
627
|
+
m = v; return m; }); }, { description: 'Running maximum' });
|
|
628
|
+
}
|
|
629
|
+
jsonFunctions(model) {
|
|
630
|
+
model.addFunction('jsonExtract(obj:any,path:string):any', (obj, path) => {
|
|
631
|
+
if (obj === null || obj === undefined)
|
|
632
|
+
return null;
|
|
633
|
+
const parts = path.replace(/^\$\.?/, '').split('.').filter(p => p);
|
|
634
|
+
let cur = obj;
|
|
635
|
+
for (const p of parts) {
|
|
636
|
+
if (cur === null || cur === undefined)
|
|
637
|
+
return null;
|
|
638
|
+
cur = cur[p];
|
|
639
|
+
}
|
|
640
|
+
return cur;
|
|
641
|
+
}, { description: 'Extract value from object by dot path ($. prefix optional)' });
|
|
642
|
+
model.addFunctionAlias('jsonValue', 'jsonExtract');
|
|
643
|
+
model.addFunctionAlias('jsonQuery', 'jsonExtract');
|
|
644
|
+
model.addFunction('jsonUnquote(value:string):any', (value) => { try {
|
|
645
|
+
return JSON.parse(value);
|
|
646
|
+
}
|
|
647
|
+
catch (_a) {
|
|
648
|
+
return value;
|
|
649
|
+
} }, { description: 'Parse JSON string, return as-is if invalid' });
|
|
650
|
+
model.addFunction('jsonArray(...values:any):any[]', (...values) => values, { description: 'Create JSON array' });
|
|
651
|
+
model.addFunction('jsonObject(...entries:any):any', (...entries) => {
|
|
652
|
+
const obj = {};
|
|
653
|
+
for (let i = 0; i + 1 < entries.length; i += 2)
|
|
654
|
+
obj[entries[i]] = entries[i + 1];
|
|
655
|
+
return obj;
|
|
656
|
+
}, { description: 'Create JSON object from key-value pairs' });
|
|
657
|
+
model.addFunction('jsonContains(obj:any,value:any):boolean', (obj, value) => {
|
|
658
|
+
if (!obj)
|
|
659
|
+
return false;
|
|
660
|
+
return JSON.stringify(obj).includes(JSON.stringify(value));
|
|
661
|
+
}, { description: 'Check if JSON contains value' });
|
|
662
|
+
model.addFunction('jsonMerge(a:any,b:any):any', (a, b) => (Object.assign(Object.assign({}, a), b)), { description: 'Merge two JSON objects' });
|
|
663
|
+
model.addFunction('jsonRemove(obj:any,key:string):any', (obj, key) => { const r = Object.assign({}, obj); delete r[key]; return r; }, { description: 'Remove property from JSON object' });
|
|
664
|
+
model.addFunction('jsonValid(value:string):boolean', (value) => { try {
|
|
665
|
+
JSON.parse(value);
|
|
666
|
+
return true;
|
|
667
|
+
}
|
|
668
|
+
catch (_a) {
|
|
669
|
+
return false;
|
|
670
|
+
} }, { description: 'Check if string is valid JSON' });
|
|
671
|
+
model.addFunctionAlias('jsonKeys', 'keys');
|
|
672
|
+
model.addFunction('jsonAgg(list:T[]):T[]', (list) => list, { description: 'Return list as JSON array' });
|
|
673
|
+
model.addFunctionAlias('jsonArrayAgg', 'jsonAgg');
|
|
674
|
+
model.addFunction('jsonObjectAgg(list:any[],keyProp:string,valueProp:string):any', (list, keyProp, valueProp) => {
|
|
675
|
+
const r = {};
|
|
676
|
+
for (const item of list)
|
|
677
|
+
r[item[keyProp]] = item[valueProp];
|
|
678
|
+
return r;
|
|
679
|
+
}, { description: 'Aggregate list to JSON object using key/value property names' });
|
|
680
|
+
model.addFunction('jsonModify(obj:any,path:string,value:any):any', (obj, path, value) => {
|
|
681
|
+
const result = JSON.parse(JSON.stringify(obj));
|
|
682
|
+
const parts = path.replace(/^\$\.?/, '').split('.').filter(p => p);
|
|
683
|
+
let cur = result;
|
|
684
|
+
for (let i = 0; i < parts.length - 1; i++) {
|
|
685
|
+
cur = cur[parts[i]];
|
|
686
|
+
}
|
|
687
|
+
if (parts.length > 0)
|
|
688
|
+
cur[parts[parts.length - 1]] = value;
|
|
689
|
+
return result;
|
|
690
|
+
}, { description: 'Set a value at a JSON path' });
|
|
691
|
+
}
|
|
692
|
+
statisticalFunctions(model) {
|
|
693
|
+
model.addFunction('corr(x:number[],y:number[]):number', (x, y) => {
|
|
694
|
+
const n = Math.min(x.length, y.length);
|
|
695
|
+
if (n === 0)
|
|
696
|
+
return 0;
|
|
697
|
+
const mx = x.slice(0, n).reduce((s, v) => s + v, 0) / n;
|
|
698
|
+
const my = y.slice(0, n).reduce((s, v) => s + v, 0) / n;
|
|
699
|
+
let num = 0;
|
|
700
|
+
let dx = 0;
|
|
701
|
+
let dy = 0;
|
|
702
|
+
for (let i = 0; i < n; i++) {
|
|
703
|
+
num += (x[i] - mx) * (y[i] - my);
|
|
704
|
+
dx += (x[i] - mx) ** 2;
|
|
705
|
+
dy += (y[i] - my) ** 2;
|
|
706
|
+
}
|
|
707
|
+
return dx === 0 || dy === 0 ? 0 : num / Math.sqrt(dx * dy);
|
|
708
|
+
}, { description: 'Pearson correlation coefficient' });
|
|
709
|
+
model.addFunction('covarPop(x:number[],y:number[]):number', (x, y) => {
|
|
710
|
+
const n = Math.min(x.length, y.length);
|
|
711
|
+
if (n === 0)
|
|
712
|
+
return 0;
|
|
713
|
+
const mx = x.slice(0, n).reduce((s, v) => s + v, 0) / n;
|
|
714
|
+
const my = y.slice(0, n).reduce((s, v) => s + v, 0) / n;
|
|
715
|
+
return x.slice(0, n).reduce((s, v, i) => s + (v - mx) * (y[i] - my), 0) / n;
|
|
716
|
+
}, { description: 'Population covariance' });
|
|
717
|
+
model.addFunction('covarSamp(x:number[],y:number[]):number', (x, y) => {
|
|
718
|
+
const n = Math.min(x.length, y.length);
|
|
719
|
+
if (n <= 1)
|
|
720
|
+
return 0;
|
|
721
|
+
const mx = x.slice(0, n).reduce((s, v) => s + v, 0) / n;
|
|
722
|
+
const my = y.slice(0, n).reduce((s, v) => s + v, 0) / n;
|
|
723
|
+
return x.slice(0, n).reduce((s, v, i) => s + (v - mx) * (y[i] - my), 0) / (n - 1);
|
|
724
|
+
}, { description: 'Sample covariance' });
|
|
725
|
+
model.addFunction('regrSlope(y:number[],x:number[]):number', (y, x) => {
|
|
726
|
+
const n = Math.min(x.length, y.length);
|
|
727
|
+
if (n === 0)
|
|
728
|
+
return 0;
|
|
729
|
+
const mx = x.slice(0, n).reduce((s, v) => s + v, 0) / n;
|
|
730
|
+
const my = y.slice(0, n).reduce((s, v) => s + v, 0) / n;
|
|
731
|
+
const num = x.slice(0, n).reduce((s, v, i) => s + (v - mx) * (y[i] - my), 0);
|
|
732
|
+
const den = x.slice(0, n).reduce((s, v) => s + (v - mx) ** 2, 0);
|
|
733
|
+
return den === 0 ? 0 : num / den;
|
|
734
|
+
}, { description: 'Slope of linear regression line' });
|
|
735
|
+
model.addFunction('regrIntercept(y:number[],x:number[]):number', (y, x) => {
|
|
736
|
+
const n = Math.min(x.length, y.length);
|
|
737
|
+
if (n === 0)
|
|
738
|
+
return 0;
|
|
739
|
+
const mx = x.slice(0, n).reduce((s, v) => s + v, 0) / n;
|
|
740
|
+
const my = y.slice(0, n).reduce((s, v) => s + v, 0) / n;
|
|
741
|
+
const num = x.slice(0, n).reduce((s, v, i) => s + (v - mx) * (y[i] - my), 0);
|
|
742
|
+
const den = x.slice(0, n).reduce((s, v) => s + (v - mx) ** 2, 0);
|
|
743
|
+
return my - (den === 0 ? 0 : num / den) * mx;
|
|
744
|
+
}, { description: 'Intercept of linear regression line' });
|
|
745
|
+
}
|
|
746
|
+
systemFunctions(model) {
|
|
747
|
+
model.addFunction('uuid():string', () => {
|
|
748
|
+
if (typeof globalThis.crypto !== 'undefined' && typeof globalThis.crypto.randomUUID === 'function') {
|
|
749
|
+
return globalThis.crypto.randomUUID();
|
|
750
|
+
}
|
|
751
|
+
return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, c => {
|
|
752
|
+
const r = Math.random() * 16 | 0;
|
|
753
|
+
return (c === 'x' ? r : (r & 0x3 | 0x8)).toString(16);
|
|
754
|
+
});
|
|
755
|
+
}, { deterministic: false, description: 'Generate UUID v4' });
|
|
756
|
+
}
|
|
404
757
|
setsFunctions(model) {
|
|
405
758
|
model.addFunction('union(a: T[], b: T[]): T[]', new Union(this.helper), { description: 'Union' });
|
|
406
759
|
model.addFunction('intersection(a: T[], b: T[]): T[]', new Intersection(this.helper), { description: 'Intersection' });
|
|
@@ -414,20 +767,14 @@ class And extends domain_2.PrototypeEvaluator {
|
|
|
414
767
|
return new And(operand);
|
|
415
768
|
}
|
|
416
769
|
eval(context) {
|
|
417
|
-
if (this.
|
|
418
|
-
throw new Error('Operand undefined');
|
|
419
|
-
}
|
|
420
|
-
if (!this.operand.children[0].eval(context))
|
|
770
|
+
if (!this.op.children[0].eval(context))
|
|
421
771
|
return false;
|
|
422
|
-
return this.
|
|
772
|
+
return this.op.children[1].eval(context);
|
|
423
773
|
}
|
|
424
774
|
async evalAsync(context) {
|
|
425
|
-
if (this.
|
|
426
|
-
throw new Error('Operand undefined');
|
|
427
|
-
}
|
|
428
|
-
if (!(await this.operand.children[0].solve(context)))
|
|
775
|
+
if (!(await this.op.children[0].solve(context)))
|
|
429
776
|
return false;
|
|
430
|
-
return await this.
|
|
777
|
+
return await this.op.children[1].solve(context);
|
|
431
778
|
}
|
|
432
779
|
}
|
|
433
780
|
class Or extends domain_2.PrototypeEvaluator {
|
|
@@ -435,20 +782,14 @@ class Or extends domain_2.PrototypeEvaluator {
|
|
|
435
782
|
return new Or(operand);
|
|
436
783
|
}
|
|
437
784
|
eval(context) {
|
|
438
|
-
if (this.
|
|
439
|
-
throw new Error('Operand undefined');
|
|
440
|
-
}
|
|
441
|
-
if (this.operand.children[0].eval(context))
|
|
785
|
+
if (this.op.children[0].eval(context))
|
|
442
786
|
return true;
|
|
443
|
-
return this.
|
|
787
|
+
return this.op.children[1].eval(context);
|
|
444
788
|
}
|
|
445
789
|
async evalAsync(context) {
|
|
446
|
-
if (this.
|
|
447
|
-
throw new Error('Operand undefined');
|
|
448
|
-
}
|
|
449
|
-
if (await this.operand.children[0].solve(context))
|
|
790
|
+
if (await this.op.children[0].solve(context))
|
|
450
791
|
return true;
|
|
451
|
-
return await this.
|
|
792
|
+
return await this.op.children[1].solve(context);
|
|
452
793
|
}
|
|
453
794
|
}
|
|
454
795
|
class Assignment extends domain_2.PrototypeEvaluator {
|
|
@@ -456,277 +797,38 @@ class Assignment extends domain_2.PrototypeEvaluator {
|
|
|
456
797
|
return new Assignment(operand);
|
|
457
798
|
}
|
|
458
799
|
eval(context) {
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
}
|
|
462
|
-
const value = this.operand.children[1].eval(context);
|
|
463
|
-
context.data.set(this.operand.children[0].name, value);
|
|
464
|
-
return value;
|
|
465
|
-
}
|
|
466
|
-
async evalAsync(context) {
|
|
467
|
-
if (this.operand === undefined) {
|
|
468
|
-
throw new Error('Operand undefined');
|
|
469
|
-
}
|
|
470
|
-
const value = await this.operand.children[1].solve(context);
|
|
471
|
-
context.data.set(this.operand.children[0].name, value);
|
|
472
|
-
return value;
|
|
473
|
-
}
|
|
474
|
-
}
|
|
475
|
-
class AssignmentAddition extends domain_2.PrototypeEvaluator {
|
|
476
|
-
clone(operand) {
|
|
477
|
-
return new AssignmentAddition(operand);
|
|
478
|
-
}
|
|
479
|
-
eval(context) {
|
|
480
|
-
if (this.operand === undefined) {
|
|
481
|
-
throw new Error('Operand undefined');
|
|
482
|
-
}
|
|
483
|
-
const value = this.operand.children[0].eval(context) + this.operand.children[1].eval(context);
|
|
484
|
-
context.data.set(this.operand.children[0].name, value);
|
|
485
|
-
return value;
|
|
486
|
-
}
|
|
487
|
-
async evalAsync(context) {
|
|
488
|
-
if (this.operand === undefined) {
|
|
489
|
-
throw new Error('Operand undefined');
|
|
490
|
-
}
|
|
491
|
-
const value = (await this.operand.children[0].solve(context)) + (await this.operand.children[1].solve(context));
|
|
492
|
-
context.data.set(this.operand.children[0].name, value);
|
|
493
|
-
return value;
|
|
494
|
-
}
|
|
495
|
-
}
|
|
496
|
-
class AssignmentSubtraction extends domain_2.PrototypeEvaluator {
|
|
497
|
-
clone(operand) {
|
|
498
|
-
return new AssignmentSubtraction(operand);
|
|
499
|
-
}
|
|
500
|
-
eval(context) {
|
|
501
|
-
if (this.operand === undefined) {
|
|
502
|
-
throw new Error('Operand undefined');
|
|
503
|
-
}
|
|
504
|
-
const value = this.operand.children[0].eval(context) - this.operand.children[1].eval(context);
|
|
505
|
-
context.data.set(this.operand.children[0].name, value);
|
|
506
|
-
return value;
|
|
507
|
-
}
|
|
508
|
-
async evalAsync(context) {
|
|
509
|
-
if (this.operand === undefined) {
|
|
510
|
-
throw new Error('Operand undefined');
|
|
511
|
-
}
|
|
512
|
-
const value = (await this.operand.children[0].solve(context)) - (await this.operand.children[1].solve(context));
|
|
513
|
-
context.data.set(this.operand.children[0].name, value);
|
|
514
|
-
return value;
|
|
515
|
-
}
|
|
516
|
-
}
|
|
517
|
-
class AssignmentMultiplication extends domain_2.PrototypeEvaluator {
|
|
518
|
-
clone(operand) {
|
|
519
|
-
return new AssignmentMultiplication(operand);
|
|
520
|
-
}
|
|
521
|
-
eval(context) {
|
|
522
|
-
if (this.operand === undefined) {
|
|
523
|
-
throw new Error('Operand undefined');
|
|
524
|
-
}
|
|
525
|
-
const value = this.operand.children[0].eval(context) * this.operand.children[1].eval(context);
|
|
526
|
-
context.data.set(this.operand.children[0].name, value);
|
|
527
|
-
return value;
|
|
528
|
-
}
|
|
529
|
-
async evalAsync(context) {
|
|
530
|
-
if (this.operand === undefined) {
|
|
531
|
-
throw new Error('Operand undefined');
|
|
532
|
-
}
|
|
533
|
-
const value = (await this.operand.children[0].solve(context)) * (await this.operand.children[1].solve(context));
|
|
534
|
-
context.data.set(this.operand.children[0].name, value);
|
|
535
|
-
return value;
|
|
536
|
-
}
|
|
537
|
-
}
|
|
538
|
-
class AssignmentDivision extends domain_2.PrototypeEvaluator {
|
|
539
|
-
clone(operand) {
|
|
540
|
-
return new AssignmentDivision(operand);
|
|
541
|
-
}
|
|
542
|
-
eval(context) {
|
|
543
|
-
if (this.operand === undefined) {
|
|
544
|
-
throw new Error('Operand undefined');
|
|
545
|
-
}
|
|
546
|
-
const value = this.operand.children[0].eval(context) / this.operand.children[1].eval(context);
|
|
547
|
-
context.data.set(this.operand.children[0].name, value);
|
|
548
|
-
return value;
|
|
549
|
-
}
|
|
550
|
-
async evalAsync(context) {
|
|
551
|
-
if (this.operand === undefined) {
|
|
552
|
-
throw new Error('Operand undefined');
|
|
553
|
-
}
|
|
554
|
-
const value = (await this.operand.children[0].solve(context)) / (await this.operand.children[1].solve(context));
|
|
555
|
-
context.data.set(this.operand.children[0].name, value);
|
|
556
|
-
return value;
|
|
557
|
-
}
|
|
558
|
-
}
|
|
559
|
-
class AssignmentExponentiation extends domain_2.PrototypeEvaluator {
|
|
560
|
-
clone(operand) {
|
|
561
|
-
return new AssignmentExponentiation(operand);
|
|
562
|
-
}
|
|
563
|
-
eval(context) {
|
|
564
|
-
if (this.operand === undefined) {
|
|
565
|
-
throw new Error('Operand undefined');
|
|
566
|
-
}
|
|
567
|
-
const value = (this.operand.children[0].eval(context)) ** (this.operand.children[1].eval(context));
|
|
568
|
-
context.data.set(this.operand.children[0].name, value);
|
|
569
|
-
return value;
|
|
570
|
-
}
|
|
571
|
-
async evalAsync(context) {
|
|
572
|
-
if (this.operand === undefined) {
|
|
573
|
-
throw new Error('Operand undefined');
|
|
574
|
-
}
|
|
575
|
-
const a = await this.operand.children[0].solve(context);
|
|
576
|
-
const b = await this.operand.children[1].solve(context);
|
|
577
|
-
const value = Math.pow(a, b);
|
|
578
|
-
context.data.set(this.operand.children[0].name, value);
|
|
579
|
-
return value;
|
|
580
|
-
}
|
|
581
|
-
}
|
|
582
|
-
class AssignmentFloorDivision extends domain_2.PrototypeEvaluator {
|
|
583
|
-
clone(operand) {
|
|
584
|
-
return new AssignmentFloorDivision(operand);
|
|
585
|
-
}
|
|
586
|
-
eval(context) {
|
|
587
|
-
if (this.operand === undefined) {
|
|
588
|
-
throw new Error('Operand undefined');
|
|
589
|
-
}
|
|
590
|
-
const value = Math.floor(this.operand.children[0].eval(context) / (this.operand.children[1].eval(context)));
|
|
591
|
-
context.data.set(this.operand.children[0].name, value);
|
|
592
|
-
return value;
|
|
593
|
-
}
|
|
594
|
-
async evalAsync(context) {
|
|
595
|
-
if (this.operand === undefined) {
|
|
596
|
-
throw new Error('Operand undefined');
|
|
597
|
-
}
|
|
598
|
-
const value = Math.floor((await this.operand.children[0].solve(context)) / (await this.operand.children[1].solve(context)));
|
|
599
|
-
context.data.set(this.operand.children[0].name, value);
|
|
600
|
-
return value;
|
|
601
|
-
}
|
|
602
|
-
}
|
|
603
|
-
class AssignmentMod extends domain_2.PrototypeEvaluator {
|
|
604
|
-
clone(operand) {
|
|
605
|
-
return new AssignmentMod(operand);
|
|
606
|
-
}
|
|
607
|
-
eval(context) {
|
|
608
|
-
if (this.operand === undefined) {
|
|
609
|
-
throw new Error('Operand undefined');
|
|
610
|
-
}
|
|
611
|
-
const value = this.operand.children[0].eval(context) % (this.operand.children[1].eval(context));
|
|
612
|
-
context.data.set(this.operand.children[0].name, value);
|
|
613
|
-
return value;
|
|
614
|
-
}
|
|
615
|
-
async evalAsync(context) {
|
|
616
|
-
if (this.operand === undefined) {
|
|
617
|
-
throw new Error('Operand undefined');
|
|
618
|
-
}
|
|
619
|
-
const value = (await this.operand.children[0].solve(context)) % (await this.operand.children[1].solve(context));
|
|
620
|
-
context.data.set(this.operand.children[0].name, value);
|
|
621
|
-
return value;
|
|
622
|
-
}
|
|
623
|
-
}
|
|
624
|
-
class AssignmentBitAnd extends domain_2.PrototypeEvaluator {
|
|
625
|
-
clone(operand) {
|
|
626
|
-
return new AssignmentBitAnd(operand);
|
|
627
|
-
}
|
|
628
|
-
eval(context) {
|
|
629
|
-
if (this.operand === undefined) {
|
|
630
|
-
throw new Error('Operand undefined');
|
|
631
|
-
}
|
|
632
|
-
const value = this.operand.children[0].eval(context) & (this.operand.children[1].eval(context));
|
|
633
|
-
context.data.set(this.operand.children[0].name, value);
|
|
634
|
-
return value;
|
|
635
|
-
}
|
|
636
|
-
async evalAsync(context) {
|
|
637
|
-
if (this.operand === undefined) {
|
|
638
|
-
throw new Error('Operand undefined');
|
|
639
|
-
}
|
|
640
|
-
const value = (await this.operand.children[0].solve(context)) & (await this.operand.children[1].solve(context));
|
|
641
|
-
context.data.set(this.operand.children[0].name, value);
|
|
642
|
-
return value;
|
|
643
|
-
}
|
|
644
|
-
}
|
|
645
|
-
class AssignmentBitOr extends domain_2.PrototypeEvaluator {
|
|
646
|
-
clone(operand) {
|
|
647
|
-
return new AssignmentBitOr(operand);
|
|
648
|
-
}
|
|
649
|
-
eval(context) {
|
|
650
|
-
if (this.operand === undefined) {
|
|
651
|
-
throw new Error('Operand undefined');
|
|
652
|
-
}
|
|
653
|
-
const value = (this.operand.children[0].eval(context)) | (this.operand.children[1].eval(context));
|
|
654
|
-
context.data.set(this.operand.children[0].name, value);
|
|
800
|
+
const value = this.op.children[1].eval(context);
|
|
801
|
+
context.data.set(this.op.children[0].name, value);
|
|
655
802
|
return value;
|
|
656
803
|
}
|
|
657
804
|
async evalAsync(context) {
|
|
658
|
-
|
|
659
|
-
|
|
660
|
-
}
|
|
661
|
-
const value = (await this.operand.children[0].solve(context)) | (await this.operand.children[1].solve(context));
|
|
662
|
-
context.data.set(this.operand.children[0].name, value);
|
|
805
|
+
const value = await this.op.children[1].solve(context);
|
|
806
|
+
context.data.set(this.op.children[0].name, value);
|
|
663
807
|
return value;
|
|
664
808
|
}
|
|
665
809
|
}
|
|
666
|
-
class
|
|
667
|
-
|
|
668
|
-
|
|
669
|
-
|
|
670
|
-
eval(context) {
|
|
671
|
-
if (this.operand === undefined) {
|
|
672
|
-
throw new Error('Operand undefined');
|
|
673
|
-
}
|
|
674
|
-
const value = (this.operand.children[0].eval(context)) ^ (this.operand.children[1].eval(context));
|
|
675
|
-
context.data.set(this.operand.children[0].name, value);
|
|
676
|
-
return value;
|
|
677
|
-
}
|
|
678
|
-
async evalAsync(context) {
|
|
679
|
-
if (this.operand === undefined) {
|
|
680
|
-
throw new Error('Operand undefined');
|
|
681
|
-
}
|
|
682
|
-
const value = (await this.operand.children[0].solve(context)) ^ (await this.operand.children[1].solve(context));
|
|
683
|
-
context.data.set(this.operand.children[0].name, value);
|
|
684
|
-
return value;
|
|
685
|
-
}
|
|
686
|
-
}
|
|
687
|
-
class AssignmentLeftShift extends domain_2.PrototypeEvaluator {
|
|
688
|
-
clone(operand) {
|
|
689
|
-
return new AssignmentLeftShift(operand);
|
|
690
|
-
}
|
|
691
|
-
eval(context) {
|
|
692
|
-
if (this.operand === undefined) {
|
|
693
|
-
throw new Error('Operand undefined');
|
|
694
|
-
}
|
|
695
|
-
const value = (this.operand.children[0].eval(context)) << (this.operand.children[1].eval(context));
|
|
696
|
-
context.data.set(this.operand.children[0].name, value);
|
|
697
|
-
return value;
|
|
698
|
-
}
|
|
699
|
-
async evalAsync(context) {
|
|
700
|
-
if (this.operand === undefined) {
|
|
701
|
-
throw new Error('Operand undefined');
|
|
702
|
-
}
|
|
703
|
-
const value = (await this.operand.children[0].solve(context)) << (await this.operand.children[1].solve(context));
|
|
704
|
-
context.data.set(this.operand.children[0].name, value);
|
|
705
|
-
return value;
|
|
810
|
+
class AssignmentOp extends domain_2.PrototypeEvaluator {
|
|
811
|
+
constructor(operate, operand) {
|
|
812
|
+
super(operand);
|
|
813
|
+
this.operate = operate;
|
|
706
814
|
}
|
|
707
|
-
}
|
|
708
|
-
class AssignmentRightShift extends domain_2.PrototypeEvaluator {
|
|
709
815
|
clone(operand) {
|
|
710
|
-
return new
|
|
816
|
+
return new AssignmentOp(this.operate, operand);
|
|
711
817
|
}
|
|
712
818
|
eval(context) {
|
|
713
|
-
|
|
714
|
-
|
|
715
|
-
}
|
|
716
|
-
const value = (this.operand.children[0].eval(context)) >> (this.operand.children[1].eval(context));
|
|
717
|
-
context.data.set(this.operand.children[0].name, value);
|
|
819
|
+
const value = this.operate(this.op.children[0].eval(context), this.op.children[1].eval(context));
|
|
820
|
+
context.data.set(this.op.children[0].name, value);
|
|
718
821
|
return value;
|
|
719
822
|
}
|
|
720
823
|
async evalAsync(context) {
|
|
721
|
-
|
|
722
|
-
|
|
723
|
-
|
|
724
|
-
|
|
725
|
-
context.data.set(this.operand.children[0].name, value);
|
|
824
|
+
const a = await this.op.children[0].solve(context);
|
|
825
|
+
const b = await this.op.children[1].solve(context);
|
|
826
|
+
const value = this.operate(a, b);
|
|
827
|
+
context.data.set(this.op.children[0].name, value);
|
|
726
828
|
return value;
|
|
727
829
|
}
|
|
728
830
|
}
|
|
729
|
-
class
|
|
831
|
+
class MapEval extends domain_2.PrototypeEvaluator {
|
|
730
832
|
// eslint-disable-next-line no-useless-constructor
|
|
731
833
|
constructor(builder, cloner, helper, operand) {
|
|
732
834
|
super(operand);
|
|
@@ -735,22 +837,18 @@ class Map extends domain_2.PrototypeEvaluator {
|
|
|
735
837
|
this.helper = helper;
|
|
736
838
|
}
|
|
737
839
|
clone(operand) {
|
|
738
|
-
return new
|
|
840
|
+
return new MapEval(this.builder, this.cloner, this.helper, operand);
|
|
739
841
|
}
|
|
740
842
|
eval(context) {
|
|
741
|
-
if (this.operand === undefined) {
|
|
742
|
-
throw new Error('Operand undefined');
|
|
743
|
-
}
|
|
744
843
|
const rows = [];
|
|
745
|
-
const list = this.
|
|
844
|
+
const list = this.op.children[0].eval(context);
|
|
746
845
|
if (!list) {
|
|
747
|
-
throw new Error(`Array ${this.
|
|
846
|
+
throw new Error(`Array ${this.op.children[0].name} undefined`);
|
|
748
847
|
}
|
|
749
|
-
if (this.
|
|
848
|
+
if (this.op.children[2].type === domain_1.OperandType.Obj) {
|
|
750
849
|
const groupers = [];
|
|
751
850
|
const aggregates = [];
|
|
752
|
-
for (const child of this.
|
|
753
|
-
// In the case of being an object the value to return, find out if there are fields that are summarized
|
|
851
|
+
for (const child of this.op.children[2].children) {
|
|
754
852
|
const keyValue = child;
|
|
755
853
|
if (keyValue) {
|
|
756
854
|
if (this.helper.operand.haveAggregates(keyValue.children[0])) {
|
|
@@ -762,10 +860,8 @@ class Map extends domain_2.PrototypeEvaluator {
|
|
|
762
860
|
}
|
|
763
861
|
}
|
|
764
862
|
if (aggregates.length > 0) {
|
|
765
|
-
|
|
766
|
-
const
|
|
767
|
-
// once you got all the keys you have to calculate the aggregates fields
|
|
768
|
-
const variable = this.operand.children[1];
|
|
863
|
+
const keys = this.helper.operand.getKeys(this.op.children[1], groupers, list, context);
|
|
864
|
+
const variable = this.op.children[1];
|
|
769
865
|
for (const key of keys) {
|
|
770
866
|
for (const keyValue of aggregates) {
|
|
771
867
|
const operandCloned = this.cloner.clone(keyValue.children[0], 'expression');
|
|
@@ -774,7 +870,6 @@ class Map extends domain_2.PrototypeEvaluator {
|
|
|
774
870
|
key.summarizers.push({ name: keyValue.name, value });
|
|
775
871
|
}
|
|
776
872
|
}
|
|
777
|
-
// build the list of results
|
|
778
873
|
for (const key of keys) {
|
|
779
874
|
const row = {};
|
|
780
875
|
for (const value of key.values) {
|
|
@@ -788,33 +883,28 @@ class Map extends domain_2.PrototypeEvaluator {
|
|
|
788
883
|
return rows;
|
|
789
884
|
}
|
|
790
885
|
}
|
|
791
|
-
else if (this.
|
|
886
|
+
else if (this.op.children[2].type === domain_1.OperandType.Var && !Array.isArray(list)) {
|
|
792
887
|
// Example orders.0.number
|
|
793
888
|
return list;
|
|
794
889
|
}
|
|
795
|
-
// simple case without aggregate functions
|
|
796
890
|
const childContext = context.newContext();
|
|
797
891
|
for (const item of list) {
|
|
798
|
-
childContext.data.set(this.
|
|
799
|
-
const row = this.
|
|
892
|
+
childContext.data.set(this.op.children[1].name, item);
|
|
893
|
+
const row = this.op.children[2].eval(childContext);
|
|
800
894
|
rows.push(row);
|
|
801
895
|
}
|
|
802
896
|
return rows;
|
|
803
897
|
}
|
|
804
898
|
async evalAsync(context) {
|
|
805
|
-
if (this.operand === undefined) {
|
|
806
|
-
throw new Error('Operand undefined');
|
|
807
|
-
}
|
|
808
899
|
const rows = [];
|
|
809
|
-
const list = await this.
|
|
900
|
+
const list = await this.op.children[0].solve(context);
|
|
810
901
|
if (!list) {
|
|
811
|
-
throw new Error(`Array ${this.
|
|
902
|
+
throw new Error(`Array ${this.op.children[0].name} undefined`);
|
|
812
903
|
}
|
|
813
|
-
if (this.
|
|
904
|
+
if (this.op.children[2].type === domain_1.OperandType.Obj) {
|
|
814
905
|
const groupers = [];
|
|
815
906
|
const aggregates = [];
|
|
816
|
-
for (const child of this.
|
|
817
|
-
// In the case of being an object the value to return, find out if there are fields that are summarized
|
|
907
|
+
for (const child of this.op.children[2].children) {
|
|
818
908
|
const keyValue = child;
|
|
819
909
|
if (keyValue) {
|
|
820
910
|
if (this.helper.operand.haveAggregates(keyValue.children[0])) {
|
|
@@ -826,10 +916,8 @@ class Map extends domain_2.PrototypeEvaluator {
|
|
|
826
916
|
}
|
|
827
917
|
}
|
|
828
918
|
if (aggregates.length > 0) {
|
|
829
|
-
|
|
830
|
-
const
|
|
831
|
-
// once you got all the keys you have to calculate the aggregates fields
|
|
832
|
-
const variable = this.operand.children[1];
|
|
919
|
+
const keys = this.helper.operand.getKeys(this.op.children[1], groupers, list, context);
|
|
920
|
+
const variable = this.op.children[1];
|
|
833
921
|
for (const key of keys) {
|
|
834
922
|
for (const keyValue of aggregates) {
|
|
835
923
|
const operandCloned = this.cloner.clone(keyValue.children[0], 'expression');
|
|
@@ -838,7 +926,6 @@ class Map extends domain_2.PrototypeEvaluator {
|
|
|
838
926
|
key.summarizers.push({ name: keyValue.name, value });
|
|
839
927
|
}
|
|
840
928
|
}
|
|
841
|
-
// build the list of results
|
|
842
929
|
for (const key of keys) {
|
|
843
930
|
const row = {};
|
|
844
931
|
for (const value of key.values) {
|
|
@@ -852,15 +939,14 @@ class Map extends domain_2.PrototypeEvaluator {
|
|
|
852
939
|
return rows;
|
|
853
940
|
}
|
|
854
941
|
}
|
|
855
|
-
else if (this.
|
|
942
|
+
else if (this.op.children[2].type === domain_1.OperandType.Var && !Array.isArray(list)) {
|
|
856
943
|
// Example orders.0.number
|
|
857
944
|
return list;
|
|
858
945
|
}
|
|
859
|
-
// simple case without aggregate functions
|
|
860
946
|
const childContext = context.newContext();
|
|
861
947
|
for (const item of list) {
|
|
862
|
-
childContext.data.set(this.
|
|
863
|
-
const row = await this.
|
|
948
|
+
childContext.data.set(this.op.children[1].name, item);
|
|
949
|
+
const row = await this.op.children[2].solve(childContext);
|
|
864
950
|
rows.push(row);
|
|
865
951
|
}
|
|
866
952
|
return rows;
|
|
@@ -875,16 +961,12 @@ class Distinct extends domain_2.PrototypeEvaluator {
|
|
|
875
961
|
return new Distinct(this.helper, operand);
|
|
876
962
|
}
|
|
877
963
|
eval(context) {
|
|
878
|
-
if (this.operand === undefined) {
|
|
879
|
-
throw new Error('Operand undefined');
|
|
880
|
-
}
|
|
881
964
|
const rows = [];
|
|
882
|
-
const list = this.
|
|
965
|
+
const list = this.op.children[0].eval(context);
|
|
883
966
|
if (!list) {
|
|
884
|
-
throw new Error(`Array ${this.
|
|
967
|
+
throw new Error(`Array ${this.op.children[0].name} undefined`);
|
|
885
968
|
}
|
|
886
|
-
if (this.
|
|
887
|
-
// simple case
|
|
969
|
+
if (this.op.children.length === 1) {
|
|
888
970
|
for (const item of list) {
|
|
889
971
|
if (rows.find((p) => p === item) === undefined) {
|
|
890
972
|
rows.push(item);
|
|
@@ -892,10 +974,8 @@ class Distinct extends domain_2.PrototypeEvaluator {
|
|
|
892
974
|
}
|
|
893
975
|
return rows;
|
|
894
976
|
}
|
|
895
|
-
else if (this.
|
|
896
|
-
|
|
897
|
-
const keys = this.helper.operand.getKeys(this.operand.children[1], this.operand.children[2].children, list, context.newContext());
|
|
898
|
-
// build the list of results
|
|
977
|
+
else if (this.op.children[2].type === domain_1.OperandType.Obj) {
|
|
978
|
+
const keys = this.helper.operand.getKeys(this.op.children[1], this.op.children[2].children, list, context.newContext());
|
|
899
979
|
for (const key of keys) {
|
|
900
980
|
const row = {};
|
|
901
981
|
for (const value of key.values) {
|
|
@@ -905,14 +985,13 @@ class Distinct extends domain_2.PrototypeEvaluator {
|
|
|
905
985
|
}
|
|
906
986
|
return rows;
|
|
907
987
|
}
|
|
908
|
-
else if (this.
|
|
988
|
+
else if (this.op.children[2].type === domain_1.OperandType.List) {
|
|
909
989
|
throw new Error('Distinct not support Array result');
|
|
910
990
|
}
|
|
911
|
-
// simple case without aggregate functions
|
|
912
991
|
const childContext = context.newContext();
|
|
913
992
|
for (const item of list) {
|
|
914
|
-
childContext.data.set(this.
|
|
915
|
-
const value = this.
|
|
993
|
+
childContext.data.set(this.op.children[1].name, item);
|
|
994
|
+
const value = this.op.children[2].eval(childContext);
|
|
916
995
|
if (rows.find((p) => p === value) === undefined) {
|
|
917
996
|
rows.push(value);
|
|
918
997
|
}
|
|
@@ -920,16 +999,12 @@ class Distinct extends domain_2.PrototypeEvaluator {
|
|
|
920
999
|
return rows;
|
|
921
1000
|
}
|
|
922
1001
|
async evalAsync(context) {
|
|
923
|
-
if (this.operand === undefined) {
|
|
924
|
-
throw new Error('Operand undefined');
|
|
925
|
-
}
|
|
926
1002
|
const rows = [];
|
|
927
|
-
const list = await this.
|
|
1003
|
+
const list = await this.op.children[0].solve(context);
|
|
928
1004
|
if (!list) {
|
|
929
|
-
throw new Error(`Array ${this.
|
|
1005
|
+
throw new Error(`Array ${this.op.children[0].name} undefined`);
|
|
930
1006
|
}
|
|
931
|
-
if (this.
|
|
932
|
-
// simple case
|
|
1007
|
+
if (this.op.children.length === 1) {
|
|
933
1008
|
for (const item of list) {
|
|
934
1009
|
if (rows.find((p) => p === item) === undefined) {
|
|
935
1010
|
rows.push(item);
|
|
@@ -937,10 +1012,8 @@ class Distinct extends domain_2.PrototypeEvaluator {
|
|
|
937
1012
|
}
|
|
938
1013
|
return rows;
|
|
939
1014
|
}
|
|
940
|
-
else if (this.
|
|
941
|
-
|
|
942
|
-
const keys = this.helper.operand.getKeys(this.operand.children[1], this.operand.children[2].children, list, context.newContext());
|
|
943
|
-
// build the list of results
|
|
1015
|
+
else if (this.op.children[2].type === domain_1.OperandType.Obj) {
|
|
1016
|
+
const keys = this.helper.operand.getKeys(this.op.children[1], this.op.children[2].children, list, context.newContext());
|
|
944
1017
|
for (const key of keys) {
|
|
945
1018
|
const row = {};
|
|
946
1019
|
for (const value of key.values) {
|
|
@@ -950,14 +1023,13 @@ class Distinct extends domain_2.PrototypeEvaluator {
|
|
|
950
1023
|
}
|
|
951
1024
|
return rows;
|
|
952
1025
|
}
|
|
953
|
-
else if (this.
|
|
1026
|
+
else if (this.op.children[2].type === domain_1.OperandType.List) {
|
|
954
1027
|
throw new Error('Distinct not support Array result');
|
|
955
1028
|
}
|
|
956
|
-
// simple case without aggregate functions
|
|
957
1029
|
const childContext = context.newContext();
|
|
958
1030
|
for (const item of list) {
|
|
959
|
-
childContext.data.set(this.
|
|
960
|
-
const value = await this.
|
|
1031
|
+
childContext.data.set(this.op.children[1].name, item);
|
|
1032
|
+
const value = await this.op.children[2].solve(childContext);
|
|
961
1033
|
if (rows.find((p) => p === value) === undefined) {
|
|
962
1034
|
rows.push(value);
|
|
963
1035
|
}
|
|
@@ -970,32 +1042,26 @@ class Foreach extends domain_2.PrototypeEvaluator {
|
|
|
970
1042
|
return new Foreach(operand);
|
|
971
1043
|
}
|
|
972
1044
|
eval(context) {
|
|
973
|
-
|
|
974
|
-
throw new Error('Operand undefined');
|
|
975
|
-
}
|
|
976
|
-
const list = this.operand.children[0].eval(context);
|
|
1045
|
+
const list = this.op.children[0].eval(context);
|
|
977
1046
|
if (!list) {
|
|
978
|
-
throw new Error(`Array ${this.
|
|
1047
|
+
throw new Error(`Array ${this.op.children[0].name} undefined`);
|
|
979
1048
|
}
|
|
980
1049
|
const childContext = context.newContext();
|
|
981
1050
|
for (const item of list) {
|
|
982
|
-
childContext.data.set(this.
|
|
983
|
-
this.
|
|
1051
|
+
childContext.data.set(this.op.children[1].name, item);
|
|
1052
|
+
this.op.children[2].eval(childContext);
|
|
984
1053
|
}
|
|
985
1054
|
return list;
|
|
986
1055
|
}
|
|
987
1056
|
async evalAsync(context) {
|
|
988
|
-
|
|
989
|
-
throw new Error('Operand undefined');
|
|
990
|
-
}
|
|
991
|
-
const list = await this.operand.children[0].solve(context);
|
|
1057
|
+
const list = await this.op.children[0].solve(context);
|
|
992
1058
|
if (!list) {
|
|
993
|
-
throw new Error(`Array ${this.
|
|
1059
|
+
throw new Error(`Array ${this.op.children[0].name} undefined`);
|
|
994
1060
|
}
|
|
995
1061
|
const childContext = context.newContext();
|
|
996
1062
|
for (const item of list) {
|
|
997
|
-
childContext.data.set(this.
|
|
998
|
-
await this.
|
|
1063
|
+
childContext.data.set(this.op.children[1].name, item);
|
|
1064
|
+
await this.op.children[2].solve(childContext);
|
|
999
1065
|
}
|
|
1000
1066
|
return list;
|
|
1001
1067
|
}
|
|
@@ -1005,36 +1071,30 @@ class Filter extends domain_2.PrototypeEvaluator {
|
|
|
1005
1071
|
return new Filter(operand);
|
|
1006
1072
|
}
|
|
1007
1073
|
eval(context) {
|
|
1008
|
-
if (this.operand === undefined) {
|
|
1009
|
-
throw new Error('Operand undefined');
|
|
1010
|
-
}
|
|
1011
1074
|
const rows = [];
|
|
1012
|
-
const list = this.
|
|
1075
|
+
const list = this.op.children[0].eval(context);
|
|
1013
1076
|
if (!list) {
|
|
1014
|
-
throw new Error(`Array ${this.
|
|
1077
|
+
throw new Error(`Array ${this.op.children[0].name} undefined`);
|
|
1015
1078
|
}
|
|
1016
1079
|
const childContext = context.newContext();
|
|
1017
1080
|
for (const item of list) {
|
|
1018
|
-
childContext.data.set(this.
|
|
1019
|
-
if (this.
|
|
1081
|
+
childContext.data.set(this.op.children[1].name, item);
|
|
1082
|
+
if (this.op.children[2].eval(childContext)) {
|
|
1020
1083
|
rows.push(item);
|
|
1021
1084
|
}
|
|
1022
1085
|
}
|
|
1023
1086
|
return rows;
|
|
1024
1087
|
}
|
|
1025
1088
|
async evalAsync(context) {
|
|
1026
|
-
if (this.operand === undefined) {
|
|
1027
|
-
throw new Error('Operand undefined');
|
|
1028
|
-
}
|
|
1029
1089
|
const rows = [];
|
|
1030
|
-
const list = await this.
|
|
1090
|
+
const list = await this.op.children[0].solve(context);
|
|
1031
1091
|
if (!list) {
|
|
1032
|
-
throw new Error(`Array ${this.
|
|
1092
|
+
throw new Error(`Array ${this.op.children[0].name} undefined`);
|
|
1033
1093
|
}
|
|
1034
1094
|
const childContext = context.newContext();
|
|
1035
1095
|
for (const item of list) {
|
|
1036
|
-
childContext.data.set(this.
|
|
1037
|
-
if (await this.
|
|
1096
|
+
childContext.data.set(this.op.children[1].name, item);
|
|
1097
|
+
if (await this.op.children[2].solve(childContext)) {
|
|
1038
1098
|
rows.push(item);
|
|
1039
1099
|
}
|
|
1040
1100
|
}
|
|
@@ -1046,21 +1106,18 @@ class Reverse extends domain_2.PrototypeEvaluator {
|
|
|
1046
1106
|
return new Reverse(operand);
|
|
1047
1107
|
}
|
|
1048
1108
|
eval(context) {
|
|
1049
|
-
|
|
1050
|
-
throw new Error('Operand undefined');
|
|
1051
|
-
}
|
|
1052
|
-
const list = this.operand.children[0].eval(context);
|
|
1109
|
+
const list = this.op.children[0].eval(context);
|
|
1053
1110
|
if (!list) {
|
|
1054
|
-
throw new Error(`Array ${this.
|
|
1111
|
+
throw new Error(`Array ${this.op.children[0].name} undefined`);
|
|
1055
1112
|
}
|
|
1056
|
-
if (this.
|
|
1113
|
+
if (this.op.children.length === 1) {
|
|
1057
1114
|
return list.reverse();
|
|
1058
1115
|
}
|
|
1059
1116
|
const values = [];
|
|
1060
1117
|
const childContext = context.newContext();
|
|
1061
1118
|
for (const item of list) {
|
|
1062
|
-
childContext.data.set(this.
|
|
1063
|
-
const value = this.
|
|
1119
|
+
childContext.data.set(this.op.children[1].name, item);
|
|
1120
|
+
const value = this.op.children[2].eval(childContext);
|
|
1064
1121
|
values.push({ value, p: item });
|
|
1065
1122
|
}
|
|
1066
1123
|
values.sort((a, b) => a.value > b.value ? 1 : a.value < b.value ? -1 : 0);
|
|
@@ -1068,21 +1125,18 @@ class Reverse extends domain_2.PrototypeEvaluator {
|
|
|
1068
1125
|
return values.map(p => p.p);
|
|
1069
1126
|
}
|
|
1070
1127
|
async evalAsync(context) {
|
|
1071
|
-
|
|
1072
|
-
throw new Error('Operand undefined');
|
|
1073
|
-
}
|
|
1074
|
-
const list = await this.operand.children[0].solve(context);
|
|
1128
|
+
const list = await this.op.children[0].solve(context);
|
|
1075
1129
|
if (!list) {
|
|
1076
|
-
throw new Error(`Array ${this.
|
|
1130
|
+
throw new Error(`Array ${this.op.children[0].name} undefined`);
|
|
1077
1131
|
}
|
|
1078
|
-
if (this.
|
|
1132
|
+
if (this.op.children.length === 1) {
|
|
1079
1133
|
return list.reverse();
|
|
1080
1134
|
}
|
|
1081
1135
|
const values = [];
|
|
1082
1136
|
const childContext = context.newContext();
|
|
1083
1137
|
for (const item of list) {
|
|
1084
|
-
childContext.data.set(this.
|
|
1085
|
-
const value = await this.
|
|
1138
|
+
childContext.data.set(this.op.children[1].name, item);
|
|
1139
|
+
const value = await this.op.children[2].solve(childContext);
|
|
1086
1140
|
values.push({ value, p: item });
|
|
1087
1141
|
}
|
|
1088
1142
|
values.sort((a, b) => a.value > b.value ? 1 : a.value < b.value ? -1 : 0);
|
|
@@ -1095,42 +1149,36 @@ class Sort extends domain_2.PrototypeEvaluator {
|
|
|
1095
1149
|
return new Sort(operand);
|
|
1096
1150
|
}
|
|
1097
1151
|
eval(context) {
|
|
1098
|
-
if (this.operand === undefined) {
|
|
1099
|
-
throw new Error('Operand undefined');
|
|
1100
|
-
}
|
|
1101
1152
|
const values = [];
|
|
1102
|
-
const list = this.
|
|
1153
|
+
const list = this.op.children[0].eval(context);
|
|
1103
1154
|
if (!list) {
|
|
1104
|
-
throw new Error(`Array ${this.
|
|
1155
|
+
throw new Error(`Array ${this.op.children[0].name} undefined`);
|
|
1105
1156
|
}
|
|
1106
|
-
if (this.
|
|
1157
|
+
if (this.op.children.length === 1) {
|
|
1107
1158
|
return list.sort();
|
|
1108
1159
|
}
|
|
1109
1160
|
const childContext = context.newContext();
|
|
1110
1161
|
for (const item of list) {
|
|
1111
|
-
childContext.data.set(this.
|
|
1112
|
-
const value = this.
|
|
1162
|
+
childContext.data.set(this.op.children[1].name, item);
|
|
1163
|
+
const value = this.op.children[2].eval(childContext);
|
|
1113
1164
|
values.push({ value, p: item });
|
|
1114
1165
|
}
|
|
1115
1166
|
values.sort((a, b) => a.value > b.value ? 1 : a.value < b.value ? -1 : 0);
|
|
1116
1167
|
return values.map(p => p.p);
|
|
1117
1168
|
}
|
|
1118
1169
|
async evalAsync(context) {
|
|
1119
|
-
if (this.operand === undefined) {
|
|
1120
|
-
throw new Error('Operand undefined');
|
|
1121
|
-
}
|
|
1122
1170
|
const values = [];
|
|
1123
|
-
const list = await this.
|
|
1171
|
+
const list = await this.op.children[0].solve(context);
|
|
1124
1172
|
if (!list) {
|
|
1125
|
-
throw new Error(`Array ${this.
|
|
1173
|
+
throw new Error(`Array ${this.op.children[0].name} undefined`);
|
|
1126
1174
|
}
|
|
1127
|
-
if (this.
|
|
1175
|
+
if (this.op.children.length === 1) {
|
|
1128
1176
|
return list.sort();
|
|
1129
1177
|
}
|
|
1130
1178
|
const childContext = context.newContext();
|
|
1131
1179
|
for (const item of list) {
|
|
1132
|
-
childContext.data.set(this.
|
|
1133
|
-
const value = await this.
|
|
1180
|
+
childContext.data.set(this.op.children[1].name, item);
|
|
1181
|
+
const value = await this.op.children[2].solve(childContext);
|
|
1134
1182
|
values.push({ value, p: item });
|
|
1135
1183
|
}
|
|
1136
1184
|
values.sort((a, b) => a.value > b.value ? 1 : a.value < b.value ? -1 : 0);
|
|
@@ -1142,36 +1190,30 @@ class Remove extends domain_2.PrototypeEvaluator {
|
|
|
1142
1190
|
return new Remove(operand);
|
|
1143
1191
|
}
|
|
1144
1192
|
eval(context) {
|
|
1145
|
-
if (this.operand === undefined) {
|
|
1146
|
-
throw new Error('Operand undefined');
|
|
1147
|
-
}
|
|
1148
1193
|
const rows = [];
|
|
1149
|
-
const list = this.
|
|
1194
|
+
const list = this.op.children[0].eval(context);
|
|
1150
1195
|
if (!list) {
|
|
1151
|
-
throw new Error(`Array ${this.
|
|
1196
|
+
throw new Error(`Array ${this.op.children[0].name} undefined`);
|
|
1152
1197
|
}
|
|
1153
1198
|
const childContext = context.newContext();
|
|
1154
1199
|
for (const item of list) {
|
|
1155
|
-
childContext.data.set(this.
|
|
1156
|
-
if (!this.
|
|
1200
|
+
childContext.data.set(this.op.children[1].name, item);
|
|
1201
|
+
if (!this.op.children[2].eval(childContext)) {
|
|
1157
1202
|
rows.push(item);
|
|
1158
1203
|
}
|
|
1159
1204
|
}
|
|
1160
1205
|
return rows;
|
|
1161
1206
|
}
|
|
1162
1207
|
async evalAsync(context) {
|
|
1163
|
-
if (this.operand === undefined) {
|
|
1164
|
-
throw new Error('Operand undefined');
|
|
1165
|
-
}
|
|
1166
1208
|
const rows = [];
|
|
1167
|
-
const list = await this.
|
|
1209
|
+
const list = await this.op.children[0].solve(context);
|
|
1168
1210
|
if (!list) {
|
|
1169
|
-
throw new Error(`Array ${this.
|
|
1211
|
+
throw new Error(`Array ${this.op.children[0].name} undefined`);
|
|
1170
1212
|
}
|
|
1171
1213
|
const childContext = context.newContext();
|
|
1172
1214
|
for (const item of list) {
|
|
1173
|
-
childContext.data.set(this.
|
|
1174
|
-
if (!(await this.
|
|
1215
|
+
childContext.data.set(this.op.children[1].name, item);
|
|
1216
|
+
if (!(await this.op.children[2].solve(childContext))) {
|
|
1175
1217
|
rows.push(item);
|
|
1176
1218
|
}
|
|
1177
1219
|
}
|
|
@@ -1187,28 +1229,19 @@ class First extends domain_2.PrototypeEvaluator {
|
|
|
1187
1229
|
return new First(this.helper, operand);
|
|
1188
1230
|
}
|
|
1189
1231
|
eval(context) {
|
|
1190
|
-
|
|
1191
|
-
throw new Error('Operand undefined');
|
|
1192
|
-
}
|
|
1193
|
-
return this.first(this.operand.children[0].eval(context), context);
|
|
1232
|
+
return this.first(this.op.children[0].eval(context), context);
|
|
1194
1233
|
}
|
|
1195
1234
|
async evalAsync(context) {
|
|
1196
|
-
|
|
1197
|
-
throw new Error('Operand undefined');
|
|
1198
|
-
}
|
|
1199
|
-
return this.first(await this.operand.children[0].solve(context), context);
|
|
1235
|
+
return this.first(await this.op.children[0].solve(context), context);
|
|
1200
1236
|
}
|
|
1201
1237
|
first(list, context) {
|
|
1202
|
-
if (this.operand === undefined) {
|
|
1203
|
-
throw new Error('Operand undefined');
|
|
1204
|
-
}
|
|
1205
1238
|
if (!list) {
|
|
1206
|
-
throw new Error(`Array ${this.
|
|
1239
|
+
throw new Error(`Array ${this.op.children[0].name} undefined`);
|
|
1207
1240
|
}
|
|
1208
|
-
if (this.
|
|
1241
|
+
if (this.op.children.length === 1) {
|
|
1209
1242
|
return list && list.length > 0 ? list[0] : null;
|
|
1210
1243
|
}
|
|
1211
|
-
return this.helper.operand.first(list, this.
|
|
1244
|
+
return this.helper.operand.first(list, this.op.children[1], this.op.children[2], context.newContext());
|
|
1212
1245
|
}
|
|
1213
1246
|
}
|
|
1214
1247
|
class Last extends domain_2.PrototypeEvaluator {
|
|
@@ -1220,28 +1253,19 @@ class Last extends domain_2.PrototypeEvaluator {
|
|
|
1220
1253
|
return new Last(this.helper, operand);
|
|
1221
1254
|
}
|
|
1222
1255
|
eval(context) {
|
|
1223
|
-
|
|
1224
|
-
throw new Error('Operand undefined');
|
|
1225
|
-
}
|
|
1226
|
-
return this.last(this.operand.children[0].eval(context), context);
|
|
1256
|
+
return this.last(this.op.children[0].eval(context), context);
|
|
1227
1257
|
}
|
|
1228
1258
|
async evalAsync(context) {
|
|
1229
|
-
|
|
1230
|
-
throw new Error('Operand undefined');
|
|
1231
|
-
}
|
|
1232
|
-
return this.last(await this.operand.children[0].solve(context), context);
|
|
1259
|
+
return this.last(await this.op.children[0].solve(context), context);
|
|
1233
1260
|
}
|
|
1234
1261
|
last(list, context) {
|
|
1235
|
-
if (this.operand === undefined) {
|
|
1236
|
-
throw new Error('Operand undefined');
|
|
1237
|
-
}
|
|
1238
1262
|
if (!list) {
|
|
1239
|
-
throw new Error(`Array ${this.
|
|
1263
|
+
throw new Error(`Array ${this.op.children[0].name} undefined`);
|
|
1240
1264
|
}
|
|
1241
|
-
if (this.
|
|
1265
|
+
if (this.op.children.length === 1) {
|
|
1242
1266
|
return list && list.length > 0 ? list[list.length - 1] : null;
|
|
1243
1267
|
}
|
|
1244
|
-
return this.helper.operand.last(list, this.
|
|
1268
|
+
return this.helper.operand.last(list, this.op.children[1], this.op.children[2], context.newContext());
|
|
1245
1269
|
}
|
|
1246
1270
|
}
|
|
1247
1271
|
class Count extends domain_2.PrototypeEvaluator {
|
|
@@ -1253,28 +1277,19 @@ class Count extends domain_2.PrototypeEvaluator {
|
|
|
1253
1277
|
return new Count(this.helper, operand);
|
|
1254
1278
|
}
|
|
1255
1279
|
eval(context) {
|
|
1256
|
-
|
|
1257
|
-
throw new Error('Operand undefined');
|
|
1258
|
-
}
|
|
1259
|
-
return this.count(this.operand.children[0].eval(context), context);
|
|
1280
|
+
return this.count(this.op.children[0].eval(context), context);
|
|
1260
1281
|
}
|
|
1261
1282
|
async evalAsync(context) {
|
|
1262
|
-
|
|
1263
|
-
throw new Error('Operand undefined');
|
|
1264
|
-
}
|
|
1265
|
-
return this.count(await this.operand.children[0].solve(context), context);
|
|
1283
|
+
return this.count(await this.op.children[0].solve(context), context);
|
|
1266
1284
|
}
|
|
1267
1285
|
count(list, context) {
|
|
1268
|
-
if (this.operand === undefined) {
|
|
1269
|
-
throw new Error('Operand undefined');
|
|
1270
|
-
}
|
|
1271
1286
|
if (!list) {
|
|
1272
|
-
throw new Error(`Array ${this.
|
|
1287
|
+
throw new Error(`Array ${this.op.children[0].name} undefined`);
|
|
1273
1288
|
}
|
|
1274
|
-
if (this.
|
|
1289
|
+
if (this.op.children.length === 1) {
|
|
1275
1290
|
return list.length;
|
|
1276
1291
|
}
|
|
1277
|
-
return this.helper.operand.count(list, this.
|
|
1292
|
+
return this.helper.operand.count(list, this.op.children[1], this.op.children[2], context.newContext());
|
|
1278
1293
|
}
|
|
1279
1294
|
}
|
|
1280
1295
|
class Max extends domain_2.PrototypeEvaluator {
|
|
@@ -1286,25 +1301,16 @@ class Max extends domain_2.PrototypeEvaluator {
|
|
|
1286
1301
|
return new Max(this.helper, operand);
|
|
1287
1302
|
}
|
|
1288
1303
|
eval(context) {
|
|
1289
|
-
|
|
1290
|
-
throw new Error('Operand undefined');
|
|
1291
|
-
}
|
|
1292
|
-
return this.max(this.operand.children[0].eval(context), context);
|
|
1304
|
+
return this.max(this.op.children[0].eval(context), context);
|
|
1293
1305
|
}
|
|
1294
1306
|
async evalAsync(context) {
|
|
1295
|
-
|
|
1296
|
-
throw new Error('Operand undefined');
|
|
1297
|
-
}
|
|
1298
|
-
return this.max(await this.operand.children[0].solve(context), context);
|
|
1307
|
+
return this.max(await this.op.children[0].solve(context), context);
|
|
1299
1308
|
}
|
|
1300
1309
|
max(list, context) {
|
|
1301
|
-
if (this.operand === undefined) {
|
|
1302
|
-
throw new Error('Operand undefined');
|
|
1303
|
-
}
|
|
1304
1310
|
if (!list) {
|
|
1305
|
-
throw new Error(`Array ${this.
|
|
1311
|
+
throw new Error(`Array ${this.op.children[0].name} undefined`);
|
|
1306
1312
|
}
|
|
1307
|
-
if (this.
|
|
1313
|
+
if (this.op.children.length === 1) {
|
|
1308
1314
|
let max;
|
|
1309
1315
|
for (const item of list) {
|
|
1310
1316
|
if (max === undefined || (item !== null && item > max)) {
|
|
@@ -1313,7 +1319,7 @@ class Max extends domain_2.PrototypeEvaluator {
|
|
|
1313
1319
|
}
|
|
1314
1320
|
return max;
|
|
1315
1321
|
}
|
|
1316
|
-
return this.helper.operand.max(list, this.
|
|
1322
|
+
return this.helper.operand.max(list, this.op.children[1], this.op.children[2], context.newContext());
|
|
1317
1323
|
}
|
|
1318
1324
|
}
|
|
1319
1325
|
class Min extends domain_2.PrototypeEvaluator {
|
|
@@ -1325,25 +1331,16 @@ class Min extends domain_2.PrototypeEvaluator {
|
|
|
1325
1331
|
return new Min(this.helper, operand);
|
|
1326
1332
|
}
|
|
1327
1333
|
eval(context) {
|
|
1328
|
-
|
|
1329
|
-
throw new Error('Operand undefined');
|
|
1330
|
-
}
|
|
1331
|
-
return this.min(this.operand.children[0].eval(context), context);
|
|
1334
|
+
return this.min(this.op.children[0].eval(context), context);
|
|
1332
1335
|
}
|
|
1333
1336
|
async evalAsync(context) {
|
|
1334
|
-
|
|
1335
|
-
throw new Error('Operand undefined');
|
|
1336
|
-
}
|
|
1337
|
-
return this.min(await this.operand.children[0].solve(context), context);
|
|
1337
|
+
return this.min(await this.op.children[0].solve(context), context);
|
|
1338
1338
|
}
|
|
1339
1339
|
min(list, context) {
|
|
1340
|
-
if (this.operand === undefined) {
|
|
1341
|
-
throw new Error('Operand undefined');
|
|
1342
|
-
}
|
|
1343
1340
|
if (!list) {
|
|
1344
|
-
throw new Error(`Array ${this.
|
|
1341
|
+
throw new Error(`Array ${this.op.children[0].name} undefined`);
|
|
1345
1342
|
}
|
|
1346
|
-
if (this.
|
|
1343
|
+
if (this.op.children.length === 1) {
|
|
1347
1344
|
let min;
|
|
1348
1345
|
for (const item of list) {
|
|
1349
1346
|
if (min === undefined || (item !== null && item < min)) {
|
|
@@ -1352,7 +1349,7 @@ class Min extends domain_2.PrototypeEvaluator {
|
|
|
1352
1349
|
}
|
|
1353
1350
|
return min;
|
|
1354
1351
|
}
|
|
1355
|
-
return this.helper.operand.min(list, this.
|
|
1352
|
+
return this.helper.operand.min(list, this.op.children[1], this.op.children[2], context.newContext());
|
|
1356
1353
|
}
|
|
1357
1354
|
}
|
|
1358
1355
|
class Avg extends domain_2.PrototypeEvaluator {
|
|
@@ -1364,22 +1361,13 @@ class Avg extends domain_2.PrototypeEvaluator {
|
|
|
1364
1361
|
return new Avg(this.helper, operand);
|
|
1365
1362
|
}
|
|
1366
1363
|
eval(context) {
|
|
1367
|
-
|
|
1368
|
-
throw new Error('Operand undefined');
|
|
1369
|
-
}
|
|
1370
|
-
return this.avg(this.operand.children[0].eval(context), context);
|
|
1364
|
+
return this.avg(this.op.children[0].eval(context), context);
|
|
1371
1365
|
}
|
|
1372
1366
|
async evalAsync(context) {
|
|
1373
|
-
|
|
1374
|
-
throw new Error('Operand undefined');
|
|
1375
|
-
}
|
|
1376
|
-
return this.avg(await this.operand.children[0].solve(context), context);
|
|
1367
|
+
return this.avg(await this.op.children[0].solve(context), context);
|
|
1377
1368
|
}
|
|
1378
1369
|
avg(list, context) {
|
|
1379
|
-
if (this.
|
|
1380
|
-
throw new Error('Operand undefined');
|
|
1381
|
-
}
|
|
1382
|
-
if (this.operand.children.length === 1) {
|
|
1370
|
+
if (this.op.children.length === 1) {
|
|
1383
1371
|
let sum = 0;
|
|
1384
1372
|
for (const item of list) {
|
|
1385
1373
|
if (item !== null) {
|
|
@@ -1388,7 +1376,7 @@ class Avg extends domain_2.PrototypeEvaluator {
|
|
|
1388
1376
|
}
|
|
1389
1377
|
return list.length > 0 ? sum / list.length : 0;
|
|
1390
1378
|
}
|
|
1391
|
-
return this.helper.operand.avg(list, this.
|
|
1379
|
+
return this.helper.operand.avg(list, this.op.children[1], this.op.children[2], context.newContext());
|
|
1392
1380
|
}
|
|
1393
1381
|
}
|
|
1394
1382
|
class Sum extends domain_2.PrototypeEvaluator {
|
|
@@ -1400,25 +1388,16 @@ class Sum extends domain_2.PrototypeEvaluator {
|
|
|
1400
1388
|
return new Sum(this.helper, operand);
|
|
1401
1389
|
}
|
|
1402
1390
|
eval(context) {
|
|
1403
|
-
|
|
1404
|
-
throw new Error('Operand undefined');
|
|
1405
|
-
}
|
|
1406
|
-
return this.sum(this.operand.children[0].eval(context), context);
|
|
1391
|
+
return this.sum(this.op.children[0].eval(context), context);
|
|
1407
1392
|
}
|
|
1408
1393
|
async evalAsync(context) {
|
|
1409
|
-
|
|
1410
|
-
throw new Error('Operand undefined');
|
|
1411
|
-
}
|
|
1412
|
-
return this.sum(await this.operand.children[0].solve(context), context);
|
|
1394
|
+
return this.sum(await this.op.children[0].solve(context), context);
|
|
1413
1395
|
}
|
|
1414
1396
|
sum(list, context) {
|
|
1415
|
-
if (this.operand === undefined) {
|
|
1416
|
-
throw new Error('Operand undefined');
|
|
1417
|
-
}
|
|
1418
1397
|
if (!list) {
|
|
1419
|
-
throw new Error(`Array ${this.
|
|
1398
|
+
throw new Error(`Array ${this.op.children[0].name} undefined`);
|
|
1420
1399
|
}
|
|
1421
|
-
if (this.
|
|
1400
|
+
if (this.op.children.length === 1) {
|
|
1422
1401
|
let sum = 0;
|
|
1423
1402
|
for (const item of list) {
|
|
1424
1403
|
if (item !== null) {
|
|
@@ -1427,7 +1406,7 @@ class Sum extends domain_2.PrototypeEvaluator {
|
|
|
1427
1406
|
}
|
|
1428
1407
|
return sum;
|
|
1429
1408
|
}
|
|
1430
|
-
return this.helper.operand.sum(list, this.
|
|
1409
|
+
return this.helper.operand.sum(list, this.op.children[1], this.op.children[2], context.newContext());
|
|
1431
1410
|
}
|
|
1432
1411
|
}
|
|
1433
1412
|
class Union extends domain_2.PrototypeEvaluator {
|
|
@@ -1439,19 +1418,13 @@ class Union extends domain_2.PrototypeEvaluator {
|
|
|
1439
1418
|
return new Union(this.helper, operand);
|
|
1440
1419
|
}
|
|
1441
1420
|
eval(context) {
|
|
1442
|
-
|
|
1443
|
-
|
|
1444
|
-
}
|
|
1445
|
-
const a = this.operand.children[0].eval(context);
|
|
1446
|
-
const b = this.operand.children[1].eval(context);
|
|
1421
|
+
const a = this.op.children[0].eval(context);
|
|
1422
|
+
const b = this.op.children[1].eval(context);
|
|
1447
1423
|
return this.union(a, b);
|
|
1448
1424
|
}
|
|
1449
1425
|
async evalAsync(context) {
|
|
1450
|
-
|
|
1451
|
-
|
|
1452
|
-
}
|
|
1453
|
-
const a = await this.operand.children[0].solve(context);
|
|
1454
|
-
const b = await this.operand.children[1].solve(context);
|
|
1426
|
+
const a = await this.op.children[0].solve(context);
|
|
1427
|
+
const b = await this.op.children[1].solve(context);
|
|
1455
1428
|
return this.union(a, b);
|
|
1456
1429
|
}
|
|
1457
1430
|
union(a, b) {
|
|
@@ -1496,37 +1469,28 @@ class Intersection extends domain_2.PrototypeEvaluator {
|
|
|
1496
1469
|
return new Intersection(this.helper, operand);
|
|
1497
1470
|
}
|
|
1498
1471
|
eval(context) {
|
|
1499
|
-
|
|
1500
|
-
|
|
1501
|
-
}
|
|
1502
|
-
const a = this.operand.children[0].eval(context);
|
|
1503
|
-
const b = this.operand.children[1].eval(context);
|
|
1472
|
+
const a = this.op.children[0].eval(context);
|
|
1473
|
+
const b = this.op.children[1].eval(context);
|
|
1504
1474
|
return this.intersection(a, b);
|
|
1505
1475
|
}
|
|
1506
1476
|
async evalAsync(context) {
|
|
1507
|
-
|
|
1508
|
-
|
|
1509
|
-
}
|
|
1510
|
-
const a = await this.operand.children[0].solve(context);
|
|
1511
|
-
const b = await this.operand.children[1].solve(context);
|
|
1477
|
+
const a = await this.op.children[0].solve(context);
|
|
1478
|
+
const b = await this.op.children[1].solve(context);
|
|
1512
1479
|
return this.intersection(a, b);
|
|
1513
1480
|
}
|
|
1514
1481
|
intersection(a, b) {
|
|
1515
|
-
if (this.operand === undefined) {
|
|
1516
|
-
throw new Error('Operand undefined');
|
|
1517
|
-
}
|
|
1518
1482
|
if (!a) {
|
|
1519
|
-
throw new Error(`Array ${this.
|
|
1483
|
+
throw new Error(`Array ${this.op.children[0].name} undefined`);
|
|
1520
1484
|
}
|
|
1521
1485
|
if (!b) {
|
|
1522
|
-
throw new Error(`Array ${this.
|
|
1486
|
+
throw new Error(`Array ${this.op.children[1].name} undefined`);
|
|
1523
1487
|
}
|
|
1524
1488
|
if (a.length === 0 || b.length === 0) {
|
|
1525
1489
|
return [];
|
|
1526
1490
|
}
|
|
1527
1491
|
const result = [];
|
|
1528
1492
|
if (Array.isArray(a[0]) || Array.isArray(b[0])) {
|
|
1529
|
-
throw new Error('Cannot
|
|
1493
|
+
throw new Error('Cannot intersect arrays of arrays');
|
|
1530
1494
|
}
|
|
1531
1495
|
else if (typeof a[0] === 'object') {
|
|
1532
1496
|
const keys = a.map((p) => this.helper.operand.objectKey(p));
|
|
@@ -1557,30 +1521,21 @@ class Difference extends domain_2.PrototypeEvaluator {
|
|
|
1557
1521
|
return new Difference(this.helper, operand);
|
|
1558
1522
|
}
|
|
1559
1523
|
eval(context) {
|
|
1560
|
-
|
|
1561
|
-
|
|
1562
|
-
}
|
|
1563
|
-
const a = this.operand.children[0].eval(context);
|
|
1564
|
-
const b = this.operand.children[1].eval(context);
|
|
1524
|
+
const a = this.op.children[0].eval(context);
|
|
1525
|
+
const b = this.op.children[1].eval(context);
|
|
1565
1526
|
return this.difference(a, b);
|
|
1566
1527
|
}
|
|
1567
1528
|
async evalAsync(context) {
|
|
1568
|
-
|
|
1569
|
-
|
|
1570
|
-
}
|
|
1571
|
-
const a = await this.operand.children[0].solve(context);
|
|
1572
|
-
const b = await this.operand.children[1].solve(context);
|
|
1529
|
+
const a = await this.op.children[0].solve(context);
|
|
1530
|
+
const b = await this.op.children[1].solve(context);
|
|
1573
1531
|
return this.difference(a, b);
|
|
1574
1532
|
}
|
|
1575
1533
|
difference(a, b) {
|
|
1576
|
-
if (this.operand === undefined) {
|
|
1577
|
-
throw new Error('Operand undefined');
|
|
1578
|
-
}
|
|
1579
1534
|
if (!a) {
|
|
1580
|
-
throw new Error(`Array ${this.
|
|
1535
|
+
throw new Error(`Array ${this.op.children[0].name} undefined`);
|
|
1581
1536
|
}
|
|
1582
1537
|
if (!b) {
|
|
1583
|
-
throw new Error(`Array ${this.
|
|
1538
|
+
throw new Error(`Array ${this.op.children[1].name} undefined`);
|
|
1584
1539
|
}
|
|
1585
1540
|
if (a.length === 0) {
|
|
1586
1541
|
return [];
|
|
@@ -1590,7 +1545,7 @@ class Difference extends domain_2.PrototypeEvaluator {
|
|
|
1590
1545
|
}
|
|
1591
1546
|
const result = [];
|
|
1592
1547
|
if (Array.isArray(a[0]) || Array.isArray(b[0])) {
|
|
1593
|
-
throw new Error('Cannot
|
|
1548
|
+
throw new Error('Cannot difference arrays of arrays');
|
|
1594
1549
|
}
|
|
1595
1550
|
else if (typeof a[0] === 'object') {
|
|
1596
1551
|
const keys = b.map((p) => this.helper.operand.objectKey(p));
|
|
@@ -1621,30 +1576,21 @@ class SymmetricDifference extends domain_2.PrototypeEvaluator {
|
|
|
1621
1576
|
return new SymmetricDifference(this.helper, operand);
|
|
1622
1577
|
}
|
|
1623
1578
|
eval(context) {
|
|
1624
|
-
|
|
1625
|
-
|
|
1626
|
-
}
|
|
1627
|
-
const a = this.operand.children[0].eval(context);
|
|
1628
|
-
const b = this.operand.children[1].eval(context);
|
|
1579
|
+
const a = this.op.children[0].eval(context);
|
|
1580
|
+
const b = this.op.children[1].eval(context);
|
|
1629
1581
|
return this.symmetricDifference(a, b);
|
|
1630
1582
|
}
|
|
1631
1583
|
async evalAsync(context) {
|
|
1632
|
-
|
|
1633
|
-
|
|
1634
|
-
}
|
|
1635
|
-
const a = await this.operand.children[0].solve(context);
|
|
1636
|
-
const b = await this.operand.children[1].solve(context);
|
|
1584
|
+
const a = await this.op.children[0].solve(context);
|
|
1585
|
+
const b = await this.op.children[1].solve(context);
|
|
1637
1586
|
return this.symmetricDifference(a, b);
|
|
1638
1587
|
}
|
|
1639
1588
|
symmetricDifference(a, b) {
|
|
1640
|
-
if (this.operand === undefined) {
|
|
1641
|
-
throw new Error('Operand undefined');
|
|
1642
|
-
}
|
|
1643
1589
|
if (!a) {
|
|
1644
|
-
throw new Error(`Array ${this.
|
|
1590
|
+
throw new Error(`Array ${this.op.children[0].name} undefined`);
|
|
1645
1591
|
}
|
|
1646
1592
|
if (!b) {
|
|
1647
|
-
throw new Error(`Array ${this.
|
|
1593
|
+
throw new Error(`Array ${this.op.children[1].name} undefined`);
|
|
1648
1594
|
}
|
|
1649
1595
|
if (a.length === 0) {
|
|
1650
1596
|
return b;
|
|
@@ -1654,7 +1600,7 @@ class SymmetricDifference extends domain_2.PrototypeEvaluator {
|
|
|
1654
1600
|
}
|
|
1655
1601
|
const result = [];
|
|
1656
1602
|
if (Array.isArray(a[0]) || Array.isArray(b[0])) {
|
|
1657
|
-
throw new Error('Cannot
|
|
1603
|
+
throw new Error('Cannot compute symmetric difference of arrays of arrays');
|
|
1658
1604
|
}
|
|
1659
1605
|
else if (typeof a[0] === 'object') {
|
|
1660
1606
|
const aKeys = a.map((p) => this.helper.operand.objectKey(p));
|
|
@@ -1688,4 +1634,180 @@ class SymmetricDifference extends domain_2.PrototypeEvaluator {
|
|
|
1688
1634
|
}
|
|
1689
1635
|
}
|
|
1690
1636
|
}
|
|
1637
|
+
class AggregateEval extends domain_2.PrototypeEvaluator {
|
|
1638
|
+
getList(context) {
|
|
1639
|
+
const list = this.op.children[0].eval(context);
|
|
1640
|
+
if (!list)
|
|
1641
|
+
throw new Error(`Array ${this.op.children[0].name} undefined`);
|
|
1642
|
+
return list;
|
|
1643
|
+
}
|
|
1644
|
+
async getListAsync(context) {
|
|
1645
|
+
const list = await this.op.children[0].solve(context);
|
|
1646
|
+
if (!list)
|
|
1647
|
+
throw new Error(`Array ${this.op.children[0].name} undefined`);
|
|
1648
|
+
return list;
|
|
1649
|
+
}
|
|
1650
|
+
evalValues(list, context) {
|
|
1651
|
+
if (this.op.children.length === 1)
|
|
1652
|
+
return list.filter(v => v !== null && v !== undefined);
|
|
1653
|
+
const values = [];
|
|
1654
|
+
const ctx = context.newContext();
|
|
1655
|
+
for (const item of list) {
|
|
1656
|
+
ctx.data.set(this.op.children[1].name, item);
|
|
1657
|
+
const v = this.op.children[2].eval(ctx);
|
|
1658
|
+
if (v !== null && v !== undefined)
|
|
1659
|
+
values.push(v);
|
|
1660
|
+
}
|
|
1661
|
+
return values;
|
|
1662
|
+
}
|
|
1663
|
+
async evalValuesAsync(list, context) {
|
|
1664
|
+
if (this.op.children.length === 1)
|
|
1665
|
+
return list.filter(v => v !== null && v !== undefined);
|
|
1666
|
+
const values = [];
|
|
1667
|
+
const ctx = context.newContext();
|
|
1668
|
+
for (const item of list) {
|
|
1669
|
+
ctx.data.set(this.op.children[1].name, item);
|
|
1670
|
+
const v = await this.op.children[2].solve(ctx);
|
|
1671
|
+
if (v !== null && v !== undefined)
|
|
1672
|
+
values.push(v);
|
|
1673
|
+
}
|
|
1674
|
+
return values;
|
|
1675
|
+
}
|
|
1676
|
+
}
|
|
1677
|
+
class CountDistinct extends AggregateEval {
|
|
1678
|
+
clone(operand) { return new CountDistinct(operand); }
|
|
1679
|
+
eval(context) { return new Set(this.evalValues(this.getList(context), context)).size; }
|
|
1680
|
+
async evalAsync(context) {
|
|
1681
|
+
return new Set(await this.evalValuesAsync(await this.getListAsync(context), context)).size;
|
|
1682
|
+
}
|
|
1683
|
+
}
|
|
1684
|
+
class SumDistinct extends AggregateEval {
|
|
1685
|
+
clone(operand) { return new SumDistinct(operand); }
|
|
1686
|
+
eval(context) { return [...new Set(this.evalValues(this.getList(context), context))].reduce((s, v) => s + v, 0); }
|
|
1687
|
+
async evalAsync(context) {
|
|
1688
|
+
return [...new Set(await this.evalValuesAsync(await this.getListAsync(context), context))].reduce((s, v) => s + v, 0);
|
|
1689
|
+
}
|
|
1690
|
+
}
|
|
1691
|
+
class AvgDistinct extends AggregateEval {
|
|
1692
|
+
clone(operand) { return new AvgDistinct(operand); }
|
|
1693
|
+
eval(context) { return this.compute(this.evalValues(this.getList(context), context)); }
|
|
1694
|
+
async evalAsync(context) { return this.compute(await this.evalValuesAsync(await this.getListAsync(context), context)); }
|
|
1695
|
+
compute(values) {
|
|
1696
|
+
const distinct = [...new Set(values)];
|
|
1697
|
+
return distinct.length === 0 ? 0 : distinct.reduce((s, v) => s + v, 0) / distinct.length;
|
|
1698
|
+
}
|
|
1699
|
+
}
|
|
1700
|
+
class Median extends AggregateEval {
|
|
1701
|
+
clone(operand) { return new Median(operand); }
|
|
1702
|
+
eval(context) { return this.compute(this.evalValues(this.getList(context), context)); }
|
|
1703
|
+
async evalAsync(context) { return this.compute(await this.evalValuesAsync(await this.getListAsync(context), context)); }
|
|
1704
|
+
compute(values) {
|
|
1705
|
+
if (!values.length)
|
|
1706
|
+
return null;
|
|
1707
|
+
const sorted = [...values].sort((a, b) => a - b);
|
|
1708
|
+
const mid = Math.floor(sorted.length / 2);
|
|
1709
|
+
return sorted.length % 2 === 0 ? (sorted[mid - 1] + sorted[mid]) / 2 : sorted[mid];
|
|
1710
|
+
}
|
|
1711
|
+
}
|
|
1712
|
+
class StdDevEval extends AggregateEval {
|
|
1713
|
+
constructor(population, operand) {
|
|
1714
|
+
super(operand);
|
|
1715
|
+
this.population = population;
|
|
1716
|
+
}
|
|
1717
|
+
clone(operand) { return new StdDevEval(this.population, operand); }
|
|
1718
|
+
eval(context) { return this.compute(this.evalValues(this.getList(context), context)); }
|
|
1719
|
+
async evalAsync(context) { return this.compute(await this.evalValuesAsync(await this.getListAsync(context), context)); }
|
|
1720
|
+
compute(values) {
|
|
1721
|
+
const n = values.length;
|
|
1722
|
+
if (n === 0)
|
|
1723
|
+
return 0;
|
|
1724
|
+
const mean = values.reduce((s, v) => s + v, 0) / n;
|
|
1725
|
+
const divisor = this.population ? n : n - 1;
|
|
1726
|
+
if (divisor === 0)
|
|
1727
|
+
return 0;
|
|
1728
|
+
return Math.sqrt(values.reduce((s, v) => s + (v - mean) ** 2, 0) / divisor);
|
|
1729
|
+
}
|
|
1730
|
+
}
|
|
1731
|
+
class VarianceEval extends AggregateEval {
|
|
1732
|
+
constructor(population, operand) {
|
|
1733
|
+
super(operand);
|
|
1734
|
+
this.population = population;
|
|
1735
|
+
}
|
|
1736
|
+
clone(operand) { return new VarianceEval(this.population, operand); }
|
|
1737
|
+
eval(context) { return this.compute(this.evalValues(this.getList(context), context)); }
|
|
1738
|
+
async evalAsync(context) { return this.compute(await this.evalValuesAsync(await this.getListAsync(context), context)); }
|
|
1739
|
+
compute(values) {
|
|
1740
|
+
const n = values.length;
|
|
1741
|
+
if (n === 0)
|
|
1742
|
+
return 0;
|
|
1743
|
+
const mean = values.reduce((s, v) => s + v, 0) / n;
|
|
1744
|
+
const divisor = this.population ? n : n - 1;
|
|
1745
|
+
if (divisor === 0)
|
|
1746
|
+
return 0;
|
|
1747
|
+
return values.reduce((s, v) => s + (v - mean) ** 2, 0) / divisor;
|
|
1748
|
+
}
|
|
1749
|
+
}
|
|
1750
|
+
class BoolAndEval extends AggregateEval {
|
|
1751
|
+
clone(operand) { return new BoolAndEval(operand); }
|
|
1752
|
+
eval(context) { return this.evalValues(this.getList(context), context).every(v => !!v); }
|
|
1753
|
+
async evalAsync(context) { return (await this.evalValuesAsync(await this.getListAsync(context), context)).every(v => !!v); }
|
|
1754
|
+
}
|
|
1755
|
+
class BoolOrEval extends AggregateEval {
|
|
1756
|
+
clone(operand) { return new BoolOrEval(operand); }
|
|
1757
|
+
eval(context) { return this.evalValues(this.getList(context), context).some(v => !!v); }
|
|
1758
|
+
async evalAsync(context) { return (await this.evalValuesAsync(await this.getListAsync(context), context)).some(v => !!v); }
|
|
1759
|
+
}
|
|
1760
|
+
class BitAndAgg extends AggregateEval {
|
|
1761
|
+
clone(operand) { return new BitAndAgg(operand); }
|
|
1762
|
+
eval(context) { return this.evalValues(this.getList(context), context).reduce((acc, v) => acc & v, -1); }
|
|
1763
|
+
async evalAsync(context) { return (await this.evalValuesAsync(await this.getListAsync(context), context)).reduce((acc, v) => acc & v, -1); }
|
|
1764
|
+
}
|
|
1765
|
+
class BitOrAgg extends AggregateEval {
|
|
1766
|
+
clone(operand) { return new BitOrAgg(operand); }
|
|
1767
|
+
eval(context) { return this.evalValues(this.getList(context), context).reduce((acc, v) => acc | v, 0); }
|
|
1768
|
+
async evalAsync(context) { return (await this.evalValuesAsync(await this.getListAsync(context), context)).reduce((acc, v) => acc | v, 0); }
|
|
1769
|
+
}
|
|
1770
|
+
class RankEval extends domain_2.PrototypeEvaluator {
|
|
1771
|
+
constructor(dense, operand) {
|
|
1772
|
+
super(operand);
|
|
1773
|
+
this.dense = dense;
|
|
1774
|
+
}
|
|
1775
|
+
clone(operand) { return new RankEval(this.dense, operand); }
|
|
1776
|
+
eval(context) { return this.computeRank(this.extractValues(this.op.children[0].eval(context), context)); }
|
|
1777
|
+
async evalAsync(context) { return this.computeRank(await this.extractValuesAsync(await this.op.children[0].solve(context), context)); }
|
|
1778
|
+
extractValues(list, context) {
|
|
1779
|
+
if (this.op.children.length === 1)
|
|
1780
|
+
return list;
|
|
1781
|
+
const values = [];
|
|
1782
|
+
const ctx = context.newContext();
|
|
1783
|
+
for (const item of list) {
|
|
1784
|
+
ctx.data.set(this.op.children[1].name, item);
|
|
1785
|
+
values.push(this.op.children[2].eval(ctx));
|
|
1786
|
+
}
|
|
1787
|
+
return values;
|
|
1788
|
+
}
|
|
1789
|
+
async extractValuesAsync(list, context) {
|
|
1790
|
+
if (this.op.children.length === 1)
|
|
1791
|
+
return list;
|
|
1792
|
+
const values = [];
|
|
1793
|
+
const ctx = context.newContext();
|
|
1794
|
+
for (const item of list) {
|
|
1795
|
+
ctx.data.set(this.op.children[1].name, item);
|
|
1796
|
+
values.push(await this.op.children[2].solve(ctx));
|
|
1797
|
+
}
|
|
1798
|
+
return values;
|
|
1799
|
+
}
|
|
1800
|
+
computeRank(values) {
|
|
1801
|
+
const sorted = [...new Set(values)].sort((a, b) => a > b ? 1 : -1);
|
|
1802
|
+
if (this.dense)
|
|
1803
|
+
return values.map(v => sorted.indexOf(v) + 1);
|
|
1804
|
+
const rankMap = new Map();
|
|
1805
|
+
let rank = 1;
|
|
1806
|
+
for (const v of sorted) {
|
|
1807
|
+
rankMap.set(v, rank);
|
|
1808
|
+
rank += values.filter(x => x === v).length;
|
|
1809
|
+
}
|
|
1810
|
+
return values.map(v => rankMap.get(v));
|
|
1811
|
+
}
|
|
1812
|
+
}
|
|
1691
1813
|
//# sourceMappingURL=library.js.map
|