@fincity/kirun-js 2.7.0 → 2.8.2
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/WaitTest.ts +1 -1
- package/__tests__/engine/function/system/array/AddFirstTest.ts +2 -6
- package/__tests__/engine/function/system/array/IndexOfTest.ts +8 -13
- package/__tests__/engine/function/system/array/LastIndexOfTest.ts +9 -28
- package/__tests__/engine/function/system/date/AddSubtractTimeTest.ts +93 -0
- package/__tests__/engine/function/system/date/DateFunctionRepositoryTest.ts +96 -0
- package/__tests__/engine/function/system/date/DifferenceTest.ts +93 -0
- package/__tests__/engine/function/system/date/EpochToTimestampTest.ts +133 -0
- package/__tests__/engine/function/system/date/FromDateStringTest.ts +51 -0
- package/__tests__/engine/function/system/date/FromNowTest.ts +71 -0
- package/__tests__/engine/function/system/date/GetCurrentTimeStampTest.ts +19 -27
- package/__tests__/engine/function/system/date/GetNamesTest.ts +105 -0
- package/__tests__/engine/function/system/date/IsBetweenTest.ts +53 -0
- package/__tests__/engine/function/system/date/IsValidISODateTest.ts +42 -54
- package/__tests__/engine/function/system/date/LastFirstOfTest.ts +64 -0
- package/__tests__/engine/function/system/date/SetTimeZoneTest.ts +48 -0
- package/__tests__/engine/function/system/date/StartEndOfTest.ts +53 -0
- package/__tests__/engine/function/system/date/TimeAsTest.ts +24 -0
- package/__tests__/engine/function/system/date/TimestampToEpochTest.ts +45 -0
- package/__tests__/engine/function/system/date/ToDateStringTest.ts +48 -0
- package/__tests__/engine/function/system/math/RandomFloatTest.ts +21 -22
- package/__tests__/engine/function/system/math/RandomIntTest.ts +5 -4
- package/__tests__/engine/repository/RepositoryFilterTest.ts +4 -1
- package/__tests__/engine/runtime/expression/ExpressionEqualityTest.ts +76 -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 +14 -13
- package/dist/types.d.ts.map +1 -1
- package/generator/generateValidationCSV.ts +51 -42
- package/generator/validation-js.csv +0 -0
- package/package.json +9 -7
- package/src/engine/function/AbstractFunction.ts +1 -1
- package/src/engine/function/system/Print.ts +19 -5
- package/src/engine/function/system/Wait.ts +1 -1
- package/src/engine/function/system/array/AbstractArrayFunction.ts +3 -3
- package/src/engine/function/system/array/Fill.ts +1 -1
- package/src/engine/function/system/array/Frequency.ts +0 -1
- package/src/engine/function/system/array/IndexOf.ts +4 -4
- package/src/engine/function/system/array/LastIndexOf.ts +3 -3
- package/src/engine/function/system/array/Rotate.ts +1 -1
- package/src/engine/function/system/array/Shuffle.ts +1 -1
- package/src/engine/function/system/array/Sort.ts +1 -1
- package/src/engine/function/system/date/AbstractDateFunction.ts +229 -111
- package/src/engine/function/system/date/AddSubtractTime.ts +99 -0
- package/src/engine/function/system/date/DateFunctionRepository.ts +228 -122
- package/src/engine/function/system/date/EpochToTimestamp.ts +75 -0
- package/src/engine/function/system/date/FromDateString.ts +44 -0
- package/src/engine/function/system/date/FromNow.ts +77 -0
- package/src/engine/function/system/date/GetCurrent.ts +20 -0
- package/src/engine/function/system/date/GetNames.ts +74 -0
- package/src/engine/function/system/date/IsBetween.ts +62 -0
- package/src/engine/function/system/date/IsValidISODate.ts +54 -40
- package/src/engine/function/system/date/LastFirstOf.ts +72 -0
- package/src/engine/function/system/date/SetTimeZone.ts +43 -0
- package/src/engine/function/system/date/StartEndOf.ts +44 -0
- package/src/engine/function/system/date/TimeAs.ts +64 -0
- package/src/engine/function/system/date/TimestampToEpoch.ts +54 -0
- package/src/engine/function/system/date/ToDateString.ts +49 -0
- package/src/engine/function/system/date/common.ts +9 -0
- package/src/engine/function/system/math/MathFunctionRepository.ts +43 -4
- package/src/engine/function/system/math/RandomAny.ts +57 -0
- package/src/engine/function/system/object/ObjectConvert.ts +45 -19
- package/src/engine/function/system/object/ObjectFunctionRepository.ts +2 -1
- package/src/engine/function/system/string/AbstractStringFunction.ts +42 -82
- package/src/engine/function/system/string/StringFunctionRepository.ts +39 -20
- package/src/engine/json/schema/SchemaUtil.ts +1 -1
- package/src/engine/repository/KIRunSchemaRepository.ts +57 -3
- package/src/engine/util/string/StringUtil.ts +12 -0
- package/tsconfig.json +1 -2
- package/__tests__/engine/function/system/date/AddTimeTest.ts +0 -115
- package/__tests__/engine/function/system/date/DateToEpochTest.ts +0 -74
- package/__tests__/engine/function/system/date/DifferenceOfTimestampsTest.ts +0 -53
- package/__tests__/engine/function/system/date/EpochToDateTest.ts +0 -105
- package/__tests__/engine/function/system/date/GetDateTest.ts +0 -85
- package/__tests__/engine/function/system/date/GetDayTest.ts +0 -85
- package/__tests__/engine/function/system/date/GetFullYearTest.ts +0 -85
- package/__tests__/engine/function/system/date/GetHoursTest.ts +0 -85
- package/__tests__/engine/function/system/date/GetMilliSecondsTest.ts +0 -85
- package/__tests__/engine/function/system/date/GetMinutesTest.ts +0 -85
- package/__tests__/engine/function/system/date/GetMonthTest.ts +0 -85
- package/__tests__/engine/function/system/date/GetSecondsTest.ts +0 -85
- package/__tests__/engine/function/system/date/GetTimeAsArrayTest.ts +0 -59
- package/__tests__/engine/function/system/date/GetTimeAsObjectTest.ts +0 -83
- package/__tests__/engine/function/system/date/GetTimeTest.ts +0 -86
- package/__tests__/engine/function/system/date/IsLeapYearTest.ts +0 -85
- package/__tests__/engine/function/system/date/MaximumTimestampTest.ts +0 -55
- package/__tests__/engine/function/system/date/MinimumTimestampTest.ts +0 -54
- package/__tests__/engine/function/system/date/SubtractTimeTest.ts +0 -95
- package/src/engine/function/system/date/DateToEpoch.ts +0 -39
- package/src/engine/function/system/date/DifferenceOfTimestamps.ts +0 -45
- package/src/engine/function/system/date/EpochToDate.ts +0 -76
- package/src/engine/function/system/date/GetCurrentTimeStamp.ts +0 -36
- package/src/engine/function/system/date/GetTimeAsArray.ts +0 -48
- package/src/engine/function/system/date/GetTimeAsObject.ts +0 -66
- package/src/engine/function/system/date/MaximumTimestamp.ts +0 -73
- package/src/engine/function/system/date/MinimumTimestamp.ts +0 -74
- package/src/engine/function/system/math/RandomFloat.ts +0 -56
- package/src/engine/function/system/math/RandomInt.ts +0 -56
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import { Schema } from '../../../json/schema/Schema';
|
|
2
|
+
import { Event } from '../../../model/Event';
|
|
3
|
+
import { EventResult } from '../../../model/EventResult';
|
|
4
|
+
import { FunctionOutput } from '../../../model/FunctionOutput';
|
|
5
|
+
import { FunctionSignature } from '../../../model/FunctionSignature';
|
|
6
|
+
import { Parameter } from '../../../model/Parameter';
|
|
7
|
+
import { Namespaces } from '../../../namespaces/Namespaces';
|
|
8
|
+
import { FunctionExecutionParameters } from '../../../runtime/FunctionExecutionParameters';
|
|
9
|
+
import { MapUtil } from '../../../util/MapUtil';
|
|
10
|
+
import { AbstractFunction } from '../../AbstractFunction';
|
|
11
|
+
|
|
12
|
+
export class RandomAny extends AbstractFunction {
|
|
13
|
+
public static readonly MIN_VALUE = 'minValue';
|
|
14
|
+
|
|
15
|
+
public static readonly MAX_VALUE = 'maxValue';
|
|
16
|
+
|
|
17
|
+
public static readonly VALUE = 'value';
|
|
18
|
+
|
|
19
|
+
private readonly signature: FunctionSignature;
|
|
20
|
+
|
|
21
|
+
private readonly randomFunction: (min: number, max: number) => number;
|
|
22
|
+
|
|
23
|
+
public constructor(
|
|
24
|
+
name: string,
|
|
25
|
+
minParameter: Parameter,
|
|
26
|
+
maxParameter: Parameter,
|
|
27
|
+
outputSchema: Schema,
|
|
28
|
+
randomFunction: (min: number, max: number) => number,
|
|
29
|
+
) {
|
|
30
|
+
super();
|
|
31
|
+
this.signature = new FunctionSignature(name)
|
|
32
|
+
.setParameters(
|
|
33
|
+
MapUtil.of(RandomAny.MIN_VALUE, minParameter, RandomAny.MAX_VALUE, maxParameter),
|
|
34
|
+
)
|
|
35
|
+
.setNamespace(Namespaces.MATH)
|
|
36
|
+
.setEvents(
|
|
37
|
+
new Map<string, Event>([
|
|
38
|
+
Event.outputEventMapEntry(MapUtil.of(RandomAny.VALUE, outputSchema)),
|
|
39
|
+
]),
|
|
40
|
+
);
|
|
41
|
+
this.randomFunction = randomFunction;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
public getSignature(): FunctionSignature {
|
|
45
|
+
return this.signature;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
protected async internalExecute(context: FunctionExecutionParameters): Promise<FunctionOutput> {
|
|
49
|
+
let min: number = context.getArguments()?.get(RandomAny.MIN_VALUE);
|
|
50
|
+
|
|
51
|
+
let max: number = context.getArguments()?.get(RandomAny.MAX_VALUE);
|
|
52
|
+
|
|
53
|
+
let num: number = this.randomFunction(min, max);
|
|
54
|
+
|
|
55
|
+
return new FunctionOutput([EventResult.outputOf(new Map([[RandomAny.VALUE, num]]))]);
|
|
56
|
+
}
|
|
57
|
+
}
|
|
@@ -19,8 +19,7 @@ import { ParameterType } from '../../../model/ParameterType';
|
|
|
19
19
|
import { KIRuntimeException } from '../../../exception/KIRuntimeException';
|
|
20
20
|
|
|
21
21
|
export class ObjectConvert extends AbstractFunction {
|
|
22
|
-
|
|
23
|
-
private static readonly SOURCE: string = 'SOURCE';
|
|
22
|
+
private static readonly SOURCE: string = 'source';
|
|
24
23
|
private static readonly SCHEMA: string = 'schema';
|
|
25
24
|
private static readonly VALUE: string = 'value';
|
|
26
25
|
private static readonly CONVERSION_MODE: string = 'conversionMode';
|
|
@@ -28,31 +27,45 @@ export class ObjectConvert extends AbstractFunction {
|
|
|
28
27
|
getSignature(): FunctionSignature {
|
|
29
28
|
return new FunctionSignature('ObjectConvert')
|
|
30
29
|
.setNamespace(Namespaces.SYSTEM_OBJECT)
|
|
31
|
-
.setParameters(
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
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
|
+
),
|
|
39
52
|
]),
|
|
40
53
|
);
|
|
41
54
|
}
|
|
42
55
|
|
|
43
|
-
protected internalExecute(
|
|
44
|
-
context: FunctionExecutionParameters,
|
|
45
|
-
): Promise<FunctionOutput> {
|
|
46
|
-
|
|
56
|
+
protected internalExecute(context: FunctionExecutionParameters): Promise<FunctionOutput> {
|
|
47
57
|
let element: any = context.getArguments()?.get(ObjectConvert.SOURCE);
|
|
48
|
-
let schema: Schema | undefined = Schema.from(
|
|
58
|
+
let schema: Schema | undefined = Schema.from(
|
|
59
|
+
context?.getArguments()?.get(ObjectConvert.SCHEMA),
|
|
60
|
+
);
|
|
49
61
|
|
|
50
62
|
if (!schema) {
|
|
51
63
|
throw new KIRuntimeException('Schema is not supplied.');
|
|
52
64
|
}
|
|
53
65
|
|
|
54
|
-
const mode: ConversionMode =
|
|
55
|
-
||
|
|
66
|
+
const mode: ConversionMode =
|
|
67
|
+
genericValueOf(context.getArguments()?.get(ObjectConvert.CONVERSION_MODE)) ||
|
|
68
|
+
ConversionMode.STRICT;
|
|
56
69
|
|
|
57
70
|
return this.convertToSchema(schema, context.getSchemaRepository(), element, mode);
|
|
58
71
|
}
|
|
@@ -64,8 +77,21 @@ export class ObjectConvert extends AbstractFunction {
|
|
|
64
77
|
mode: ConversionMode,
|
|
65
78
|
): Promise<FunctionOutput> {
|
|
66
79
|
try {
|
|
67
|
-
return new FunctionOutput([
|
|
68
|
-
|
|
80
|
+
return new FunctionOutput([
|
|
81
|
+
EventResult.outputOf(
|
|
82
|
+
MapUtil.of(
|
|
83
|
+
ObjectConvert.VALUE,
|
|
84
|
+
SchemaValidator.validate(
|
|
85
|
+
[],
|
|
86
|
+
targetSchema,
|
|
87
|
+
targetSchemaRepository,
|
|
88
|
+
element,
|
|
89
|
+
true,
|
|
90
|
+
mode,
|
|
91
|
+
),
|
|
92
|
+
),
|
|
93
|
+
),
|
|
94
|
+
]);
|
|
69
95
|
} catch (error: any) {
|
|
70
96
|
throw new KIRuntimeException(error?.message);
|
|
71
97
|
}
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import { SchemaType } from '../../../json/schema/type/SchemaType';
|
|
2
1
|
import { Namespaces } from '../../../namespaces/Namespaces';
|
|
3
2
|
import { Repository } from '../../../Repository';
|
|
4
3
|
import { AbstractFunction } from '../../AbstractFunction';
|
|
5
4
|
import { Function } from '../../Function';
|
|
5
|
+
import { ObjectConvert } from './ObjectConvert';
|
|
6
6
|
import { ObjectDeleteKey } from './ObjectDeleteKey';
|
|
7
7
|
import { ObjectEntries } from './ObjectEntries';
|
|
8
8
|
import { ObjectKeys } from './ObjectKeys';
|
|
@@ -15,6 +15,7 @@ const functionObjectsIndex: { [key: string]: AbstractFunction } = {
|
|
|
15
15
|
ObjectEntries: new ObjectEntries(),
|
|
16
16
|
ObjectDeleteKey: new ObjectDeleteKey(),
|
|
17
17
|
ObjectPutValue: new ObjectPutValue(),
|
|
18
|
+
ObjectConvert: new ObjectConvert(),
|
|
18
19
|
};
|
|
19
20
|
|
|
20
21
|
const filterableNames = Object.values(functionObjectsIndex).map((e) =>
|
|
@@ -87,7 +87,7 @@ export abstract class AbstractStringFunction extends AbstractFunction {
|
|
|
87
87
|
),
|
|
88
88
|
);
|
|
89
89
|
|
|
90
|
-
private signature: FunctionSignature;
|
|
90
|
+
private readonly signature: FunctionSignature;
|
|
91
91
|
|
|
92
92
|
constructor(namespace: string, functionName: string, event: Event, ...parameter: Parameter[]) {
|
|
93
93
|
super();
|
|
@@ -104,22 +104,13 @@ export abstract class AbstractStringFunction extends AbstractFunction {
|
|
|
104
104
|
return this.signature;
|
|
105
105
|
}
|
|
106
106
|
|
|
107
|
-
public static
|
|
107
|
+
public static ofEntryStringStringAndBooleanOutput(
|
|
108
108
|
name: string,
|
|
109
109
|
fun: (a: string, b: string) => boolean,
|
|
110
110
|
): [string, Function] {
|
|
111
111
|
return [
|
|
112
112
|
name,
|
|
113
113
|
new (class extends AbstractStringFunction {
|
|
114
|
-
constructor(
|
|
115
|
-
namespace: string,
|
|
116
|
-
functionName: string,
|
|
117
|
-
event: Event,
|
|
118
|
-
...parameter: Parameter[]
|
|
119
|
-
) {
|
|
120
|
-
super(namespace, functionName, event, ...parameter);
|
|
121
|
-
}
|
|
122
|
-
|
|
123
114
|
protected async internalExecute(
|
|
124
115
|
context: FunctionExecutionParameters,
|
|
125
116
|
): Promise<FunctionOutput> {
|
|
@@ -146,22 +137,13 @@ export abstract class AbstractStringFunction extends AbstractFunction {
|
|
|
146
137
|
];
|
|
147
138
|
}
|
|
148
139
|
|
|
149
|
-
public static
|
|
140
|
+
public static ofEntryStringIntegerAndStringOutput(
|
|
150
141
|
name: string,
|
|
151
142
|
fun: (a: string, b: number) => string,
|
|
152
143
|
): [string, Function] {
|
|
153
144
|
return [
|
|
154
145
|
name,
|
|
155
146
|
new (class extends AbstractStringFunction {
|
|
156
|
-
constructor(
|
|
157
|
-
namespace: string,
|
|
158
|
-
functionName: string,
|
|
159
|
-
event: Event,
|
|
160
|
-
...parameter: Parameter[]
|
|
161
|
-
) {
|
|
162
|
-
super(namespace, functionName, event, ...parameter);
|
|
163
|
-
}
|
|
164
|
-
|
|
165
147
|
protected async internalExecute(
|
|
166
148
|
context: FunctionExecutionParameters,
|
|
167
149
|
): Promise<FunctionOutput> {
|
|
@@ -188,22 +170,13 @@ export abstract class AbstractStringFunction extends AbstractFunction {
|
|
|
188
170
|
];
|
|
189
171
|
}
|
|
190
172
|
|
|
191
|
-
public static
|
|
173
|
+
public static ofEntryStringStringAndIntegerOutput(
|
|
192
174
|
name: string,
|
|
193
175
|
fun: (a: string, b: string) => number,
|
|
194
176
|
): [string, Function] {
|
|
195
177
|
return [
|
|
196
178
|
name,
|
|
197
179
|
new (class extends AbstractStringFunction {
|
|
198
|
-
constructor(
|
|
199
|
-
namespace: string,
|
|
200
|
-
functionName: string,
|
|
201
|
-
event: Event,
|
|
202
|
-
...parameter: Parameter[]
|
|
203
|
-
) {
|
|
204
|
-
super(namespace, functionName, event, ...parameter);
|
|
205
|
-
}
|
|
206
|
-
|
|
207
180
|
protected async internalExecute(
|
|
208
181
|
context: FunctionExecutionParameters,
|
|
209
182
|
): Promise<FunctionOutput> {
|
|
@@ -230,19 +203,13 @@ export abstract class AbstractStringFunction extends AbstractFunction {
|
|
|
230
203
|
];
|
|
231
204
|
}
|
|
232
205
|
|
|
233
|
-
public static
|
|
206
|
+
public static ofEntryStringAndStringOutput(
|
|
207
|
+
name: string,
|
|
208
|
+
fun: (a: string) => string,
|
|
209
|
+
): [string, Function] {
|
|
234
210
|
return [
|
|
235
211
|
name,
|
|
236
212
|
new (class extends AbstractStringFunction {
|
|
237
|
-
constructor(
|
|
238
|
-
namespace: string,
|
|
239
|
-
functionName: string,
|
|
240
|
-
event: Event,
|
|
241
|
-
...parameter: Parameter[]
|
|
242
|
-
) {
|
|
243
|
-
super(namespace, functionName, event, ...parameter);
|
|
244
|
-
}
|
|
245
|
-
|
|
246
213
|
protected async internalExecute(
|
|
247
214
|
context: FunctionExecutionParameters,
|
|
248
215
|
): Promise<FunctionOutput> {
|
|
@@ -264,22 +231,13 @@ export abstract class AbstractStringFunction extends AbstractFunction {
|
|
|
264
231
|
),
|
|
265
232
|
];
|
|
266
233
|
}
|
|
267
|
-
public static
|
|
234
|
+
public static ofEntryStringAndBooleanOutput(
|
|
268
235
|
name: string,
|
|
269
236
|
fun: (a: string) => boolean,
|
|
270
237
|
): [string, Function] {
|
|
271
238
|
return [
|
|
272
239
|
name,
|
|
273
240
|
new (class extends AbstractStringFunction {
|
|
274
|
-
constructor(
|
|
275
|
-
namespace: string,
|
|
276
|
-
functionName: string,
|
|
277
|
-
event: Event,
|
|
278
|
-
...parameter: Parameter[]
|
|
279
|
-
) {
|
|
280
|
-
super(namespace, functionName, event, ...parameter);
|
|
281
|
-
}
|
|
282
|
-
|
|
283
241
|
protected async internalExecute(
|
|
284
242
|
context: FunctionExecutionParameters,
|
|
285
243
|
): Promise<FunctionOutput> {
|
|
@@ -302,22 +260,13 @@ export abstract class AbstractStringFunction extends AbstractFunction {
|
|
|
302
260
|
];
|
|
303
261
|
}
|
|
304
262
|
|
|
305
|
-
public static
|
|
263
|
+
public static ofEntryStringStringIntegerAndIntegerOutput(
|
|
306
264
|
name: string,
|
|
307
265
|
fun: (a: string, b: string, c: number) => number,
|
|
308
266
|
): [string, Function] {
|
|
309
267
|
return [
|
|
310
268
|
name,
|
|
311
269
|
new (class extends AbstractStringFunction {
|
|
312
|
-
constructor(
|
|
313
|
-
namespace: string,
|
|
314
|
-
functionName: string,
|
|
315
|
-
event: Event,
|
|
316
|
-
...parameter: Parameter[]
|
|
317
|
-
) {
|
|
318
|
-
super(namespace, functionName, event, ...parameter);
|
|
319
|
-
}
|
|
320
|
-
|
|
321
270
|
protected async internalExecute(
|
|
322
271
|
context: FunctionExecutionParameters,
|
|
323
272
|
): Promise<FunctionOutput> {
|
|
@@ -349,22 +298,13 @@ export abstract class AbstractStringFunction extends AbstractFunction {
|
|
|
349
298
|
];
|
|
350
299
|
}
|
|
351
300
|
|
|
352
|
-
public static
|
|
301
|
+
public static ofEntryStringIntegerIntegerAndStringOutput(
|
|
353
302
|
name: string,
|
|
354
303
|
fun: (a: string, b: number, c: number) => string,
|
|
355
304
|
): [string, Function] {
|
|
356
305
|
return [
|
|
357
306
|
name,
|
|
358
307
|
new (class extends AbstractStringFunction {
|
|
359
|
-
constructor(
|
|
360
|
-
namespace: string,
|
|
361
|
-
functionName: string,
|
|
362
|
-
event: Event,
|
|
363
|
-
...parameter: Parameter[]
|
|
364
|
-
) {
|
|
365
|
-
super(namespace, functionName, event, ...parameter);
|
|
366
|
-
}
|
|
367
|
-
|
|
368
308
|
protected async internalExecute(
|
|
369
309
|
context: FunctionExecutionParameters,
|
|
370
310
|
): Promise<FunctionOutput> {
|
|
@@ -391,7 +331,7 @@ export abstract class AbstractStringFunction extends AbstractFunction {
|
|
|
391
331
|
})(
|
|
392
332
|
Namespaces.STRING,
|
|
393
333
|
name,
|
|
394
|
-
AbstractStringFunction.
|
|
334
|
+
AbstractStringFunction.EVENT_STRING,
|
|
395
335
|
AbstractStringFunction.PARAMETER_STRING,
|
|
396
336
|
AbstractStringFunction.PARAMETER_INDEX,
|
|
397
337
|
AbstractStringFunction.PARAMETER_SECOND_INDEX,
|
|
@@ -399,22 +339,13 @@ export abstract class AbstractStringFunction extends AbstractFunction {
|
|
|
399
339
|
];
|
|
400
340
|
}
|
|
401
341
|
|
|
402
|
-
public static
|
|
342
|
+
public static ofEntryStringStringStringAndStringOutput(
|
|
403
343
|
name: string,
|
|
404
344
|
fun: (a: string, b: string, c: string) => string,
|
|
405
345
|
): [string, Function] {
|
|
406
346
|
return [
|
|
407
347
|
name,
|
|
408
348
|
new (class extends AbstractStringFunction {
|
|
409
|
-
constructor(
|
|
410
|
-
namespace: string,
|
|
411
|
-
functionName: string,
|
|
412
|
-
event: Event,
|
|
413
|
-
...parameter: Parameter[]
|
|
414
|
-
) {
|
|
415
|
-
super(namespace, functionName, event, ...parameter);
|
|
416
|
-
}
|
|
417
|
-
|
|
418
349
|
protected async internalExecute(
|
|
419
350
|
context: FunctionExecutionParameters,
|
|
420
351
|
): Promise<FunctionOutput> {
|
|
@@ -444,4 +375,33 @@ export abstract class AbstractStringFunction extends AbstractFunction {
|
|
|
444
375
|
),
|
|
445
376
|
];
|
|
446
377
|
}
|
|
378
|
+
|
|
379
|
+
public static ofEntryStringAndIntegerOutput(
|
|
380
|
+
name: string,
|
|
381
|
+
fun: (a: string) => number,
|
|
382
|
+
): [string, Function] {
|
|
383
|
+
return [
|
|
384
|
+
name,
|
|
385
|
+
new (class extends AbstractStringFunction {
|
|
386
|
+
protected async internalExecute(
|
|
387
|
+
context: FunctionExecutionParameters,
|
|
388
|
+
): Promise<FunctionOutput> {
|
|
389
|
+
let s: string = context
|
|
390
|
+
?.getArguments()
|
|
391
|
+
?.get(AbstractStringFunction.PARAMETER_STRING_NAME);
|
|
392
|
+
|
|
393
|
+
return new FunctionOutput([
|
|
394
|
+
EventResult.outputOf(
|
|
395
|
+
MapUtil.of(AbstractStringFunction.EVENT_RESULT_NAME, fun(s)),
|
|
396
|
+
),
|
|
397
|
+
]);
|
|
398
|
+
}
|
|
399
|
+
})(
|
|
400
|
+
Namespaces.STRING,
|
|
401
|
+
name,
|
|
402
|
+
AbstractStringFunction.EVENT_INT,
|
|
403
|
+
AbstractStringFunction.PARAMETER_STRING,
|
|
404
|
+
),
|
|
405
|
+
];
|
|
406
|
+
}
|
|
447
407
|
}
|
|
@@ -19,50 +19,69 @@ import { TrimTo } from './TrimTo';
|
|
|
19
19
|
|
|
20
20
|
export class StringFunctionRepository implements Repository<Function> {
|
|
21
21
|
private static readonly repoMap: Map<string, Function> = MapUtil.ofArrayEntries(
|
|
22
|
-
AbstractStringFunction.
|
|
23
|
-
AbstractStringFunction.
|
|
24
|
-
AbstractStringFunction.
|
|
25
|
-
AbstractStringFunction.ofEntryStringBooleanOutput('IsBlank', (e) => e.trim() === ''),
|
|
26
|
-
AbstractStringFunction.ofEntryStringBooleanOutput('IsEmpty', (e) => e === ''),
|
|
22
|
+
AbstractStringFunction.ofEntryStringAndStringOutput('Trim', (e) => e.trim()),
|
|
23
|
+
AbstractStringFunction.ofEntryStringAndStringOutput('TrimStart', (e) => e.trimStart()),
|
|
24
|
+
AbstractStringFunction.ofEntryStringAndStringOutput('TrimEnd', (e) => e.trimEnd()),
|
|
27
25
|
|
|
28
|
-
AbstractStringFunction.
|
|
26
|
+
AbstractStringFunction.ofEntryStringAndIntegerOutput('Length', (e) => e.length),
|
|
27
|
+
|
|
28
|
+
AbstractStringFunction.ofEntryStringStringAndIntegerOutput('Frequency', (a, b) => {
|
|
29
|
+
let count = 0;
|
|
30
|
+
let index = a.indexOf(b);
|
|
31
|
+
while (index != -1) {
|
|
32
|
+
count++;
|
|
33
|
+
index = a.indexOf(b, index + 1);
|
|
34
|
+
}
|
|
35
|
+
return count;
|
|
36
|
+
}),
|
|
37
|
+
|
|
38
|
+
AbstractStringFunction.ofEntryStringAndStringOutput('LowerCase', (e) =>
|
|
39
|
+
e.toLocaleLowerCase(),
|
|
40
|
+
),
|
|
41
|
+
AbstractStringFunction.ofEntryStringAndStringOutput('UpperCase', (e) => e.toUpperCase()),
|
|
42
|
+
AbstractStringFunction.ofEntryStringAndBooleanOutput('IsBlank', (e) => e.trim() === ''),
|
|
43
|
+
AbstractStringFunction.ofEntryStringAndBooleanOutput('IsEmpty', (e) => e === ''),
|
|
44
|
+
|
|
45
|
+
AbstractStringFunction.ofEntryStringStringAndBooleanOutput(
|
|
29
46
|
'Contains',
|
|
30
47
|
(a, b) => a.indexOf(b) != -1,
|
|
31
48
|
),
|
|
32
|
-
AbstractStringFunction.
|
|
33
|
-
|
|
49
|
+
AbstractStringFunction.ofEntryStringStringAndBooleanOutput('EndsWith', (a, b) =>
|
|
50
|
+
a.endsWith(b),
|
|
51
|
+
),
|
|
52
|
+
AbstractStringFunction.ofEntryStringStringAndBooleanOutput('StartsWith', (a, b) =>
|
|
34
53
|
a.startsWith(b),
|
|
35
54
|
),
|
|
36
|
-
AbstractStringFunction.
|
|
55
|
+
AbstractStringFunction.ofEntryStringStringAndBooleanOutput(
|
|
37
56
|
'EqualsIgnoreCase',
|
|
38
57
|
(a, b) => a.toUpperCase() == b.toUpperCase(),
|
|
39
58
|
),
|
|
40
|
-
AbstractStringFunction.
|
|
59
|
+
AbstractStringFunction.ofEntryStringStringAndBooleanOutput('Matches', (a, b) =>
|
|
41
60
|
new RegExp(b).test(a),
|
|
42
61
|
),
|
|
43
|
-
AbstractStringFunction.
|
|
44
|
-
|
|
45
|
-
a.lastIndexOf(b),
|
|
62
|
+
AbstractStringFunction.ofEntryStringStringAndIntegerOutput('IndexOf', (a, b) =>
|
|
63
|
+
a.indexOf(b),
|
|
46
64
|
),
|
|
47
|
-
AbstractStringFunction.
|
|
48
|
-
a.
|
|
65
|
+
AbstractStringFunction.ofEntryStringStringAndIntegerOutput('LastIndexOf', (a, b) =>
|
|
66
|
+
a.lastIndexOf(b),
|
|
49
67
|
),
|
|
68
|
+
AbstractStringFunction.ofEntryStringIntegerAndStringOutput('Repeat', (a, b) => a.repeat(b)),
|
|
50
69
|
|
|
51
|
-
AbstractStringFunction.
|
|
70
|
+
AbstractStringFunction.ofEntryStringStringIntegerAndIntegerOutput(
|
|
52
71
|
'IndexOfWithStartPoint',
|
|
53
72
|
(a, b, c) => a.indexOf(b, c),
|
|
54
73
|
),
|
|
55
|
-
AbstractStringFunction.
|
|
74
|
+
AbstractStringFunction.ofEntryStringStringIntegerAndIntegerOutput(
|
|
56
75
|
'LastIndexOfWithStartPoint',
|
|
57
76
|
(a, b, c) => a.lastIndexOf(b, c),
|
|
58
77
|
),
|
|
59
|
-
AbstractStringFunction.
|
|
78
|
+
AbstractStringFunction.ofEntryStringStringStringAndStringOutput('Replace', (a, b, c) => {
|
|
60
79
|
return a.replaceAll(b, c);
|
|
61
80
|
}),
|
|
62
|
-
AbstractStringFunction.
|
|
81
|
+
AbstractStringFunction.ofEntryStringStringStringAndStringOutput('ReplaceFirst', (a, b, c) =>
|
|
63
82
|
a.replace(b, c),
|
|
64
83
|
),
|
|
65
|
-
AbstractStringFunction.
|
|
84
|
+
AbstractStringFunction.ofEntryStringIntegerIntegerAndStringOutput('SubString', (a, b, c) =>
|
|
66
85
|
a.substring(b, c),
|
|
67
86
|
),
|
|
68
87
|
mapEntry(new Concatenate()),
|
|
@@ -149,7 +149,7 @@ export class SchemaUtil {
|
|
|
149
149
|
let nms = StringUtil.splitAtFirstOccurance(ref ?? '', '/');
|
|
150
150
|
if (!nms[0]) return Promise.resolve(undefined);
|
|
151
151
|
|
|
152
|
-
let nmspnm = StringUtil.
|
|
152
|
+
let nmspnm = StringUtil.splitAtLastOccurance(nms[0], '.');
|
|
153
153
|
if (!nmspnm[0] || !nmspnm[1]) return Promise.resolve(undefined);
|
|
154
154
|
|
|
155
155
|
let schema = await sRepository.find(nmspnm[0], nmspnm[1]);
|
|
@@ -1,7 +1,8 @@
|
|
|
1
|
-
import { Schema } from '../json/schema/Schema';
|
|
1
|
+
import { AdditionalType, Schema } from '../json/schema/Schema';
|
|
2
2
|
import { Parameter } from '../model/Parameter';
|
|
3
3
|
import { Namespaces } from '../namespaces/Namespaces';
|
|
4
4
|
import { Repository } from '../Repository';
|
|
5
|
+
import { MapUtil } from '../util/MapUtil';
|
|
5
6
|
|
|
6
7
|
const map: Map<string, Schema> = new Map([
|
|
7
8
|
['any', Schema.ofAny('any').setNamespace(Namespaces.SYSTEM)],
|
|
@@ -12,7 +13,59 @@ const map: Map<string, Schema> = new Map([
|
|
|
12
13
|
['long', Schema.ofLong('long').setNamespace(Namespaces.SYSTEM)],
|
|
13
14
|
['number', Schema.ofNumber('number').setNamespace(Namespaces.SYSTEM)],
|
|
14
15
|
['string', Schema.ofString('string').setNamespace(Namespaces.SYSTEM)],
|
|
15
|
-
['
|
|
16
|
+
['Timestamp', Schema.ofString('Timestamp').setNamespace(Namespaces.DATE)],
|
|
17
|
+
[
|
|
18
|
+
'Timeunit',
|
|
19
|
+
Schema.ofString('Timeunit')
|
|
20
|
+
.setNamespace(Namespaces.DATE)
|
|
21
|
+
.setEnums([
|
|
22
|
+
'YEARS',
|
|
23
|
+
'QUARTERS',
|
|
24
|
+
'MONTHS',
|
|
25
|
+
'WEEKS',
|
|
26
|
+
'DAYS',
|
|
27
|
+
'HOURS',
|
|
28
|
+
'MINUTES',
|
|
29
|
+
'SECONDS',
|
|
30
|
+
'MILLISECONDS',
|
|
31
|
+
]),
|
|
32
|
+
],
|
|
33
|
+
[
|
|
34
|
+
'Duration',
|
|
35
|
+
Schema.ofObject('Duration')
|
|
36
|
+
.setNamespace(Namespaces.DATE)
|
|
37
|
+
.setProperties(
|
|
38
|
+
MapUtil.ofArrayEntries(
|
|
39
|
+
['years', Schema.ofInteger('years')],
|
|
40
|
+
['quarters', Schema.ofInteger('quarters')],
|
|
41
|
+
['months', Schema.ofInteger('months')],
|
|
42
|
+
['weeks', Schema.ofInteger('weeks')],
|
|
43
|
+
['days', Schema.ofInteger('days')],
|
|
44
|
+
['hours', Schema.ofInteger('hours')],
|
|
45
|
+
['minutes', Schema.ofInteger('minutes')],
|
|
46
|
+
['seconds', Schema.ofLong('seconds')],
|
|
47
|
+
['milliseconds', Schema.ofLong('milliseconds')],
|
|
48
|
+
),
|
|
49
|
+
)
|
|
50
|
+
.setAdditionalItems(AdditionalType.from(false)!),
|
|
51
|
+
],
|
|
52
|
+
[
|
|
53
|
+
'TimeObject',
|
|
54
|
+
Schema.ofObject('TimeObject')
|
|
55
|
+
.setNamespace(Namespaces.DATE)
|
|
56
|
+
.setProperties(
|
|
57
|
+
MapUtil.ofArrayEntries(
|
|
58
|
+
['year', Schema.ofInteger('year')],
|
|
59
|
+
['month', Schema.ofInteger('month')],
|
|
60
|
+
['day', Schema.ofInteger('day')],
|
|
61
|
+
['hour', Schema.ofInteger('hour')],
|
|
62
|
+
['minute', Schema.ofInteger('minute')],
|
|
63
|
+
['second', Schema.ofLong('second')],
|
|
64
|
+
['millisecond', Schema.ofLong('millisecond')],
|
|
65
|
+
),
|
|
66
|
+
)
|
|
67
|
+
.setAdditionalItems(AdditionalType.from(false)!),
|
|
68
|
+
],
|
|
16
69
|
[Parameter.EXPRESSION.getName()!, Parameter.EXPRESSION],
|
|
17
70
|
[Schema.NULL.getName()!, Schema.NULL],
|
|
18
71
|
[Schema.SCHEMA.getName()!, Schema.SCHEMA],
|
|
@@ -22,7 +75,8 @@ const filterableNames = Array.from(map.values()).map((e) => e.getFullName());
|
|
|
22
75
|
|
|
23
76
|
export class KIRunSchemaRepository implements Repository<Schema> {
|
|
24
77
|
public async find(namespace: string, name: string): Promise<Schema | undefined> {
|
|
25
|
-
if (Namespaces.SYSTEM != namespace
|
|
78
|
+
if (Namespaces.SYSTEM != namespace && Namespaces.DATE != namespace)
|
|
79
|
+
return Promise.resolve(undefined);
|
|
26
80
|
|
|
27
81
|
return Promise.resolve(map.get(name));
|
|
28
82
|
}
|
|
@@ -42,6 +42,18 @@ export class StringUtil {
|
|
|
42
42
|
return [str.substring(0, index), str.substring(index + 1)];
|
|
43
43
|
}
|
|
44
44
|
|
|
45
|
+
public static splitAtLastOccurance(
|
|
46
|
+
str: string,
|
|
47
|
+
c: string,
|
|
48
|
+
): [string | undefined, string | undefined] {
|
|
49
|
+
if (!str) return [undefined, undefined];
|
|
50
|
+
|
|
51
|
+
let index: number = str.lastIndexOf(c);
|
|
52
|
+
if (index == -1) return [str, undefined];
|
|
53
|
+
|
|
54
|
+
return [str.substring(0, index), str.substring(index + 1)];
|
|
55
|
+
}
|
|
56
|
+
|
|
45
57
|
public static isNullOrBlank(str: string | undefined): boolean {
|
|
46
58
|
return !str || str.trim() == '';
|
|
47
59
|
}
|