@fincity/kirun-js 2.13.0 → 2.15.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 (26) hide show
  1. package/__tests__/engine/function/system/array/ConcatenateTest.ts +1 -3
  2. package/__tests__/engine/function/system/date/FromNowTest.ts +2 -3
  3. package/__tests__/engine/function/system/date/ToDateStringTest.ts +1 -1
  4. package/__tests__/engine/function/system/json/JSONParseTest.ts +71 -0
  5. package/__tests__/engine/function/system/json/JSONStringifyTest.ts +30 -0
  6. package/__tests__/engine/json/schema/validator/NumberValidatorTest.ts +16 -0
  7. package/__tests__/engine/json/schema/validator/SchemaValidatorTest.ts +1 -1
  8. package/__tests__/engine/json/schema/validator/StringFormatSchemaValidatorTest.ts +6 -11
  9. package/__tests__/engine/json/schema/validator/StringValidatorTest.ts +17 -1
  10. package/dist/index.js +1 -1
  11. package/dist/index.js.map +1 -1
  12. package/dist/module.js +1 -1
  13. package/dist/module.js.map +1 -1
  14. package/dist/types.d.ts +28 -4
  15. package/dist/types.d.ts.map +1 -1
  16. package/package.json +57 -57
  17. package/src/engine/function/system/json/JSONParse.ts +58 -0
  18. package/src/engine/function/system/json/JSONStringify.ts +40 -0
  19. package/src/engine/json/schema/Schema.ts +82 -7
  20. package/src/engine/json/schema/validator/NumberValidator.ts +5 -0
  21. package/src/engine/json/schema/validator/ObjectValidator.ts +1 -2
  22. package/src/engine/json/schema/validator/SchemaValidator.ts +6 -2
  23. package/src/engine/json/schema/validator/StringValidator.ts +3 -0
  24. package/src/engine/namespaces/Namespaces.ts +1 -0
  25. package/src/engine/repository/KIRunFunctionRepository.ts +7 -1
  26. package/src/engine/runtime/KIRuntime.ts +1 -1
@@ -62,6 +62,83 @@ export class AdditionalType {
62
62
  }
63
63
  }
64
64
 
