@fincity/kirun-js 1.0.1 → 1.0.2
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/function/system/array/BinarySearchTest.ts +51 -42
- package/__tests__/engine/function/system/array/IndexOfTest.ts +1 -1
- package/__tests__/engine/function/system/context/SetFunctionTest.ts +52 -0
- package/__tests__/engine/function/system/string/InsertAtGivenPositionTest.ts +2 -2
- package/__tests__/engine/function/system/string/StringFunctionRepoTest2.ts +10 -0
- package/__tests__/engine/function/system/string/StringFunctionRepoTest3.ts +18 -10
- package/__tests__/engine/function/system/string/StringFunctionRepositoryTest.ts +5 -7
- package/__tests__/engine/runtime/expression/ExpressionTest.ts +6 -0
- package/__tests__/engine/runtime/expression/tokenextractor/OutputMapTokenValueExtractorTest.ts +1 -1
- 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 +3 -1
- package/dist/types.d.ts.map +1 -1
- package/package.json +1 -1
- package/src/engine/function/system/array/AbstractArrayFunction.ts +12 -0
- package/src/engine/function/system/array/BinarySearch.ts +3 -3
- package/src/engine/function/system/context/SetFunction.ts +94 -107
- package/src/engine/function/system/string/AbstractStringFunction.ts +61 -39
- package/src/engine/function/system/string/StringFunctionRepository.ts +2 -2
- package/src/engine/json/schema/validator/StringValidator.ts +1 -1
- package/src/engine/runtime/expression/Expression.ts +6 -8
- package/src/engine/runtime/expression/Operation.ts +26 -4
- package/src/engine/util/MapUtil.ts +10 -10
- package/src/engine/util/primitive/PrimitiveUtil.ts +2 -1
|
@@ -10,9 +10,9 @@ test('Binary Search test 1', () => {
|
|
|
10
10
|
|
|
11
11
|
let fep: FunctionExecutionParameters = new FunctionExecutionParameters().setArguments(
|
|
12
12
|
new Map<string, any>([
|
|
13
|
-
[BinarySearch.
|
|
13
|
+
[BinarySearch.PARAMETER_ARRAY_SOURCE_PRIMITIVE.getParameterName(), src],
|
|
14
14
|
[BinarySearch.PARAMETER_INT_SOURCE_FROM.getParameterName(), 1],
|
|
15
|
-
[BinarySearch.
|
|
15
|
+
[BinarySearch.PARAMETER_FIND_PRIMITIVE.getParameterName(), search],
|
|
16
16
|
[BinarySearch.PARAMETER_INT_LENGTH.getParameterName(), 6],
|
|
17
17
|
]),
|
|
18
18
|
);
|
|
@@ -29,9 +29,9 @@ test('Binary Search test 2', () => {
|
|
|
29
29
|
|
|
30
30
|
let fep: FunctionExecutionParameters = new FunctionExecutionParameters().setArguments(
|
|
31
31
|
new Map<string, any>([
|
|
32
|
-
[BinarySearch.
|
|
32
|
+
[BinarySearch.PARAMETER_ARRAY_SOURCE_PRIMITIVE.getParameterName(), src],
|
|
33
33
|
[BinarySearch.PARAMETER_INT_SOURCE_FROM.getParameterName(), 1],
|
|
34
|
-
[BinarySearch.
|
|
34
|
+
[BinarySearch.PARAMETER_FIND_PRIMITIVE.getParameterName(), search],
|
|
35
35
|
[BinarySearch.PARAMETER_INT_LENGTH.getParameterName(), src.length - 2],
|
|
36
36
|
]),
|
|
37
37
|
);
|
|
@@ -48,9 +48,9 @@ test('Binary Search test 3', () => {
|
|
|
48
48
|
|
|
49
49
|
let fep: FunctionExecutionParameters = new FunctionExecutionParameters().setArguments(
|
|
50
50
|
new Map<string, any>([
|
|
51
|
-
[BinarySearch.
|
|
51
|
+
[BinarySearch.PARAMETER_ARRAY_SOURCE_PRIMITIVE.getParameterName(), src],
|
|
52
52
|
[BinarySearch.PARAMETER_INT_SOURCE_FROM.getParameterName(), 1],
|
|
53
|
-
[BinarySearch.
|
|
53
|
+
[BinarySearch.PARAMETER_FIND_PRIMITIVE.getParameterName(), search],
|
|
54
54
|
[BinarySearch.PARAMETER_INT_LENGTH.getParameterName(), 100],
|
|
55
55
|
]),
|
|
56
56
|
);
|
|
@@ -59,77 +59,86 @@ test('Binary Search test 3', () => {
|
|
|
59
59
|
});
|
|
60
60
|
|
|
61
61
|
test('Binary Search test 6', () => {
|
|
62
|
-
let src: any[] = [1, 4, 6, 7, 10,
|
|
62
|
+
let src: any[] = [1, 4, 6, 7, 10, 14, 17, 20];
|
|
63
63
|
|
|
64
|
-
let search:
|
|
64
|
+
let search: number = 17;
|
|
65
65
|
|
|
66
66
|
let fep: FunctionExecutionParameters = new FunctionExecutionParameters().setArguments(
|
|
67
67
|
new Map<string, any>([
|
|
68
|
-
[BinarySearch.
|
|
69
|
-
[BinarySearch.PARAMETER_INT_SOURCE_FROM.getParameterName(),
|
|
70
|
-
[BinarySearch.
|
|
68
|
+
[BinarySearch.PARAMETER_ARRAY_SOURCE_PRIMITIVE.getParameterName(), src],
|
|
69
|
+
[BinarySearch.PARAMETER_INT_SOURCE_FROM.getParameterName(), 0],
|
|
70
|
+
[BinarySearch.PARAMETER_FIND_PRIMITIVE.getParameterName(), search],
|
|
71
71
|
[BinarySearch.PARAMETER_INT_LENGTH.getParameterName(), 5],
|
|
72
72
|
]),
|
|
73
73
|
);
|
|
74
74
|
|
|
75
75
|
expect(
|
|
76
76
|
bsearch.execute(fep).allResults()[0].getResult().get(BinarySearch.EVENT_INDEX.getName()),
|
|
77
|
-
).toBe(
|
|
77
|
+
).toBe(-1);
|
|
78
78
|
});
|
|
79
79
|
|
|
80
|
-
test('Binary Search test 7', () => {
|
|
81
|
-
|
|
80
|
+
// test('Binary Search test 7', () => {
|
|
81
|
+
// let src: any[] = [1, 4, 6, 7, 10, 14, 16, 20];
|
|
82
82
|
|
|
83
|
-
|
|
83
|
+
// let search: any[] = [10];
|
|
84
84
|
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
85
|
+
// let fep: FunctionExecutionParameters = new FunctionExecutionParameters().setArguments(
|
|
86
|
+
// new Map<string, any>([
|
|
87
|
+
// [BinarySearch.PARAMETER_ARRAY_SOURCE_PRIMITIVE.getParameterName(), src],
|
|
88
|
+
// [BinarySearch.PARAMETER_INT_SOURCE_FROM.getParameterName(), 1],
|
|
89
|
+
// [BinarySearch.PARAMETER_FIND_PRIMITIVE.getParameterName(), search],
|
|
90
|
+
// [BinarySearch.PARAMETER_INT_LENGTH.getParameterName(), 5],
|
|
91
|
+
// ]),
|
|
92
|
+
// );
|
|
93
93
|
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
).toBe(-1);
|
|
97
|
-
});
|
|
94
|
+
// expect(bsearch.execute(fep)).toThrow();
|
|
95
|
+
// });
|
|
98
96
|
|
|
99
97
|
test('Binary Search test 4', () => {
|
|
100
|
-
let src: any[] = ['a', 'b', 'd', 'f', 'h',
|
|
98
|
+
let src: any[] = ['a', 'b', 'd', 'f', 'h', 'k', 'z'];
|
|
101
99
|
|
|
102
|
-
let search: any =
|
|
100
|
+
let search: any = 'z';
|
|
103
101
|
|
|
104
102
|
let fep: FunctionExecutionParameters = new FunctionExecutionParameters().setArguments(
|
|
105
103
|
new Map<string, any>([
|
|
106
|
-
[BinarySearch.
|
|
107
|
-
|
|
108
|
-
[BinarySearch.
|
|
109
|
-
[BinarySearch.PARAMETER_INT_LENGTH.getParameterName(), 4],
|
|
104
|
+
[BinarySearch.PARAMETER_ARRAY_SOURCE_PRIMITIVE.getParameterName(), src],
|
|
105
|
+
|
|
106
|
+
[BinarySearch.PARAMETER_FIND_PRIMITIVE.getParameterName(), search],
|
|
110
107
|
]),
|
|
111
108
|
);
|
|
112
109
|
|
|
113
110
|
expect(
|
|
114
111
|
bsearch.execute(fep).allResults()[0].getResult().get(BinarySearch.EVENT_INDEX.getName()),
|
|
115
|
-
).toBe(
|
|
112
|
+
).toBe(src.length - 1);
|
|
116
113
|
});
|
|
117
114
|
|
|
118
115
|
test('Binary Search test 5', () => {
|
|
119
|
-
let
|
|
120
|
-
|
|
121
|
-
|
|
116
|
+
let arr: any[] = [];
|
|
117
|
+
arr.push('a');
|
|
118
|
+
arr.push('b');
|
|
119
|
+
arr.push('c');
|
|
120
|
+
arr.push('d');
|
|
121
|
+
arr.push('e');
|
|
122
|
+
arr.push('g');
|
|
123
|
+
arr.push('i');
|
|
124
|
+
arr.push('j');
|
|
125
|
+
arr.push('k');
|
|
126
|
+
arr.push('r');
|
|
127
|
+
arr.push('s');
|
|
128
|
+
arr.push('z');
|
|
129
|
+
|
|
130
|
+
let search: any = 's';
|
|
122
131
|
|
|
123
132
|
let fep: FunctionExecutionParameters = new FunctionExecutionParameters().setArguments(
|
|
124
133
|
new Map<string, any>([
|
|
125
|
-
[BinarySearch.
|
|
126
|
-
|
|
127
|
-
[BinarySearch.
|
|
128
|
-
[BinarySearch.PARAMETER_INT_LENGTH.getParameterName(),
|
|
134
|
+
[BinarySearch.PARAMETER_ARRAY_SOURCE_PRIMITIVE.getParameterName(), arr],
|
|
135
|
+
|
|
136
|
+
[BinarySearch.PARAMETER_FIND_PRIMITIVE.getParameterName(), search],
|
|
137
|
+
[BinarySearch.PARAMETER_INT_LENGTH.getParameterName(), arr.length - 1],
|
|
129
138
|
]),
|
|
130
139
|
);
|
|
131
140
|
|
|
132
141
|
expect(
|
|
133
142
|
bsearch.execute(fep).allResults()[0].getResult().get(BinarySearch.EVENT_INDEX.getName()),
|
|
134
|
-
).toBe(
|
|
143
|
+
).toBe(10);
|
|
135
144
|
});
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import { Schema } from '../../../../../src';
|
|
2
|
+
import { SetFunction } from '../../../../../src/engine/function/system/context/SetFunction';
|
|
3
|
+
import { ContextElement } from '../../../../../src/engine/runtime/ContextElement';
|
|
4
|
+
import { FunctionExecutionParameters } from '../../../../../src/engine/runtime/FunctionExecutionParameters';
|
|
5
|
+
|
|
6
|
+
test('Set function test 1', () => {
|
|
7
|
+
let setFunction: SetFunction = new SetFunction();
|
|
8
|
+
|
|
9
|
+
let fep: FunctionExecutionParameters = new FunctionExecutionParameters();
|
|
10
|
+
|
|
11
|
+
let contextMap: Map<string, ContextElement> = new Map();
|
|
12
|
+
contextMap.set('a', new ContextElement(Schema.ofAny('test'), {}));
|
|
13
|
+
fep.setContext(contextMap);
|
|
14
|
+
fep.setArguments(
|
|
15
|
+
new Map<string, any>([
|
|
16
|
+
['name', 'Context.a.b'],
|
|
17
|
+
['value', 20],
|
|
18
|
+
]),
|
|
19
|
+
);
|
|
20
|
+
|
|
21
|
+
setFunction.execute(fep);
|
|
22
|
+
expect(contextMap.get('a')?.getElement()['b']).toBe(20);
|
|
23
|
+
|
|
24
|
+
fep.setArguments(
|
|
25
|
+
new Map<string, any>([
|
|
26
|
+
['name', 'Context.a.c[2].d'],
|
|
27
|
+
['value', 25],
|
|
28
|
+
]),
|
|
29
|
+
);
|
|
30
|
+
|
|
31
|
+
setFunction.execute(fep);
|
|
32
|
+
expect(contextMap.get('a')?.getElement()['c'][2].d).toBe(25);
|
|
33
|
+
});
|
|
34
|
+
|
|
35
|
+
test('Set function test 2', () => {
|
|
36
|
+
let setFunction: SetFunction = new SetFunction();
|
|
37
|
+
|
|
38
|
+
let fep: FunctionExecutionParameters = new FunctionExecutionParameters();
|
|
39
|
+
|
|
40
|
+
let contextMap: Map<string, ContextElement> = new Map();
|
|
41
|
+
contextMap.set('a', new ContextElement(Schema.ofAny('test'), []));
|
|
42
|
+
fep.setContext(contextMap);
|
|
43
|
+
fep.setArguments(
|
|
44
|
+
new Map<string, any>([
|
|
45
|
+
['name', 'Context.a[1]'],
|
|
46
|
+
['value', 240],
|
|
47
|
+
]),
|
|
48
|
+
);
|
|
49
|
+
|
|
50
|
+
setFunction.execute(fep);
|
|
51
|
+
expect(contextMap.get('a')?.getElement()[1]).toBe(240);
|
|
52
|
+
});
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { InsertAtGivenPosition } from '../../../../../src/engine/function/system/string/
|
|
1
|
+
import { InsertAtGivenPosition } from '../../../../../src/engine/function/system/string/InsertAtGivenPosition';
|
|
2
|
+
|
|
2
3
|
import { FunctionExecutionParameters } from '../../../../../src/engine/runtime/FunctionExecutionParameters';
|
|
3
|
-
import { MapEntry, MapUtil } from '../../../../../src/engine/util/MapUtil';
|
|
4
4
|
|
|
5
5
|
const reve: InsertAtGivenPosition = new InsertAtGivenPosition();
|
|
6
6
|
|
|
@@ -110,6 +110,16 @@ test('string function repo 2', () => {
|
|
|
110
110
|
expect(
|
|
111
111
|
fun.execute(fep).allResults()[0].getResult().get(AbstractStringFunction.EVENT_RESULT_NAME),
|
|
112
112
|
).toBe(true);
|
|
113
|
+
});
|
|
114
|
+
|
|
115
|
+
test('string function repo 3', () => {
|
|
116
|
+
let fun = stringRepo.find(Namespaces.STRING, 'EndsWith');
|
|
117
|
+
|
|
118
|
+
if (!fun) {
|
|
119
|
+
throw new Error('Function not available');
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
let fep: FunctionExecutionParameters = new FunctionExecutionParameters();
|
|
113
123
|
|
|
114
124
|
fep.setArguments(
|
|
115
125
|
MapUtil.of(
|
|
@@ -31,24 +31,32 @@ test('StringRepo3 - EqualsIgnoreCase', () => {
|
|
|
31
31
|
AbstractStringFunction.PARAMETER_STRING_NAME,
|
|
32
32
|
' 20934 123 123 245-0 34" 3434 " 123',
|
|
33
33
|
AbstractStringFunction.PARAMETER_SEARCH_STRING_NAME,
|
|
34
|
-
'
|
|
34
|
+
' w20934 123 123 245-0 34" 3434 " 123 ',
|
|
35
35
|
),
|
|
36
36
|
);
|
|
37
37
|
|
|
38
38
|
expect(
|
|
39
39
|
fun.execute(fep).allResults()[0].getResult().get(AbstractStringFunction.EVENT_RESULT_NAME),
|
|
40
|
-
).
|
|
40
|
+
).toBeFalsy();
|
|
41
|
+
});
|
|
41
42
|
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
AbstractStringFunction.
|
|
47
|
-
|
|
48
|
-
|
|
43
|
+
test('StringRepo3 - EqualsIgnoreCase', () => {
|
|
44
|
+
let fun = stringRepo.find(Namespaces.STRING, 'EqualsIgnoreCase');
|
|
45
|
+
let fep: FunctionExecutionParameters = new FunctionExecutionParameters().setArguments(
|
|
46
|
+
new Map([
|
|
47
|
+
[AbstractStringFunction.PARAMETER_STRING_NAME, ' no code Kirun PLATform '],
|
|
48
|
+
[
|
|
49
|
+
AbstractStringFunction.PARAMETER_SEARCH_STRING_NAME,
|
|
50
|
+
' NO CODE KIRUN PLATFORM ',
|
|
51
|
+
],
|
|
52
|
+
]),
|
|
49
53
|
);
|
|
50
54
|
|
|
55
|
+
if (!fun) {
|
|
56
|
+
throw new Error('Function not available');
|
|
57
|
+
}
|
|
58
|
+
|
|
51
59
|
expect(
|
|
52
60
|
fun.execute(fep).allResults()[0].getResult().get(AbstractStringFunction.EVENT_RESULT_NAME),
|
|
53
|
-
).toBe(
|
|
61
|
+
).toBe(true);
|
|
54
62
|
});
|
|
@@ -79,15 +79,13 @@ test('StringFunctionRepo -UpperCase', () => {
|
|
|
79
79
|
});
|
|
80
80
|
|
|
81
81
|
test('StringFunctionRepo -Blank1', () => {
|
|
82
|
-
let fun = repo.find(Namespaces.STRING, '
|
|
82
|
+
let fun = repo.find(Namespaces.STRING, 'IsBlank');
|
|
83
83
|
if (!fun) {
|
|
84
84
|
throw new Error('Function not available');
|
|
85
85
|
}
|
|
86
86
|
let fep: FunctionExecutionParameters = new FunctionExecutionParameters();
|
|
87
87
|
|
|
88
|
-
fep.setArguments(
|
|
89
|
-
MapUtil.of<string, string | number>(AbstractStringFunction.PARAMETER_STRING_NAME, ''),
|
|
90
|
-
);
|
|
88
|
+
fep.setArguments(MapUtil.of<string, string>(AbstractStringFunction.PARAMETER_STRING_NAME, ''));
|
|
91
89
|
|
|
92
90
|
expect(
|
|
93
91
|
fun.execute(fep).allResults()[0].getResult().get(AbstractStringFunction.EVENT_RESULT_NAME),
|
|
@@ -95,7 +93,7 @@ test('StringFunctionRepo -Blank1', () => {
|
|
|
95
93
|
});
|
|
96
94
|
|
|
97
95
|
test('StringFunctionRepo -Blank2', () => {
|
|
98
|
-
let fun = repo.find(Namespaces.STRING, '
|
|
96
|
+
let fun = repo.find(Namespaces.STRING, 'IsBlank');
|
|
99
97
|
if (!fun) {
|
|
100
98
|
throw new Error('Function not available');
|
|
101
99
|
}
|
|
@@ -114,7 +112,7 @@ test('StringFunctionRepo -Blank2', () => {
|
|
|
114
112
|
});
|
|
115
113
|
|
|
116
114
|
test('StringFunctionRepo -Empty1', () => {
|
|
117
|
-
let fun = repo.find(Namespaces.STRING, '
|
|
115
|
+
let fun = repo.find(Namespaces.STRING, 'IsEmpty');
|
|
118
116
|
if (!fun) {
|
|
119
117
|
throw new Error('Function not available');
|
|
120
118
|
}
|
|
@@ -130,7 +128,7 @@ test('StringFunctionRepo -Empty1', () => {
|
|
|
130
128
|
});
|
|
131
129
|
|
|
132
130
|
test('StringFunctionRepo -Empty2', () => {
|
|
133
|
-
let fun = repo.find(Namespaces.STRING, '
|
|
131
|
+
let fun = repo.find(Namespaces.STRING, 'IsEmpty');
|
|
134
132
|
if (!fun) {
|
|
135
133
|
throw new Error('Function not available');
|
|
136
134
|
}
|
|
@@ -30,4 +30,10 @@ test('Expression Test', () => {
|
|
|
30
30
|
);
|
|
31
31
|
expect(deepObject.toString()).toBe('(Context.(a.(b.c)))');
|
|
32
32
|
expect(deepObjectWithArray.toString()).toBe('(Context.(a.(b[(2.c))))');
|
|
33
|
+
|
|
34
|
+
let opInTheName = new Expression('Store.a.b.c or Store.c.d.x');
|
|
35
|
+
expect(opInTheName.toString()).toBe('((Store.(a.(b.c)))or(Store.(c.(d.x))))');
|
|
36
|
+
|
|
37
|
+
opInTheName = new Expression('Store.a.b.corStore.c.d.x');
|
|
38
|
+
expect(opInTheName.toString()).toBe('(Store.(a.(b.(corStore.(c.(d.x))))))');
|
|
33
39
|
});
|
package/__tests__/engine/runtime/expression/tokenextractor/OutputMapTokenValueExtractorTest.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { OutputMapTokenValueExtractor } from '../../../../../src/engine/runtime/
|
|
1
|
+
import { OutputMapTokenValueExtractor } from '../../../../../src/engine/runtime/tokenextractor/OutputMapTokenValueExtractor';
|
|
2
2
|
|
|
3
3
|
test('OutputMapTokenValueExtractor Test', () => {
|
|
4
4
|
let phone: any = {
|