@fincity/kirun-js 2.8.6 → 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.
Files changed (52) hide show
  1. package/__tests__/engine/runtime/expression/ExpressionArrayStringIndexing.ts +67 -0
  2. package/dist/index.js +1 -1
  3. package/dist/index.js.map +1 -1
  4. package/dist/module.js +1 -1
  5. package/dist/module.js.map +1 -1
  6. package/dist/types.d.ts +10 -5
  7. package/dist/types.d.ts.map +1 -1
  8. package/package.json +57 -57
  9. package/src/engine/function/system/GenerateEvent.ts +23 -21
  10. package/src/engine/function/system/If.ts +2 -3
  11. package/src/engine/function/system/Print.ts +2 -3
  12. package/src/engine/function/system/Wait.ts +2 -3
  13. package/src/engine/function/system/array/ArrayFunctionRepository.ts +7 -9
  14. package/src/engine/function/system/array/Join.ts +29 -28
  15. package/src/engine/function/system/context/Create.ts +20 -22
  16. package/src/engine/function/system/context/Get.ts +19 -19
  17. package/src/engine/function/system/context/SetFunction.ts +17 -14
  18. package/src/engine/function/system/date/DateFunctionRepository.ts +6 -8
  19. package/src/engine/function/system/date/EpochToTimestamp.ts +1 -1
  20. package/src/engine/function/system/date/GetNames.ts +1 -1
  21. package/src/engine/function/system/date/IsValidISODate.ts +4 -6
  22. package/src/engine/function/system/loop/Break.ts +7 -7
  23. package/src/engine/function/system/loop/CountLoop.ts +13 -14
  24. package/src/engine/function/system/loop/ForEachLoop.ts +18 -19
  25. package/src/engine/function/system/loop/RangeLoop.ts +68 -69
  26. package/src/engine/function/system/math/Add.ts +11 -9
  27. package/src/engine/function/system/math/GenericMathFunction.ts +13 -13
  28. package/src/engine/function/system/math/Hypotenuse.ts +2 -2
  29. package/src/engine/function/system/math/MathFunctionRepository.ts +107 -90
  30. package/src/engine/function/system/math/Maximum.ts +12 -11
  31. package/src/engine/function/system/math/Minimum.ts +12 -11
  32. package/src/engine/function/system/math/Random.ts +2 -2
  33. package/src/engine/function/system/object/AbstractObjectFunction.ts +1 -2
  34. package/src/engine/function/system/object/ObjectConvert.ts +26 -26
  35. package/src/engine/function/system/object/ObjectDeleteKey.ts +1 -2
  36. package/src/engine/function/system/object/ObjectFunctionRepository.ts +18 -14
  37. package/src/engine/function/system/string/Concatenate.ts +8 -7
  38. package/src/engine/function/system/string/Matches.ts +2 -2
  39. package/src/engine/function/system/string/Reverse.ts +2 -2
  40. package/src/engine/function/system/string/Split.ts +16 -15
  41. package/src/engine/function/system/string/StringFunctionRepository.ts +6 -8
  42. package/src/engine/function/system/string/ToString.ts +9 -8
  43. package/src/engine/repository/KIRunFunctionRepository.ts +47 -39
  44. package/src/engine/repository/KIRunSchemaRepository.ts +75 -70
  45. package/src/engine/runtime/expression/Expression.ts +15 -1
  46. package/src/engine/runtime/expression/ExpressionEvaluator.ts +36 -31
  47. package/src/engine/runtime/expression/Operation.ts +10 -4
  48. package/src/engine/runtime/expression/operators/binary/ArrayRangeOperator.ts +7 -0
  49. package/src/engine/runtime/expression/operators/binary/index.ts +1 -0
  50. package/src/engine/runtime/expression/tokenextractor/TokenValueExtractor.ts +33 -6
  51. package/src/engine/util/duplicate.ts +1 -1
  52. package/tsconfig.json +4 -2
@@ -13,39 +13,40 @@ const VALUE = 'source';
13
13
  const DELIMITTER = 'delimiter';