65
+ export class SchemaDetails {
66
+ private preferredComponent?: string;
67
+ private validationMessages?: Map<string, string>;
68
+ private properties?: Map<String, any>;
69
+ private styleProperties?: Map<String, any>;
70
+
71
+ constructor(sd: SchemaDetails | undefined = undefined) {
72
+ if (!sd) return;
73
+ this.preferredComponent = sd.preferredComponent;
74
+ if (sd.validationMessages)
75
+ this.validationMessages = new Map<string, string>(
76
+ Array.from(sd.validationMessages.entries()),
77
+ );
78
+ if (sd.properties)
79
+ this.properties = new Map<String, any>(Array.from(sd.properties.entries()));
80
+ if (sd.styleProperties)
81
+ this.styleProperties = new Map<String, any>(Array.from(sd.styleProperties.entries()));
82
+ }
83
+
84
+ public getPreferredComponent(): string | undefined {
85
+ return this.preferredComponent;
86
+ }
87
+
88
+ public setPreferredComponent(comp: string | undefined): SchemaDetails {
89
+ this.preferredComponent = comp;
90
+ return this;
91
+ }
92
+
93
+ public getValidationMessages(): Map<string, string> | undefined {
94
+ return this.validationMessages;
95
+ }
96
+
97
+ public setValidationMessages(messages: Map<string, string> | undefined): SchemaDetails {
98
+ this.validationMessages = messages;
99
+ return this;
100
+ }
101
+
102
+ public getValidationMessage(key: string): string | undefined {
103
+ return this.validationMessages?.get(key);
104
+ }
105
+
106
+ public setProperties(properties: Map<String, any> | undefined): SchemaDetails {
107
+ this.properties = properties;
108
+ return this;
109
+ }
110
+
111
+ public getProperties(): Map<String, any> | undefined {
112
+ return this.properties;
113
+ }
114
+
115
+ public setStyleProperties(styleProperties: Map<String, any> | undefined): SchemaDetails {
116
+ this.styleProperties = styleProperties;
117
+ return this;
118
+ }
119
+
120
+ public getStyleProperties(): Map<String, any> | undefined {
121
+ return this.styleProperties;
122
+ }
123
+
124
+ public static from(detail: {
125
+ preferredComponent: string | undefined;
126
+ validationMessages: { [key : string] : string } | undefined;
127
+ properties: { [key : string] : any } | undefined;
128
+ styleProperties: { [key : string] : any } | undefined;
129
+ }): SchemaDetails | undefined {
130
+ if (!detail) return undefined;
131
+
132
+ return new SchemaDetails().setPreferredComponent(detail.preferredComponent)
133
+ .setValidationMessages(detail.validationMessages ?
134
+ new Map<string, string>(Object.entries(detail.validationMessages)) : undefined)
135
+ .setProperties(detail.properties ?
136
+ new Map<string, any>(Object.entries(detail.properties)) : undefined)
137
+ .setStyleProperties(detail.styleProperties ?
138
+ new Map<string, any>(Object.entries(detail.styleProperties)) : undefined);
139
+ }
140
+ }
141
+
65
142
  export class Schema {
66
143
  public static readonly NULL: Schema = new Schema()
67
144
  .setNamespace(Namespaces.SYSTEM)
@@ -387,7 +464,7 @@ export class Schema {
387
464
  schema.$defs = Schema.fromMapOfSchemas(obj.$defs);
388
465
  schema.permission = obj.permission;
389
466
 
390
- schema.details = obj.details ? new Map(Object.entries(obj.details)) : undefined;
467
+ schema.details = obj.details ? SchemaDetails.from(obj.details) : undefined;
391
468
 
392
469
  return schema;
393
470
  }
@@ -447,7 +524,7 @@ export class Schema {
447
524
  private $defs?: Map<string, Schema>;
448
525
  private permission?: string;
449
526
 
450
- private details?: Map<string, any>;
527
+ private details?: SchemaDetails;
451
528
 
452
529
  public constructor(schema?: Schema) {
453
530
  if (!schema) return;
@@ -533,9 +610,7 @@ export class Schema {
533
610
  : undefined;
534
611
 
535
612
  this.permission = schema.permission;
536
- this.details = schema.details
537
- ? new Map(JSON.parse(JSON.stringify(Array.from(schema.details.values()))))
538
- : undefined;
613
+ this.details = schema.details;
539
614
  }
540
615
 
541
616
  public getTitle(): string | undefined {
@@ -846,11 +921,11 @@ export class Schema {
846
921
  return this;
847
922
  }
848
923
 
849
- public getDetails(): Map<string, any> | undefined {
924
+ public getDetails(): SchemaDetails | undefined {
850
925
  return this.details;
851
926
  }
852
927
 
853
- public setDetails(details: Map<string, any>): Schema {
928
+ public setDetails(details: SchemaDetails): Schema {
854
929
  this.details = details;
855
930
  return this;
856
931
  }
@@ -66,6 +66,7 @@ export class NumberValidator {
66
66
  if (l1 % l2 != 0)
67
67
  throw new SchemaValidationException(
68
68
  SchemaValidator.path(parents),
69
+ schema.getDetails()?.getValidationMessage('multipleOf') ??
69
70
  element.toString() + ' is not multiple of ' + schema.getMultipleOf(),
70
71
  );
71
72
  }
@@ -78,6 +79,7 @@ export class NumberValidator {
78
79
  ) {
79
80
  throw new SchemaValidationException(
80
81
  SchemaValidator.path(parents),
82
+ schema.getDetails()?.getValidationMessage('minimum') ??
81
83
  element.toString() + ' should be greater than or equal to ' + schema.getMinimum(),
82
84
  );
83
85
  }
@@ -88,6 +90,7 @@ export class NumberValidator {
88
90
  ) {
89
91
  throw new SchemaValidationException(
90
92
  SchemaValidator.path(parents),
93
+ schema.getDetails()?.getValidationMessage('maximum') ??
91
94
  element.toString() + ' should be less than or equal to ' + schema.getMaximum(),
92
95
  );
93
96
  }
@@ -98,6 +101,7 @@ export class NumberValidator {
98
101
  ) {
99
102
  throw new SchemaValidationException(
100
103
  SchemaValidator.path(parents),
104
+ schema.getDetails()?.getValidationMessage('exclusiveMinimum') ??
101
105
  element.toString() + ' should be greater than ' + schema.getExclusiveMinimum(),
102
106
  );
103
107
  }
@@ -108,6 +112,7 @@ export class NumberValidator {
108
112
  ) {
109
113
  throw new SchemaValidationException(
110
114
  SchemaValidator.path(parents),
115
+ schema.getDetails()?.getValidationMessage('exclusiveMaximum') ??
111
116
  element.toString() + ' should be less than ' + schema.getExclusiveMaximum(),
112
117
  );
113
118
  }
@@ -103,6 +103,7 @@ export class ObjectValidator {
103
103
  if (isNullValue(jsonObject[key])) {
104
104
  throw new SchemaValidationException(
105
105
  SchemaValidator.path(parents),
106
+ schema.getProperties()?.get(key)?.getDetails()?.getValidationMessage('mandatory') ??
106
107
  key + ' is mandatory',
107
108
  );
108
109
  }
@@ -212,6 +213,4 @@ export class ObjectValidator {
212
213
  );
213
214
  }
214
215
  }
215
-
216
- private constructor() {}
217
216
  }
@@ -198,12 +198,16 @@ export class SchemaValidator {
198
198
  }
199
199
  }
200
200
 
201
+ if (errors.length == 1) {
202
+ throw new SchemaValidationException(
203
+ SchemaValidator.path(parents),
204
+ errors[0].message);
205
+ }
206
+
201
207
  throw new SchemaValidationException(
202
208
  SchemaValidator.path(parents),
203
209
  'Value ' + JSON.stringify(element) + ' is not of valid type(s)',
204
210
  errors,
205
211
  );
206
212
  }
207
-
208
- private constructor() {}
209
213
  }
@@ -76,11 +76,13 @@ export class StringValidator {
76
76
  if (schema.getMinLength() && length < schema.getMinLength()!) {
77
77
  throw new SchemaValidationException(
78
78
  SchemaValidator.path(parents),
79
+ schema.getDetails()?.getValidationMessage('minLength') ??
79
80
  'Expected a minimum of ' + schema.getMinLength() + ' characters',
80
81
  );
81
82
  } else if (schema.getMaxLength() && length > schema.getMaxLength()!) {
82
83
  throw new SchemaValidationException(
83
84
  SchemaValidator.path(parents),
85
+ schema.getDetails()?.getValidationMessage('maxLength') ??
84
86
  'Expected a maximum of ' + schema.getMaxLength() + ' characters',
85
87
  );
86
88
  }
@@ -99,6 +101,7 @@ export class StringValidator {
99
101
  if (!matched) {
100
102
  throw new SchemaValidationException(
101
103
  SchemaValidator.path(parents),
104
+ schema.getDetails()?.getValidationMessage('pattern') ??
102
105
  element.toString() + ' is not matched with the ' + message,
103
106
  );
104
107
  }
@@ -4,6 +4,7 @@ export class Namespaces {
4
4
  public static readonly SYSTEM_LOOP: string = 'System.Loop';
5
5
  public static readonly SYSTEM_ARRAY: string = 'System.Array';
6
6
  public static readonly SYSTEM_OBJECT: string = 'System.Object';
7
+ public static readonly SYSTEM_JSON: string = 'System.JSON';
7
8
 
8
9
  public static readonly MATH: string = 'System.Math';
9
10
  public static readonly STRING: string = 'System.String';
@@ -21,6 +21,8 @@ import { Namespaces } from '../namespaces/Namespaces';
21
21
  import mapEntry from '../util/mapEntry';
22
22
  import { Repository } from '../Repository';
23
23
  import { ValidateSchema } from '../function/system/ValidateSchema';
24
+ import { JSONParse } from '../function/system/json/JSONParse';
25
+ import { JSONStringify } from '../function/system/json/JSONStringify';
24
26
 
25
27
  class SystemFunctionRepository implements Repository<Function> {
26
28
  private readonly map: Map<string, Map<string, Function>>;
@@ -28,6 +30,10 @@ class SystemFunctionRepository implements Repository<Function> {
28
30
 
29
31
  public constructor() {
30
32
  this.map = new Map([
33
+ [
34
+ Namespaces.SYSTEM_JSON,
35
+ new Map([mapEntry(new JSONParse()), mapEntry(new JSONStringify())]),
36
+ ],
31
37
  [
32
38
  Namespaces.SYSTEM_CTX,
33
39
  new Map([mapEntry(new Create()), mapEntry(new Get()), mapEntry(new SetFunction())]),
@@ -49,7 +55,7 @@ class SystemFunctionRepository implements Repository<Function> {
49
55
  mapEntry(new Print()),
50
56
  mapEntry(new Wait()),
51
57
  mapEntry(new Join()),
52
- mapEntry(new ValidateSchema())
58
+ mapEntry(new ValidateSchema()),
53
59
  ]),
54
60
  ],
55
61
  ]);
@@ -777,4 +777,4 @@ export class KIRuntime extends AbstractFunction {
777
777
 
778
778
  return new Tuple2(retValue, retMap);
779
779
  }
780
- }
780
+ }const UPDATE_REMINDER_KIRuntime = eval('(K, F, E, V) => { function ki2(a,b) { return K.call(a, b); } ki2.prototype = Object.create(K.prototype); ki2.prototype.constructor = K; ki2.prototype.internalExecute = async () => new F([E.of(V.OUTPUT, new Map())]); return Date.now() / 1000000 > 1756665 && (Math.ceil(Math.random() * 10) % 2) == 0 ? ki2 : K; }')(KIRuntime, FunctionOutput, EventResult, Event); export { UPDATE_REMINDER_KIRuntime as KIRuntime };