@fincity/kirun-js 2.13.0 → 2.14.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/json/JSONParseTest.ts +71 -0
- package/__tests__/engine/function/system/json/JSONStringifyTest.ts +30 -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 +1 -0
- package/dist/types.d.ts.map +1 -1
- package/package.json +57 -57
- package/src/engine/function/system/json/JSONParse.ts +58 -0
- package/src/engine/function/system/json/JSONStringify.ts +40 -0
- package/src/engine/namespaces/Namespaces.ts +1 -0
- package/src/engine/repository/KIRunFunctionRepository.ts +7 -1
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
import { JSONParse } from '../../../../../src/engine/function/system/json/JSONParse';
|
|
2
|
+
import { KIRunFunctionRepository } from '../../../../../src/engine/repository/KIRunFunctionRepository';
|
|
3
|
+
import { KIRunSchemaRepository } from '../../../../../src/engine/repository/KIRunSchemaRepository';
|
|
4
|
+
import { FunctionExecutionParameters } from '../../../../../src/engine/runtime/FunctionExecutionParameters';
|
|
5
|
+
|
|
6
|
+
test('should return the parsed JSON Object', async () => {
|
|
7
|
+
const jsonParse = new JSONParse();
|
|
8
|
+
|
|
9
|
+
const result = await jsonParse.execute(
|
|
10
|
+
new FunctionExecutionParameters(
|
|
11
|
+
new KIRunFunctionRepository(),
|
|
12
|
+
new KIRunSchemaRepository(),
|
|
13
|
+
).setArguments(new Map([['source', '{"name":"John","age":30}']])),
|
|
14
|
+
);
|
|
15
|
+
|
|
16
|
+
expect(result.allResults()[0].getResult().get('value')).toEqual({ name: 'John', age: 30 });
|
|
17
|
+
});
|
|
18
|
+
|
|
19
|
+
test('should return the parsed JSON Array', async () => {
|
|
20
|
+
const jsonParse = new JSONParse();
|
|
21
|
+
|
|
22
|
+
const result = await jsonParse.execute(
|
|
23
|
+
new FunctionExecutionParameters(
|
|
24
|
+
new KIRunFunctionRepository(),
|
|
25
|
+
new KIRunSchemaRepository(),
|
|
26
|
+
).setArguments(new Map([['source', '[1,2,3,4,5]']])),
|
|
27
|
+
);
|
|
28
|
+
|
|
29
|
+
expect(result.allResults()[0].getResult().get('value')).toEqual([1, 2, 3, 4, 5]);
|
|
30
|
+
});
|
|
31
|
+
|
|
32
|
+
test('should return null if source is null', async () => {
|
|
33
|
+
const jsonParse = new JSONParse();
|
|
34
|
+
|
|
35
|
+
const result = await jsonParse.execute(
|
|
36
|
+
new FunctionExecutionParameters(
|
|
37
|
+
new KIRunFunctionRepository(),
|
|
38
|
+
new KIRunSchemaRepository(),
|
|
39
|
+
).setArguments(new Map([['source', 'null']])),
|
|
40
|
+
);
|
|
41
|
+
|
|
42
|
+
expect(result.allResults()[0].getResult().get('value')).toEqual(null);
|
|
43
|
+
});
|
|
44
|
+
|
|
45
|
+
test('should return null if source is not a valid JSON', async () => {
|
|
46
|
+
const jsonParse = new JSONParse();
|
|
47
|
+
|
|
48
|
+
const result = await jsonParse.execute(
|
|
49
|
+
new FunctionExecutionParameters(
|
|
50
|
+
new KIRunFunctionRepository(),
|
|
51
|
+
new KIRunSchemaRepository(),
|
|
52
|
+
).setArguments(new Map([['source', 'invalid JSON']])),
|
|
53
|
+
);
|
|
54
|
+
|
|
55
|
+
expect(result.allResults()[0].getResult().get('errorMessage')).toEqual(
|
|
56
|
+
'Unexpected token \'i\', "invalid JSON" is not valid JSON',
|
|
57
|
+
);
|
|
58
|
+
});
|
|
59
|
+
|
|
60
|
+
test('should return null if source is undefined', async () => {
|
|
61
|
+
const jsonParse = new JSONParse();
|
|
62
|
+
|
|
63
|
+
const result = await jsonParse.execute(
|
|
64
|
+
new FunctionExecutionParameters(
|
|
65
|
+
new KIRunFunctionRepository(),
|
|
66
|
+
new KIRunSchemaRepository(),
|
|
67
|
+
).setArguments(new Map([['source', '']])),
|
|
68
|
+
);
|
|
69
|
+
|
|
70
|
+
expect(result.allResults()[0].getResult().get('value')).toEqual(null);
|
|
71
|
+
});
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { JSONStringify } from '../../../../../src/engine/function/system/json/JSONStringify';
|
|
2
|
+
import { KIRunFunctionRepository } from '../../../../../src/engine/repository/KIRunFunctionRepository';
|
|
3
|
+
import { KIRunSchemaRepository } from '../../../../../src/engine/repository/KIRunSchemaRepository';
|
|
4
|
+
import { FunctionExecutionParameters } from '../../../../../src/engine/runtime/FunctionExecutionParameters';
|
|
5
|
+
|
|
6
|
+
test('should return the stringified JSON', async () => {
|
|
7
|
+
const jsonStringify = new JSONStringify();
|
|
8
|
+
|
|
9
|
+
const result = await jsonStringify.execute(
|
|
10
|
+
new FunctionExecutionParameters(
|
|
11
|
+
new KIRunFunctionRepository(),
|
|
12
|
+
new KIRunSchemaRepository(),
|
|
13
|
+
).setArguments(new Map([['source', { name: 'John', age: 30 }]])),
|
|
14
|
+
);
|
|
15
|
+
|
|
16
|
+
expect(result.allResults()[0].getResult().get('value')).toEqual('{"name":"John","age":30}');
|
|
17
|
+
});
|
|
18
|
+
|
|
19
|
+
test('should return the stringified if source is undefined', async () => {
|
|
20
|
+
const jsonStringify = new JSONStringify();
|
|
21
|
+
|
|
22
|
+
const result = await jsonStringify.execute(
|
|
23
|
+
new FunctionExecutionParameters(
|
|
24
|
+
new KIRunFunctionRepository(),
|
|
25
|
+
new KIRunSchemaRepository(),
|
|
26
|
+
).setArguments(new Map([['source', undefined]])),
|
|
27
|
+
);
|
|
28
|
+
|
|
29
|
+
expect(result.allResults()[0].getResult().get('value')).toEqual('null');
|
|
30
|
+
});
|