3xpr 1.5.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (151) hide show
  1. package/LICENSE +201 -0
  2. package/README.md +126 -0
  3. package/__tests__/array.test.d.ts +1 -0
  4. package/__tests__/array.test.js +37 -0
  5. package/__tests__/array.test.js.map +1 -0
  6. package/__tests__/auto/access.test.d.ts +1 -0
  7. package/__tests__/auto/access.test.js +31 -0
  8. package/__tests__/auto/access.test.js.map +1 -0
  9. package/__tests__/auto/arithmetic.test.d.ts +1 -0
  10. package/__tests__/auto/arithmetic.test.js +20 -0
  11. package/__tests__/auto/arithmetic.test.js.map +1 -0
  12. package/__tests__/auto/array.test.d.ts +1 -0
  13. package/__tests__/auto/array.test.js +25 -0
  14. package/__tests__/auto/array.test.js.map +1 -0
  15. package/__tests__/auto/arrow.test.d.ts +1 -0
  16. package/__tests__/auto/arrow.test.js +29 -0
  17. package/__tests__/auto/arrow.test.js.map +1 -0
  18. package/__tests__/auto/assignment.test.d.ts +1 -0
  19. package/__tests__/auto/assignment.test.js +14 -0
  20. package/__tests__/auto/assignment.test.js.map +1 -0
  21. package/__tests__/auto/bitwise.test.d.ts +1 -0
  22. package/__tests__/auto/bitwise.test.js +16 -0
  23. package/__tests__/auto/bitwise.test.js.map +1 -0
  24. package/__tests__/auto/comparison.test.d.ts +1 -0
  25. package/__tests__/auto/comparison.test.js +65 -0
  26. package/__tests__/auto/comparison.test.js.map +1 -0
  27. package/__tests__/auto/constants.test.d.ts +1 -0
  28. package/__tests__/auto/constants.test.js +15 -0
  29. package/__tests__/auto/constants.test.js.map +1 -0
  30. package/__tests__/auto/dateTime.test.d.ts +1 -0
  31. package/__tests__/auto/dateTime.test.js +38 -0
  32. package/__tests__/auto/dateTime.test.js.map +1 -0
  33. package/__tests__/auto/flows.test.d.ts +1 -0
  34. package/__tests__/auto/flows.test.js +78 -0
  35. package/__tests__/auto/flows.test.js.map +1 -0
  36. package/__tests__/auto/nullable.test.d.ts +1 -0
  37. package/__tests__/auto/nullable.test.js +15 -0
  38. package/__tests__/auto/nullable.test.js.map +1 -0
  39. package/__tests__/auto/numeric.test.d.ts +1 -0
  40. package/__tests__/auto/numeric.test.js +32 -0
  41. package/__tests__/auto/numeric.test.js.map +1 -0
  42. package/__tests__/auto/parameters.test.d.ts +1 -0
  43. package/__tests__/auto/parameters.test.js +25 -0
  44. package/__tests__/auto/parameters.test.js.map +1 -0
  45. package/__tests__/auto/sets.test.d.ts +1 -0
  46. package/__tests__/auto/sets.test.js +18 -0
  47. package/__tests__/auto/sets.test.js.map +1 -0
  48. package/__tests__/auto/string.test.d.ts +1 -0
  49. package/__tests__/auto/string.test.js +45 -0
  50. package/__tests__/auto/string.test.js.map +1 -0
  51. package/__tests__/auto/type.test.d.ts +1 -0
  52. package/__tests__/auto/type.test.js +25 -0
  53. package/__tests__/auto/type.test.js.map +1 -0
  54. package/__tests__/cache.test.d.ts +1 -0
  55. package/__tests__/cache.test.js +282 -0
  56. package/__tests__/cache.test.js.map +1 -0
  57. package/__tests__/datetime.test.d.ts +1 -0
  58. package/__tests__/datetime.test.js +38 -0
  59. package/__tests__/datetime.test.js.map +1 -0
  60. package/__tests__/enums.test.d.ts +1 -0
  61. package/__tests__/enums.test.js +12 -0
  62. package/__tests__/enums.test.js.map +1 -0
  63. package/__tests__/flows.test.d.ts +1 -0
  64. package/__tests__/flows.test.js +19 -0
  65. package/__tests__/flows.test.js.map +1 -0
  66. package/__tests__/numeric.test.d.ts +1 -0
  67. package/__tests__/numeric.test.js +55 -0
  68. package/__tests__/numeric.test.js.map +1 -0
  69. package/__tests__/pending/conversion.test.d.ts +1 -0
  70. package/__tests__/pending/conversion.test.js +20 -0
  71. package/__tests__/pending/conversion.test.js.map +1 -0
  72. package/__tests__/pending/groups.test.d.ts +1 -0
  73. package/__tests__/pending/groups.test.js +27 -0
  74. package/__tests__/pending/groups.test.js.map +1 -0
  75. package/__tests__/pending/quick.test.d.ts +1 -0
  76. package/__tests__/pending/quick.test.js +21 -0
  77. package/__tests__/pending/quick.test.js.map +1 -0
  78. package/__tests__/string.test.d.ts +1 -0
  79. package/__tests__/string.test.js +18 -0
  80. package/__tests__/string.test.js.map +1 -0
  81. package/expression/contract/base.d.ts +31 -0
  82. package/expression/contract/base.js +12 -0
  83. package/expression/contract/base.js.map +1 -0
  84. package/expression/contract/context.d.ts +36 -0
  85. package/expression/contract/context.js +93 -0
  86. package/expression/contract/context.js.map +1 -0
  87. package/expression/contract/index.d.ts +5 -0
  88. package/expression/contract/index.js +22 -0
  89. package/expression/contract/index.js.map +1 -0
  90. package/expression/contract/managers.d.ts +73 -0
  91. package/expression/contract/managers.js +11 -0
  92. package/expression/contract/managers.js.map +1 -0
  93. package/expression/contract/operand.d.ts +92 -0
  94. package/expression/contract/operand.js +69 -0
  95. package/expression/contract/operand.js.map +1 -0
  96. package/expression/contract/type.d.ts +50 -0
  97. package/expression/contract/type.js +164 -0
  98. package/expression/contract/type.js.map +1 -0
  99. package/expression/expressions.d.ts +57 -0
  100. package/expression/expressions.js +232 -0
  101. package/expression/expressions.js.map +1 -0
  102. package/expression/helper.d.ts +7 -0
  103. package/expression/helper.js +14 -0
  104. package/expression/helper.js.map +1 -0
  105. package/expression/index.d.ts +4 -0
  106. package/expression/index.js +21 -0
  107. package/expression/index.js.map +1 -0
  108. package/expression/operand/builder.d.ts +11 -0
  109. package/expression/operand/builder.js +79 -0
  110. package/expression/operand/builder.js.map +1 -0
  111. package/expression/operand/coreLibrary.d.ts +20 -0
  112. package/expression/operand/coreLibrary.js +1162 -0
  113. package/expression/operand/coreLibrary.js.map +1 -0
  114. package/expression/operand/evaluators.d.ts +67 -0
  115. package/expression/operand/evaluators.js +238 -0
  116. package/expression/operand/evaluators.js.map +1 -0
  117. package/expression/operand/factory.d.ts +11 -0
  118. package/expression/operand/factory.js +127 -0
  119. package/expression/operand/factory.js.map +1 -0
  120. package/expression/operand/helper.d.ts +17 -0
  121. package/expression/operand/helper.js +269 -0
  122. package/expression/operand/helper.js.map +1 -0
  123. package/expression/operand/index.d.ts +9 -0
  124. package/expression/operand/index.js +26 -0
  125. package/expression/operand/index.js.map +1 -0
  126. package/expression/operand/model.d.ts +34 -0
  127. package/expression/operand/model.js +282 -0
  128. package/expression/operand/model.js.map +1 -0
  129. package/expression/operand/parser.d.ts +42 -0
  130. package/expression/operand/parser.js +738 -0
  131. package/expression/operand/parser.js.map +1 -0
  132. package/expression/operand/type.d.ts +31 -0
  133. package/expression/operand/type.js +352 -0
  134. package/expression/operand/type.js.map +1 -0
  135. package/expression/process/evaluators.d.ts +58 -0
  136. package/expression/process/evaluators.js +317 -0
  137. package/expression/process/evaluators.js.map +1 -0
  138. package/expression/process/factory.d.ts +8 -0
  139. package/expression/process/factory.js +122 -0
  140. package/expression/process/factory.js.map +1 -0
  141. package/expression/process/index.d.ts +3 -0
  142. package/expression/process/index.js +20 -0
  143. package/expression/process/index.js.map +1 -0
  144. package/expression/process/model.d.ts +7 -0
  145. package/expression/process/model.js +3 -0
  146. package/expression/process/model.js.map +1 -0
  147. package/index.d.ts +19 -0
  148. package/index.js +52 -0
  149. package/index.js.map +1 -0
  150. package/jest-unit-config.json +15 -0
  151. package/package.json +39 -0