14
14
  const OUTPUT = 'result';
15
15
 
16
- const SIGNATURE = new FunctionSignature('Join')
17
- .setNamespace(Namespaces.SYSTEM_ARRAY)
18
- .setParameters(
19
- new Map([
20
- [
21
- VALUE,
22
- new Parameter(
16
+ export class Join extends AbstractFunction {
17
+ private readonly signature = new FunctionSignature('Join')
18
+ .setNamespace(Namespaces.SYSTEM_ARRAY)
19
+ .setParameters(
20
+ new Map([
21
+ [
23
22
  VALUE,
24
- Schema.ofArray(
23
+ new Parameter(
25
24
  VALUE,
26
- Schema.of(
27
- 'each',
28
- SchemaType.STRING,
29
- SchemaType.INTEGER,
30
- SchemaType.LONG,
31
- SchemaType.DOUBLE,
32
- SchemaType.FLOAT,
33
- SchemaType.NULL,
25
+ Schema.ofArray(
26
+ VALUE,
27
+ Schema.of(
28
+ 'each',
29
+ SchemaType.STRING,
30
+ SchemaType.INTEGER,
31
+ SchemaType.LONG,
32
+ SchemaType.DOUBLE,
33
+ SchemaType.FLOAT,
34
+ SchemaType.NULL,
35
+ ),
34
36
  ),
35
37
  ),
36
- ),
37
- ],
38
- [
39
- DELIMITTER,
40
- new Parameter(DELIMITTER, Schema.ofString(DELIMITTER).setDefaultValue('')),
41
- ],
42
- ]),
43
- )
44
- .setEvents(new Map([Event.outputEventMapEntry(new Map([[OUTPUT, Schema.ofString(OUTPUT)]]))]));
45
-
46
- export class Join extends AbstractFunction {
38
+ ],
39
+ [
40
+ DELIMITTER,
41
+ new Parameter(DELIMITTER, Schema.ofString(DELIMITTER).setDefaultValue('')),
42
+ ],
43
+ ]),
44
+ )
45
+ .setEvents(
46
+ new Map([Event.outputEventMapEntry(new Map([[OUTPUT, Schema.ofString(OUTPUT)]]))]),
47
+ );
47
48
  public getSignature(): FunctionSignature {
48
- return SIGNATURE;
49
+ return this.signature;
49
50
  }
50
51
 
51
52
  protected async internalExecute(context: FunctionExecutionParameters): Promise<FunctionOutput> {
@@ -18,30 +18,28 @@ import { AbstractFunction } from '../../AbstractFunction';
18
18
 
19
19
  const NAME = 'name';
20
20
  const SCHEMA = 'schema';
21
-
22
- const SIGNATURE: FunctionSignature = new FunctionSignature('Create')
23
- .setNamespace(Namespaces.SYSTEM_CTX)
24
- .setParameters(
25
- new Map([
26
- Parameter.ofEntry(
27
- NAME,
28
- new Schema()
29
- .setName(NAME)
30
- .setType(TypeUtil.of(SchemaType.STRING))
31
- .setMinLength(1)
32
- .setFormat(StringFormat.REGEX)
33
- .setPattern('^[a-zA-Z_$][a-zA-Z_$0-9]*$'),
34
- false,
35
- ParameterType.CONSTANT,
36
- ),
37
- Parameter.ofEntry(SCHEMA, Schema.SCHEMA, false, ParameterType.CONSTANT),
38
- ]),
39
- )
40
- .setEvents(new Map([Event.outputEventMapEntry(new Map())]));
41
-
42
21
  export class Create extends AbstractFunction {
22
+ private readonly signature = new FunctionSignature('Create')
23
+ .setNamespace(Namespaces.SYSTEM_CTX)
24
+ .setParameters(
25
+ new Map([
26
+ Parameter.ofEntry(
27
+ NAME,
28
+ new Schema()
29
+ .setName(NAME)
30
+ .setType(TypeUtil.of(SchemaType.STRING))
31
+ .setMinLength(1)
32
+ .setFormat(StringFormat.REGEX)
33
+ .setPattern('^[a-zA-Z_$][a-zA-Z_$0-9]*$'),
34
+ false,
35
+ ParameterType.CONSTANT,
36
+ ),
37
+ Parameter.ofEntry(SCHEMA, Schema.SCHEMA, false, ParameterType.CONSTANT),
38
+ ]),
39
+ )
40
+ .setEvents(new Map([Event.outputEventMapEntry(new Map())]));
43
41
  public getSignature(): FunctionSignature {
44
- return SIGNATURE;
42
+ return this.signature;
45
43
  }
46
44
 
47
45
  protected async internalExecute(context: FunctionExecutionParameters): Promise<FunctionOutput> {
@@ -16,28 +16,28 @@ import { AbstractFunction } from '../../AbstractFunction';
16
16
 
17
17
  const NAME = 'name';
18
18
  const VALUE = 'value';
19
- const SIGNATURE = new FunctionSignature('Get')
20
- .setNamespace(Namespaces.SYSTEM_CTX)
21
- .setParameters(
22
- new Map([
23
- Parameter.ofEntry(
24
- NAME,
25
- new Schema()
26
- .setName(NAME)
27
- .setType(TypeUtil.of(SchemaType.STRING))
28
- .setMinLength(1)
29
- .setFormat(StringFormat.REGEX)
30
- .setPattern('^[a-zA-Z_$][a-zA-Z_$0-9]*$'),
31
- false,
32
- ParameterType.CONSTANT,
33
- ),
34
- ]),
35
- )
36
- .setEvents(new Map([Event.outputEventMapEntry(new Map([[VALUE, Schema.ofAny(VALUE)]]))]));
37
19
 
38
20
  export class Get extends AbstractFunction {
21
+ private readonly signature = new FunctionSignature('Get')
22
+ .setNamespace(Namespaces.SYSTEM_CTX)
23
+ .setParameters(
24
+ new Map([
25
+ Parameter.ofEntry(
26
+ NAME,
27
+ new Schema()
28
+ .setName(NAME)
29
+ .setType(TypeUtil.of(SchemaType.STRING))
30
+ .setMinLength(1)
31
+ .setFormat(StringFormat.REGEX)
32
+ .setPattern('^[a-zA-Z_$][a-zA-Z_$0-9]*$'),
33
+ false,
34
+ ParameterType.CONSTANT,
35
+ ),
36
+ ]),
37
+ )
38
+ .setEvents(new Map([Event.outputEventMapEntry(new Map([[VALUE, Schema.ofAny(VALUE)]]))]));
39
39
  public getSignature(): FunctionSignature {
40
- return SIGNATURE;
40
+ return this.signature;
41
41
  }
42
42
 
43
43
  protected async internalExecute(context: FunctionExecutionParameters): Promise<FunctionOutput> {
@@ -23,23 +23,26 @@ import { AbstractFunction } from '../../AbstractFunction';
23
23
 
24
24
  const NAME = 'name';
25
25
  const VALUE = 'value';
26
- const SIGNATURE = new FunctionSignature('Set')
27
- .setNamespace(Namespaces.SYSTEM_CTX)
28
- .setParameters(
29
- new Map([
30
- Parameter.ofEntry(
31
- NAME,
32
- new Schema().setName(NAME).setType(TypeUtil.of(SchemaType.STRING)).setMinLength(1),
33
- false,
34
- ),
35
- Parameter.ofEntry(VALUE, Schema.ofAny(VALUE)),
36
- ]),
37
- )
38
- .setEvents(new Map([Event.outputEventMapEntry(new Map())]));
39
26
 
40
27
  export class SetFunction extends AbstractFunction {
28
+ private readonly signature = new FunctionSignature('Set')
29
+ .setNamespace(Namespaces.SYSTEM_CTX)
30
+ .setParameters(
31
+ new Map([
32
+ Parameter.ofEntry(
33
+ NAME,
34
+ new Schema()
35
+ .setName(NAME)
36
+ .setType(TypeUtil.of(SchemaType.STRING))
37
+ .setMinLength(1),
38
+ false,
39
+ ),
40
+ Parameter.ofEntry(VALUE, Schema.ofAny(VALUE)),
41
+ ]),
42
+ )
43
+ .setEvents(new Map([Event.outputEventMapEntry(new Map())]));
41
44
  public getSignature(): FunctionSignature {
42
- return SIGNATURE;
45
+ return this.signature;
43
46
  }
44
47
 
45
48
  protected async internalExecute(context: FunctionExecutionParameters): Promise<FunctionOutput> {
@@ -23,7 +23,7 @@ import { FromDateString } from './FromDateString';
23
23
  import { GetCurrentTimestamp } from './GetCurrent';
24
24
 
25
25
  export class DateFunctionRepository implements Repository<Function> {
26
- private static readonly repoMap: Map<string, Function> = MapUtil.ofArrayEntries(
26
+ private readonly repoMap: Map<string, Function> = MapUtil.ofArrayEntries(
27
27
  ['EpochSecondsToTimestamp', new EpochToTimestamp('EpochSecondsToTimestamp', true)],
28
28
  [
29
29
  'EpochMillisecondsToTimestamp',
@@ -246,21 +246,19 @@ export class DateFunctionRepository implements Repository<Function> {
246
246
  ['FromDateString', new FromDateString()],
247
247
  );
248
248
 
249
- private static readonly filterableNames = Array.from(
250
- DateFunctionRepository.repoMap.values(),
251
- ).map((e) => e.getSignature().getFullName());
249
+ private readonly filterableNames = Array.from(this.repoMap.values()).map((e) =>
250
+ e.getSignature().getFullName(),
251
+ );
252
252
 
253
253
  find(namespace: string, name: string): Promise<Function | undefined> {
254
254
  if (namespace != Namespaces.DATE) {
255
255
  return Promise.resolve(undefined);
256
256
  }
257
- return Promise.resolve(DateFunctionRepository.repoMap.get(name));
257
+ return Promise.resolve(this.repoMap.get(name));
258
258
  }
259
259
  filter(name: string): Promise<string[]> {
260
260
  return Promise.resolve(
261
- DateFunctionRepository.filterableNames.filter(
262
- (e) => e.toLowerCase().indexOf(name.toLowerCase()) !== -1,
263
- ),
261
+ this.filterableNames.filter((e) => e.toLowerCase().indexOf(name.toLowerCase()) !== -1),
264
262
  );
265
263
  }
266
264
  }
@@ -12,7 +12,6 @@ import { AbstractFunction } from '../../AbstractFunction';
12
12
  import { AbstractDateFunction } from './AbstractDateFunction';
13
13
 
14
14
  export class EpochToTimestamp extends AbstractFunction {
15
- private readonly signature: FunctionSignature;
16
15
  private readonly isSeconds: boolean;
17
16
  private readonly paramName: string;
18
17
 
@@ -51,6 +50,7 @@ export class EpochToTimestamp extends AbstractFunction {
51
50
  );
52
51
  }
53
52
 
53
+ private readonly signature;
54
54
  public getSignature(): FunctionSignature {
55
55
  return this.signature;
56
56
  }
@@ -65,7 +65,7 @@ export class GetNames extends AbstractDateFunction {
65
65
 
66
66
  if (unit === 'WEEKDAYS') {
67
67
  return [1, 2, 3, 4, 5, 6, 7].map((day) =>
68
- DateTime.now().setLocale(locale).set({ month: 7, day }).toFormat('EEEE'),
68
+ DateTime.now().setLocale(locale).set({ month: 7, year: 2024, day }).toFormat('EEEE'),
69
69
  );
70
70
  }
71
71
 
@@ -12,7 +12,7 @@ import { AbstractDateFunction } from './AbstractDateFunction';
12
12
  import { DateTime } from 'luxon';
13
13
 
14
14
  export class IsValidISODate extends AbstractFunction {
15
- private static readonly SIGNATURE = new FunctionSignature('IsValidISODate')
15
+ private readonly signature = new FunctionSignature('IsValidISODate')
16
16
  .setNamespace(Namespaces.DATE)
17
17
  .setParameters(
18
18
  new Map([
@@ -43,15 +43,13 @@ export class IsValidISODate extends AbstractFunction {
43
43
  return Promise.resolve(
44
44
  new FunctionOutput([
45
45
  EventResult.outputOf(
46
- MapUtil.of(
47
- AbstractDateFunction.EVENT_RESULT_NAME,
48
- dt.isValid,
49
- ),
46
+ MapUtil.of(AbstractDateFunction.EVENT_RESULT_NAME, dt.isValid),
50
47
  ),
51
48
  ]),
52
49
  );
53
50
  }
51
+
54
52
  public getSignature(): FunctionSignature {
55
- return IsValidISODate.SIGNATURE;
53
+ return this.signature;
56
54
  }
57
55
  }
@@ -10,15 +10,15 @@ import { FunctionExecutionParameters } from '../../../runtime/FunctionExecutionP
10
10
  import { AbstractFunction } from '../../AbstractFunction';
11
11
 
12
12
  const STEP_NAME = 'stepName';
13
-
14
- const SIGNATURE = new FunctionSignature('Break')
15
- .setNamespace(Namespaces.SYSTEM_LOOP)
16
- .setParameters(new Map([Parameter.ofEntry(STEP_NAME, Schema.of(STEP_NAME, SchemaType.STRING))]))
17
- .setEvents(new Map([Event.outputEventMapEntry(new Map([]))]));
18
-
19
13
  export class Break extends AbstractFunction {
14
+ private readonly signature = new FunctionSignature('Break')
15
+ .setNamespace(Namespaces.SYSTEM_LOOP)
16
+ .setParameters(
17
+ new Map([Parameter.ofEntry(STEP_NAME, Schema.of(STEP_NAME, SchemaType.STRING))]),
18
+ )
19
+ .setEvents(new Map([Event.outputEventMapEntry(new Map([]))]));
20
20
  public getSignature(): FunctionSignature {
21
- return SIGNATURE;
21
+ return this.signature;
22
22
  }
23
23
 
24
24
  protected async internalExecute(context: FunctionExecutionParameters): Promise<FunctionOutput> {
@@ -13,22 +13,21 @@ const COUNT = 'count';
13
13
  const VALUE = 'value';
14
14
  const INDEX = 'index';
15
15
 
16
- const SIGNATURE = new FunctionSignature('CountLoop')
17
- .setNamespace(Namespaces.SYSTEM_LOOP)
18
- .setParameters(new Map([Parameter.ofEntry(COUNT, Schema.of(COUNT, SchemaType.INTEGER))]))
19
- .setEvents(
20
- new Map([
21
- Event.eventMapEntry(
22
- Event.ITERATION,
23
- new Map([[INDEX, Schema.of(INDEX, SchemaType.INTEGER)]]),
24
- ),
25
- Event.outputEventMapEntry(new Map([[VALUE, Schema.of(VALUE, SchemaType.INTEGER)]])),
26
- ]),
27
- );
28
-
29
16
  export class CountLoop extends AbstractFunction {
17
+ private readonly signature = new FunctionSignature('CountLoop')
18
+ .setNamespace(Namespaces.SYSTEM_LOOP)
19
+ .setParameters(new Map([Parameter.ofEntry(COUNT, Schema.of(COUNT, SchemaType.INTEGER))]))
20
+ .setEvents(
21
+ new Map([
22
+ Event.eventMapEntry(
23
+ Event.ITERATION,
24
+ new Map([[INDEX, Schema.of(INDEX, SchemaType.INTEGER)]]),
25
+ ),
26
+ Event.outputEventMapEntry(new Map([[VALUE, Schema.of(VALUE, SchemaType.INTEGER)]])),
27
+ ]),
28
+ );
30
29
  public getSignature(): FunctionSignature {
31
- return SIGNATURE;
30
+ return this.signature;
32
31
  }
33
32
 
34
33
  protected async internalExecute(context: FunctionExecutionParameters): Promise<FunctionOutput> {
@@ -14,27 +14,26 @@ const EACH = 'each';
14
14
  const INDEX = 'index';
15
15
  const VALUE = 'value';
16
16
 
17
- const SIGNATURE = new FunctionSignature('ForEachLoop')
18
- .setNamespace(Namespaces.SYSTEM_LOOP)
19
- .setParameters(
20
- new Map([Parameter.ofEntry(SOURCE, Schema.ofArray(SOURCE, Schema.ofAny(SOURCE)))]),
21
- )
22
- .setEvents(
23
- new Map([
24
- Event.eventMapEntry(
25
- Event.ITERATION,
26
- new Map([
27
- [INDEX, Schema.of(INDEX, SchemaType.INTEGER)],
28
- [EACH, Schema.ofAny(EACH)],
29
- ]),
30
- ),
31
- Event.outputEventMapEntry(new Map([[VALUE, Schema.of(VALUE, SchemaType.INTEGER)]])),
32
- ]),
33
- );
34
-
35
17
  export class ForEachLoop extends AbstractFunction {
18
+ private readonly signature = new FunctionSignature('ForEachLoop')
19
+ .setNamespace(Namespaces.SYSTEM_LOOP)
20
+ .setParameters(
21
+ new Map([Parameter.ofEntry(SOURCE, Schema.ofArray(SOURCE, Schema.ofAny(SOURCE)))]),
22
+ )
23
+ .setEvents(
24
+ new Map([
25
+ Event.eventMapEntry(
26
+ Event.ITERATION,
27
+ new Map([
28
+ [INDEX, Schema.of(INDEX, SchemaType.INTEGER)],
29
+ [EACH, Schema.ofAny(EACH)],
30
+ ]),
31
+ ),
32
+ Event.outputEventMapEntry(new Map([[VALUE, Schema.of(VALUE, SchemaType.INTEGER)]])),
33
+ ]),
34
+ );
36
35
  public getSignature(): FunctionSignature {
37
- return SIGNATURE;
36
+ return this.signature;
38
37
  }
39
38
 
40
39
  protected async internalExecute(context: FunctionExecutionParameters): Promise<FunctionOutput> {
@@ -15,81 +15,80 @@ const STEP = 'step';
15
15
  const VALUE = 'value';
16
16
  const INDEX = 'index';
17
17
 
18
- const SIGNATURE = new FunctionSignature('RangeLoop')
19
- .setNamespace(Namespaces.SYSTEM_LOOP)
20
- .setParameters(
21
- new Map([
22
- Parameter.ofEntry(
23
- FROM,
24
- Schema.of(
18
+ export class RangeLoop extends AbstractFunction {
19
+ private readonly signature = new FunctionSignature('RangeLoop')
20
+ .setNamespace(Namespaces.SYSTEM_LOOP)
21
+ .setParameters(
22
+ new Map([
23
+ Parameter.ofEntry(
25
24
  FROM,
26
- SchemaType.INTEGER,
27
- SchemaType.LONG,
28
- SchemaType.FLOAT,
29
- SchemaType.DOUBLE,
30
- ).setDefaultValue(0),
31
- ),
32
- Parameter.ofEntry(
33
- TO,
34
- Schema.of(
25
+ Schema.of(
26
+ FROM,
27
+ SchemaType.INTEGER,
28
+ SchemaType.LONG,
29
+ SchemaType.FLOAT,
30
+ SchemaType.DOUBLE,
31
+ ).setDefaultValue(0),
32
+ ),
33
+ Parameter.ofEntry(
35
34
  TO,
36
- SchemaType.INTEGER,
37
- SchemaType.LONG,
38
- SchemaType.FLOAT,
39
- SchemaType.DOUBLE,
40
- ).setDefaultValue(1),
41
- ),
42
- Parameter.ofEntry(
43
- STEP,
44
- Schema.of(
35
+ Schema.of(
36
+ TO,
37
+ SchemaType.INTEGER,
38
+ SchemaType.LONG,
39
+ SchemaType.FLOAT,
40
+ SchemaType.DOUBLE,
41
+ ).setDefaultValue(1),
42
+ ),
43
+ Parameter.ofEntry(
45
44
  STEP,
46
- SchemaType.INTEGER,
47
- SchemaType.LONG,
48
- SchemaType.FLOAT,
49
- SchemaType.DOUBLE,
50
- )
51
- .setDefaultValue(1)
52
- .setNot(new Schema().setConstant(0)),
53
- ),
54
- ]),
55
- )
56
- .setEvents(
57
- new Map([
58
- Event.eventMapEntry(
59
- Event.ITERATION,
60
- new Map([
61
- [
62
- INDEX,
63
- Schema.of(
45
+ Schema.of(
46
+ STEP,
47
+ SchemaType.INTEGER,
48
+ SchemaType.LONG,
49
+ SchemaType.FLOAT,
50
+ SchemaType.DOUBLE,
51
+ )
52
+ .setDefaultValue(1)
53
+ .setNot(new Schema().setConstant(0)),
54
+ ),
55
+ ]),
56
+ )
57
+ .setEvents(
58
+ new Map([
59
+ Event.eventMapEntry(
60
+ Event.ITERATION,
61
+ new Map([
62
+ [
64
63
  INDEX,
65
- SchemaType.INTEGER,
66
- SchemaType.LONG,
67
- SchemaType.FLOAT,
68
- SchemaType.DOUBLE,
69
- ),
70
- ],
71
- ]),
72
- ),
73
- Event.outputEventMapEntry(
74
- new Map([
75
- [
76
- VALUE,
77
- Schema.of(
64
+ Schema.of(
65
+ INDEX,
66
+ SchemaType.INTEGER,
67
+ SchemaType.LONG,
68
+ SchemaType.FLOAT,
69
+ SchemaType.DOUBLE,
70
+ ),
71
+ ],
72
+ ]),
73
+ ),
74
+ Event.outputEventMapEntry(
75
+ new Map([
76
+ [
78
77
  VALUE,
79
- SchemaType.INTEGER,
80
- SchemaType.LONG,
81
- SchemaType.FLOAT,
82
- SchemaType.DOUBLE,
83
- ),
84
- ],
85
- ]),
86
- ),
87
- ]),
88
- );
89
-
90
- export class RangeLoop extends AbstractFunction {
78
+ Schema.of(
79
+ VALUE,
80
+ SchemaType.INTEGER,
81
+ SchemaType.LONG,
82
+ SchemaType.FLOAT,
83
+ SchemaType.DOUBLE,
84
+ ),
85
+ ],
86
+ ]),
87
+ ),
88
+ ]),
89
+ );
91
90
  public getSignature(): FunctionSignature {
92
- return SIGNATURE;
91
+ return this.signature;
93
92
  }
94
93
 
95
94
  protected async internalExecute(context: FunctionExecutionParameters): Promise<FunctionOutput> {
@@ -9,17 +9,19 @@ import { FunctionExecutionParameters } from '../../../runtime/FunctionExecutionP
9
9
  import { AbstractFunction } from '../../AbstractFunction';
10
10
 
11
11
  const VALUE = 'value';
12
-
13
- const SIGNATURE = new FunctionSignature('Add')
14
- .setNamespace(Namespaces.MATH)
15
- .setParameters(
16
- new Map([[VALUE, new Parameter(VALUE, Schema.ofNumber(VALUE)).setVariableArgument(true)]]),
17
- )
18
- .setEvents(new Map([Event.outputEventMapEntry(new Map([[VALUE, Schema.ofNumber(VALUE)]]))]));
19
-
20
12
  export class Add extends AbstractFunction {
13
+ private readonly signature = new FunctionSignature('Add')
14
+ .setNamespace(Namespaces.MATH)
15
+ .setParameters(
16
+ new Map([
17
+ [VALUE, new Parameter(VALUE, Schema.ofNumber(VALUE)).setVariableArgument(true)],
18
+ ]),
19
+ )
20
+ .setEvents(
21
+ new Map([Event.outputEventMapEntry(new Map([[VALUE, Schema.ofNumber(VALUE)]]))]),
22
+ );
21
23
  public getSignature(): FunctionSignature {
22
- return SIGNATURE;
24
+ return this.signature;
23
25
  }
24
26
 
25
27
  protected async internalExecute(context: FunctionExecutionParameters): Promise<FunctionOutput> {
@@ -15,22 +15,11 @@ const VALUE = 'value';
15
15
  const VALUE1 = 'value1';
16
16
  const VALUE2 = 'value2';
17
17
 
18
- const paramFunctions = [
19
- () => {
20
- return new Map([[VALUE, new Parameter(VALUE, Schema.ofNumber(VALUE))]]);
21
- },
22
- () => {
23
- return new Map([
24
- [VALUE1, new Parameter(VALUE1, Schema.ofNumber(VALUE1))],
25
- [VALUE2, new Parameter(VALUE2, Schema.ofNumber(VALUE2))],
26
- ]);
27
- },
28
- ];
29
-
30
18
  export class GenericMathFunction extends AbstractFunction {
31
19
  private signature: FunctionSignature;
32
20
  private parametersNumber: number;
33
21
  private mathFunction: (v1: number, v2?: number) => number;
22
+ private readonly paramFunctions: Array<() => Map<string, Parameter>>;
34
23
 
35
24
  public constructor(
36
25
  functionName: string,
@@ -39,12 +28,23 @@ export class GenericMathFunction extends AbstractFunction {
39
28
  ...returnType: SchemaType[]
40
29
  ) {
41
30
  super();
31
+ this.paramFunctions = [
32
+ () => {
33
+ return new Map([[VALUE, new Parameter(VALUE, Schema.ofNumber(VALUE))]]);
34
+ },
35
+ () => {
36
+ return new Map([
37
+ [VALUE1, new Parameter(VALUE1, Schema.ofNumber(VALUE1))],
38
+ [VALUE2, new Parameter(VALUE2, Schema.ofNumber(VALUE2))],
39
+ ]);
40
+ },
41
+ ];
42
42
  if (!returnType || !returnType.length) returnType = [SchemaType.DOUBLE];
43
43
  this.parametersNumber = parametersNumber;
44
44
  this.mathFunction = mathFunction;
45
45
  this.signature = new FunctionSignature(functionName)
46
46
  .setNamespace(Namespaces.MATH)
47
- .setParameters(paramFunctions[parametersNumber - 1]())
47
+ .setParameters(this.paramFunctions[parametersNumber - 1]())
48
48
  .setEvents(
49
49
  new Map([
50
50
  Event.outputEventMapEntry(
@@ -13,7 +13,7 @@ import { AbstractFunction } from '../../AbstractFunction';
13
13
  const VALUE = 'value';
14
14
 
15
15
  export class Hypotenuse extends AbstractFunction {
16
- private static readonly SIGNATURE: FunctionSignature = new FunctionSignature('Hypotenuse')
16
+ private readonly signature: FunctionSignature = new FunctionSignature('Hypotenuse')
17
17
  .setNamespace(Namespaces.MATH)
18
18
  .setParameters(
19
19
  new Map([
@@ -38,7 +38,7 @@ export class Hypotenuse extends AbstractFunction {
38
38
  }
39
39
 
40
40
  public getSignature(): FunctionSignature {
41
- return Hypotenuse.SIGNATURE;
41
+ return this.signature;
42
42
  }
43
43
 
44
44
  protected async internalExecute(context: FunctionExecutionParameters): Promise<FunctionOutput> {