@fincity/kirun-js 1.6.17 → 1.8.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/function/system/array/AddFirstTest.ts +28 -19
- package/__tests__/engine/function/system/array/ArrayToArrayOfObjectsTest.ts +0 -2
- package/__tests__/engine/function/system/array/ArrayToObjectTest.ts +180 -0
- package/__tests__/engine/function/system/array/BinarySearchTest.ts +5 -20
- package/__tests__/engine/function/system/array/{AddTest.ts → ConcatenateTest.ts} +22 -24
- package/__tests__/engine/function/system/array/CopyTest.ts +1 -1
- package/__tests__/engine/function/system/array/DeleteFirstTest.ts +7 -9
- package/__tests__/engine/function/system/array/DeleteFromTest.ts +4 -12
- package/__tests__/engine/function/system/array/DeleteLastTest.ts +7 -9
- package/__tests__/engine/function/system/array/DeleteTest.ts +7 -9
- package/__tests__/engine/function/system/array/DisjointTest.ts +3 -3
- package/__tests__/engine/function/system/array/FillTest.ts +6 -6
- package/__tests__/engine/function/system/array/FrequencyTest.ts +2 -2
- package/__tests__/engine/function/system/array/IndexOfArrayTest.ts +6 -24
- package/__tests__/engine/function/system/array/IndexOfTest.ts +5 -17
- package/__tests__/engine/function/system/array/InsertTest.ts +5 -15
- package/__tests__/engine/function/system/array/LastIndexOfArrayTest.ts +3 -3
- package/__tests__/engine/function/system/array/LastIndexOfTest.ts +4 -18
- package/__tests__/engine/function/system/array/MaxTest.ts +6 -8
- package/__tests__/engine/function/system/array/MinTest.ts +8 -8
- package/__tests__/engine/function/system/array/MisMatchTest.ts +3 -12
- package/__tests__/engine/function/system/array/RemoveDuplicatesTest.ts +74 -0
- package/__tests__/engine/function/system/array/ReverseTest.ts +4 -8
- package/__tests__/engine/function/system/array/RotateTest.ts +9 -9
- package/__tests__/engine/function/system/array/SortTest.ts +5 -5
- package/__tests__/engine/function/system/array/SubArrayTest.ts +4 -13
- package/__tests__/engine/function/system/loop/BreakLoopTest.ts +173 -0
- package/__tests__/engine/function/system/loop/CountLoopTest.ts +1 -1
- package/__tests__/engine/function/system/loop/RangeLoopTest.ts +145 -0
- package/__tests__/engine/function/system/string/SplitTest.ts +2 -2
- package/__tests__/engine/json/schema/validator/ArraySchemaAdapterTypeTest.ts +0 -1
- package/__tests__/engine/json/schema/validator/NotValidatorTest.ts +47 -0
- package/__tests__/engine/runtime/KIRuntimeNoValuesTest.ts +0 -1
- package/__tests__/engine/runtime/expression/tokenextractor/ObjectValueSetterExtractorTest.ts +51 -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 +41 -30
- package/dist/types.d.ts.map +1 -1
- package/package.json +1 -1
- package/src/engine/function/system/array/AbstractArrayFunction.ts +5 -0
- package/src/engine/function/system/array/AddFirst.ts +8 -7
- package/src/engine/function/system/array/ArrayFunctionRepository.ts +8 -2
- package/src/engine/function/system/array/ArrayToObject.ts +77 -0
- package/src/engine/function/system/array/BinarySearch.ts +1 -1
- package/src/engine/function/system/array/{Add.ts → Concatenate.ts} +8 -6
- package/src/engine/function/system/array/Copy.ts +2 -2
- package/src/engine/function/system/array/Delete.ts +11 -7
- package/src/engine/function/system/array/DeleteFirst.ts +5 -2
- package/src/engine/function/system/array/DeleteFrom.ts +5 -2
- package/src/engine/function/system/array/DeleteLast.ts +5 -2
- package/src/engine/function/system/array/Disjoint.ts +1 -5
- package/src/engine/function/system/array/Fill.ts +6 -2
- package/src/engine/function/system/array/Frequency.ts +2 -5
- package/src/engine/function/system/array/IndexOf.ts +2 -2
- package/src/engine/function/system/array/IndexOfArray.ts +2 -2
- package/src/engine/function/system/array/Insert.ts +9 -3
- package/src/engine/function/system/array/InsertLast.ts +31 -0
- package/src/engine/function/system/array/LastIndexOf.ts +2 -7
- package/src/engine/function/system/array/LastIndexOfArray.ts +2 -6
- package/src/engine/function/system/array/Max.ts +1 -3
- package/src/engine/function/system/array/Min.ts +1 -3
- package/src/engine/function/system/array/MisMatch.ts +1 -1
- package/src/engine/function/system/array/RemoveDuplicates.ts +64 -0
- package/src/engine/function/system/array/Reverse.ts +6 -2
- package/src/engine/function/system/array/Rotate.ts +10 -3
- package/src/engine/function/system/array/Shuffle.ts +9 -3
- package/src/engine/function/system/array/Sort.ts +4 -3
- package/src/engine/function/system/array/SubArray.ts +1 -1
- package/src/engine/function/system/loop/Break.ts +31 -0
- package/src/engine/function/system/loop/CountLoop.ts +8 -2
- package/src/engine/function/system/loop/ForEachLoop.ts +70 -0
- package/src/engine/function/system/loop/RangeLoop.ts +7 -1
- package/src/engine/function/system/object/ObjectFunctionRepository.ts +2 -0
- package/src/engine/function/system/object/ObjectPutValue.ts +61 -0
- package/src/engine/json/schema/validator/SchemaValidator.ts +3 -2
- package/src/engine/repository/KIRunFunctionRepository.ts +5 -1
- package/src/engine/runtime/FunctionExecutionParameters.ts +10 -1
- package/src/engine/runtime/KIRuntime.ts +2 -1
- package/src/engine/runtime/expression/operators/binary/ArithmeticAdditionOperator.ts +3 -2
- package/src/engine/runtime/expression/tokenextractor/ObjectValueSetterExtractor.ts +172 -0
- package/src/engine/runtime/expression/tokenextractor/TokenValueExtractor.ts +1 -1
- package/src/index.ts +1 -0
|
@@ -0,0 +1,173 @@
|
|
|
1
|
+
import {
|
|
2
|
+
FunctionDefinition,
|
|
3
|
+
FunctionExecutionParameters,
|
|
4
|
+
KIRunFunctionRepository,
|
|
5
|
+
KIRunSchemaRepository,
|
|
6
|
+
KIRuntime,
|
|
7
|
+
} from '../../../../../src';
|
|
8
|
+
|
|
9
|
+
test('Range Loop Break Test', async () => {
|
|
10
|
+
const breakDefinition = {
|
|
11
|
+
name: 'Break Me 1',
|
|
12
|
+
events: {
|
|
13
|
+
output: {
|
|
14
|
+
name: 'output',
|
|
15
|
+
parameters: {
|
|
16
|
+
returnValue: {
|
|
17
|
+
schema: { type: 'ARRAY', items: { type: 'INTEGER' } },
|
|
18
|
+
},
|
|
19
|
+
},
|
|
20
|
+
},
|
|
21
|
+
},
|
|
22
|
+
steps: {
|
|
23
|
+
create: {
|
|
24
|
+
name: 'Create',
|
|
25
|
+
namespace: 'System.Context',
|
|
26
|
+
statementName: 'create',
|
|
27
|
+
parameterMap: {
|
|
28
|
+
name: { one: { key: 'one', type: 'VALUE', value: 'array' } },
|
|
29
|
+
schema: {
|
|
30
|
+
one: {
|
|
31
|
+
key: 'one',
|
|
32
|
+
type: 'VALUE',
|
|
33
|
+
value: { type: 'ARRAY', items: { type: 'INTEGER' } },
|
|
34
|
+
},
|
|
35
|
+
},
|
|
36
|
+
},
|
|
37
|
+
},
|
|
38
|
+
createSet: {
|
|
39
|
+
name: 'Set',
|
|
40
|
+
namespace: 'System.Context',
|
|
41
|
+
statementName: 'createSet',
|
|
42
|
+
parameterMap: {
|
|
43
|
+
name: { one: { key: 'one', type: 'VALUE', value: 'Context.array' } },
|
|
44
|
+
value: { one: { key: 'one', type: 'VALUE', value: [] } },
|
|
45
|
+
},
|
|
46
|
+
dependentStatements: {
|
|
47
|
+
'Steps.create.output': true,
|
|
48
|
+
},
|
|
49
|
+
},
|
|
50
|
+
loop: {
|
|
51
|
+
name: 'RangeLoop',
|
|
52
|
+
namespace: 'System.Loop',
|
|
53
|
+
statementName: 'loop',
|
|
54
|
+
parameterMap: {
|
|
55
|
+
from: {
|
|
56
|
+
one: { key: 'one', type: 'VALUE', value: 5 },
|
|
57
|
+
},
|
|
58
|
+
to: { one: { key: 'one', type: 'VALUE', value: 10 } },
|
|
59
|
+
step: { one: { key: 'one', type: 'VALUE', value: 1 } },
|
|
60
|
+
},
|
|
61
|
+
dependentStatements: {
|
|
62
|
+
'Steps.createSet.output': true,
|
|
63
|
+
},
|
|
64
|
+
},
|
|
65
|
+
insert: {
|
|
66
|
+
name: 'InsertLast',
|
|
67
|
+
namespace: 'System.Array',
|
|
68
|
+
statementName: 'insert',
|
|
69
|
+
parameterMap: {
|
|
70
|
+
source: {
|
|
71
|
+
one: { key: 'one', type: 'EXPRESSION', expression: 'Context.array' },
|
|
72
|
+
},
|
|
73
|
+
element: {
|
|
74
|
+
one: {
|
|
75
|
+
key: 'one',
|
|
76
|
+
type: 'EXPRESSION',
|
|
77
|
+
expression: 'Steps.loop.iteration.index',
|
|
78
|
+
},
|
|
79
|
+
},
|
|
80
|
+
},
|
|
81
|
+
dependentStatements: {
|
|
82
|
+
'Steps.if.false': true,
|
|
83
|
+
},
|
|
84
|
+
},
|
|
85
|
+
set: {
|
|
86
|
+
name: 'Set',
|
|
87
|
+
namespace: 'System.Context',
|
|
88
|
+
statementName: 'set',
|
|
89
|
+
parameterMap: {
|
|
90
|
+
name: { one: { key: 'one', type: 'VALUE', value: 'Context.array' } },
|
|
91
|
+
value: {
|
|
92
|
+
one: {
|
|
93
|
+
key: 'one',
|
|
94
|
+
type: 'EXPRESSION',
|
|
95
|
+
expression: 'Steps.insert.output.result',
|
|
96
|
+
},
|
|
97
|
+
},
|
|
98
|
+
},
|
|
99
|
+
},
|
|
100
|
+
if: {
|
|
101
|
+
name: 'If',
|
|
102
|
+
namespace: 'System',
|
|
103
|
+
statementName: 'if',
|
|
104
|
+
parameterMap: {
|
|
105
|
+
condition: {
|
|
106
|
+
one: {
|
|
107
|
+
key: 'one',
|
|
108
|
+
type: 'EXPRESSION',
|
|
109
|
+
expression: 'Steps.loop.iteration.index = 7',
|
|
110
|
+
},
|
|
111
|
+
},
|
|
112
|
+
},
|
|
113
|
+
},
|
|
114
|
+
break: {
|
|
115
|
+
name: 'Break',
|
|
116
|
+
namespace: 'System.Loop',
|
|
117
|
+
statementName: 'break',
|
|
118
|
+
parameterMap: {
|
|
119
|
+
stepName: { one: { key: 'one', type: 'VALUE', value: 'loop' } },
|
|
120
|
+
},
|
|
121
|
+
dependentStatements: {
|
|
122
|
+
'Steps.if.true': true,
|
|
123
|
+
},
|
|
124
|
+
},
|
|
125
|
+
generateEvent: {
|
|
126
|
+
statementName: 'generateEvent',
|
|
127
|
+
name: 'GenerateEvent',
|
|
128
|
+
namespace: 'System',
|
|
129
|
+
parameterMap: {
|
|
130
|
+
eventName: {
|
|
131
|
+
'5OdGxruBiEyysESbAubdX2': {
|
|
132
|
+
key: '5OdGxruBiEyysESbAubdX2',
|
|
133
|
+
type: 'VALUE',
|
|
134
|
+
expression: '',
|
|
135
|
+
value: 'output',
|
|
136
|
+
},
|
|
137
|
+
},
|
|
138
|
+
results: {
|
|
139
|
+
'4o0c0kvVtWiGjgb37hMTBX': {
|
|
140
|
+
key: '4o0c0kvVtWiGjgb37hMTBX',
|
|
141
|
+
type: 'VALUE',
|
|
142
|
+
order: 1,
|
|
143
|
+
value: {
|
|
144
|
+
name: 'returnValue',
|
|
145
|
+
value: {
|
|
146
|
+
isExpression: true,
|
|
147
|
+
value: 'Context.array',
|
|
148
|
+
},
|
|
149
|
+
},
|
|
150
|
+
},
|
|
151
|
+
},
|
|
152
|
+
},
|
|
153
|
+
dependentStatements: {
|
|
154
|
+
'Steps.loop.output': true,
|
|
155
|
+
},
|
|
156
|
+
},
|
|
157
|
+
},
|
|
158
|
+
};
|
|
159
|
+
|
|
160
|
+
const fd = FunctionDefinition.from(breakDefinition);
|
|
161
|
+
const result = (
|
|
162
|
+
await new KIRuntime(fd, true).execute(
|
|
163
|
+
new FunctionExecutionParameters(
|
|
164
|
+
new KIRunFunctionRepository(),
|
|
165
|
+
new KIRunSchemaRepository(),
|
|
166
|
+
),
|
|
167
|
+
)
|
|
168
|
+
)
|
|
169
|
+
.next()
|
|
170
|
+
?.getResult()
|
|
171
|
+
.get('returnValue');
|
|
172
|
+
expect(result).toMatchObject([5, 6]);
|
|
173
|
+
});
|
|
@@ -43,7 +43,7 @@ test('Count Loop2', async () => {
|
|
|
43
43
|
|
|
44
44
|
expect(iterations).toMatchObject([]);
|
|
45
45
|
expect(er?.getName()).toBe('output');
|
|
46
|
-
expect(er?.getResult().get('value')).toBe(
|
|
46
|
+
expect(er?.getResult().get('value')).toBe(0);
|
|
47
47
|
});
|
|
48
48
|
|
|
49
49
|
test('Count Loop3', async () => {
|
|
@@ -0,0 +1,145 @@
|
|
|
1
|
+
import {
|
|
2
|
+
FunctionDefinition,
|
|
3
|
+
FunctionExecutionParameters,
|
|
4
|
+
KIRunFunctionRepository,
|
|
5
|
+
KIRunSchemaRepository,
|
|
6
|
+
KIRuntime,
|
|
7
|
+
} from '../../../../../src';
|
|
8
|
+
|
|
9
|
+
test('Range Loop Test', async () => {
|
|
10
|
+
const breakDefinition = {
|
|
11
|
+
name: 'Break Me 1',
|
|
12
|
+
events: {
|
|
13
|
+
output: {
|
|
14
|
+
name: 'output',
|
|
15
|
+
parameters: {
|
|
16
|
+
returnValue: {
|
|
17
|
+
schema: { type: 'ARRAY', items: { type: 'INTEGER' } },
|
|
18
|
+
},
|
|
19
|
+
},
|
|
20
|
+
},
|
|
21
|
+
},
|
|
22
|
+
steps: {
|
|
23
|
+
create: {
|
|
24
|
+
name: 'Create',
|
|
25
|
+
namespace: 'System.Context',
|
|
26
|
+
statementName: 'create',
|
|
27
|
+
parameterMap: {
|
|
28
|
+
name: { one: { key: 'one', type: 'VALUE', value: 'array' } },
|
|
29
|
+
schema: {
|
|
30
|
+
one: {
|
|
31
|
+
key: 'one',
|
|
32
|
+
type: 'VALUE',
|
|
33
|
+
value: { type: 'ARRAY', items: { type: 'INTEGER' } },
|
|
34
|
+
},
|
|
35
|
+
},
|
|
36
|
+
},
|
|
37
|
+
},
|
|
38
|
+
createSet: {
|
|
39
|
+
name: 'Set',
|
|
40
|
+
namespace: 'System.Context',
|
|
41
|
+
statementName: 'createSet',
|
|
42
|
+
parameterMap: {
|
|
43
|
+
name: { one: { key: 'one', type: 'VALUE', value: 'Context.array' } },
|
|
44
|
+
value: { one: { key: 'one', type: 'VALUE', value: [] } },
|
|
45
|
+
},
|
|
46
|
+
dependentStatements: {
|
|
47
|
+
'Steps.create.output': true,
|
|
48
|
+
},
|
|
49
|
+
},
|
|
50
|
+
loop: {
|
|
51
|
+
name: 'RangeLoop',
|
|
52
|
+
namespace: 'System.Loop',
|
|
53
|
+
statementName: 'loop',
|
|
54
|
+
parameterMap: {
|
|
55
|
+
from: {
|
|
56
|
+
one: { key: 'one', type: 'VALUE', value: 5 },
|
|
57
|
+
},
|
|
58
|
+
to: { one: { key: 'one', type: 'VALUE', value: 10 } },
|
|
59
|
+
step: { one: { key: 'one', type: 'VALUE', value: 1 } },
|
|
60
|
+
},
|
|
61
|
+
dependentStatements: {
|
|
62
|
+
'Steps.createSet.output': true,
|
|
63
|
+
},
|
|
64
|
+
},
|
|
65
|
+
insert: {
|
|
66
|
+
name: 'InsertLast',
|
|
67
|
+
namespace: 'System.Array',
|
|
68
|
+
statementName: 'insert',
|
|
69
|
+
parameterMap: {
|
|
70
|
+
source: {
|
|
71
|
+
one: { key: 'one', type: 'EXPRESSION', expression: 'Context.array' },
|
|
72
|
+
},
|
|
73
|
+
element: {
|
|
74
|
+
one: {
|
|
75
|
+
key: 'one',
|
|
76
|
+
type: 'EXPRESSION',
|
|
77
|
+
expression: 'Steps.loop.iteration.index',
|
|
78
|
+
},
|
|
79
|
+
},
|
|
80
|
+
},
|
|
81
|
+
},
|
|
82
|
+
set: {
|
|
83
|
+
name: 'Set',
|
|
84
|
+
namespace: 'System.Context',
|
|
85
|
+
statementName: 'set',
|
|
86
|
+
parameterMap: {
|
|
87
|
+
name: { one: { key: 'one', type: 'VALUE', value: 'Context.array' } },
|
|
88
|
+
value: {
|
|
89
|
+
one: {
|
|
90
|
+
key: 'one',
|
|
91
|
+
type: 'EXPRESSION',
|
|
92
|
+
expression: 'Steps.insert.output.result',
|
|
93
|
+
},
|
|
94
|
+
},
|
|
95
|
+
},
|
|
96
|
+
},
|
|
97
|
+
generateEvent: {
|
|
98
|
+
statementName: 'generateEvent',
|
|
99
|
+
name: 'GenerateEvent',
|
|
100
|
+
namespace: 'System',
|
|
101
|
+
parameterMap: {
|
|
102
|
+
eventName: {
|
|
103
|
+
'5OdGxruBiEyysESbAubdX2': {
|
|
104
|
+
key: '5OdGxruBiEyysESbAubdX2',
|
|
105
|
+
type: 'VALUE',
|
|
106
|
+
expression: '',
|
|
107
|
+
value: 'output',
|
|
108
|
+
},
|
|
109
|
+
},
|
|
110
|
+
results: {
|
|
111
|
+
'4o0c0kvVtWiGjgb37hMTBX': {
|
|
112
|
+
key: '4o0c0kvVtWiGjgb37hMTBX',
|
|
113
|
+
type: 'VALUE',
|
|
114
|
+
order: 1,
|
|
115
|
+
value: {
|
|
116
|
+
name: 'returnValue',
|
|
117
|
+
value: {
|
|
118
|
+
isExpression: true,
|
|
119
|
+
value: 'Context.array',
|
|
120
|
+
},
|
|
121
|
+
},
|
|
122
|
+
},
|
|
123
|
+
},
|
|
124
|
+
},
|
|
125
|
+
dependentStatements: {
|
|
126
|
+
'Steps.loop.output': true,
|
|
127
|
+
},
|
|
128
|
+
},
|
|
129
|
+
},
|
|
130
|
+
};
|
|
131
|
+
|
|
132
|
+
const fd = FunctionDefinition.from(breakDefinition);
|
|
133
|
+
const result = (
|
|
134
|
+
await new KIRuntime(fd, true).execute(
|
|
135
|
+
new FunctionExecutionParameters(
|
|
136
|
+
new KIRunFunctionRepository(),
|
|
137
|
+
new KIRunSchemaRepository(),
|
|
138
|
+
),
|
|
139
|
+
)
|
|
140
|
+
)
|
|
141
|
+
.next()
|
|
142
|
+
?.getResult()
|
|
143
|
+
.get('returnValue');
|
|
144
|
+
expect(result).toMatchObject([5, 6, 7, 8, 9]);
|
|
145
|
+
});
|
|
@@ -33,7 +33,7 @@ test('split test1', async () => {
|
|
|
33
33
|
array.push('Driven');
|
|
34
34
|
array.push('developement');
|
|
35
35
|
|
|
36
|
-
expect((await Spli.execute(fep)).allResults()[0].getResult().get('
|
|
36
|
+
expect((await Spli.execute(fep)).allResults()[0].getResult().get('result')).toStrictEqual(
|
|
37
37
|
array,
|
|
38
38
|
);
|
|
39
39
|
});
|
|
@@ -66,7 +66,7 @@ test('split test2', async () => {
|
|
|
66
66
|
array.push('m');
|
|
67
67
|
array.push('nt');
|
|
68
68
|
|
|
69
|
-
expect((await Spli.execute(fep)).allResults()[0].getResult().get('
|
|
69
|
+
expect((await Spli.execute(fep)).allResults()[0].getResult().get('result')).toStrictEqual(
|
|
70
70
|
array,
|
|
71
71
|
);
|
|
72
72
|
});
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import { Schema, SchemaType, SchemaValidator } from '../../../../../src';
|
|
2
|
+
|
|
3
|
+
test('NotValidation', async () => {
|
|
4
|
+
let sch = Schema.of(
|
|
5
|
+
'Not Schema',
|
|
6
|
+
SchemaType.INTEGER,
|
|
7
|
+
SchemaType.LONG,
|
|
8
|
+
SchemaType.FLOAT,
|
|
9
|
+
SchemaType.DOUBLE,
|
|
10
|
+
SchemaType.STRING,
|
|
11
|
+
)
|
|
12
|
+
.setDefaultValue(1)
|
|
13
|
+
.setNot(Schema.of('Not Schema', SchemaType.STRING));
|
|
14
|
+
|
|
15
|
+
const value = SchemaValidator.validate(undefined, sch, undefined, 0);
|
|
16
|
+
expect(value).toBe(0);
|
|
17
|
+
|
|
18
|
+
sch = Schema.of(
|
|
19
|
+
'Not Schema',
|
|
20
|
+
SchemaType.INTEGER,
|
|
21
|
+
SchemaType.LONG,
|
|
22
|
+
SchemaType.FLOAT,
|
|
23
|
+
SchemaType.DOUBLE,
|
|
24
|
+
SchemaType.STRING,
|
|
25
|
+
)
|
|
26
|
+
.setDefaultValue(1)
|
|
27
|
+
.setNot(Schema.of('Not Schema', SchemaType.INTEGER));
|
|
28
|
+
|
|
29
|
+
expect(() => SchemaValidator.validate(undefined, sch, undefined, 0)).toThrow();
|
|
30
|
+
|
|
31
|
+
sch = Schema.of('Not Schema', SchemaType.INTEGER, SchemaType.LONG, SchemaType.FLOAT)
|
|
32
|
+
.setDefaultValue(1)
|
|
33
|
+
.setNot(new Schema().setConstant(0));
|
|
34
|
+
|
|
35
|
+
expect(() => SchemaValidator.validate(undefined, sch, undefined, 0)).toThrow();
|
|
36
|
+
expect(SchemaValidator.validate(undefined, sch, undefined, null)).toBe(1);
|
|
37
|
+
expect(SchemaValidator.validate(undefined, sch, undefined, 2)).toBe(2);
|
|
38
|
+
});
|
|
39
|
+
|
|
40
|
+
test('constantValidation', async () => {
|
|
41
|
+
let sch = Schema.of('Constant Schema', SchemaType.INTEGER).setConstant(1);
|
|
42
|
+
|
|
43
|
+
const value = SchemaValidator.validate(undefined, sch, undefined, 1);
|
|
44
|
+
expect(value).toBe(1);
|
|
45
|
+
|
|
46
|
+
expect(() => SchemaValidator.validate(undefined, sch, undefined, 0)).toThrow();
|
|
47
|
+
});
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import { ObjectValueSetterExtractor } from '../../../../../src';
|
|
2
|
+
|
|
3
|
+
test('ObjectValueSetterExtractor Test', async () => {
|
|
4
|
+
let store = {
|
|
5
|
+
name: 'Kiran',
|
|
6
|
+
addresses: [
|
|
7
|
+
{
|
|
8
|
+
city: 'Bangalore',
|
|
9
|
+
state: 'Karnataka',
|
|
10
|
+
country: 'India',
|
|
11
|
+
},
|
|
12
|
+
{
|
|
13
|
+
city: 'Kakinada',
|
|
14
|
+
state: 'Andhra Pradesh',
|
|
15
|
+
country: 'India',
|
|
16
|
+
},
|
|
17
|
+
{ city: 'Beaverton', state: 'Oregon' },
|
|
18
|
+
],
|
|
19
|
+
phone: {
|
|
20
|
+
home: '080-23456789',
|
|
21
|
+
office: '080-23456789',
|
|
22
|
+
mobile: '080-23456789',
|
|
23
|
+
mobile2: '503-23456789',
|
|
24
|
+
},
|
|
25
|
+
plain: [1, 2, 3, 4],
|
|
26
|
+
};
|
|
27
|
+
|
|
28
|
+
let extractor: ObjectValueSetterExtractor = new ObjectValueSetterExtractor(store, 'Store');
|
|
29
|
+
|
|
30
|
+
expect(extractor.getValue('Store.name')).toStrictEqual('Kiran');
|
|
31
|
+
|
|
32
|
+
extractor.setValue('Store.name', 'Kiran Kumar');
|
|
33
|
+
store = extractor.getStore();
|
|
34
|
+
|
|
35
|
+
expect(store.name).toStrictEqual('Kiran Kumar');
|
|
36
|
+
|
|
37
|
+
extractor.setValue('Store.addresses[0].city', 'Bengaluru');
|
|
38
|
+
expect(extractor.getValue('Store.addresses[0].city')).toStrictEqual('Bengaluru');
|
|
39
|
+
|
|
40
|
+
extractor.setValue('Store.plain[0]', '123');
|
|
41
|
+
expect(extractor.getValue('Store.plain')).toMatchObject(['123', 2, 3, 4]);
|
|
42
|
+
|
|
43
|
+
extractor.setValue('Store.plain[0]', 1, false);
|
|
44
|
+
expect(extractor.getValue('Store.plain')).toMatchObject(['123', 2, 3, 4]);
|
|
45
|
+
|
|
46
|
+
extractor.setValue('Store.plain', undefined, true, true);
|
|
47
|
+
expect(Object.keys(extractor.getValue('Store'))).toMatchObject(['name', 'addresses', 'phone']);
|
|
48
|
+
|
|
49
|
+
extractor.setValue('Store.plain', 'plainString', false, false);
|
|
50
|
+
expect(extractor.getValue('Store.plain')).toStrictEqual('plainString');
|
|
51
|
+
});
|