@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,105 +13,122 @@ import { Minimum } from './Minimum';
13
13
  import { Random } from './Random';
14
14
  import { RandomAny } from './RandomAny';
15
15
 
16
- const functionObjectsIndex: { [key: string]: AbstractFunction } = {
17
- Absolute: new GenericMathFunction(
18
- 'Absolute',
19
- (v) => Math.abs(v),
20
- 1,
21
- SchemaType.INTEGER,
22
- SchemaType.LONG,
23
- SchemaType.FLOAT,
24
- SchemaType.DOUBLE,
25
- ),
26
- ArcCosine: new GenericMathFunction('ArcCosine', (v) => Math.acos(v)),
27
- ArcSine: new GenericMathFunction('ArcSine', (v) => Math.asin(v)),
28
- ArcTangent: new GenericMathFunction('ArcTangent', (v) => Math.atan(v)),
29
- Ceiling: new GenericMathFunction('Ceiling', (v) => Math.ceil(v)),
30
- Cosine: new GenericMathFunction('Cosine', (v) => Math.cos(v)),
31
- HyperbolicCosine: new GenericMathFunction('HyperbolicCosine', (v) => Math.cosh(v)),
32
- CubeRoot: new GenericMathFunction('CubeRoot', (v) => Math.cbrt(v)),
33
- Exponential: new GenericMathFunction('Exponential', (v) => Math.exp(v)),
34
- ExponentialMinus1: new GenericMathFunction('ExponentialMinus1', (v) => Math.expm1(v)),
35
- Floor: new GenericMathFunction('Floor', (v) => Math.floor(v)),
36
- LogNatural: new GenericMathFunction('LogNatural', (v) => Math.log(v)),
37
- Log10: new GenericMathFunction('Log10', (v) => Math.log10(v)),
38
- Round: new GenericMathFunction(
39
- 'Round',
40
- (v) => Math.round(v),
41
- 1,
42
- SchemaType.INTEGER,
43
- SchemaType.LONG,
44
- ),
45
- Sine: new GenericMathFunction('Sine', (v) => Math.sin(v)),
46
- HyperbolicSine: new GenericMathFunction('HyperbolicSine', (v) => Math.sinh(v)),
47
- Tangent: new GenericMathFunction('Tangent', (v) => Math.tan(v)),
48
- HyperbolicTangent: new GenericMathFunction('HyperbolicTangent', (v) => Math.tanh(v)),
49
- ToDegrees: new GenericMathFunction('ToDegrees', (v) => v * (Math.PI / 180)),
50
- ToRadians: new GenericMathFunction('ToRadians', (v) => v * (180 / Math.PI)),
51
- SquareRoot: new GenericMathFunction('SquareRoot', (v) => Math.sqrt(v)),
52
- ArcTangent2: new GenericMathFunction('ArcTangent2', (v1, v2) => Math.atan2(v1, v2!), 2),
53
- Power: new GenericMathFunction('Power', (v1, v2) => Math.pow(v1, v2!), 2),
54
- Add: new Add(),
55
- Hypotenuse: new Hypotenuse(),
56
- Maximum: new Maximum(),
57
- Minimum: new Minimum(),
58
- Random: new Random(),
59
- RandomFloat: new RandomAny(
60
- 'RandomFloat',
61
- Parameter.of(RandomAny.MIN_VALUE, Schema.ofFloat(RandomAny.MIN_VALUE).setDefaultValue(0)),
62
- Parameter.of(
63
- RandomAny.MAX_VALUE,
64
- Schema.ofFloat(RandomAny.MAX_VALUE).setDefaultValue(2147483647),
65
- ),
66
- Schema.ofFloat(RandomAny.VALUE),
67
- (min, max) => Math.random() * (max - min) + min,
68
- ),
69
- RandomInt: new RandomAny(
70
- 'RandomInt',
71
- Parameter.of(RandomAny.MIN_VALUE, Schema.ofInteger(RandomAny.MIN_VALUE).setDefaultValue(0)),
72
- Parameter.of(
73
- RandomAny.MAX_VALUE,
74
- Schema.ofInteger(RandomAny.MAX_VALUE).setDefaultValue(2147483647),
75
- ),
76
- Schema.ofInteger(RandomAny.VALUE),
77
- (min, max) => Math.round(Math.random() * (max - min) + min),
78
- ),
79
- RandomLong: new RandomAny(
80
- 'RandomLong',
81
- Parameter.of(RandomAny.MIN_VALUE, Schema.ofLong(RandomAny.MIN_VALUE).setDefaultValue(0)),
82
- Parameter.of(
83
- RandomAny.MAX_VALUE,
84
- Schema.ofLong(RandomAny.MAX_VALUE).setDefaultValue(Number.MAX_SAFE_INTEGER),
85
- ),
86
- Schema.ofLong(RandomAny.VALUE),
87
- (min, max) => Math.round(Math.random() * (max - min) + min),
88
- ),
89
- RandomDouble: new RandomAny(
90
- 'RandomDouble',
91
- Parameter.of(RandomAny.MIN_VALUE, Schema.ofDouble(RandomAny.MIN_VALUE).setDefaultValue(0)),
92
- Parameter.of(
93
- RandomAny.MAX_VALUE,
94
- Schema.ofDouble(RandomAny.MAX_VALUE).setDefaultValue(Number.MAX_VALUE),
95
- ),
96
- Schema.ofDouble(RandomAny.VALUE),
97
- (min, max) => Math.random() * (max - min) + min,
98
- ),
99
- };
16
+ export class MathFunctionRepository implements Repository<Function> {
17
+ private readonly functionObjectsIndex: { [key: string]: AbstractFunction };
18
+ private readonly filterableNames: string[];
100
19
 
101
- const filterableNames = Object.values(functionObjectsIndex).map((e) =>
102
- e.getSignature().getFullName(),
103
- );
20
+ public constructor() {
21
+ this.functionObjectsIndex = {
22
+ Absolute: new GenericMathFunction(
23
+ 'Absolute',
24
+ (v) => Math.abs(v),
25
+ 1,
26
+ SchemaType.INTEGER,
27
+ SchemaType.LONG,
28
+ SchemaType.FLOAT,
29
+ SchemaType.DOUBLE,
30
+ ),
31
+ ArcCosine: new GenericMathFunction('ArcCosine', (v) => Math.acos(v)),
32
+ ArcSine: new GenericMathFunction('ArcSine', (v) => Math.asin(v)),
33
+ ArcTangent: new GenericMathFunction('ArcTangent', (v) => Math.atan(v)),
34
+ Ceiling: new GenericMathFunction('Ceiling', (v) => Math.ceil(v)),
35
+ Cosine: new GenericMathFunction('Cosine', (v) => Math.cos(v)),
36
+ HyperbolicCosine: new GenericMathFunction('HyperbolicCosine', (v) => Math.cosh(v)),
37
+ CubeRoot: new GenericMathFunction('CubeRoot', (v) => Math.cbrt(v)),
38
+ Exponential: new GenericMathFunction('Exponential', (v) => Math.exp(v)),
39
+ ExponentialMinus1: new GenericMathFunction('ExponentialMinus1', (v) => Math.expm1(v)),
40
+ Floor: new GenericMathFunction('Floor', (v) => Math.floor(v)),
41
+ LogNatural: new GenericMathFunction('LogNatural', (v) => Math.log(v)),
42
+ Log10: new GenericMathFunction('Log10', (v) => Math.log10(v)),
43
+ Round: new GenericMathFunction(
44
+ 'Round',
45
+ (v) => Math.round(v),
46
+ 1,
47
+ SchemaType.INTEGER,
48
+ SchemaType.LONG,
49
+ ),
50
+ Sine: new GenericMathFunction('Sine', (v) => Math.sin(v)),
51
+ HyperbolicSine: new GenericMathFunction('HyperbolicSine', (v) => Math.sinh(v)),
52
+ Tangent: new GenericMathFunction('Tangent', (v) => Math.tan(v)),
53
+ HyperbolicTangent: new GenericMathFunction('HyperbolicTangent', (v) => Math.tanh(v)),
54
+ ToDegrees: new GenericMathFunction('ToDegrees', (v) => v * (Math.PI / 180)),
55
+ ToRadians: new GenericMathFunction('ToRadians', (v) => v * (180 / Math.PI)),
56
+ SquareRoot: new GenericMathFunction('SquareRoot', (v) => Math.sqrt(v)),
57
+ ArcTangent2: new GenericMathFunction('ArcTangent2', (v1, v2) => Math.atan2(v1, v2!), 2),
58
+ Power: new GenericMathFunction('Power', (v1, v2) => Math.pow(v1, v2!), 2),
59
+ Add: new Add(),
60
+ Hypotenuse: new Hypotenuse(),
61
+ Maximum: new Maximum(),
62
+ Minimum: new Minimum(),
63
+ Random: new Random(),
64
+ RandomFloat: new RandomAny(
65
+ 'RandomFloat',
66
+ Parameter.of(
67
+ RandomAny.MIN_VALUE,
68
+ Schema.ofFloat(RandomAny.MIN_VALUE).setDefaultValue(0),
69
+ ),
70
+ Parameter.of(
71
+ RandomAny.MAX_VALUE,
72
+ Schema.ofFloat(RandomAny.MAX_VALUE).setDefaultValue(2147483647),
73
+ ),
74
+ Schema.ofFloat(RandomAny.VALUE),
75
+ (min, max) => Math.random() * (max - min) + min,
76
+ ),
77
+ RandomInt: new RandomAny(
78
+ 'RandomInt',
79
+ Parameter.of(
80
+ RandomAny.MIN_VALUE,
81
+ Schema.ofInteger(RandomAny.MIN_VALUE).setDefaultValue(0),
82
+ ),
83
+ Parameter.of(
84
+ RandomAny.MAX_VALUE,
85
+ Schema.ofInteger(RandomAny.MAX_VALUE).setDefaultValue(2147483647),
86
+ ),
87
+ Schema.ofInteger(RandomAny.VALUE),
88
+ (min, max) => Math.round(Math.random() * (max - min) + min),
89
+ ),
90
+ RandomLong: new RandomAny(
91
+ 'RandomLong',
92
+ Parameter.of(
93
+ RandomAny.MIN_VALUE,
94
+ Schema.ofLong(RandomAny.MIN_VALUE).setDefaultValue(0),
95
+ ),
96
+ Parameter.of(
97
+ RandomAny.MAX_VALUE,
98
+ Schema.ofLong(RandomAny.MAX_VALUE).setDefaultValue(Number.MAX_SAFE_INTEGER),
99
+ ),
100
+ Schema.ofLong(RandomAny.VALUE),
101
+ (min, max) => Math.round(Math.random() * (max - min) + min),
102
+ ),
103
+ RandomDouble: new RandomAny(
104
+ 'RandomDouble',
105
+ Parameter.of(
106
+ RandomAny.MIN_VALUE,
107
+ Schema.ofDouble(RandomAny.MIN_VALUE).setDefaultValue(0),
108
+ ),
109
+ Parameter.of(
110
+ RandomAny.MAX_VALUE,
111
+ Schema.ofDouble(RandomAny.MAX_VALUE).setDefaultValue(Number.MAX_VALUE),
112
+ ),
113
+ Schema.ofDouble(RandomAny.VALUE),
114
+ (min, max) => Math.random() * (max - min) + min,
115
+ ),
116
+ };
117
+
118
+ this.filterableNames = Object.values(this.functionObjectsIndex).map((e) =>
119
+ e.getSignature().getFullName(),
120
+ );
121
+ }
104
122
 
105
- export class MathFunctionRepository implements Repository<Function> {
106
123
  public async find(namespace: string, name: string): Promise<Function | undefined> {
107
124
  if (namespace != Namespaces.MATH) return Promise.resolve(undefined);
108
125
 
109
- return Promise.resolve(functionObjectsIndex[name]);
126
+ return Promise.resolve(this.functionObjectsIndex[name]);
110
127
  }
111
128
 
112
129
  public async filter(name: string): Promise<string[]> {
113
130
  return Promise.resolve(
114
- filterableNames.filter((e) => e.toLowerCase().indexOf(name.toLowerCase()) !== -1),
131
+ this.filterableNames.filter((e) => e.toLowerCase().indexOf(name.toLowerCase()) !== -1),
115
132
  );
116
133
  }
117
134
  }
@@ -10,16 +10,19 @@ import { AbstractFunction } from '../../AbstractFunction';
10
10
 
11
11
  const VALUE = 'value';
12
12
 
13
- const SIGNATURE = new FunctionSignature('Maximum')
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
13
  export class Maximum extends AbstractFunction {
14
+ private readonly signature = new FunctionSignature('Maximum')
15
+ .setNamespace(Namespaces.MATH)
16
+ .setParameters(
17
+ new Map([
18
+ [VALUE, new Parameter(VALUE, Schema.ofNumber(VALUE)).setVariableArgument(true)],
19
+ ]),
20
+ )
21
+ .setEvents(
22
+ new Map([Event.outputEventMapEntry(new Map([[VALUE, Schema.ofNumber(VALUE)]]))]),
23
+ );
21
24
  public getSignature(): FunctionSignature {
22
- return SIGNATURE;
25
+ return this.signature;
23
26
  }
24
27
 
25
28
  protected async internalExecute(context: FunctionExecutionParameters): Promise<FunctionOutput> {
@@ -27,9 +30,7 @@ export class Maximum extends AbstractFunction {
27
30
 
28
31
  return new FunctionOutput([
29
32
  EventResult.outputOf(
30
- new Map([
31
- [VALUE, nums.reduce((a, c) => ((!a && a !== 0) || c > a ? c : a))],
32
- ]),
33
+ new Map([[VALUE, nums.reduce((a, c) => ((!a && a !== 0) || c > a ? c : a))]]),
33
34
  ),
34
35
  ]);
35
36
  }
@@ -10,16 +10,19 @@ import { AbstractFunction } from '../../AbstractFunction';
10
10
 
11
11
  const VALUE = 'value';
12
12
 
13
- const SIGNATURE = new FunctionSignature('Minimum')
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
13
  export class Minimum extends AbstractFunction {
14
+ private readonly signature = new FunctionSignature('Minimum')
15
+ .setNamespace(Namespaces.MATH)
16
+ .setParameters(
17
+ new Map([
18
+ [VALUE, new Parameter(VALUE, Schema.ofNumber(VALUE)).setVariableArgument(true)],
19
+ ]),
20
+ )
21
+ .setEvents(
22
+ new Map([Event.outputEventMapEntry(new Map([[VALUE, Schema.ofNumber(VALUE)]]))]),
23
+ );
21
24
  public getSignature(): FunctionSignature {
22
- return SIGNATURE;
25
+ return this.signature;
23
26
  }
24
27
 
25
28
  protected async internalExecute(context: FunctionExecutionParameters): Promise<FunctionOutput> {
@@ -27,9 +30,7 @@ export class Minimum extends AbstractFunction {
27
30
 
28
31
  return new FunctionOutput([
29
32
  EventResult.outputOf(
30
- new Map([
31
- [VALUE, nums.reduce((a, c) => ((!a && a !== 0) || c < a ? c : a))],
32
- ]),
33
+ new Map([[VALUE, nums.reduce((a, c) => ((!a && a !== 0) || c < a ? c : a))]]),
33
34
  ),
34
35
  ]);
35
36
  }
@@ -10,7 +10,7 @@ import { AbstractFunction } from '../../AbstractFunction';
10
10
 
11
11
  const VALUE = 'value';
12
12
  export class Random extends AbstractFunction {
13
- private static readonly SIGNATURE: FunctionSignature = new FunctionSignature('Random')
13
+ private readonly signature: FunctionSignature = new FunctionSignature('Random')
14
14
  .setNamespace(Namespaces.MATH)
15
15
  .setEvents(
16
16
  new Map<string, Event>([
@@ -19,7 +19,7 @@ export class Random extends AbstractFunction {
19
19
  );
20
20
 
21
21
  public getSignature(): FunctionSignature {
22
- return Random.SIGNATURE;
22
+ return this.signature;
23
23
  }
24
24
  protected async internalExecute(context: FunctionExecutionParameters): Promise<FunctionOutput> {
25
25
  return new FunctionOutput([EventResult.outputOf(new Map([[VALUE, Math.random()]]))]);
@@ -13,8 +13,6 @@ const VALUE = 'value';
13
13
  const SOURCE = 'source';
14
14
 
15
15
  export abstract class AbstractObjectFunction extends AbstractFunction {
16
- private signature: FunctionSignature;
17
-
18
16
  protected constructor(functionName: string, valueSchema: Schema) {
19
17
  super();
20
18
  this.signature = new FunctionSignature(functionName)
@@ -23,6 +21,7 @@ export abstract class AbstractObjectFunction extends AbstractFunction {
23
21
  .setEvents(new Map([Event.outputEventMapEntry(new Map([[VALUE, valueSchema]]))]));
24
22
  }
25
23
 
24
+ private readonly signature;
26
25
  public getSignature(): FunctionSignature {
27
26
  return this.signature;
28
27
  }
@@ -24,33 +24,33 @@ export class ObjectConvert extends AbstractFunction {
24
24
  private static readonly VALUE: string = 'value';
25
25
  private static readonly CONVERSION_MODE: string = 'conversionMode';
26
26
 
27
+ private readonly signature: FunctionSignature = new FunctionSignature('ObjectConvert')
28
+ .setNamespace(Namespaces.SYSTEM_OBJECT)
29
+ .setParameters(
30
+ new Map([
31
+ Parameter.ofEntry(ObjectConvert.SOURCE, Schema.ofAny(ObjectConvert.SCHEMA)),
32
+ Parameter.ofEntry(
33
+ ObjectConvert.SCHEMA,
34
+ Schema.SCHEMA,
35
+ false,
36
+ ParameterType.CONSTANT,
37
+ ),
38
+ Parameter.ofEntry(
39
+ ObjectConvert.CONVERSION_MODE,
40
+ Schema.ofString(ObjectConvert.CONVERSION_MODE).setEnums(getConversionModes()),
41
+ ),
42
+ ]),
43
+ )
44
+ .setEvents(
45
+ new Map([
46
+ Event.outputEventMapEntry(
47
+ MapUtil.of(ObjectConvert.VALUE, Schema.ofAny(ObjectConvert.VALUE)),
48
+ ),
49
+ ]),
50
+ );
51
+
27
52
  getSignature(): FunctionSignature {
28
- return new FunctionSignature('ObjectConvert')
29
- .setNamespace(Namespaces.SYSTEM_OBJECT)
30
- .setParameters(
31
- new Map([
32
- Parameter.ofEntry(ObjectConvert.SOURCE, Schema.ofAny(ObjectConvert.SCHEMA)),
33
- Parameter.ofEntry(
34
- ObjectConvert.SCHEMA,
35
- Schema.SCHEMA,
36
- false,
37
- ParameterType.CONSTANT,
38
- ),
39
- Parameter.ofEntry(
40
- ObjectConvert.CONVERSION_MODE,
41
- Schema.ofString(ObjectConvert.CONVERSION_MODE).setEnums(
42
- getConversionModes(),
43
- ),
44
- ),
45
- ]),
46
- )
47
- .setEvents(
48
- new Map([
49
- Event.outputEventMapEntry(
50
- MapUtil.of(ObjectConvert.VALUE, Schema.ofAny(ObjectConvert.VALUE)),
51
- ),
52
- ]),
53
- );
53
+ return this.signature;
54
54
  }
55
55
 
56
56
  protected internalExecute(context: FunctionExecutionParameters): Promise<FunctionOutput> {
@@ -16,8 +16,6 @@ const SOURCE = 'source';
16
16
  const KEY = 'key';
17
17
 
18
18
  export class ObjectDeleteKey extends AbstractFunction {
19
- private signature: FunctionSignature;
20
-
21
19
  public constructor() {
22
20
  super();
23
21
  this.signature = new FunctionSignature('ObjectDeleteKey')
@@ -33,6 +31,7 @@ export class ObjectDeleteKey extends AbstractFunction {
33
31
  );
34
32
  }
35
33
 
34
+ private readonly signature;
36
35
  public getSignature(): FunctionSignature {
37
36
  return this.signature;
38
37
  }
@@ -9,29 +9,33 @@ import { ObjectKeys } from './ObjectKeys';
9
9
  import { ObjectPutValue } from './ObjectPutValue';
10
10
  import { ObjectValues } from './ObjectValues';
11
11
 
12
- const functionObjectsIndex: { [key: string]: AbstractFunction } = {
13
- ObjectValues: new ObjectValues(),
14
- ObjectKeys: new ObjectKeys(),
15
- ObjectEntries: new ObjectEntries(),
16
- ObjectDeleteKey: new ObjectDeleteKey(),
17
- ObjectPutValue: new ObjectPutValue(),
18
- ObjectConvert: new ObjectConvert(),
19
- };
12
+ export class ObjectFunctionRepository implements Repository<Function> {
13
+ private readonly functionObjectsIndex: { [key: string]: AbstractFunction };
14
+ private readonly filterableNames: string[];
20
15
 
21
- const filterableNames = Object.values(functionObjectsIndex).map((e) =>
22
- e.getSignature().getFullName(),
23
- );
16
+ public constructor() {
17
+ this.functionObjectsIndex = {
18
+ ObjectValues: new ObjectValues(),
19
+ ObjectKeys: new ObjectKeys(),
20
+ ObjectEntries: new ObjectEntries(),
21
+ ObjectDeleteKey: new ObjectDeleteKey(),
22
+ ObjectPutValue: new ObjectPutValue(),
23
+ ObjectConvert: new ObjectConvert(),
24
+ };
25
+ this.filterableNames = Object.values(this.functionObjectsIndex).map((e) =>
26
+ e.getSignature().getFullName(),
27
+ );
28
+ }
24
29
 
25
- export class ObjectFunctionRepository implements Repository<Function> {
26
30
  public async find(namespace: string, name: string): Promise<Function | undefined> {
27
31
  if (namespace != Namespaces.SYSTEM_OBJECT) return Promise.resolve(undefined);
28
32
 
29
- return Promise.resolve(functionObjectsIndex[name]);
33
+ return Promise.resolve(this.functionObjectsIndex[name]);
30
34
  }
31
35
 
32
36
  public async filter(name: string): Promise<string[]> {
33
37
  return Promise.resolve(
34
- filterableNames.filter((e) => e.toLowerCase().indexOf(name.toLowerCase()) !== -1),
38
+ this.filterableNames.filter((e) => e.toLowerCase().indexOf(name.toLowerCase()) !== -1),
35
39
  );
36
40
  }
37
41
  }
@@ -13,17 +13,18 @@ import { AbstractFunction } from '../../AbstractFunction';
13
13
  export class Concatenate extends AbstractFunction {
14
14
  public static VALUE: string = 'value';
15
15
 
16
- private static SCHEMA: Schema = new Schema()
17
- .setName(Concatenate.VALUE)
18
- .setType(new SingleType(SchemaType.STRING));
19
-
20
- private static SIGNATURE: FunctionSignature = new FunctionSignature('Concatenate')
16
+ private readonly signature: FunctionSignature = new FunctionSignature('Concatenate')
21
17
  .setNamespace(Namespaces.STRING)
22
18
  .setParameters(
23
19
  new Map([
24
20
  [
25
21
  Concatenate.VALUE,
26
- new Parameter(Concatenate.VALUE, Concatenate.SCHEMA).setVariableArgument(true),
22
+ new Parameter(
23
+ Concatenate.VALUE,
24
+ new Schema()
25
+ .setName(Concatenate.VALUE)
26
+ .setType(new SingleType(SchemaType.STRING)),
27
+ ).setVariableArgument(true),
27
28
  ],
28
29
  ]),
29
30
  )
@@ -40,7 +41,7 @@ export class Concatenate extends AbstractFunction {
40
41
  }
41
42
 
42
43
  public getSignature(): FunctionSignature {
43
- return Concatenate.SIGNATURE;
44
+ return this.signature;
44
45
  }
45
46
 
46
47
  protected async internalExecute(context: FunctionExecutionParameters): Promise<FunctionOutput> {
@@ -16,7 +16,7 @@ export class Matches extends AbstractFunction {
16
16
 
17
17
  protected static EVENT_RESULT_NAME: string = 'result';
18
18
 
19
- private static signature: FunctionSignature = new FunctionSignature('Matches')
19
+ private readonly signature: FunctionSignature = new FunctionSignature('Matches')
20
20
  .setNamespace(Namespaces.STRING)
21
21
  .setParameters(
22
22
  MapUtil.ofEntries(
@@ -50,7 +50,7 @@ export class Matches extends AbstractFunction {
50
50
  );
51
51
 
52
52
  public getSignature(): FunctionSignature {
53
- return Matches.signature;
53
+ return this.signature;
54
54
  }
55
55
 
56
56
  protected async internalExecute(context: FunctionExecutionParameters): Promise<FunctionOutput> {
@@ -14,7 +14,7 @@ import { SchemaType } from '../../../json/schema/type/SchemaType';
14
14
  export class Reverse extends AbstractFunction {
15
15
  protected readonly VALUE: string = 'value';
16
16
 
17
- private readonly SIGNATURE: FunctionSignature = new FunctionSignature('Reverse')
17
+ private readonly signature: FunctionSignature = new FunctionSignature('Reverse')
18
18
  .setNamespace(Namespaces.STRING)
19
19
  .setParameters(
20
20
  new Map([
@@ -46,7 +46,7 @@ export class Reverse extends AbstractFunction {
46
46
  }
47
47
 
48
48
  public getSignature(): FunctionSignature {
49
- return this.SIGNATURE;
49
+ return this.signature;
50
50
  }
51
51
 
52
52
  protected async internalExecute(context: FunctionExecutionParameters): Promise<FunctionOutput> {
@@ -29,22 +29,23 @@ export class Split extends AbstractFunction {
29
29
  MapUtil.of(this.EVENT_RESULT_NAME, Schema.ofArray(this.EVENT_RESULT_NAME)),
30
30
  );
31
31
 
32
+ private readonly signature = new FunctionSignature('Split')
33
+ .setNamespace(Namespaces.STRING)
34
+ .setParameters(
35
+ new Map([
36
+ [this.PARAMETER_STRING_NAME, this.PARAMETER_STRING],
37
+ [this.PARAMETER_SPLIT_STRING_NAME, this.PARAMETER_SPLIT_STRING],
38
+ ]),
39
+ )
40
+ .setEvents(
41
+ new Map([
42
+ Event.outputEventMapEntry(
43
+ new Map([[this.EVENT_RESULT_NAME, Schema.ofArray(this.EVENT_RESULT_NAME)]]),
44
+ ) as [string, Event],
45
+ ]),
46
+ );
32
47
  public getSignature(): FunctionSignature {
33
- return new FunctionSignature('Split')
34
- .setNamespace(Namespaces.STRING)
35
- .setParameters(
36
- new Map([
37
- [this.PARAMETER_STRING_NAME, this.PARAMETER_STRING],
38
- [this.PARAMETER_SPLIT_STRING_NAME, this.PARAMETER_SPLIT_STRING],
39
- ]),
40
- )
41
- .setEvents(
42
- new Map([
43
- Event.outputEventMapEntry(
44
- new Map([[this.EVENT_RESULT_NAME, Schema.ofArray(this.EVENT_RESULT_NAME)]]),
45
- ) as [string, Event],
46
- ]),
47
- );
48
+ return this.signature;
48
49
  }
49
50
 
50
51
  public constructor() {
@@ -18,7 +18,7 @@ import { ToString } from './ToString';
18
18
  import { TrimTo } from './TrimTo';
19
19
 
20
20
  export class StringFunctionRepository implements Repository<Function> {
21
- private static readonly repoMap: Map<string, Function> = MapUtil.ofArrayEntries(
21
+ private readonly repoMap: Map<string, Function> = MapUtil.ofArrayEntries(
22
22
  AbstractStringFunction.ofEntryStringAndStringOutput('Trim', (e) => e.trim()),
23
23
  AbstractStringFunction.ofEntryStringAndStringOutput('TrimStart', (e) => e.trimStart()),
24
24
  AbstractStringFunction.ofEntryStringAndStringOutput('TrimEnd', (e) => e.trimEnd()),
@@ -98,22 +98,20 @@ export class StringFunctionRepository implements Repository<Function> {
98
98
  mapEntry(new Matches()),
99
99
  );
100
100
 
101
- private static readonly filterableNames = Array.from(
102
- StringFunctionRepository.repoMap.values(),
103
- ).map((e) => e.getSignature().getFullName());
101
+ private readonly filterableNames = Array.from(this.repoMap.values()).map((e) =>
102
+ e.getSignature().getFullName(),
103
+ );
104
104
 
105
105
  public async find(namespace: string, name: string): Promise<Function | undefined> {
106
106
  if (namespace != Namespaces.STRING) {
107
107
  return Promise.resolve(undefined);
108
108
  }
109
- return Promise.resolve(StringFunctionRepository.repoMap.get(name));
109
+ return Promise.resolve(this.repoMap.get(name));
110
110
  }
111
111
 
112
112
  public async filter(name: string): Promise<string[]> {
113
113
  return Promise.resolve(
114
- StringFunctionRepository.filterableNames.filter(
115
- (e) => e.toLowerCase().indexOf(name.toLowerCase()) !== -1,
116
- ),
114
+ this.filterableNames.filter((e) => e.toLowerCase().indexOf(name.toLowerCase()) !== -1),
117
115
  );
118
116
  }
119
117
  }
@@ -23,15 +23,16 @@ export class ToString extends AbstractFunction {
23
23
  new Map([[this.EVENT_RESULT_NAME, Schema.ofString(this.EVENT_RESULT_NAME)]]),
24
24
  );
25
25
 
26
+ private readonly signature = new FunctionSignature('ToString')
27
+ .setNamespace(Namespaces.STRING)
28
+ .setParameters(
29
+ new Map([
30
+ [this.PARAMETER_INPUT_ANYTYPE.getParameterName(), this.PARAMETER_INPUT_ANYTYPE],
31
+ ]),
32
+ )
33
+ .setEvents(new Map([[this.EVENT_STRING.getName(), this.EVENT_STRING]]));
26
34
  public getSignature(): FunctionSignature {
27
- return new FunctionSignature('ToString')
28
- .setNamespace(Namespaces.STRING)
29
- .setParameters(
30
- new Map([
31
- [this.PARAMETER_INPUT_ANYTYPE.getParameterName(), this.PARAMETER_INPUT_ANYTYPE],
32
- ]),
33
- )
34
- .setEvents(new Map([[this.EVENT_STRING.getName(), this.EVENT_STRING]]));
35
+ return this.signature;
35
36
  }
36
37
 
37
38
  public constructor() {