@fincity/kirun-js 1.4.4 → 1.4.6

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.
@@ -1,9 +1,9 @@
1
1
  import { SchemaType, TypeUtil } from '../../../../../src';
2
2
 
3
3
  test('TypeUtilTest', () => {
4
- expect(TypeUtil.from('Object')?.contains(SchemaType.OBJECT)).toBeTruthy();
4
+ expect(TypeUtil.from('OBJECT')?.contains(SchemaType.OBJECT)).toBeTruthy();
5
5
 
6
- let type = TypeUtil.from(['Object', 'String']);
6
+ let type = TypeUtil.from(['OBJECT', 'STRING']);
7
7
 
8
8
  expect(type?.contains(SchemaType.STRING)).toBeTruthy();
9
9
  expect(type?.contains(SchemaType.OBJECT)).toBeTruthy();
@@ -30,9 +30,9 @@ test('Schema validation when ref of ref', () => {
30
30
  const locationSchema = Schema.from({
31
31
  name: 'Location',
32
32
  namespace: 'Test',
33
- type: 'Object',
33
+ type: 'OBJECT',
34
34
  properties: {
35
- url: { name: 'url', type: 'String' },
35
+ url: { name: 'url', type: 'STRING' },
36
36
  },
37
37
  required: ['url'],
38
38
  });
@@ -66,7 +66,7 @@ test('Schema validation when ref of ref', () => {
66
66
  },
67
67
  new KIRunSchemaRepository(),
68
68
  );
69
- const obj = { url: 'http://xxxxxx.com' };
69
+ const obj = { obj: { url: 'http://xxxxxx.com' } };
70
70
  const queryParams = {
71
71
  obj: { obj: { url: 'http://xxxxxx.com' } },
72
72
  };
@@ -80,9 +80,9 @@ test('Schema Validator Test 2', () => {
80
80
  const locationSchema = Schema.from({
81
81
  name: 'Location',
82
82
  namespace: 'Test',
83
- type: 'Object',
83
+ type: 'OBJECT',
84
84
  properties: {
85
- url: { name: 'url', type: 'String' },
85
+ url: { name: 'url', type: 'STRING' },
86
86
  },
87
87
  required: ['url'],
88
88
  });
@@ -116,7 +116,7 @@ test('Schema Validator Test 3', () => {
116
116
  const locationSchema = Schema.from({
117
117
  name: 'Location',
118
118
  namespace: 'Test',
119
- type: 'Object',
119
+ type: 'OBJECT',
120
120
  properties: {
121
121
  url: { name: 'url', type: 'String' },
122
122
  },
@@ -0,0 +1,135 @@
1
+ import {
2
+ KIRunSchemaRepository,
3
+ Schema,
4
+ SchemaType,
5
+ StringFormat,
6
+ TypeUtil,
7
+ } from '../../../../../src';
8
+ import { StringValidator } from '../../../../../src';
9
+
10
+ const repo = new KIRunSchemaRepository();
11
+
12
+ test('String valid case', () => {
13
+ let value: String = 'surendhar';
14
+ let schema: Schema = new Schema().setType(TypeUtil.of(SchemaType.STRING));
15
+
16
+ expect(StringValidator.validate([], schema, value)).toBe(value);
17
+ });
18
+
19
+ test('String invalid case', () => {
20
+ let schema: Schema = new Schema().setType(TypeUtil.of(SchemaType.STRING));
21
+
22
+ expect(() => StringValidator.validate([], schema, 123).toThrow(123 + ' is not String'));
23
+ });
24
+
25
+ test('String min length invalid', () => {
26
+ let value: String = 'abcd';
27
+ let schema: Schema = new Schema().setType(TypeUtil.of(SchemaType.STRING)).setMinLength(5);
28
+
29
+ expect(() =>
30
+ StringValidator.validate([], schema, value).toThrow(
31
+ 'Expected a minimum of ' + value.length + ' characters',
32
+ ),
33
+ );
34
+ });
35
+
36
+ test('String max length invalid', () => {
37
+ let value: String = 'surendhar';
38
+ let schema: Schema = new Schema().setType(TypeUtil.of(SchemaType.STRING)).setMaxLength(8);
39
+
40
+ expect(() =>
41
+ StringValidator.validate([], schema, value).toThrow(
42
+ 'Expected a maximum of ' + value.length + ' characters',
43
+ ),
44
+ );
45
+ });
46
+
47
+ test('String min length', () => {
48
+ let value: String = 'abcdefg';
49
+ let schema: Schema = new Schema().setType(TypeUtil.of(SchemaType.STRING)).setMinLength(5);
50
+
51
+ expect(StringValidator.validate([], schema, value)).toBe(value);
52
+ });
53
+
54
+ test('String max length', () => {
55
+ let value: String = 'surendhar';
56
+ let schema: Schema = new Schema().setType(TypeUtil.of(SchemaType.STRING)).setMaxLength(12323);
57
+
58
+ expect(StringValidator.validate([], schema, value)).toBe(value);
59
+ });
60
+
61
+ test('String date invalid case', () => {
62
+ let value: String = '1234-12-1245';
63
+
64
+ let schema: Schema = new Schema().setFormat(StringFormat.DATE);
65
+
66
+ expect(() =>
67
+ StringValidator.validate([], schema, value).toThrow(
68
+ value + ' is not matched with the ' + 'date pattern',
69
+ ),
70
+ );
71
+ });
72
+
73
+ test('String date valid case', () => {
74
+ let value: String = '2023-01-26';
75
+
76
+ let schema: Schema = new Schema().setFormat(StringFormat.DATE);
77
+
78
+ expect(StringValidator.validate([], schema, value)).toBe(value);
79
+ });
80
+
81
+ test('String time invalid case', () => {
82
+ let value: String = '231:45:56';
83
+
84
+ let schema: Schema = new Schema().setFormat(StringFormat.TIME);
85
+
86
+ expect(() => StringValidator.validate([], schema, value)).toThrow(
87
+ value + ' is not matched with the ' + 'time pattern',
88
+ );
89
+ });
90
+
91
+ test('String time valid case', () => {
92
+ let value: String = '22:32:45';
93
+
94
+ let schema: Schema = new Schema().setFormat(StringFormat.TIME);
95
+
96
+ expect(StringValidator.validate([], schema, value)).toBe(value);
97
+ });
98
+
99
+ test('String date time invalid case', () => {
100
+ let value: String = '26-jan-2023 231:45:56';
101
+
102
+ let schema: Schema = new Schema().setFormat(StringFormat.DATETIME);
103
+
104
+ expect(() => StringValidator.validate([], schema, value)).toThrow(
105
+ value + ' is not matched with the ' + 'date time pattern',
106
+ );
107
+ });
108
+
109
+ test('String date time valid case', () => {
110
+ let value: String = '2032-02-12T02:54:23';
111
+
112
+ let schema: Schema = new Schema().setFormat(StringFormat.DATETIME);
113
+
114
+ expect(StringValidator.validate([], schema, value)).toBe(value);
115
+ });
116
+
117
+ test('String email invalid case', () => {
118
+ let value: String = 'testemail fai%6&8ls@gmail.com';
119
+
120
+ let schema: Schema = new Schema().setFormat(StringFormat.EMAIL);
121
+
122
+ expect(() => StringValidator.validate([], schema, value)).toThrow(
123
+ value + ' is not matched with the ' + 'email pattern',
124
+ );
125
+ });
126
+
127
+ test('String email valid case', () => {
128
+ let value: String = 'testemaifai%6&8lworkings@magil.com';
129
+
130
+ let schema: Schema = new Schema().setFormat(StringFormat.EMAIL);
131
+
132
+ console.log(StringValidator.validate([], schema, value));
133
+
134
+ expect(StringValidator.validate([], schema, value)).toBe(value);
135
+ });
@@ -0,0 +1,142 @@
1
+ import { KIRuntime } from '../../../src/engine/runtime/KIRuntime';
2
+ import { EventResult } from '../../../src/engine/model/EventResult';
3
+ import { Event } from '../../../src/engine/model/Event';
4
+ import { FunctionDefinition } from '../../../src/engine/model/FunctionDefinition';
5
+ import { Parameter } from '../../../src/engine/model/Parameter';
6
+ import { FunctionExecutionParameters } from '../../../src/engine/runtime/FunctionExecutionParameters';
7
+ import { Create } from '../../../src/engine/function/system/context/Create';
8
+ import { SetFunction } from '../../../src/engine/function/system/context/SetFunction';
9
+ import { GenerateEvent } from '../../../src/engine/function/system/GenerateEvent';
10
+ import { If } from '../../../src/engine/function/system/If';
11
+ import { RangeLoop } from '../../../src/engine/function/system/loop/RangeLoop';
12
+ import { Statement } from '../../../src/engine/model/Statement';
13
+ import { ParameterReference } from '../../../src/engine/model/ParameterReference';
14
+ import { Schema } from '../../../src/engine/json/schema/Schema';
15
+ import { KIRunFunctionRepository } from '../../../src/engine/repository/KIRunFunctionRepository';
16
+ import { KIRunSchemaRepository } from '../../../src/engine/repository/KIRunSchemaRepository';
17
+ import { Namespaces } from '../../../src/engine/namespaces/Namespaces';
18
+ import { FunctionSignature } from '../../../src/engine/model/FunctionSignature';
19
+ import { AbstractFunction } from '../../../src/engine/function/AbstractFunction';
20
+ import { FunctionOutput } from '../../../src/engine/model/FunctionOutput';
21
+ import { HybridRepository } from '../../../src/engine/HybridRepository';
22
+ import { Function } from '../../../src/engine/function/Function';
23
+
24
+ test('KIRuntime Extended Definition', async () => {
25
+ var def = {
26
+ name: 'checkExtendedFunction',
27
+ namespace: 'Test',
28
+ parameters: {
29
+ a: { parameterName: 'a', schema: { name: 'INTEGER', type: 'INTEGER' } },
30
+ },
31
+ events: {
32
+ output: {
33
+ name: 'output',
34
+ parameters: { additionResult: { name: 'additionResult', type: 'INTEGER' } },
35
+ },
36
+ },
37
+ steps: {
38
+ add1: {
39
+ statementName: 'add1',
40
+ namespace: Namespaces.MATH,
41
+ name: 'Add',
42
+ parameterMap: {
43
+ value: {
44
+ one: { key: 'one', type: 'EXPRESSION', expression: 'Arguments.a' },
45
+ two: { key: 'two', type: 'VALUE', value: 1 },
46
+ },
47
+ },
48
+ },
49
+ if1: {
50
+ statementName: 'if1',
51
+ namespace: Namespaces.SYSTEM,
52
+ name: 'If',
53
+ parameterMap: {
54
+ condition: {
55
+ one: {
56
+ key: 'one',
57
+ type: 'EXPRESSION',
58
+ expression: 'Steps.add1.output.value % 2 = 0',
59
+ },
60
+ },
61
+ },
62
+ },
63
+ add2: {
64
+ statementName: 'add2',
65
+ namespace: Namespaces.MATH,
66
+ name: 'Add',
67
+ parameterMap: {
68
+ value: {
69
+ one: {
70
+ key: 'one',
71
+ type: 'EXPRESSION',
72
+ expression: 'Steps.add1.output.value',
73
+ },
74
+ two: { key: 'two', type: 'VALUE', value: 2 },
75
+ },
76
+ },
77
+ dependentStatements: {
78
+ 'Steps.if1.true': true,
79
+ },
80
+ },
81
+ add3: {
82
+ statementName: 'add3',
83
+ namespace: Namespaces.MATH,
84
+ name: 'Add',
85
+ parameterMap: {
86
+ value: {
87
+ one: {
88
+ key: 'one',
89
+ type: 'EXPRESSION',
90
+ expression: 'Steps.add2.output.value',
91
+ },
92
+ two: { key: 'two', type: 'VALUE', value: 2 },
93
+ },
94
+ },
95
+ },
96
+ add4: {
97
+ statementName: 'add4',
98
+ namespace: Namespaces.MATH,
99
+ name: 'Add',
100
+ parameterMap: {
101
+ value: {
102
+ one: {
103
+ key: 'one',
104
+ type: 'EXPRESSION',
105
+ expression: 'Steps.add1.output.value',
106
+ },
107
+ two: { key: 'two', type: 'VALUE', value: 1 },
108
+ },
109
+ },
110
+ },
111
+ genOutput: {
112
+ statementName: 'genOutput',
113
+ namespace: Namespaces.SYSTEM,
114
+ name: 'GenerateEvent',
115
+ parameterMap: {
116
+ eventName: { one: { key: 'one', type: 'VALUE', value: 'output' } },
117
+ results: {
118
+ one: {
119
+ key: 'one',
120
+ type: 'VALUE',
121
+ value: {
122
+ name: 'additionResult',
123
+ value: { isExpression: true, value: 'Steps.add4.output.value' },
124
+ },
125
+ },
126
+ },
127
+ },
128
+ },
129
+ },
130
+ };
131
+
132
+ const fd = FunctionDefinition.from(def);
133
+
134
+ let result = await new KIRuntime(fd, true).execute(
135
+ new FunctionExecutionParameters(
136
+ new KIRunFunctionRepository(),
137
+ new KIRunSchemaRepository(),
138
+ ).setArguments(new Map([['a', 7]])),
139
+ );
140
+
141
+ expect(result.allResults()[0].getResult().get('additionResult')).toBe(9);
142
+ });
@@ -72,7 +72,7 @@ test('KIRuntime With Definition 1', async () => {
72
72
 
73
73
  const fd = FunctionDefinition.from(def);
74
74
 
75
- let result = await new KIRuntime(fd).execute(
75
+ let result = await new KIRuntime(fd, true).execute(
76
76
  new FunctionExecutionParameters(
77
77
  new KIRunFunctionRepository(),
78
78
  new KIRunSchemaRepository(),
@@ -0,0 +1,17 @@
1
+ import { LogicalNotOperator } from '../../../../../../src';
2
+
3
+ test('Logical Not Test', () => {
4
+ expect(new LogicalNotOperator().apply(null)).toBeTruthy();
5
+ expect(new LogicalNotOperator().apply(undefined)).toBeTruthy();
6
+ expect(new LogicalNotOperator().apply(false)).toBeTruthy();
7
+ expect(new LogicalNotOperator().apply(0)).toBeTruthy();
8
+
9
+ expect(new LogicalNotOperator().apply(true)).toBeFalsy();
10
+ expect(new LogicalNotOperator().apply(1)).toBeFalsy();
11
+
12
+ expect(new LogicalNotOperator().apply({ name: 'Kiran' })).toBeFalsy();
13
+
14
+ expect(new LogicalNotOperator().apply([])).toBeFalsy();
15
+ expect(new LogicalNotOperator().apply('')).toBeFalsy();
16
+ expect(new LogicalNotOperator().apply('TRUE')).toBeFalsy();
17
+ });