@fincity/kirun-js 2.9.0 → 2.10.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/__tests__/engine/runtime/expression/ExpressionArrayStringIndexing.ts +67 -0
- package/dist/index.js +1 -1
- package/dist/index.js.map +1 -1
- package/dist/module.js +1 -1
- package/dist/module.js.map +1 -1
- package/dist/types.d.ts +9 -5
- package/dist/types.d.ts.map +1 -1
- package/package.json +57 -57
- package/src/engine/function/system/date/GetNames.ts +1 -1
- package/src/engine/runtime/expression/Expression.ts +15 -1
- package/src/engine/runtime/expression/ExpressionEvaluator.ts +36 -31
- package/src/engine/runtime/expression/Operation.ts +10 -4
- package/src/engine/runtime/expression/operators/binary/ArrayRangeOperator.ts +7 -0
- package/src/engine/runtime/expression/operators/binary/index.ts +1 -0
- package/src/engine/runtime/expression/tokenextractor/TokenValueExtractor.ts +33 -6
|
@@ -30,6 +30,7 @@ export class Operation {
|
|
|
30
30
|
public static readonly UNARY_BITWISE_COMPLEMENT: Operation = new Operation('UN: ~', '~');
|
|
31
31
|
|
|
32
32
|
public static readonly ARRAY_OPERATOR: Operation = new Operation('[');
|
|
33
|
+
public static readonly ARRAY_RANGE_INDEX_OPERATOR: Operation = new Operation('..');
|
|
33
34
|
public static readonly OBJECT_OPERATOR: Operation = new Operation('.');
|
|
34
35
|
|
|
35
36
|
public static readonly NULLISH_COALESCING_OPERATOR: Operation = new Operation('??');
|
|
@@ -39,7 +40,7 @@ export class Operation {
|
|
|
39
40
|
private static readonly VALUE_OF: Map<string, Operation> = new Map([
|
|
40
41
|
['MULTIPLICATION', Operation.MULTIPLICATION],
|
|
41
42
|
['DIVISION', Operation.DIVISION],
|
|
42
|
-
['
|
|
43
|
+
['INTEGER_DIVISION', Operation.INTEGER_DIVISION],
|
|
43
44
|
['MOD', Operation.MOD],
|
|
44
45
|
['ADDITION', Operation.ADDITION],
|
|
45
46
|
['SUBTRACTION', Operation.SUBTRACTION],
|
|
@@ -64,6 +65,7 @@ export class Operation {
|
|
|
64
65
|
['UNARY_LOGICAL_NOT', Operation.UNARY_LOGICAL_NOT],
|
|
65
66
|
['UNARY_BITWISE_COMPLEMENT', Operation.UNARY_BITWISE_COMPLEMENT],
|
|
66
67
|
['ARRAY_OPERATOR', Operation.ARRAY_OPERATOR],
|
|
68
|
+
['ARRAY_RANGE_INDEX_OPERATOR', Operation.ARRAY_RANGE_INDEX_OPERATOR],
|
|
67
69
|
['OBJECT_OPERATOR', Operation.OBJECT_OPERATOR],
|
|
68
70
|
['NULLISH_COALESCING_OPERATOR', Operation.NULLISH_COALESCING_OPERATOR],
|
|
69
71
|
['CONDITIONAL_TERNARY_OPERATOR', Operation.CONDITIONAL_TERNARY_OPERATOR],
|
|
@@ -123,6 +125,7 @@ export class Operation {
|
|
|
123
125
|
[Operation.UNARY_BITWISE_COMPLEMENT, 1],
|
|
124
126
|
[Operation.ARRAY_OPERATOR, 1],
|
|
125
127
|
[Operation.OBJECT_OPERATOR, 1],
|
|
128
|
+
[Operation.ARRAY_RANGE_INDEX_OPERATOR, 2],
|
|
126
129
|
[Operation.MULTIPLICATION, 2],
|
|
127
130
|
[Operation.DIVISION, 2],
|
|
128
131
|
[Operation.INTEGER_DIVISION, 2],
|
|
@@ -153,6 +156,7 @@ export class Operation {
|
|
|
153
156
|
...Array.from(Operation.LOGICAL_OPERATORS),
|
|
154
157
|
...Array.from(Operation.BITWISE_OPERATORS),
|
|
155
158
|
Operation.ARRAY_OPERATOR,
|
|
159
|
+
Operation.ARRAY_RANGE_INDEX_OPERATOR,
|
|
156
160
|
Operation.OBJECT_OPERATOR,
|
|
157
161
|
...Array.from(Operation.CONDITIONAL_OPERATORS),
|
|
158
162
|
].map((e) => e.getOperator()),
|
|
@@ -164,6 +168,7 @@ export class Operation {
|
|
|
164
168
|
...Array.from(Operation.LOGICAL_OPERATORS),
|
|
165
169
|
...Array.from(Operation.BITWISE_OPERATORS),
|
|
166
170
|
Operation.ARRAY_OPERATOR,
|
|
171
|
+
Operation.ARRAY_RANGE_INDEX_OPERATOR,
|
|
167
172
|
Operation.OBJECT_OPERATOR,
|
|
168
173
|
...Array.from(Operation.CONDITIONAL_OPERATORS),
|
|
169
174
|
]
|
|
@@ -192,9 +197,10 @@ export class Operation {
|
|
|
192
197
|
.map((e) => e.length)
|
|
193
198
|
.reduce((a, c) => (a > c ? a : c), 0);
|
|
194
199
|
|
|
195
|
-
private operator: string;
|
|
196
|
-
private operatorName: string;
|
|
197
|
-
private _shouldBeWrappedInSpace: boolean;
|
|
200
|
+
private readonly operator: string;
|
|
201
|
+
private readonly operatorName: string;
|
|
202
|
+
private readonly _shouldBeWrappedInSpace: boolean;
|
|
203
|
+
|
|
198
204
|
public constructor(
|
|
199
205
|
operator: string,
|
|
200
206
|
operatorName?: string,
|
|
@@ -6,7 +6,7 @@ import { ExpressionEvaluationException } from '../exception/ExpressionEvaluation
|
|
|
6
6
|
|
|
7
7
|
export abstract class TokenValueExtractor {
|
|
8
8
|
public static readonly REGEX_SQUARE_BRACKETS: RegExp = /[\[\]]/;
|
|
9
|
-
public static readonly REGEX_DOT: RegExp =
|
|
9
|
+
public static readonly REGEX_DOT: RegExp = /(?<!\.)\.(?!\.)/;
|
|
10
10
|
|
|
11
11
|
public getValue(token: string): any {
|
|
12
12
|
let prefix: string = this.getPrefix();
|
|
@@ -71,7 +71,8 @@ export abstract class TokenValueExtractor {
|
|
|
71
71
|
|
|
72
72
|
if (cPart === 'length') return this.getLength(token, cElement);
|
|
73
73
|
|
|
74
|
-
if (Array.isArray(cElement))
|
|
74
|
+
if (typeof cElement == 'string' || Array.isArray(cElement))
|
|
75
|
+
return this.handleArrayAccess(token, cPart, cElement);
|
|
75
76
|
|
|
76
77
|
return this.handleObjectAccess(token, parts, partNumber, cPart, cElement);
|
|
77
78
|
}
|
|
@@ -91,8 +92,29 @@ export abstract class TokenValueExtractor {
|
|
|
91
92
|
);
|
|
92
93
|
}
|
|
93
94
|
|
|
94
|
-
private handleArrayAccess(token: string, cPart: string, cArray: any[]): any {
|
|
95
|
-
const
|
|
95
|
+
private handleArrayAccess(token: string, cPart: string, cArray: any[] | string): any {
|
|
96
|
+
const dotDotIndex = cPart.indexOf('..');
|
|
97
|
+
if (dotDotIndex >= 0) {
|
|
98
|
+
const startIndex = cPart.substring(0, dotDotIndex);
|
|
99
|
+
const endIndex = cPart.substring(dotDotIndex + 2);
|
|
100
|
+
|
|
101
|
+
let intStart = startIndex.length == 0 ? 0 : parseInt(startIndex);
|
|
102
|
+
let intEnd = endIndex.length == 0 ? cArray.length : parseInt(endIndex);
|
|
103
|
+
|
|
104
|
+
if (isNaN(intStart) || isNaN(intEnd)) return undefined;
|
|
105
|
+
|
|
106
|
+
while (intStart < 0) intStart += cArray.length;
|
|
107
|
+
while (intEnd < 0) intEnd += cArray.length;
|
|
108
|
+
|
|
109
|
+
const cArrayType = typeof cArray;
|
|
110
|
+
if (intStart >= intEnd) return cArrayType == 'string' ? '' : [];
|
|
111
|
+
|
|
112
|
+
return cArrayType == 'string'
|
|
113
|
+
? (cArray as string).substring(intStart, intEnd)
|
|
114
|
+
: cArray.slice(intStart, intEnd);
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
let index: number = parseInt(cPart);
|
|
96
118
|
|
|
97
119
|
if (isNaN(index)) {
|
|
98
120
|
throw new ExpressionEvaluationException(
|
|
@@ -101,7 +123,8 @@ export abstract class TokenValueExtractor {
|
|
|
101
123
|
);
|
|
102
124
|
}
|
|
103
125
|
|
|
104
|
-
|
|
126
|
+
while (index < 0) index = cArray.length + index;
|
|
127
|
+
if (index >= cArray.length) {
|
|
105
128
|
return undefined;
|
|
106
129
|
}
|
|
107
130
|
|
|
@@ -137,7 +160,11 @@ export abstract class TokenValueExtractor {
|
|
|
137
160
|
partNumber: number,
|
|
138
161
|
jsonElement: any,
|
|
139
162
|
): void {
|
|
140
|
-
|
|
163
|
+
const jsonElementType = typeof jsonElement;
|
|
164
|
+
if (
|
|
165
|
+
(jsonElementType != 'object' && jsonElementType != 'string') ||
|
|
166
|
+
Array.isArray(jsonElement)
|
|
167
|
+
)
|
|
141
168
|
throw new ExpressionEvaluationException(
|
|
142
169
|
token,
|
|
143
170
|
StringFormatter.format(
|