@@ -0,0 +1,1162 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.CoreLibrary = void 0;
4
+ const h3lp_1 = require("h3lp");
5
+ const contract_1 = require("../contract");
6
+ const __1 = require("../..");
7
+ class CoreLibrary {
8
+ // eslint-disable-next-line no-useless-constructor
9
+ constructor(model) {
10
+ this.model = model;
11
+ }
12
+ load() {
13
+ this.constants();
14
+ this.enums();
15
+ this.formats();
16
+ this.operators();
17
+ this.generalFunctions();
18
+ this.comparisonFunctions();
19
+ this.nullFunctions();
20
+ this.numberFunctions();
21
+ this.stringFunctions();
22
+ this.arrayFunctions();
23
+ this.groupFunctions();
24
+ this.dateTimeFunctions();
25
+ this.conversionFunctions();
26
+ this.setsFunctions();
27
+ }
28
+ constants() {
29
+ this.model.addConstant('true', true);
30
+ this.model.addConstant('false', false);
31
+ this.model.addConstant('null', null);
32
+ }
33
+ enums() {
34
+ this.model.addEnum('DayOfWeek', [['Sunday', 0], ['Monday', 1], ['Tuesday', 2], ['Wednesday', 3], ['Thursday', 4], ['Friday', 5], ['Saturday', 6]]);
35
+ }
36
+ formats() {
37
+ this.model.addFormat('email', '^\\w+([\\.-]?\\w+)*@\\w+([\\.-]?\\w+)*(\\.\\w{2,3})+$');
38
+ this.model.addFormat('integer', '^\\d+$');
39
+ this.model.addFormat('decimal', '^\\d+\\.\\d+$');
40
+ this.model.addFormat('string', '^[a-zA-Z0-9_.]+$');
41
+ // https://stackoverflow.com/questions/3143070/javascript-regex-iso-dateTime
42
+ this.model.addFormat('date', '^\\d{4}-\\d{2}-\\d{2}$');
43
+ this.model.addFormat('dateTime', '\\d{4}-[01]\\d-[0-3]\\dT[0-2]\\d:[0-5]\\d:[0-5]\\d\\.\\d+([+-][0-2]\\d:[0-5]\\d|Z)');
44
+ this.model.addFormat('time', '\\[0-2]\\d:[0-5]\\d:[0-5]\\d');
45
+ }
46
+ operators() {
47
+ this.model.addOperator('+(a:T,b:T):T', (a, b) => a + b, { priority: 5 });
48
+ this.model.addOperator('-(a:number,b:number):number', (a, b) => a - b, { priority: 5 });
49
+ this.model.addOperator('-(a:number):number', (a) => a * -1, { priority: 9 });
50
+ this.model.addOperator('*(a:number,b:number):number', (a, b) => a * b, { priority: 6 });
51
+ this.model.addOperator('/(a:number,b:number):number', (a, b) => a / b, { priority: 6 });
52
+ this.model.addOperator('**(a:number,b:number):number', (a, b) => a ** b, { priority: 7 });
53
+ this.model.addOperator('//(a:number,b:number):number', (a, b) => Math.pow(a, 1 / b), { priority: 7 });
54
+ this.model.addOperator('%(a:number,b:number):number', (a, b) => a % b, { priority: 8 });
55
+ this.model.addOperator('&(a:number,b:number):number', (a, b) => a & b, { priority: 5 });
56
+ this.model.addOperator('|(a:number,b:number):number', (a, b) => a | b, { priority: 5 });
57
+ this.model.addOperator('^(a:number,b:number):number', (a, b) => a ^ b, { priority: 5 });
58
+ this.model.addOperator('~(a:number):number', (a) => ~a, { priority: 9 });
59
+ this.model.addOperator('<<(a:number,b:number):number', (a, b) => a << b, { priority: 5 });
60
+ this.model.addOperator('>>(a:number,b:number):number', (a, b) => a >> b, { priority: 5 });
61
+ this.model.addOperator('==(a:T,b:T):boolean', (a, b) => a === b, { priority: 4 });
62
+ this.model.addOperatorAlias('===', '==');
63
+ this.model.addOperator('!=(a:T,b:T):boolean', (a, b) => a !== b, { priority: 4 });
64
+ this.model.addOperatorAlias('!==', '!=');
65
+ this.model.addOperatorAlias('<>', '!=');
66
+ this.model.addOperator('>(a:T,b:T):boolean', (a, b) => a > b, { priority: 4 });
67
+ this.model.addOperator('<(a:T,b:T):boolean', (a, b) => a < b, { priority: 4 });
68
+ this.model.addOperator('>=(a:T,b:T):boolean', (a, b) => a >= b, { priority: 4 });
69
+ this.model.addOperator('<=(a:T,b:T):boolean', (a, b) => a <= b, { priority: 3 });
70
+ this.model.addOperator('&&(a:T,b:T):boolean', new And(), { priority: 3 });
71
+ this.model.addOperator('||(a:T,b:T):boolean', new Or(), { priority: 3 });
72
+ this.model.addOperator('!(a:boolean):boolean', (a) => !a, { priority: 5 });
73
+ this.model.addOperator('[](list:T[],index:integer):T', (list, index) => list[index], { priority: 2 });
74
+ this.model.addOperator('$(name:string):string', (name) => process.env[name], { priority: 9 });
75
+ this.model.addOperator('=(a:T,b:T):T', new Assignment(), { priority: 1 });
76
+ this.model.addOperator('+=(a:number,b:number):number', new AssignmentAddition(), { priority: 1 });
77
+ this.model.addOperator('-=(a:number,b:number):number', new AssignmentSubtraction(), { priority: 1 });
78
+ this.model.addOperator('*=(a:number,b:number):number', new AssignmentMultiplication(), { priority: 1 });
79
+ this.model.addOperator('/=(a:number,b:number):number', new AssignmentDivision(), { priority: 1 });
80
+ this.model.addOperator('**=(a:number,b:number):number', new AssignmentExponentiation(), { priority: 1 });
81
+ this.model.addOperator('//=(a:number,b:number):number', new AssignmentFloorDivision(), { priority: 1 });
82
+ this.model.addOperator('%=(a:number,b:number):number', new AssignmentMod(), { priority: 1 });
83
+ this.model.addOperator('&=(a:number,b:number):number', new AssignmentBitAnd(), { priority: 1 });
84
+ this.model.addOperator('|=(a:number,b:number):number', new AssignmentBitOr(), { priority: 1 });
85
+ this.model.addOperator('^=(a:number,b:number):number', new AssignmentBitXor(), { priority: 1 });
86
+ this.model.addOperator('<<=(a:number,b:number):number', new AssignmentLeftShift(), { priority: 1 });
87
+ this.model.addOperator('>>=(a:number,b:number):number', new AssignmentRightShift(), { priority: 1 });
88
+ }
89
+ generalFunctions() {
90
+ // this.model.addFunction('async sleep(ms?: number)', Functions.sleep)
91
+ this.model.addFunction('console(value:any)', (value) => {
92
+ console.log(typeof value === 'object' ? JSON.stringify(value) : value);
93
+ });
94
+ }
95
+ nullFunctions() {
96
+ this.model.addFunction('nvl(value:T, default:T):T', (value, _default) => h3lp_1.h3lp.utils.nvl(value, _default));
97
+ this.model.addFunction('nvl2(value:any, a:T,b:T):T', (value, a, b) => h3lp_1.h3lp.utils.nvl2(value, a, b));
98
+ }
99
+ comparisonFunctions() {
100
+ this.model.addFunction('between(value:any,from:any,to:any):boolean', (value, from, to) => h3lp_1.h3lp.val.between(value, from, to));
101
+ this.model.addFunction('includes(source:string|any[],value:any):boolean', (source, value) => source && value ? source.includes(value) : false);
102
+ this.model.addFunctionAlias('in', 'includes');
103
+ this.model.addFunction('isNull(value:any):boolean', (value) => h3lp_1.h3lp.val.isNull(value));
104
+ this.model.addFunction('isNotNull(value:any):boolean', (value) => h3lp_1.h3lp.val.isNotNull(value));
105
+ this.model.addFunction('isEmpty(value:string):boolean', (value) => h3lp_1.h3lp.val.isEmpty(value));
106
+ this.model.addFunction('isNotEmpty(value:string):boolean', (value) => h3lp_1.h3lp.val.isNotEmpty(value));
107
+ this.model.addFunction('isBoolean(value:any):boolean', (value) => h3lp_1.h3lp.val.isBoolean(value));
108
+ this.model.addFunction('isNumber(value:any):boolean', (value) => h3lp_1.h3lp.val.isNumber(value));
109
+ this.model.addFunction('isInteger(value:any):boolean', (value) => h3lp_1.h3lp.val.isInteger(value));
110
+ this.model.addFunction('isDecimal(value:any):boolean', (value) => h3lp_1.h3lp.val.isDecimal(value));
111
+ this.model.addFunction('isString(value:any):boolean', (value) => h3lp_1.h3lp.val.isString(value));
112
+ this.model.addFunction('isDate(value:any):boolean', (value) => h3lp_1.h3lp.val.isDate(value));
113
+ this.model.addFunction('isDateTime(value:any):boolean', (value) => h3lp_1.h3lp.val.isDateTime(value));
114
+ this.model.addFunction('isTime(value:any):boolean', (value) => h3lp_1.h3lp.val.isTime(value));
115
+ this.model.addFunction('isObject(value:any):boolean', (value) => h3lp_1.h3lp.val.isObject(value));
116
+ this.model.addFunction('isArray(value:any):boolean', (value) => h3lp_1.h3lp.val.isArray(value));
117
+ this.model.addFunction('isBooleanFormat(value:string):boolean', (value) => h3lp_1.h3lp.val.isBooleanFormat(value));
118
+ this.model.addFunction('isNumberFormat(value:string):boolean', (value) => h3lp_1.h3lp.val.isNumberFormat(value));
119
+ this.model.addFunction('isIntegerFormat(value:string):boolean', (value) => h3lp_1.h3lp.val.isIntegerFormat(value));
120
+ this.model.addFunction('isDecimalFormat(value:string):boolean', (value) => h3lp_1.h3lp.val.isDecimalFormat(value));
121
+ this.model.addFunction('isDateFormat(value:string):boolean', (value) => h3lp_1.h3lp.val.isDateFormat(value));
122
+ this.model.addFunction('isDateTimeFormat(value:string):boolean', (value) => h3lp_1.h3lp.val.isDateTimeFormat(value));
123
+ this.model.addFunction('isTimeFormat(value:string):boolean', (value) => h3lp_1.h3lp.val.isTimeFormat(value));
124
+ }
125
+ numberFunctions() {
126
+ this.model.addFunction('abs(x:number):number', Math.abs);
127
+ this.model.addFunction('acos(x:number):number', Math.acos);
128
+ this.model.addFunction('asin(x:number):number', Math.asin);
129
+ this.model.addFunction('atan(x:number):number', Math.atan);
130
+ this.model.addFunction('atan2(x:number):number', Math.atan2);
131
+ this.model.addFunction('ceil(x:number):number', Math.ceil);
132
+ this.model.addFunction('cos(x:number):number', Math.cos);
133
+ this.model.addFunction('cosh(x:number):number', Math.cosh);
134
+ this.model.addFunction('exp(x:number):number', Math.exp);
135
+ this.model.addFunction('floor(x:number):number', Math.floor);
136
+ this.model.addFunction('ln(x:number):number', Math.log);
137
+ this.model.addFunction('log10(x:number):number', Math.log10);
138
+ this.model.addFunction('log(x:number):number', Math.log);
139
+ this.model.addFunction('remainder(n1:number,n2:number):number', (n1, n2) => n1 % n2);
140
+ this.model.addFunction('round(num:number,decimals=0):number', (num, decimals = 0) => decimals > 0 ? Number(num.toFixed(decimals)) : Math.round(num));
141
+ this.model.addFunction('sign(x:number):number', Math.sign);
142
+ this.model.addFunction('sin(x:number):number', Math.sin);
143
+ this.model.addFunction('sinh(x:number):number', Math.sinh);
144
+ this.model.addFunction('tan(x:number):number', Math.tan);
145
+ this.model.addFunction('tanh(x:number):number', Math.tanh);
146
+ this.model.addFunction('trunc(x:number):number', Math.trunc);
147
+ }
148
+ conversionFunctions() {
149
+ this.model.addFunction('toString(value:any):string', (value) => h3lp_1.h3lp.str.toString(value));
150
+ this.model.addFunction('toNumber(value:any):number', (value) => h3lp_1.h3lp.utils.toNumber(value));
151
+ this.model.addFunction('dateToString(date:date):string', (date) => {
152
+ if (typeof date === 'string') {
153
+ return new Date(date).toISOString();
154
+ }
155
+ return date.toISOString();
156
+ });
157
+ this.model.addFunction('stringify(value:any):string', (value) => JSON.stringify(value));
158
+ this.model.addFunction('parse(value:string):any', (value) => JSON.parse(value));
159
+ this.model.addFunction('keys(obj: any):string[]', (obj) => typeof obj === 'object' ? Object.keys(obj) : []);
160
+ this.model.addFunction('values(obj: any):any[]', (obj) => typeof obj === 'object' ? Object.values(obj) : []);
161
+ this.model.addFunction('entries(obj: any):[string,any][]', (obj) => typeof obj === 'object' ? Object.entries(obj) : []);
162
+ this.model.addFunction('fromEntries(entries: [string,any][]): any', (entries) => h3lp_1.h3lp.obj.fromEntries(entries));
163
+ }
164
+ stringFunctions() {
165
+ this.model.addFunction('chr(ascii: number):string', (ascii) => String.fromCharCode(ascii));
166
+ this.model.addFunction('capitalize(value:string):string', (value) => h3lp_1.h3lp.str.capitalize(value));
167
+ this.model.addFunction('endsWith(value:string, sub:string, start:number):boolean', (value, sub, start) => value.endsWith(sub, start));
168
+ this.model.addFunction('strCount(source: string, value: string):number', (source, value) => source.split(value).length - 1);
169
+ this.model.addFunction('lower(value: string):string', (value) => value.toLowerCase());
170
+ this.model.addFunction('lpad(value: string, len: number, pad: string):string', (value, len, pad) => value.padStart(len, pad));
171
+ this.model.addFunction('ltrim(value: string):string', (value) => value.trimLeft());
172
+ this.model.addFunction('indexOf(value:string, sub:string, start:number):number', (value, sub, start) => value.indexOf(sub, start));
173
+ this.model.addFunction('join(values:string[],separator:string=","):string', (values, separator = ',') => values.join(separator));
174
+ this.model.addFunction('replace(value: string, source: string, target: string):string', (value, source, target) => h3lp_1.h3lp.str.replace(value, source, target));
175
+ this.model.addFunction('rpad(value: string, len: number, pad: string):string', (value, len, pad) => value.padEnd(len, pad));
176
+ this.model.addFunction('rtrim(value: string):string', (value) => value.trimRight());
177
+ this.model.addFunction('substring(value: string, from: number, count: number):string', (value, from, count) => value.substring(from, count));
178
+ this.model.addFunctionAlias('substr', 'substring');
179
+ this.model.addFunction('trim(value: string):string', (value) => value.trim());
180
+ this.model.addFunction('upper(value: string):string', (value) => value.toUpperCase());
181
+ this.model.addFunction('concat(...values:any):string', (...values) => h3lp_1.h3lp.str.concat(values));
182
+ this.model.addFunctionAlias('concatenate', 'concat');
183
+ this.model.addFunction('test(value: string, regexp: string):boolean', (value, regexp) => new RegExp(regexp).test(value));
184
+ this.model.addFunction('title(value:string):string', (value) => h3lp_1.h3lp.str.initCap(value));
185
+ this.model.addFunction('match(value: string, regexp: string):any', (value, regexp) => value ? value.match(regexp) : null);
186
+ this.model.addFunction('mask(value: string):string', (value) => {
187
+ if (!value)
188
+ return value;
189
+ if (value.length > 8) {
190
+ return value.substring(0, 3) + '*****' + value.substring(value.length - 3, value.length);
191
+ }
192
+ else if (value.length > 5) {
193
+ return value.substring(0, 1) + '*****' + value.substring(value.length - 1, value.length);
194
+ }
195
+ else {
196
+ return '*';
197
+ }
198
+ });
199
+ this.model.addFunction('split(value:string,separator:string=","):string[]', (value, separator = ',') => value.split(separator));
200
+ this.model.addFunction('startWith(value:string, sub:string, start:number):boolean', (value, sub, start) => value.startsWith(sub, start));
201
+ }
202
+ dateTimeFunctions() {
203
+ this.model.addFunction('curTime():time', () => {
204
+ const date = new Date();
205
+ return date.getHours() + ':' + (date.getMinutes() + 1) + ':' + date.getSeconds();
206
+ });
207
+ this.model.addFunction('today():date', () => {
208
+ const date = new Date();
209
+ return date.getFullYear() + '-' + (date.getMonth() + 1) + '-' + date.getDate();
210
+ });
211
+ this.model.addFunction('now():dateTime', () => new Date().toISOString());
212
+ this.model.addFunction('time(value: string):time', (value) => {
213
+ const date = new Date(value);
214
+ return date.getHours() + ':' + (date.getMinutes() + 1) + ':' + date.getSeconds();
215
+ });
216
+ this.model.addFunction('date(value: string):date', (value) => {
217
+ const date = new Date(value);
218
+ return date.getFullYear() + '-' + (date.getMonth() + 1) + '-' + date.getDate();
219
+ });
220
+ this.model.addFunction('dateTime(value: string):dateTime', (value) => new Date(value).toISOString());
221
+ this.model.addFunction('year(value: dateTime):integer', (value) => {
222
+ return new Date(value).getFullYear();
223
+ });
224
+ this.model.addFunction('month(value: dateTime):integer', (value) => {
225
+ return new Date(value).getMonth() + 1;
226
+ });
227
+ this.model.addFunction('day(value: dateTime):integer', (value) => {
228
+ return new Date(value).getDate();
229
+ });
230
+ this.model.addFunction('weekday(value: dateTime):integer', (value) => {
231
+ return new Date(value).getDay();
232
+ });
233
+ this.model.addFunction('hour(value: dateTime):integer', (value) => {
234
+ return new Date(value).getHours();
235
+ });
236
+ this.model.addFunction('minute(value: dateTime):integer', (value) => {
237
+ return new Date(value).getMinutes();
238
+ });
239
+ this.model.addFunction('second(value: dateTime):integer', (value) => {
240
+ return new Date(value).getSeconds();
241
+ });
242
+ this.model.addFunction('millisecond(value: dateTime):integer', (value) => {
243
+ return new Date(value).getMilliseconds();
244
+ });
245
+ this.model.addFunction('addYear(date: dateTime, value: number):dateTime', (date, value) => {
246
+ const _date = new Date(date);
247
+ _date.setFullYear(_date.getFullYear() + value);
248
+ return _date.toISOString();
249
+ });
250
+ this.model.addFunction('addMonth(date: dateTime, value: number):dateTime', (date, value) => {
251
+ const _date = new Date(date);
252
+ _date.setMonth(_date.getMonth() + value);
253
+ return _date.toISOString();
254
+ });
255
+ this.model.addFunction('addDay(date: dateTime, value: number):dateTime', (date, value) => {
256
+ const _date = new Date(date);
257
+ _date.setDate(_date.getDate() + value);
258
+ return _date.toISOString();
259
+ });
260
+ this.model.addFunction('addHour(date: dateTime, value: number):dateTime', (date, value) => {
261
+ const _date = new Date(date);
262
+ _date.setHours(_date.getHours() + value);
263
+ return _date.toISOString();
264
+ });
265
+ this.model.addFunction('addMinute(date: dateTime, value: number):dateTime', (date, value) => {
266
+ const _date = new Date(date);
267
+ _date.setMinutes(_date.getMinutes() + value);
268
+ return _date.toISOString();
269
+ });
270
+ this.model.addFunction('addSecond(date: dateTime, value: number):dateTime', (date, value) => {
271
+ const _date = new Date(date);
272
+ _date.setSeconds(_date.getSeconds() + value);
273
+ return _date.toISOString();
274
+ });
275
+ this.model.addFunction('addMillisecond(date: dateTime, value: number):dateTime', (date, value) => {
276
+ const _date = new Date(date);
277
+ _date.setMilliseconds(_date.getMilliseconds() + value);
278
+ return _date.toISOString();
279
+ });
280
+ this.model.addFunction('addTime(date: dateTime, time: time):dateTime', (date, time) => {
281
+ const _time = new Date('2000-01-01T' + time);
282
+ const _date = new Date(date);
283
+ _date.setHours(_date.getHours() + _time.getHours());
284
+ _date.setMinutes(_date.getMinutes() + _time.getMinutes());
285
+ _date.setSeconds(_date.getSeconds() + _time.getSeconds());
286
+ _date.setMilliseconds(_date.getSeconds() + _time.getMilliseconds());
287
+ return _date.toISOString();
288
+ });
289
+ this.model.addFunction('subtractTime(date: dateTime, time: time):dateTime', (date, time) => {
290
+ const _time = new Date('2000-01-01T' + time);
291
+ const _date = new Date(date);
292
+ _date.setHours(_date.getHours() - _time.getHours());
293
+ _date.setMinutes(_date.getMinutes() - _time.getMinutes());
294
+ _date.setSeconds(_date.getSeconds() - _time.getSeconds());
295
+ _date.setMilliseconds(_date.getSeconds() - _time.getMilliseconds());
296
+ return _date.toISOString();
297
+ });
298
+ this.model.addFunction('yearDiff(date1: dateTime, date2: dateTime):integer', (date1, date2) => {
299
+ const _date1 = new Date(date1);
300
+ const _date2 = new Date(date2);
301
+ return Math.abs(_date2.getFullYear() - _date1.getFullYear());
302
+ });
303
+ this.model.addFunction('dayDiff(date1: dateTime, date2: dateTime):integer', (date1, date2) => {
304
+ const _date1 = new Date(date1);
305
+ const _date2 = new Date(date2);
306
+ return Math.floor((_date1.getTime() - _date2.getTime()) / (24 * 3600 * 1000));
307
+ });
308
+ this.model.addFunction('hourDiff(date1: dateTime, date2: dateTime):integer', (date1, date2) => {
309
+ const _date1 = new Date(date1);
310
+ const _date2 = new Date(date2);
311
+ return Math.floor((_date1.getTime() - _date2.getTime()) / (3600 * 1000));
312
+ });
313
+ this.model.addFunction('secondDiff(date1: dateTime, date2: dateTime):integer', (date1, date2) => {
314
+ const _date1 = new Date(date1);
315
+ const _date2 = new Date(date2);
316
+ return Math.floor((_date1.getTime() - _date2.getTime()) / (1000));
317
+ });
318
+ this.model.addFunction('millisecondDiff(date1: dateTime, date2: dateTime):integer', (date1, date2) => {
319
+ const _date1 = new Date(date1);
320
+ const _date2 = new Date(date2);
321
+ return Math.floor(_date1.getTime() - _date2.getTime());
322
+ });
323
+ this.model.addFunction('dayToDate(value: number):dateTime', (value) => {
324
+ return new Date(value * 24 * 3600 * 1000).toISOString();
325
+ });
326
+ this.model.addFunction('hourToDate(value: number):dateTime', (value) => {
327
+ return new Date(value * 3600 * 1000).toISOString();
328
+ });
329
+ this.model.addFunction('secondToDate(value: number):dateTime', (value) => {
330
+ return new Date(value * 1000).toISOString();
331
+ });
332
+ this.model.addFunction('millisecondToDate(value: number):dateTime', (value) => {
333
+ return new Date(value).toISOString();
334
+ });
335
+ }
336
+ arrayFunctions() {
337
+ this.model.addFunction('map(list: any[], predicate: T):T[]', new Map());
338
+ this.model.addFunctionAlias('select', 'map');
339
+ this.model.addFunction('foreach(list: any[], predicate: any)', new Foreach());
340
+ this.model.addFunctionAlias('each', 'foreach');
341
+ this.model.addFunction('filter(list: T[], predicate: boolean):T[]', new Filter());
342
+ this.model.addFunctionAlias('where', 'filter');
343
+ this.model.addFunction('reverse(list: T[], predicate: any):T[]', new Reverse());
344
+ this.model.addFunction('sort(list: T[], predicate: any):T[]', new Sort());
345
+ this.model.addFunctionAlias('order', 'sort');
346
+ this.model.addFunction('remove(list: T[], predicate: boolean):T[]', new Remove());
347
+ this.model.addFunctionAlias('delete', 'remove');
348
+ this.model.addFunction('push(list: T[], value: T):T[]', (list, item) => {
349
+ list.push(item);
350
+ return list;
351
+ });
352
+ this.model.addFunctionAlias('insert', 'push');
353
+ this.model.addFunction('pop(list: T[]): T', (list) => list.pop());
354
+ this.model.addFunction('length(source: any[]|string):number', (source) => source.length);
355
+ this.model.addFunctionAlias('len', 'length');
356
+ this.model.addFunction('slice(list: T[], from:integer, to:integer):T[]', (list, from, to) => list.slice(from, to));
357
+ this.model.addFunction('page(list: T[], page:integer, records:integer):T[]', (list, page, records) => {
358
+ let from = (page - 1) * records;
359
+ if (from < 0) {
360
+ from = 0;
361
+ }
362
+ let to = from + records;
363
+ if (to > list.length) {
364
+ to = list.length - 1;
365
+ }
366
+ return list.slice(from, to);
367
+ });
368
+ // this.addFunction('update', ArrayFunctions.update, OperatorType.arrow, Update)
369
+ }
370
+ groupFunctions() {
371
+ this.model.addFunction('distinct(list: any[], predicate: any): any[]', new Distinct());
372
+ this.model.addFunction('first(list: T[], predicate: boolean): T', new First());
373
+ this.model.addFunction('last(list: T[], predicate: boolean): T', new Last());
374
+ this.model.addFunction('count(list: T[], predicate: boolean): integer', new Count());
375
+ this.model.addFunction('max(list: T[], predicate: boolean): T', new Max());
376
+ this.model.addFunction('min(list: T[], predicate: boolean): T', new Min());
377
+ this.model.addFunction('avg(list: T[], value: number): number', new Avg());
378
+ this.model.addFunction('sum(list: T[], value: number): number', new Sum());
379
+ }
380
+ setsFunctions() {
381
+ this.model.addFunction('union(a: T[], b: T[]): T[]', new Union());
382
+ this.model.addFunction('intersection(a: T[], b: T[]): T[]', new Intersection());
383
+ this.model.addFunction('difference(a: T[], b: T[]): T[]', new Difference());
384
+ this.model.addFunction('symmetricDifference(a: T[], b: T[]): T[]', new SymmetricDifference());
385
+ }
386
+ }
387
+ exports.CoreLibrary = CoreLibrary;
388
+ class And extends contract_1.PrototypeEvaluator {
389
+ clone(operand) {
390
+ return new And(operand);
391
+ }
392
+ eval(context) {
393
+ if (this.operand === undefined) {
394
+ throw new Error('Operand undefined');
395
+ }
396
+ if (!this.operand.children[0].eval(context))
397
+ return false;
398
+ return this.operand.children[1].eval(context);
399
+ }
400
+ }
401
+ class Or extends contract_1.PrototypeEvaluator {
402
+ clone(operand) {
403
+ return new Or(operand);
404
+ }
405
+ eval(context) {
406
+ if (this.operand === undefined) {
407
+ throw new Error('Operand undefined');
408
+ }
409
+ if (this.operand.children[0].eval(context))
410
+ return true;
411
+ return this.operand.children[1].eval(context);
412
+ }
413
+ }
414
+ class Assignment extends contract_1.PrototypeEvaluator {
415
+ clone(operand) {
416
+ return new Assignment(operand);
417
+ }
418
+ eval(context) {
419
+ if (this.operand === undefined) {
420
+ throw new Error('Operand undefined');
421
+ }
422
+ const value = this.operand.children[1].eval(context);
423
+ context.data.set(this.operand.children[0].name, value);
424
+ return value;
425
+ }
426
+ }
427
+ class AssignmentAddition extends contract_1.PrototypeEvaluator {
428
+ clone(operand) {
429
+ return new AssignmentAddition(operand);
430
+ }
431
+ eval(context) {
432
+ if (this.operand === undefined) {
433
+ throw new Error('Operand undefined');
434
+ }
435
+ const value = this.operand.children[0].eval(context) + this.operand.children[1].eval(context);
436
+ context.data.set(this.operand.children[0].name, value);
437
+ return value;
438
+ }
439
+ }
440
+ class AssignmentSubtraction extends contract_1.PrototypeEvaluator {
441
+ clone(operand) {
442
+ return new AssignmentSubtraction(operand);
443
+ }
444
+ eval(context) {
445
+ if (this.operand === undefined) {
446
+ throw new Error('Operand undefined');
447
+ }
448
+ const value = this.operand.children[0].eval(context) - this.operand.children[1].eval(context);
449
+ context.data.set(this.operand.children[0].name, value);
450
+ return value;
451
+ }
452
+ }
453
+ class AssignmentMultiplication extends contract_1.PrototypeEvaluator {
454
+ clone(operand) {
455
+ return new AssignmentMultiplication(operand);
456
+ }
457
+ eval(context) {
458
+ if (this.operand === undefined) {
459
+ throw new Error('Operand undefined');
460
+ }
461
+ const value = this.operand.children[0].eval(context) * this.operand.children[1].eval(context);
462
+ context.data.set(this.operand.children[0].name, value);
463
+ return value;
464
+ }
465
+ }
466
+ class AssignmentDivision extends contract_1.PrototypeEvaluator {
467
+ clone(operand) {
468
+ return new AssignmentDivision(operand);
469
+ }
470
+ eval(context) {
471
+ if (this.operand === undefined) {
472
+ throw new Error('Operand undefined');
473
+ }
474
+ const value = this.operand.children[0].eval(context) / this.operand.children[1].eval(context);
475
+ context.data.set(this.operand.children[0].name, value);
476
+ return value;
477
+ }
478
+ }
479
+ class AssignmentExponentiation extends contract_1.PrototypeEvaluator {
480
+ clone(operand) {
481
+ return new AssignmentExponentiation(operand);
482
+ }
483
+ eval(context) {
484
+ if (this.operand === undefined) {
485
+ throw new Error('Operand undefined');
486
+ }
487
+ const value = this.operand.children[0].eval(context) ** this.operand.children[1].eval(context);
488
+ context.data.set(this.operand.children[0].name, value);
489
+ return value;
490
+ }
491
+ }
492
+ class AssignmentFloorDivision extends contract_1.PrototypeEvaluator {
493
+ clone(operand) {
494
+ return new AssignmentFloorDivision(operand);
495
+ }
496
+ eval(context) {
497
+ if (this.operand === undefined) {
498
+ throw new Error('Operand undefined');
499
+ }
500
+ const value = Math.floor(this.operand.children[0].eval(context) / this.operand.children[1].eval(context));
501
+ context.data.set(this.operand.children[0].name, value);
502
+ return value;
503
+ }
504
+ }
505
+ class AssignmentMod extends contract_1.PrototypeEvaluator {
506
+ clone(operand) {
507
+ return new AssignmentMod(operand);
508
+ }
509
+ eval(context) {
510
+ if (this.operand === undefined) {
511
+ throw new Error('Operand undefined');
512
+ }
513
+ const value = this.operand.children[0].eval(context) % this.operand.children[1].eval(context);
514
+ context.data.set(this.operand.children[0].name, value);
515
+ return value;
516
+ }
517
+ }
518
+ class AssignmentBitAnd extends contract_1.PrototypeEvaluator {
519
+ clone(operand) {
520
+ return new AssignmentBitAnd(operand);
521
+ }
522
+ eval(context) {
523
+ if (this.operand === undefined) {
524
+ throw new Error('Operand undefined');
525
+ }
526
+ const value = this.operand.children[0].eval(context) & this.operand.children[1].eval(context);
527
+ context.data.set(this.operand.children[0].name, value);
528
+ return value;
529
+ }
530
+ }
531
+ class AssignmentBitOr extends contract_1.PrototypeEvaluator {
532
+ clone(operand) {
533
+ return new AssignmentBitOr(operand);
534
+ }
535
+ eval(context) {
536
+ if (this.operand === undefined) {
537
+ throw new Error('Operand undefined');
538
+ }
539
+ const value = this.operand.children[0].eval(context) | this.operand.children[1].eval(context);
540
+ context.data.set(this.operand.children[0].name, value);
541
+ return value;
542
+ }
543
+ }
544
+ class AssignmentBitXor extends contract_1.PrototypeEvaluator {
545
+ clone(operand) {
546
+ return new AssignmentBitXor(operand);
547
+ }
548
+ eval(context) {
549
+ if (this.operand === undefined) {
550
+ throw new Error('Operand undefined');
551
+ }
552
+ const value = this.operand.children[0].eval(context) ^ this.operand.children[1].eval(context);
553
+ context.data.set(this.operand.children[0].name, value);
554
+ return value;
555
+ }
556
+ }
557
+ class AssignmentLeftShift extends contract_1.PrototypeEvaluator {
558
+ clone(operand) {
559
+ return new AssignmentLeftShift(operand);
560
+ }
561
+ eval(context) {
562
+ if (this.operand === undefined) {
563
+ throw new Error('Operand undefined');
564
+ }
565
+ const value = this.operand.children[0].eval(context) << this.operand.children[1].eval(context);
566
+ context.data.set(this.operand.children[0].name, value);
567
+ return value;
568
+ }
569
+ }
570
+ class AssignmentRightShift extends contract_1.PrototypeEvaluator {
571
+ clone(operand) {
572
+ return new AssignmentRightShift(operand);
573
+ }
574
+ eval(context) {
575
+ if (this.operand === undefined) {
576
+ throw new Error('Operand undefined');
577
+ }
578
+ const value = this.operand.children[0].eval(context) >> this.operand.children[1].eval(context);
579
+ context.data.set(this.operand.children[0].name, value);
580
+ return value;
581
+ }
582
+ }
583
+ class Map extends contract_1.PrototypeEvaluator {
584
+ clone(operand) {
585
+ return new Map(operand);
586
+ }
587
+ eval(context) {
588
+ if (this.operand === undefined) {
589
+ throw new Error('Operand undefined');
590
+ }
591
+ const rows = [];
592
+ const list = this.operand.children[0].eval(context);
593
+ if (!list) {
594
+ throw new Error(`Array ${this.operand.children[0].name} undefined`);
595
+ }
596
+ if (this.operand.children[2].type === contract_1.OperandType.Obj) {
597
+ const groupers = [];
598
+ const aggregates = [];
599
+ for (const child of this.operand.children[2].children) {
600
+ // In the case of being an object the value to return, find out if there are fields that are summarized
601
+ const keyValue = child;
602
+ if (keyValue) {
603
+ if (__1.operandHelper.haveAggregates(keyValue.children[0])) {
604
+ aggregates.push(keyValue);
605
+ }
606
+ else {
607
+ groupers.push(keyValue);
608
+ }
609
+ }
610
+ }
611
+ if (aggregates.length > 0) {
612
+ // case with aggregate functions
613
+ const keys = __1.operandHelper.getKeys(this.operand.children[1], groupers, list, context);
614
+ // once you got all the keys you have to calculate the aggregates fields
615
+ const variable = this.operand.children[1];
616
+ for (const key of keys) {
617
+ for (const keyValue of aggregates) {
618
+ const operandCloned = __1.expressions.clone(keyValue.children[0]);
619
+ const operandResolved = __1.operandHelper.solveAggregates(key.items, variable, operandCloned, context);
620
+ const value = operandResolved.eval(context);
621
+ key.summarizers.push({ name: keyValue.name, value });
622
+ }
623
+ }
624
+ // build the list of results
625
+ for (const key of keys) {
626
+ const row = {};
627
+ for (const value of key.values) {
628
+ row[value.name] = value.value;
629
+ }
630
+ for (const summarizer of key.summarizers) {
631
+ row[summarizer.name] = summarizer.value;
632
+ }
633
+ rows.push(row);
634
+ }
635
+ return rows;
636
+ }
637
+ }
638
+ // simple case without aggregate functions
639
+ const childContext = context.newContext();
640
+ for (const item of list) {
641
+ childContext.data.set(this.operand.children[1].name, item);
642
+ const row = this.operand.children[2].eval(childContext);
643
+ rows.push(row);
644
+ }
645
+ return rows;
646
+ }
647
+ }
648
+ class Distinct extends contract_1.PrototypeEvaluator {
649
+ clone(operand) {
650
+ return new Distinct(operand);
651
+ }
652
+ eval(context) {
653
+ if (this.operand === undefined) {
654
+ throw new Error('Operand undefined');
655
+ }
656
+ const rows = [];
657
+ const list = this.operand.children[0].eval(context);
658
+ if (!list) {
659
+ throw new Error(`Array ${this.operand.children[0].name} undefined`);
660
+ }
661
+ if (this.operand.children.length === 1) {
662
+ // simple case
663
+ for (const item of list) {
664
+ if (rows.find((p) => p === item) === undefined) {
665
+ rows.push(item);
666
+ }
667
+ }
668
+ return rows;
669
+ }
670
+ else if (this.operand.children[2].type === contract_1.OperandType.Obj) {
671
+ // case with aggregate functions
672
+ const keys = __1.operandHelper.getKeys(this.operand.children[1], this.operand.children[2].children, list, context.newContext());
673
+ // build the list of results
674
+ for (const key of keys) {
675
+ const row = {};
676
+ for (const value of key.values) {
677
+ row[value.name] = value.value;
678
+ }
679
+ rows.push(row);
680
+ }
681
+ return rows;
682
+ }
683
+ else if (this.operand.children[2].type === contract_1.OperandType.List) {
684
+ throw new Error('Distinct not support Array result');
685
+ }
686
+ // simple case without aggregate functions
687
+ const childContext = context.newContext();
688
+ for (const item of list) {
689
+ childContext.data.set(this.operand.children[1].name, item);
690
+ const value = this.operand.children[2].eval(childContext);
691
+ if (rows.find((p) => p === value) === undefined) {
692
+ rows.push(value);
693
+ }
694
+ }
695
+ return rows;
696
+ }
697
+ }
698
+ class Foreach extends contract_1.PrototypeEvaluator {
699
+ clone(operand) {
700
+ return new Foreach(operand);
701
+ }
702
+ eval(context) {
703
+ if (this.operand === undefined) {
704
+ throw new Error('Operand undefined');
705
+ }
706
+ const list = this.operand.children[0].eval(context);
707
+ if (!list) {
708
+ throw new Error(`Array ${this.operand.children[0].name} undefined`);
709
+ }
710
+ const childContext = context.newContext();
711
+ for (const item of list) {
712
+ childContext.data.set(this.operand.children[1].name, item);
713
+ this.operand.children[2].eval(childContext);
714
+ }
715
+ return list;
716
+ }
717
+ }
718
+ class Filter extends contract_1.PrototypeEvaluator {
719
+ clone(operand) {
720
+ return new Filter(operand);
721
+ }
722
+ eval(context) {
723
+ if (this.operand === undefined) {
724
+ throw new Error('Operand undefined');
725
+ }
726
+ const rows = [];
727
+ const list = this.operand.children[0].eval(context);
728
+ if (!list) {
729
+ throw new Error(`Array ${this.operand.children[0].name} undefined`);
730
+ }
731
+ const childContext = context.newContext();
732
+ for (const item of list) {
733
+ childContext.data.set(this.operand.children[1].name, item);
734
+ if (this.operand.children[2].eval(childContext)) {
735
+ rows.push(item);
736
+ }
737
+ }
738
+ return rows;
739
+ }
740
+ }
741
+ class Reverse extends contract_1.PrototypeEvaluator {
742
+ clone(operand) {
743
+ return new Reverse(operand);
744
+ }
745
+ eval(context) {
746
+ if (this.operand === undefined) {
747
+ throw new Error('Operand undefined');
748
+ }
749
+ const list = this.operand.children[0].eval(context);
750
+ if (!list) {
751
+ throw new Error(`Array ${this.operand.children[0].name} undefined`);
752
+ }
753
+ if (this.operand.children.length === 1) {
754
+ return list.reverse();
755
+ }
756
+ const values = [];
757
+ const childContext = context.newContext();
758
+ for (const item of list) {
759
+ childContext.data.set(this.operand.children[1].name, item);
760
+ const value = this.operand.children[2].eval(childContext);
761
+ values.push({ value, p: item });
762
+ }
763
+ values.sort((a, b) => a.value > b.value ? 1 : a.value < b.value ? -1 : 0);
764
+ values.reverse();
765
+ return values.map(p => p.p);
766
+ }
767
+ }
768
+ class Sort extends contract_1.PrototypeEvaluator {
769
+ clone(operand) {
770
+ return new Sort(operand);
771
+ }
772
+ eval(context) {
773
+ if (this.operand === undefined) {
774
+ throw new Error('Operand undefined');
775
+ }
776
+ const values = [];
777
+ const list = this.operand.children[0].eval(context);
778
+ if (!list) {
779
+ throw new Error(`Array ${this.operand.children[0].name} undefined`);
780
+ }
781
+ if (this.operand.children.length === 1) {
782
+ return list.sort();
783
+ }
784
+ const childContext = context.newContext();
785
+ for (const item of list) {
786
+ childContext.data.set(this.operand.children[1].name, item);
787
+ const value = this.operand.children[2].eval(childContext);
788
+ values.push({ value, p: item });
789
+ }
790
+ values.sort((a, b) => a.value > b.value ? 1 : a.value < b.value ? -1 : 0);
791
+ return values.map(p => p.p);
792
+ }
793
+ }
794
+ class Remove extends contract_1.PrototypeEvaluator {
795
+ clone(operand) {
796
+ return new Remove(operand);
797
+ }
798
+ eval(context) {
799
+ if (this.operand === undefined) {
800
+ throw new Error('Operand undefined');
801
+ }
802
+ const rows = [];
803
+ const list = this.operand.children[0].eval(context);
804
+ if (!list) {
805
+ throw new Error(`Array ${this.operand.children[0].name} undefined`);
806
+ }
807
+ const childContext = context.newContext();
808
+ for (const item of list) {
809
+ childContext.data.set(this.operand.children[1].name, item);
810
+ if (!this.operand.children[2].eval(childContext)) {
811
+ rows.push(item);
812
+ }
813
+ }
814
+ return rows;
815
+ }
816
+ }
817
+ class First extends contract_1.PrototypeEvaluator {
818
+ clone(operand) {
819
+ return new First(operand);
820
+ }
821
+ eval(context) {
822
+ if (this.operand === undefined) {
823
+ throw new Error('Operand undefined');
824
+ }
825
+ const list = this.operand.children[0].eval(context);
826
+ if (!list) {
827
+ throw new Error(`Array ${this.operand.children[0].name} undefined`);
828
+ }
829
+ if (this.operand.children.length === 1) {
830
+ return list && list.length > 0 ? list[0] : null;
831
+ }
832
+ return __1.operandHelper.first(list, this.operand.children[1], this.operand.children[2], context.newContext());
833
+ }
834
+ }
835
+ class Last extends contract_1.PrototypeEvaluator {
836
+ clone(operand) {
837
+ return new Last(operand);
838
+ }
839
+ eval(context) {
840
+ if (this.operand === undefined) {
841
+ throw new Error('Operand undefined');
842
+ }
843
+ const list = this.operand.children[0].eval(context);
844
+ if (!list) {
845
+ throw new Error(`Array ${this.operand.children[0].name} undefined`);
846
+ }
847
+ if (this.operand.children.length === 1) {
848
+ return list && list.length > 0 ? list[list.length - 1] : null;
849
+ }
850
+ return __1.operandHelper.last(list, this.operand.children[1], this.operand.children[2], context.newContext());
851
+ }
852
+ }
853
+ class Count extends contract_1.PrototypeEvaluator {
854
+ clone(operand) {
855
+ return new Count(operand);
856
+ }
857
+ eval(context) {
858
+ if (this.operand === undefined) {
859
+ throw new Error('Operand undefined');
860
+ }
861
+ const list = this.operand.children[0].eval(context);
862
+ if (!list) {
863
+ throw new Error(`Array ${this.operand.children[0].name} undefined`);
864
+ }
865
+ if (this.operand.children.length === 1) {
866
+ return list.length;
867
+ }
868
+ return __1.operandHelper.count(list, this.operand.children[1], this.operand.children[2], context.newContext());
869
+ }
870
+ }
871
+ class Max extends contract_1.PrototypeEvaluator {
872
+ clone(operand) {
873
+ return new Max(operand);
874
+ }
875
+ eval(context) {
876
+ if (this.operand === undefined) {
877
+ throw new Error('Operand undefined');
878
+ }
879
+ const list = this.operand.children[0].eval(context);
880
+ if (!list) {
881
+ throw new Error(`Array ${this.operand.children[0].name} undefined`);
882
+ }
883
+ if (this.operand.children.length === 1) {
884
+ let max;
885
+ for (const item of list) {
886
+ if (max === undefined || (item !== null && item > max)) {
887
+ max = item;
888
+ }
889
+ }
890
+ return max;
891
+ }
892
+ return __1.operandHelper.max(list, this.operand.children[1], this.operand.children[2], context.newContext());
893
+ }
894
+ }
895
+ class Min extends contract_1.PrototypeEvaluator {
896
+ clone(operand) {
897
+ return new Min(operand);
898
+ }
899
+ eval(context) {
900
+ if (this.operand === undefined) {
901
+ throw new Error('Operand undefined');
902
+ }
903
+ const list = this.operand.children[0].eval(context);
904
+ if (!list) {
905
+ throw new Error(`Array ${this.operand.children[0].name} undefined`);
906
+ }
907
+ if (this.operand.children.length === 1) {
908
+ let min;
909
+ for (const item of list) {
910
+ if (min === undefined || (item !== null && item < min)) {
911
+ min = item;
912
+ }
913
+ }
914
+ return min;
915
+ }
916
+ return __1.operandHelper.min(list, this.operand.children[1], this.operand.children[2], context.newContext());
917
+ }
918
+ }
919
+ class Avg extends contract_1.PrototypeEvaluator {
920
+ clone(operand) {
921
+ return new Avg(operand);
922
+ }
923
+ eval(context) {
924
+ if (this.operand === undefined) {
925
+ throw new Error('Operand undefined');
926
+ }
927
+ const list = this.operand.children[0].eval(context);
928
+ if (!list) {
929
+ throw new Error(`Array ${this.operand.children[0].name} undefined`);
930
+ }
931
+ if (this.operand.children.length === 1) {
932
+ let sum = 0;
933
+ for (const item of list) {
934
+ if (item !== null) {
935
+ sum = sum + item;
936
+ }
937
+ }
938
+ return list.length > 0 ? sum / list.length : 0;
939
+ }
940
+ return __1.operandHelper.avg(list, this.operand.children[1], this.operand.children[2], context.newContext());
941
+ }
942
+ }
943
+ class Sum extends contract_1.PrototypeEvaluator {
944
+ clone(operand) {
945
+ return new Sum(operand);
946
+ }
947
+ eval(context) {
948
+ if (this.operand === undefined) {
949
+ throw new Error('Operand undefined');
950
+ }
951
+ const list = this.operand.children[0].eval(context);
952
+ if (!list) {
953
+ throw new Error(`Array ${this.operand.children[0].name} undefined`);
954
+ }
955
+ if (this.operand.children.length === 1) {
956
+ let sum = 0;
957
+ for (const item of list) {
958
+ if (item !== null) {
959
+ sum = sum + item;
960
+ }
961
+ }
962
+ return sum;
963
+ }
964
+ return __1.operandHelper.sum(list, this.operand.children[1], this.operand.children[2], context.newContext());
965
+ }
966
+ }
967
+ class Union extends contract_1.PrototypeEvaluator {
968
+ clone(operand) {
969
+ return new Union(operand);
970
+ }
971
+ eval(context) {
972
+ if (this.operand === undefined) {
973
+ throw new Error('Operand undefined');
974
+ }
975
+ const a = this.operand.children[0].eval(context);
976
+ const b = this.operand.children[1].eval(context);
977
+ if (!a) {
978
+ throw new Error(`Array ${this.operand.children[0].name} undefined`);
979
+ }
980
+ if (!b) {
981
+ throw new Error(`Array ${this.operand.children[1].name} undefined`);
982
+ }
983
+ if (a.length === 0) {
984
+ return b;
985
+ }
986
+ if (b.length === 0) {
987
+ return a;
988
+ }
989
+ let result = [];
990
+ if (Array.isArray(a[0]) || Array.isArray(b[0])) {
991
+ throw new Error('Cannot union arrays of arrays');
992
+ }
993
+ else if (typeof a[0] === 'object') {
994
+ for (const element of a) {
995
+ const key = __1.operandHelper.objectKey(element);
996
+ result.push({ key, value: element });
997
+ }
998
+ for (const element of b) {
999
+ const key = __1.operandHelper.objectKey(element);
1000
+ if (!result.find((p) => p.key === key)) {
1001
+ result.push({ key, value: element });
1002
+ }
1003
+ }
1004
+ return result.map((p) => p.value);
1005
+ }
1006
+ result = result.concat(a);
1007
+ for (const element of b) {
1008
+ if (!result.includes(element)) {
1009
+ result.push(element);
1010
+ }
1011
+ }
1012
+ return result;
1013
+ }
1014
+ }
1015
+ class Intersection extends contract_1.PrototypeEvaluator {
1016
+ clone(operand) {
1017
+ return new Intersection(operand);
1018
+ }
1019
+ eval(context) {
1020
+ if (this.operand === undefined) {
1021
+ throw new Error('Operand undefined');
1022
+ }
1023
+ const a = this.operand.children[0].eval(context);
1024
+ const b = this.operand.children[1].eval(context);
1025
+ if (!a) {
1026
+ throw new Error(`Array ${this.operand.children[0].name} undefined`);
1027
+ }
1028
+ if (!b) {
1029
+ throw new Error(`Array ${this.operand.children[1].name} undefined`);
1030
+ }
1031
+ if (a.length === 0 || b.length === 0) {
1032
+ return [];
1033
+ }
1034
+ const result = [];
1035
+ if (Array.isArray(a[0]) || Array.isArray(b[0])) {
1036
+ throw new Error('Cannot union arrays of arrays');
1037
+ }
1038
+ else if (typeof a[0] === 'object') {
1039
+ const keys = a.map((p) => __1.operandHelper.objectKey(p));
1040
+ for (const element of b) {
1041
+ const key = __1.operandHelper.objectKey(element);
1042
+ if (keys.includes(key)) {
1043
+ result.push(element);
1044
+ }
1045
+ }
1046
+ return result;
1047
+ }
1048
+ else {
1049
+ for (const element of b) {
1050
+ if (a.includes(element)) {
1051
+ result.push(element);
1052
+ }
1053
+ }
1054
+ return result;
1055
+ }
1056
+ }
1057
+ }
1058
+ class Difference extends contract_1.PrototypeEvaluator {
1059
+ clone(operand) {
1060
+ return new Difference(operand);
1061
+ }
1062
+ eval(context) {
1063
+ if (this.operand === undefined) {
1064
+ throw new Error('Operand undefined');
1065
+ }
1066
+ const a = this.operand.children[0].eval(context);
1067
+ const b = this.operand.children[1].eval(context);
1068
+ if (!a) {
1069
+ throw new Error(`Array ${this.operand.children[0].name} undefined`);
1070
+ }
1071
+ if (!b) {
1072
+ throw new Error(`Array ${this.operand.children[1].name} undefined`);
1073
+ }
1074
+ if (a.length === 0) {
1075
+ return [];
1076
+ }
1077
+ if (b.length === 0) {
1078
+ return a;
1079
+ }
1080
+ const result = [];
1081
+ if (Array.isArray(a[0]) || Array.isArray(b[0])) {
1082
+ throw new Error('Cannot union arrays of arrays');
1083
+ }
1084
+ else if (typeof a[0] === 'object') {
1085
+ const keys = b.map((p) => __1.operandHelper.objectKey(p));
1086
+ for (const element of a) {
1087
+ const key = __1.operandHelper.objectKey(element);
1088
+ if (!keys.includes(key)) {
1089
+ result.push(element);
1090
+ }
1091
+ }
1092
+ return result;
1093
+ }
1094
+ else {
1095
+ for (const element of a) {
1096
+ if (!b.includes(element)) {
1097
+ result.push(element);
1098
+ }
1099
+ }
1100
+ return result;
1101
+ }
1102
+ }
1103
+ }
1104
+ class SymmetricDifference extends contract_1.PrototypeEvaluator {
1105
+ clone(operand) {
1106
+ return new SymmetricDifference(operand);
1107
+ }
1108
+ eval(context) {
1109
+ if (this.operand === undefined) {
1110
+ throw new Error('Operand undefined');
1111
+ }
1112
+ const a = this.operand.children[0].eval(context);
1113
+ const b = this.operand.children[1].eval(context);
1114
+ if (!a) {
1115
+ throw new Error(`Array ${this.operand.children[0].name} undefined`);
1116
+ }
1117
+ if (!b) {
1118
+ throw new Error(`Array ${this.operand.children[1].name} undefined`);
1119
+ }
1120
+ if (a.length === 0) {
1121
+ return b;
1122
+ }
1123
+ if (b.length === 0) {
1124
+ return a;
1125
+ }
1126
+ const result = [];
1127
+ if (Array.isArray(a[0]) || Array.isArray(b[0])) {
1128
+ throw new Error('Cannot union arrays of arrays');
1129
+ }
1130
+ else if (typeof a[0] === 'object') {
1131
+ const aKeys = a.map((p) => __1.operandHelper.objectKey(p));
1132
+ const bKeys = b.map((p) => __1.operandHelper.objectKey(p));
1133
+ for (const element of a) {
1134
+ const key = __1.operandHelper.objectKey(element);
1135
+ if (!bKeys.includes(key)) {
1136
+ result.push(element);
1137
+ }
1138
+ }
1139
+ for (const element of b) {
1140
+ const key = __1.operandHelper.objectKey(element);
1141
+ if (!aKeys.includes(key)) {
1142
+ result.push(element);
1143
+ }
1144
+ }
1145
+ return result;
1146
+ }
1147
+ else {
1148
+ for (const element of a) {
1149
+ if (!b.includes(element)) {
1150
+ result.push(element);
1151
+ }
1152
+ }
1153
+ for (const element of b) {
1154
+ if (!a.includes(element)) {
1155
+ result.push(element);
1156
+ }
1157
+ }
1158
+ return result;
1159
+ }
1160
+ }
1161
+ }
1162
+ //# sourceMappingURL=coreLibrary.js.map