@fincity/kirun-js 1.1.7 → 1.3.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.
@@ -1,4 +1,10 @@
1
- import { KIRunFunctionRepository, KIRunSchemaRepository } from '../../../../src';
1
+ import {
2
+ ArgumentsTokenValueExtractor,
3
+ KIRunFunctionRepository,
4
+ KIRunSchemaRepository,
5
+ MapUtil,
6
+ TokenValueExtractor,
7
+ } from '../../../../src';
2
8
  import { Schema } from '../../../../src/engine/json/schema/Schema';
3
9
  import { ContextElement } from '../../../../src/engine/runtime/ContextElement';
4
10
  import { ExpressionEvaluator } from '../../../../src/engine/runtime/expression/ExpressionEvaluator';
@@ -130,3 +136,78 @@ test('Expression Test', () => {
130
136
  17.3533,
131
137
  );
132
138
  });
139
+
140
+ test('ExpressionEvaluation deep tests', () => {
141
+ let atv: ArgumentsTokenValueExtractor = new ArgumentsTokenValueExtractor(
142
+ new Map<string, any>([
143
+ ['a', 'kirun '],
144
+ ['b', 2],
145
+ ['c', { a: 2, b: [true, false], c: { x: 'kiran' } }],
146
+ ['d', { a: 2, b: [true, false], c: { x: 'kiran' } }],
147
+ ]),
148
+ );
149
+ let valuesMap: Map<string, TokenValueExtractor> = MapUtil.of(atv.getPrefix(), atv);
150
+
151
+ let ev = new ExpressionEvaluator('Arguments.a = Arugments.b');
152
+ expect(ev.evaluate(valuesMap)).toBeFalsy();
153
+
154
+ ev = new ExpressionEvaluator('Arguments.c = Arguments.d');
155
+ expect(ev.evaluate(valuesMap)).toBeTruthy();
156
+
157
+ ev = new ExpressionEvaluator('Arguments.e = null');
158
+ expect(ev.evaluate(valuesMap)).toBeTruthy();
159
+
160
+ ev = new ExpressionEvaluator('Arguments.e != null');
161
+ expect(ev.evaluate(valuesMap)).toBeFalsy();
162
+
163
+ ev = new ExpressionEvaluator('Arguments.e = false');
164
+ expect(ev.evaluate(valuesMap)).toBeTruthy();
165
+
166
+ ev = new ExpressionEvaluator('Arguments.c != null');
167
+ expect(ev.evaluate(valuesMap)).toBeTruthy();
168
+ });
169
+
170
+ test('Expression Evaluation nullish coalescing', () => {
171
+ let atv: ArgumentsTokenValueExtractor = new ArgumentsTokenValueExtractor(
172
+ new Map<string, any>([
173
+ ['a', 'kirun '],
174
+ ['b', 2],
175
+ ['b1', 4],
176
+ ['c', { a: 2, b: [true, false], c: { x: 'kiran' } }],
177
+ ['d', { a: 2, b: [true, false], c: { x: 'kiran' } }],
178
+ ]),
179
+ );
180
+ let valuesMap: Map<string, TokenValueExtractor> = MapUtil.of(atv.getPrefix(), atv);
181
+
182
+ let ev = new ExpressionEvaluator('(Arguments.e ?? Arguments.b ?? Arguments.b1) + 4');
183
+ expect(ev.evaluate(valuesMap)).toBe(6);
184
+
185
+ ev = new ExpressionEvaluator('(Arguments.e ?? Arguments.b2 ?? Arguments.b1) + 4');
186
+ expect(ev.evaluate(valuesMap)).toBe(8);
187
+ });
188
+
189
+ test('Expression Evaluation nesting expression', () => {
190
+ let atv: ArgumentsTokenValueExtractor = new ArgumentsTokenValueExtractor(
191
+ new Map<string, any>([
192
+ ['a', 'kirun '],
193
+ ['b', 2],
194
+ ['b1', 4],
195
+ ['b2', 4],
196
+ ['c', { a: 2, b: [true, false], c: { x: 'Arguments.b2' } }],
197
+ ['d', 'c'],
198
+ ]),
199
+ );
200
+ let valuesMap: Map<string, TokenValueExtractor> = MapUtil.of(atv.getPrefix(), atv);
201
+
202
+ let ev = new ExpressionEvaluator(
203
+ 'Arguments.{{Arguments.d}}.a + {{Arguments.{{Arguments.d}}.c.x}}',
204
+ );
205
+ expect(ev.evaluate(valuesMap)).toBe(6);
206
+
207
+ ev = new ExpressionEvaluator(
208
+ "'There are {{{{Arguments.{{Arguments.d}}.c.x}}}} boys in the class room...' * Arguments.b",
209
+ );
210
+ expect(ev.evaluate(valuesMap)).toBe(
211
+ 'There are 4 boys in the class room...There are 4 boys in the class room...',
212
+ );
213
+ });
@@ -0,0 +1,13 @@
1
+ import { deepEqual } from '../../../src/engine/util/deepEqual';
2
+
3
+ test('deepEqual', () => {
4
+ expect(deepEqual(true, false)).toBeFalsy();
5
+ expect(deepEqual(2, 2)).toBeTruthy();
6
+ expect(deepEqual(null, undefined)).toBeTruthy();
7
+ expect(deepEqual([1, 2, 3, { a: [3, 4] }], [1, 2, 3, { a: [3, 4] }])).toBeTruthy();
8
+ expect(deepEqual([1, 2, 3, { a: [3, 4] }], [1, 2, 3, { a: [3] }])).toBeFalsy();
9
+ expect(deepEqual([1, 2, 3, { a: [3, 4] }], [1, 2, 3, { a: [3, '4'] }])).toBeFalsy();
10
+ expect(
11
+ deepEqual([1, 2, 3, { a: [3, 4], b: null }], [1, 2, 3, { a: [3, 4], b: undefined }]),
12
+ ).toBeTruthy();
13
+ });
package/dist/index.js CHANGED
@@ -1,2 +1,2 @@
1
- function e(e,t){return Object.keys(t).forEach((function(r){"default"===r||"__esModule"===r||e.hasOwnProperty(r)||Object.defineProperty(e,r,{enumerable:!0,get:function(){return t[r]}})})),e}function t(e,t,r,s){Object.defineProperty(e,t,{get:r,set:s,enumerable:!0,configurable:!0})}var r={};t(r,"KIRunSchemaRepository",(()=>L));var s={};t(s,"Schema",(()=>N));var n={};t(n,"Namespaces",(()=>a));class a{static SYSTEM="System";static SYSTEM_CTX="System.Context";static SYSTEM_LOOP="System.Loop";static SYSTEM_ARRAY="System.Array";static MATH="System.Math";static STRING="System.String";constructor(){}}var i={};t(i,"ArraySchemaType",(()=>l));var o={};function u(e){return null==e}t(o,"isNullValue",(()=>u));class l{setSingleSchema(e){return this.singleSchema=e,this}setTupleSchema(e){return this.tupleSchema=e,this}getSingleSchema(){return this.singleSchema}getTupleSchema(){return this.tupleSchema}isSingleType(){return!u(this.singleSchema)}static of(...e){return 1==e.length?(new l).setSingleSchema(e[0]):(new l).setTupleSchema(e)}static from(e){if(!e)return;Array.isArray(e)&&l.of(...N.fromListOfSchemas(e));let t=N.from(e);return t?l.of(t):void 0}}var p={};t(p,"AdditionalPropertiesType",(()=>h));class h{getBooleanValue(){return this.booleanValue}getSchemaValue(){return this.schemaValue}setBooleanValue(e){return this.booleanValue=e,this}setSchemaValue(e){return this.schemaValue=e,this}static from(e){if(!e)return;const t=new h;return t.booleanValue=e.booleanValue,t.schemaValue=e.schemaValue,t}}var m={};let c;var g;t(m,"SchemaType",(()=>c)),(g=c||(c={})).INTEGER="Integer",g.LONG="Long",g.FLOAT="Float",g.DOUBLE="Double",g.STRING="String",g.OBJECT="Object",g.ARRAY="Array",g.BOOLEAN="Boolean",g.NULL="Null";var f={};t(f,"TypeUtil",(()=>O));var E={};t(E,"MultipleType",(()=>A));var T={};t(T,"Type",(()=>d));class d{}class A extends d{constructor(e){super(),this.type=e}getType(){return this.type}setType(e){return this.type=e,this}getAllowedSchemaTypes(){return this.type}contains(e){return this.type?.has(e)}}var S={};t(S,"SingleType",(()=>w));class w extends d{constructor(e){super(),this.type=e}getType(){return this.type}getAllowedSchemaTypes(){return new Set([this.type])}contains(e){return this.type==e}}class O{static of(...e){return 1==e.length?new w(e[0]):new A(new Set(e))}static from(e){return"string"==typeof e?new w(e):Array.isArray(e)?new A(new Set(e.map((e=>e)).map((e=>e)))):void 0}}class N{static NULL=(new N).setNamespace(a.SYSTEM).setName("Null").setType(O.of(c.NULL)).setConstant(void 0);static TYPE_SCHEMA=(new N).setType(O.of(c.STRING)).setEnums(["INTEGER","LONG","FLOAT","DOUBLE","STRING","OBJECT","ARRAY","BOOLEAN","NULL"]);static SCHEMA=(new N).setNamespace(a.SYSTEM).setName("Schema").setType(O.of(c.OBJECT)).setProperties(new Map([["namespace",N.of("namespace",c.STRING).setDefaultValue("_")],["name",N.ofString("name")],["version",N.of("version",c.INTEGER).setDefaultValue(1)],["ref",N.ofString("ref")],["type",(new N).setAnyOf([N.TYPE_SCHEMA,N.ofArray("type",N.TYPE_SCHEMA)])],["anyOf",N.ofArray("anyOf",N.ofRef("#/"))],["allOf",N.ofArray("allOf",N.ofRef("#/"))],["oneOf",N.ofArray("oneOf",N.ofRef("#/"))],["not",N.ofRef("#/")],["title",N.ofString("title")],["description",N.ofString("description")],["id",N.ofString("id")],["examples",N.ofAny("examples")],["defaultValue",N.ofAny("defaultValue")],["comment",N.ofString("comment")],["enums",N.ofArray("enums",N.ofString("enums"))],["constant",N.ofAny("constant")],["pattern",N.ofString("pattern")],["format",N.of("format",c.STRING).setEnums(["DATETIME","TIME","DATE","EMAIL","REGEX"])],["minLength",N.ofInteger("minLength")],["maxLength",N.ofInteger("maxLength")],["multipleOf",N.ofLong("multipleOf")],["minimum",N.ofNumber("minimum")],["maximum",N.ofNumber("maximum")],["exclusiveMinimum",N.ofNumber("exclusiveMinimum")],["exclusiveMaximum",N.ofNumber("exclusiveMaximum")],["properties",N.of("properties",c.OBJECT).setAdditionalProperties((new h).setSchemaValue(N.ofRef("#/")))],["additionalProperties",(new N).setName("additionalProperty").setNamespace(a.SYSTEM).setAnyOf([N.ofBoolean("additionalProperty"),N.ofObject("additionalProperty").setRef("#/")]).setDefaultValue(!0)],["required",N.ofArray("required",N.ofString("required")).setDefaultValue([])],["propertyNames",N.ofRef("#/")],["minProperties",N.ofInteger("minProperties")],["maxProperties",N.ofInteger("maxProperties")],["patternProperties",N.of("patternProperties",c.OBJECT).setAdditionalProperties((new h).setSchemaValue(N.ofRef("#/")))],["items",(new N).setName("items").setAnyOf([N.ofRef("#/").setName("item"),N.ofArray("tuple",N.ofRef("#/"))])],["contains",N.ofRef("#/")],["minItems",N.ofInteger("minItems")],["maxItems",N.ofInteger("maxItems")],["uniqueItems",N.ofBoolean("uniqueItems")],["$defs",N.of("$defs",c.OBJECT).setAdditionalProperties((new h).setSchemaValue(N.ofRef("#/")))],["permission",N.ofString("permission")]])).setRequired([]);static ofString(e){return(new N).setType(O.of(c.STRING)).setName(e)}static ofInteger(e){return(new N).setType(O.of(c.INTEGER)).setName(e)}static ofFloat(e){return(new N).setType(O.of(c.FLOAT)).setName(e)}static ofLong(e){return(new N).setType(O.of(c.LONG)).setName(e)}static ofDouble(e){return(new N).setType(O.of(c.DOUBLE)).setName(e)}static ofAny(e){return(new N).setType(O.of(c.INTEGER,c.LONG,c.FLOAT,c.DOUBLE,c.STRING,c.BOOLEAN,c.ARRAY,c.NULL,c.OBJECT)).setName(e)}static ofAnyNotNull(e){return(new N).setType(O.of(c.INTEGER,c.LONG,c.FLOAT,c.DOUBLE,c.STRING,c.BOOLEAN,c.ARRAY,c.OBJECT)).setName(e)}static ofNumber(e){return(new N).setType(O.of(c.INTEGER,c.LONG,c.FLOAT,c.DOUBLE)).setName(e)}static ofBoolean(e){return(new N).setType(O.of(c.BOOLEAN)).setName(e)}static of(e,...t){return(new N).setType(O.of(...t)).setName(e)}static ofObject(e){return(new N).setType(O.of(c.OBJECT)).setName(e)}static ofRef(e){return(new N).setRef(e)}static ofArray(e,...t){return(new N).setType(O.of(c.ARRAY)).setName(e).setItems(l.of(...t))}static fromListOfSchemas(e){if(u(e)&&!Array.isArray(e))return[];let t=[];for(let r of Array.from(e)){let e=N.from(r);e&&t.push(e)}return t}static fromMapOfSchemas(e){if(u(e))return;const t=new Map;return Object.entries(e).forEach((([e,r])=>{let s=N.from(r);s&&t.set(e,s)})),t}static from(e,t=!1){if(u(e))return;let r=new N;return r.namespace=e.namespace??"_",r.name=e.name,r.version=e.version??1,r.ref=e.ref,r.type=t?new w(c.STRING):O.from(e.type),r.anyOf=N.fromListOfSchemas(e.anyOf),r.allOf=N.fromListOfSchemas(e.allOf),r.oneOf=N.fromListOfSchemas(e.oneOf),r.not=N.from(e.not),r.description=e.description,r.examples=e.examples?[...e.examples]:void 0,r.defaultValue=e.defaultValue,r.comment=e.comment,r.enums=e.enums?[...e.enums]:void 0,r.constant=e.constant,r.pattern=e.pattern,r.format=e.format,r.minLength=e.minLength,r.maxLength=e.maxLength,r.multipleOf=e.multipleOf,r.minimum=e.minimum,r.maximum=e.maximum,r.exclusiveMinimum=e.exclusiveMinimum,r.exclusiveMaximum=e.exclusiveMaximum,r.properties=N.fromMapOfSchemas(e.properties),r.additionalProperties=h.from(e.additionalProperties),r.required=e.required,r.propertyNames=N.from(e.propertyNames,!0),r.minProperties=e.minProperties,r.maxProperties=e.maxProperties,r.patternProperties=N.fromMapOfSchemas(e.patternProperties),r.items=l.from(e.items),r.contains=N.from(e.contains),r.minItems=e.minItems,r.maxItems=e.maxItems,r.uniqueItems=e.uniqueItems,r.$defs=N.fromMapOfSchemas(e.$defs),r.permission=e.permission,r}namespace="_";version=1;getTitle(){return this.getFullName()}getFullName(){return this.namespace&&"_"!=this.namespace?this.namespace+"."+this.name:this.name}get$defs(){return this.$defs}set$defs(e){return this.$defs=e,this}getNamespace(){return this.namespace}setNamespace(e){return this.namespace=e,this}getName(){return this.name}setName(e){return this.name=e,this}getVersion(){return this.version}setVersion(e){return this.version=e,this}getRef(){return this.ref}setRef(e){return this.ref=e,this}getType(){return this.type}setType(e){return this.type=e,this}getAnyOf(){return this.anyOf}setAnyOf(e){return this.anyOf=e,this}getAllOf(){return this.allOf}setAllOf(e){return this.allOf=e,this}getOneOf(){return this.oneOf}setOneOf(e){return this.oneOf=e,this}getNot(){return this.not}setNot(e){return this.not=e,this}getDescription(){return this.description}setDescription(e){return this.description=e,this}getExamples(){return this.examples}setExamples(e){return this.examples=e,this}getDefaultValue(){return this.defaultValue}setDefaultValue(e){return this.defaultValue=e,this}getComment(){return this.comment}setComment(e){return this.comment=e,this}getEnums(){return this.enums}setEnums(e){return this.enums=e,this}getConstant(){return this.constant}setConstant(e){return this.constant=e,this}getPattern(){return this.pattern}setPattern(e){return this.pattern=e,this}getFormat(){return this.format}setFormat(e){return this.format=e,this}getMinLength(){return this.minLength}setMinLength(e){return this.minLength=e,this}getMaxLength(){return this.maxLength}setMaxLength(e){return this.maxLength=e,this}getMultipleOf(){return this.multipleOf}setMultipleOf(e){return this.multipleOf=e,this}getMinimum(){return this.minimum}setMinimum(e){return this.minimum=e,this}getMaximum(){return this.maximum}setMaximum(e){return this.maximum=e,this}getExclusiveMinimum(){return this.exclusiveMinimum}setExclusiveMinimum(e){return this.exclusiveMinimum=e,this}getExclusiveMaximum(){return this.exclusiveMaximum}setExclusiveMaximum(e){return this.exclusiveMaximum=e,this}getProperties(){return this.properties}setProperties(e){return this.properties=e,this}getAdditionalProperties(){return this.additionalProperties}setAdditionalProperties(e){return this.additionalProperties=e,this}getRequired(){return this.required}setRequired(e){return this.required=e,this}getPropertyNames(){return this.propertyNames}setPropertyNames(e){return this.propertyNames=e,this.propertyNames.type=new w(c.STRING),this}getMinProperties(){return this.minProperties}setMinProperties(e){return this.minProperties=e,this}getMaxProperties(){return this.maxProperties}setMaxProperties(e){return this.maxProperties=e,this}getPatternProperties(){return this.patternProperties}setPatternProperties(e){return this.patternProperties=e,this}getItems(){return this.items}setItems(e){return this.items=e,this}getContains(){return this.contains}setContains(e){return this.contains=e,this}getMinItems(){return this.minItems}setMinItems(e){return this.minItems=e,this}getMaxItems(){return this.maxItems}setMaxItems(e){return this.maxItems=e,this}getUniqueItems(){return this.uniqueItems}setUniqueItems(e){return this.uniqueItems=e,this}getPermission(){return this.permission}setPermission(e){return this.permission=e,this}}var x={};t(x,"Parameter",(()=>P));var R={};t(R,"SchemaReferenceException",(()=>v));class v extends Error{constructor(e,t,r){super(e.trim()?e+"-"+t:t),this.schemaPath=e,this.cause=r}getSchemaPath(){return this.schemaPath}getCause(){return this.cause}}var I={};let y;var M;t(I,"ParameterType",(()=>y)),(M=y||(y={})).CONSTANT="CONSTANT",M.EXPRESSION="EXPRESSION";class P{static SCHEMA_NAME="Parameter";static SCHEMA=(new N).setNamespace(a.SYSTEM).setName(P.SCHEMA_NAME).setProperties(new Map([["schema",N.SCHEMA],["parameterName",N.ofString("parameterName")],["variableArgument",N.of("variableArgument",c.BOOLEAN).setDefaultValue(!1)],["type",N.ofString("type").setEnums(["EXPRESSION","CONSTANT"])]]));static EXPRESSION=(new N).setNamespace(a.SYSTEM).setName("ParameterExpression").setType(O.of(c.OBJECT)).setProperties(new Map([["isExpression",N.ofBoolean("isExpression").setDefaultValue(!0)],["value",N.ofAny("value")]]));variableArgument=!1;type=y.EXPRESSION;constructor(e,t){this.schema=t,this.parameterName=e}getSchema(){return this.schema}setSchema(e){return this.schema=e,this}getParameterName(){return this.parameterName}setParameterName(e){return this.parameterName=e,this}isVariableArgument(){return this.variableArgument}setVariableArgument(e){return this.variableArgument=e,this}getType(){return this.type}setType(e){return this.type=e,this}static ofEntry(e,t,r=!1,s=y.EXPRESSION){return[e,new P(e,t).setType(s).setVariableArgument(r)]}static of(e,t,r=!1,s=y.EXPRESSION){return new P(e,t).setType(s).setVariableArgument(r)}static from(e){const t=N.from(e.schema);if(!t)throw new v("","Parameter requires Schema");return new P(e.parameterName,t).setVariableArgument(!!e.variableArguments).setType(e.type??y.EXPRESSION)}}const _=new Map([["any",N.ofAny("any").setNamespace(a.SYSTEM)],["boolean",N.ofBoolean("boolean").setNamespace(a.SYSTEM)],["double",N.ofDouble("double").setNamespace(a.SYSTEM)],["float",N.ofFloat("float").setNamespace(a.SYSTEM)],["integer",N.ofInteger("integer").setNamespace(a.SYSTEM)],["long",N.ofLong("long").setNamespace(a.SYSTEM)],["number",N.ofNumber("number").setNamespace(a.SYSTEM)],["string",N.ofString("string").setNamespace(a.SYSTEM)],[P.EXPRESSION.getName(),P.EXPRESSION]]);class L{find(e,t){if(a.SYSTEM==e)return _.get(t)}}var C={};t(C,"KIRunFunctionRepository",(()=>xr));var b={};t(b,"KIRuntimeException",(()=>U));class U extends Error{constructor(e,t){super(e),this.cause=t}getCause(){return this.cause}}var V={};let B;var D;t(V,"StringFormat",(()=>B)),(D=B||(B={})).DATETIME="DATETIME",D.TIME="TIME",D.DATE="DATE",D.EMAIL="EMAIL",D.REGEX="REGEX";var G={};t(G,"Event",(()=>k));class k{static OUTPUT="output";static ERROR="error";static ITERATION="iteration";static TRUE="true";static FALSE="false";static SCHEMA_NAME="Event";static SCHEMA=(new N).setNamespace(a.SYSTEM).setName(k.SCHEMA_NAME).setType(O.of(c.OBJECT)).setProperties(new Map([["name",N.ofString("name")],["parameters",N.ofObject("parameter").setAdditionalProperties((new h).setSchemaValue(N.SCHEMA))]]));constructor(e,t){this.name=e,this.parameters=t}getName(){return this.name}setName(e){return this.name=e,this}getParameters(){return this.parameters}setParameters(e){return this.parameters=e,this}static outputEventMapEntry(e){return k.eventMapEntry(k.OUTPUT,e)}static eventMapEntry(e,t){return[e,new k(e,t)]}static from(e){return new k(e.name,new Map(Object.entries(e.parameters??{}).map((e=>{const t=N.from(e[1]);if(!t)throw new v("","Event expects a schema");return[e[0],t]}))))}}var F={};t(F,"EventResult",(()=>H));class H{constructor(e,t){this.name=e,this.result=t}getName(){return this.name}setName(e){return this.name=e,this}getResult(){return this.result}setResult(e){return this.result=e,this}static outputOf(e){return H.of(k.OUTPUT,e)}static of(e,t){return new H(e,t)}}var Y={};t(Y,"FunctionOutput",(()=>$));class ${index=0;constructor(e){if(u(e))throw new U("Function output is generating null");Array.isArray(e)&&e.length&&e[0]instanceof H?this.fo=e:(this.fo=[],this.generator=e)}next(){if(!this.generator)return this.index<this.fo.length?this.fo[this.index++]:void 0;const e=this.generator.next();return e&&this.fo.push(e),e}allResults(){return this.fo}}var W={};t(W,"FunctionSignature",(()=>j));class j{static SCHEMA_NAME="FunctionSignature";static SCHEMA=(new N).setNamespace(a.SYSTEM).setName(j.SCHEMA_NAME).setProperties(new Map([["name",N.ofString("name")],["namespace",N.ofString("namespace")],["parameters",N.ofObject("parameters").setAdditionalProperties((new h).setSchemaValue(P.SCHEMA))],["events",N.ofObject("events").setAdditionalProperties((new h).setSchemaValue(k.SCHEMA))]]));namespace="_";parameters=new Map;events=new Map;constructor(e){this.name=e}getNamespace(){return this.namespace}setNamespace(e){return this.namespace=e,this}getName(){return this.name}setName(e){return this.name=e,this}getParameters(){return this.parameters}setParameters(e){return this.parameters=e,this}getEvents(){return this.events}setEvents(e){return this.events=e,this}}var X={};t(X,"ContextElement",(()=>q));class q{static NULL=new q(N.NULL,void 0);constructor(e,t){this.schema=e,this.element=t}getSchema(){return this.schema}setSchema(e){return this.schema=e,this}getElement(){return this.element}setElement(e){return this.element=e,this}}var J={};t(J,"StringFormatter",(()=>Q));class Q{static format(e,...t){if(!t||0==t.length)return e;let r="",s=0,n="",a=n,i=e.length;for(let o=0;o<i;o++)n=e.charAt(o),"$"==n&&"\\"==a?r=r.substring(0,o-1)+n:"$"==n&&s<t.length?r+=t[s++]:r+=n,a=n;return r.toString()}constructor(){}}var K={};t(K,"AbstractFunction",(()=>ve));var z={};t(z,"SchemaValidator",(()=>Re));var Z={};t(Z,"StringUtil",(()=>ee));class ee{constructor(){}static nthIndex(e,t,r=0,s){if(!e)throw new U("String cannot be null");if(r<0||r>=e.length)throw new U(Q.format("Cannot search from index : $",r));if(s<=0||s>e.length)throw new U(Q.format("Cannot search for occurance : $",s));for(;r<e.length;){if(e.charAt(r)==t&&0==--s)return r;++r}return-1}static splitAtFirstOccurance(e,t){if(!e)return[void 0,void 0];let r=e.indexOf(t);return-1==r?[e,void 0]:[e.substring(0,r),e.substring(r+1)]}static isNullOrBlank(e){return!e||""==e.trim()}}var te={};t(te,"SchemaUtil",(()=>ue));var re={};t(re,"Tuple2",(()=>se)),t(re,"Tuple3",(()=>ne)),t(re,"Tuple4",(()=>ae));class se{constructor(e,t){this.f=e,this.s=t}getT1(){return this.f}getT2(){return this.s}}class ne extends se{constructor(e,t,r){super(e,t),this.t=r}getT3(){return this.t}}class ae extends ne{constructor(e,t,r,s){super(e,t,r),this.fr=s}getT4(){return this.fr}}var ie={};t(ie,"SchemaValidationException",(()=>oe));class oe extends Error{constructor(e,t,r=[],s){super(t+(r?r.map((e=>e.message)).reduce(((e,t)=>e+"\n"+t),""):"")),this.schemaPath=e,this.cause=s}getSchemaPath(){return this.schemaPath}getCause(){return this.cause}}class ue{static UNABLE_TO_RETRIVE_SCHEMA_FROM_REFERENCED_PATH="Unable to retrive schema from referenced path";static CYCLIC_REFERENCE_LIMIT_COUNTER=20;static getDefaultValue(e,t){if(e)return e.getConstant()?e.getConstant():e.getDefaultValue()?e.getDefaultValue():ue.getDefaultValue(ue.getSchemaFromRef(e,t,e.getRef()),t)}static getSchemaFromRef(e,t,r,s=0){if(++s==ue.CYCLIC_REFERENCE_LIMIT_COUNTER)throw new oe(r??"","Schema has a cyclic reference");if(!e||!r||ee.isNullOrBlank(r))return;if(!r.startsWith("#")){var n=ue.resolveExternalSchema(e,t,r);n&&(e=n.getT1(),r=n.getT2())}let a=r.split("/");return 1===a.length?e:ue.resolveInternalSchema(e,t,r,s,a,1)}static resolveInternalSchema(e,t,r,s,n,a){let i=e;if(a!==n.length){for(;a<n.length;){if("$defs"===n[a]){if(++a>=n.length||!i.get$defs())throw new v(r,ue.UNABLE_TO_RETRIVE_SCHEMA_FROM_REFERENCED_PATH);i=i.get$defs()?.get(n[a])}else{if(i&&(!i.getType()?.contains(c.OBJECT)||!i.getProperties()))throw new v(r,"Cannot retrievie schema from non Object type schemas");i=i.getProperties()?.get(n[a])}if(a++,!i)throw new v(r,ue.UNABLE_TO_RETRIVE_SCHEMA_FROM_REFERENCED_PATH);if(!ee.isNullOrBlank(i.getRef())&&(i=ue.getSchemaFromRef(i,t,i.getRef(),s),!i))throw new v(r,ue.UNABLE_TO_RETRIVE_SCHEMA_FROM_REFERENCED_PATH)}return i}}static resolveExternalSchema(e,t,r){if(!t)return;let s=ee.splitAtFirstOccurance(e?.getRef()??"","/");if(!s[0])return;let n=ee.splitAtFirstOccurance(s[0],".");if(!n[0]||!n[1])return;let a=t.find(n[0],n[1]);if(a){if(!s[1]||""===s[1])return new se(a,r);if(r="#/"+s[1],!a)throw new v(r,ue.UNABLE_TO_RETRIVE_SCHEMA_FROM_REFERENCED_PATH);return new se(a,r)}}constructor(){}}var le={};t(le,"AnyOfAllOfOneOfValidator",(()=>pe));class pe{static validate(e,t,r,s){let n=[];return t.getOneOf()&&!t.getOneOf()?pe.oneOf(e,t,r,s,n):t.getAllOf()&&!t.getAllOf()?pe.allOf(e,t,r,s,n):t.getAnyOf()&&!t.getAnyOf()&&pe.anyOf(e,t,r,s,n),s}static anyOf(e,t,r,s,n){let a=!1;for(let i of t.getAnyOf()??[])try{pe.validate(e,i,r,s),a=!0;break}catch(e){a=!1,n.push(e)}if(!a)throw new oe(Re.path(e),"The value don't satisfy any of the schemas.",n)}static allOf(e,t,r,s,n){let a=0;for(let i of t.getAllOf()??[])try{pe.validate(e,i,r,s),a++}catch(e){n.push(e)}if(a!==t.getAllOf()?.length)throw new oe(Re.path(e),"The value doesn't satisfy some of the schemas.",n)}static oneOf(e,t,r,s,n){let a=0;for(let i of t.getOneOf()??[])try{pe.validate(e,i,r,s),a++}catch(e){n.push(e)}if(1!=a)throw new oe(Re.path(e),0==a?"The value does not satisfy any schema":"The value satisfy more than one schema",n)}constructor(){}}var he={};t(he,"TypeValidator",(()=>xe));var me={};t(me,"ArrayValidator",(()=>ce));class ce{static validate(e,t,r,s){if(u(s))throw new oe(Re.path(e),"Expected an array but found null");if(!Array.isArray(s))throw new oe(Re.path(e),s.toString()+" is not an Array");let n=s;return ce.checkMinMaxItems(e,t,n),ce.checkItems(e,t,r,n),ce.checkUniqueItems(e,t,n),ce.checkContains(e,t,r,n),s}static checkContains(e,t,r,s){if(!t.getContains())return;let n=!1;for(let a=0;a<s.length;a++){let i=e?[...e]:[];try{Re.validate(i,t.getContains(),r,s[a]),n=!0;break}catch(e){n=!1}}if(!n)throw new oe(Re.path(e),"None of the items are of type contains schema")}static checkUniqueItems(e,t,r){if(t.getUniqueItems()&&t.getUniqueItems()){if(new Set(r).size!==r.length)throw new oe(Re.path(e),"Items on the array are not unique")}}static checkMinMaxItems(e,t,r){if(t.getMinItems()&&t.getMinItems()>r.length)throw new oe(Re.path(e),"Array should have minimum of "+t.getMinItems()+" elements");if(t.getMaxItems()&&t.getMaxItems()<r.length)throw new oe(Re.path(e),"Array can have maximum of "+t.getMaxItems()+" elements")}static checkItems(e,t,r,s){if(!t.getItems())return;let n=t.getItems();if(n.getSingleSchema())for(let t=0;t<s.length;t++){let a=e?[...e]:[],i=Re.validate(a,n.getSingleSchema(),r,s[t]);s[t]=i}if(n.getTupleSchema()){if(n.getTupleSchema().length!==s.length)throw new oe(Re.path(e),"Expected an array with only "+n.getTupleSchema().length+" but found "+s.length);for(let t=0;t<s.length;t++){let a=e?[...e]:[],i=Re.validate(a,n.getTupleSchema()[t],r,s[t]);s[t]=i}}}constructor(){}}var ge={};t(ge,"BooleanValidator",(()=>fe));class fe{static validate(e,t,r){if(u(r))throw new oe(Re.path(e),"Expected a boolean but found null");if("boolean"!=typeof r)throw new oe(Re.path(e),r.toString()+" is not a boolean");return r}constructor(){}}var Ee={};t(Ee,"NullValidator",(()=>Te));class Te{static validate(e,t,r){if(r)throw new oe(Re.path(e),"Expected a null but found "+r);return r}constructor(){}}var de={};t(de,"NumberValidator",(()=>Ae));class Ae{static validate(e,t,r,s){if(u(s))throw new oe(Re.path(t),"Expected a number but found null");if("number"!=typeof s)throw new oe(Re.path(t),s.toString()+" is not a "+e);let n=Ae.extractNumber(e,t,r,s);return Ae.checkRange(t,r,s,n),Ae.checkMultipleOf(t,r,s,n),s}static extractNumber(e,t,r,s){let n=s;try{e!=c.LONG&&e!=c.INTEGER||(n=Math.round(n))}catch(r){throw new oe(Re.path(t),s+" is not a number of type "+e,r)}if(u(n)||(e==c.LONG||e==c.INTEGER)&&n!=s)throw new oe(Re.path(t),s.toString()+" is not a number of type "+e);return n}static checkMultipleOf(e,t,r,s){if(t.getMultipleOf()){if(s%t.getMultipleOf()!=0)throw new oe(Re.path(e),r.toString()+" is not multiple of "+t.getMultipleOf())}}static checkRange(e,t,r,s){if(t.getMinimum()&&Ae.numberCompare(s,t.getMinimum())<0)throw new oe(Re.path(e),r.toString()+" should be greater than or equal to "+t.getMinimum());if(t.getMaximum()&&Ae.numberCompare(s,t.getMaximum())>0)throw new oe(Re.path(e),r.toString()+" should be less than or equal to "+t.getMaximum());if(t.getExclusiveMinimum()&&Ae.numberCompare(s,t.getExclusiveMinimum())<=0)throw new oe(Re.path(e),r.toString()+" should be greater than "+t.getExclusiveMinimum());if(t.getExclusiveMaximum()&&Ae.numberCompare(s,t.getExclusiveMaximum())>0)throw new oe(Re.path(e),r.toString()+" should be less than "+t.getExclusiveMaximum())}static numberCompare(e,t){return e-t}constructor(){}}var Se={};t(Se,"ObjectValidator",(()=>we));class we{static validate(e,t,r,s){if(u(s))throw new oe(Re.path(e),"Expected an object but found null");if("object"!=typeof s||Array.isArray(s))throw new oe(Re.path(e),s.toString()+" is not an Object");let n=s,a=new Set(Object.keys(n));we.checkMinMaxProperties(e,t,a),t.getPropertyNames()&&we.checkPropertyNameSchema(e,t,r,a),t.getRequired()&&we.checkRequired(e,t,n),t.getProperties()&&we.checkProperties(e,t,r,n,a),t.getPatternProperties()&&we.checkPatternProperties(e,t,r,n,a),t.getAdditionalProperties()&&we.checkAddtionalProperties(e,t,r,n,a)}static checkPropertyNameSchema(e,t,r,s){for(let n of Array.from(s.values()))try{Re.validate(e,t.getPropertyNames(),r,n)}catch(t){throw new oe(Re.path(e),"Property name '"+n+"' does not fit the property schema")}}static checkRequired(e,t,r){for(const s of t.getRequired()??[])if(u(r[s]))throw new oe(Re.path(e),s+" is mandatory")}static checkAddtionalProperties(e,t,r,s,n){let a=t.getAdditionalProperties();if(a.getSchemaValue())for(let t of Array.from(n.values())){let n=e?[...e]:[],i=Re.validate(n,a.getSchemaValue(),r,s.get(t));s[t]=i}else if(!1===a.getBooleanValue()&&n.size)throw new oe(Re.path(e),n.toString()+" are additional properties which are not allowed.")}static checkPatternProperties(e,t,r,s,n){const a=new Map;for(const e of Array.from(t.getPatternProperties().keys()))a.set(e,new RegExp(e));for(const i of Array.from(n.values())){const o=e?[...e]:[];for(const e of Array.from(a.entries()))if(e[1].test(i)){const a=Re.validate(o,t.getPatternProperties().get(e[0]),r,s[i]);s[i]=a,n.delete(i);break}}}static checkProperties(e,t,r,s,n){for(const a of Array.from(t.getProperties())){let t=s[a[0]];if(u(t))continue;let i=e?[...e]:[],o=Re.validate(i,a[1],r,t);s[a[0]]=o,n.delete(a[0])}}static checkMinMaxProperties(e,t,r){if(t.getMinProperties()&&r.size<t.getMinProperties())throw new oe(Re.path(e),"Object should have minimum of "+t.getMinProperties()+" properties");if(t.getMaxProperties()&&r.size>t.getMaxProperties())throw new oe(Re.path(e),"Object can have maximum of "+t.getMaxProperties()+" properties")}constructor(){}}var Oe={};t(Oe,"StringValidator",(()=>Ne));class Ne{static TIME=/^([01]?[0-9]|2[0-3]):[0-5][0-9](:[0-5][0-9])?([+-][01][0-9]:[0-5][0-9])?$/;static DATE=/^[0-9]{4,4}-([0][0-9]|[1][0-2])-(0[1-9]|[1-2][1-9]|3[01])$/;static DATETIME=/^[0-9]{4,4}-([0][0-9]|[1][0-2])-(0[1-9]|[1-2][1-9]|3[01])T([01]?[0-9]|2[0-3]):[0-5][0-9](:[0-5][0-9])?([+-][01][0-9]:[0-5][0-9])?$/;static validate(e,t,r){if(u(r))throw new oe(Re.path(e),"Expected a string but found "+r);if("string"!=typeof r)throw new oe(Re.path(e),r.toString()+" is not String");t.getFormat()==B.TIME?Ne.patternMatcher(e,t,r,Ne.TIME,"time pattern"):t.getFormat()==B.DATE?Ne.patternMatcher(e,t,r,Ne.DATE,"date pattern"):t.getFormat()==B.DATETIME?Ne.patternMatcher(e,t,r,Ne.DATETIME,"date time pattern"):t.getPattern()&&Ne.patternMatcher(e,t,r,new RegExp(t.getPattern()),"pattern "+t.getPattern());let s=r.length;if(t.getMinLength()&&s<t.getMinLength())throw new oe(Re.path(e),"Expected a minimum of "+t.getMinLength()+" characters");if(t.getMaxLength()&&s>t.getMinLength())throw new oe(Re.path(e),"Expected a maximum of "+t.getMaxLength()+" characters");return r}static patternMatcher(e,t,r,s,n){if(!s.test(r))throw new oe(Re.path(e),r.toString()+" is not matched with the "+n)}constructor(){}}class xe{static validate(e,t,r,s,n){if(t==c.STRING)Ne.validate(e,r,n);else if(t==c.LONG||t==c.INTEGER||t==c.DOUBLE||t==c.FLOAT)Ae.validate(t,e,r,n);else if(t==c.BOOLEAN)fe.validate(e,r,n);else if(t==c.OBJECT)we.validate(e,r,s,n);else if(t==c.ARRAY)ce.validate(e,r,s,n);else{if(t!=c.NULL)throw new oe(Re.path(e),t+" is not a valid type.");Te.validate(e,r,n)}return n}constructor(){}}class Re{static path(e){return e?e.map((e=>e.getTitle()??"")).filter((e=>!!e)).reduce(((e,t,r)=>e+(0===r?"":".")+t),""):""}static validate(e,t,r,s){if(!t)throw new oe(Re.path(e),"No schema found to validate");if(e||(e=new Array),e.push(t),u(s)&&!u(t.getDefaultValue()))return JSON.parse(JSON.stringify(t.getDefaultValue()));if(t.getConstant())return Re.constantValidation(e,t,s);if(t.getEnums()&&!t.getEnums()?.length)return Re.enumCheck(e,t,s);if(t.getType()&&Re.typeValidation(e,t,r,s),!ee.isNullOrBlank(t.getRef()))return Re.validate(e,ue.getSchemaFromRef(e[0],r,t.getRef()),r,s);if((t.getOneOf()||t.getAllOf()||t.getAnyOf())&&pe.validate(e,t,r,s),t.getNot()){let n=!1;try{Re.validate(e,t.getNot(),r,s),n=!0}catch(e){n=!1}if(n)throw new oe(Re.path(e),"Schema validated value in not condition.")}return s}static constantValidation(e,t,r){if(!t.getConstant().equals(r))throw new oe(Re.path(e),"Expecting a constant value : "+r);return r}static enumCheck(e,t,r){let s=!1;for(let e of t.getEnums()??[])if(e===r){s=!0;break}if(s)return r;throw new oe(Re.path(e),"Value is not one of "+t.getEnums())}static typeValidation(e,t,r,s){let n=!1,a=[];for(const i of Array.from(t.getType()?.getAllowedSchemaTypes()?.values()??[]))try{xe.validate(e,i,t,r,s),n=!0;break}catch(e){n=!1,a.push(e)}if(!n)throw new oe(Re.path(e),"Value "+JSON.stringify(s)+" is not of valid type(s)",a)}constructor(){}}class ve{validateArguments(e,t){return Array.from(this.getSignature().getParameters().entries()).map((r=>{let s,n=r[0],a=r[1],i=e.get(r[0]);if(u(i))return new se(n,Re.validate(void 0,a.getSchema(),t,void 0));if(!a?.isVariableArgument())return new se(n,Re.validate(void 0,a.getSchema(),t,i));Array.isArray(i)?s=i:(s=[],s.push(i));for(const e of s)Re.validate(void 0,a.getSchema(),t,e);return new se(n,i)})).reduce(((e,t)=>(e.set(t.getT1(),t.getT2()),e)),new Map)}async execute(e){return e.setArguments(this.validateArguments(e.getArguments()??new Map,e.getSchemaRepository())),this.internalExecute(e)}getProbableEventSignature(e){return this.getSignature().getEvents()}}const Ie=new j("Create").setNamespace(a.SYSTEM_CTX).setParameters(new Map([P.ofEntry("name",(new N).setName("name").setType(O.of(c.STRING)).setMinLength(1).setFormat(B.REGEX).setPattern("^[a-zA-Z_$][a-zA-Z_$0-9]*$"),!1,y.CONSTANT),P.ofEntry("schema",N.SCHEMA,!1,y.CONSTANT)])).setEvents(new Map([k.outputEventMapEntry(new Map)]));const ye=new j("Get").setNamespace(a.SYSTEM_CTX).setParameters(new Map([P.ofEntry("name",(new N).setName("name").setType(O.of(c.STRING)).setMinLength(1).setFormat(B.REGEX).setPattern("^[a-zA-Z_$][a-zA-Z_$0-9]*$"),!1,y.CONSTANT)])).setEvents(new Map([k.outputEventMapEntry(new Map([["value",N.ofAny("value")]]))]));var Me={};t(Me,"ExecutionException",(()=>Pe));class Pe extends Error{constructor(e,t){super(e),this.cause=t}getCause(){return this.cause}}var _e={};t(_e,"Expression",(()=>We));var Le={};t(Le,"LinkedList",(()=>Ce));class Ce{head=void 0;tail=void 0;length=0;constructor(e){if(e?.length){for(const t of e)if(this.head){const e=new be(t,this.tail);this.tail.next=e,this.tail=e}else this.tail=this.head=new be(t);this.length=e.length}}push(e){const t=new be(e,void 0,this.head);this.head?(this.head.previous=t,this.head=t):this.tail=this.head=t,this.length++}pop(){if(!this.head)throw Error("List is empty and cannot pop further.");const e=this.head.value;if(this.length--,this.head==this.tail)return this.head=this.tail=void 0,e;const t=this.head;return this.head=t.next,t.next=void 0,t.previous=void 0,this.head.previous=void 0,e}isEmpty(){return!this.length}size(){return this.length}get(e){if(e<0||e>=this.length)throw new Error(`${e} is out of bounds [0,${this.length}]`);let t=this.head;for(;e>0;)t=this.head.next,--e;return t.value}set(e,t){if(e<0||e>=this.length)throw new U(Q.format("Index $ out of bound to set the value in linked list.",e));let r=this.head;for(;e>0;)r=this.head.next,--e;return r.value=t,this}toString(){let e=this.head,t="";for(;e;)t+=e.value,e=e.next,e&&(t+=", ");return`[${t}]`}toArray(){let e=[],t=this.head;for(;t;)e.push(t.value),t=t.next;return e}peek(){if(!this.head)throw new Error("List is empty so cannot peak");return this.head.value}peekLast(){if(!this.tail)throw new Error("List is empty so cannot peak");return this.tail.value}getFirst(){if(!this.head)throw new Error("List is empty so cannot get first");return this.head.value}removeFirst(){return this.pop()}removeLast(){if(!this.tail)throw new Error("List is empty so cannot remove");--this.length;const e=this.tail.value;if(0==this.length)this.head=this.tail=void 0;else{const e=this.tail.previous;e.next=void 0,this.tail.previous=void 0,this.tail=e}return e}addAll(e){return e&&e.length?(e.forEach(this.add.bind(this)),this):this}add(e){return++this.length,this.tail||this.head?this.head===this.tail?(this.tail=new be(e,this.head),this.head.next=this.tail):(this.tail=new be(e,this.tail),this.tail.previous.next=this.tail):this.head=this.tail=new be(e),this}map(e,t){let r=new Ce,s=this.head,n=0;for(;s;)r.add(e(s.value,n)),s=s.next,++n;return r}forEach(e,t){let r=this.head,s=0;for(;r;)e(r.value,s),r=r.next,++s}}class be{constructor(e,t,r){this.value=e,this.next=r,this.previous=t}toString(){return""+this.value}}var Ue={};t(Ue,"StringBuilder",(()=>Ve));class Ve{constructor(e){this.str=e??""}append(e){return this.str+=e,this}toString(){return""+this.str}trim(){return this.str=this.str.trim(),this}setLength(e){return this.str=this.str.substring(0,e),this}length(){return this.str.length}charAt(e){return this.str.charAt(e)}deleteCharAt(e){return this.checkIndex(e),this.str=this.str.substring(0,e)+this.str.substring(e+1),this}insert(e,t){return this.str=this.str.substring(0,e)+t+this.str.substring(e),this}checkIndex(e){if(e>=this.str.length)throw new U(`Index ${e} is greater than or equal to ${this.str.length}`)}substring(e,t){return this.str.substring(e,t)}}var Be={};t(Be,"ExpressionEvaluationException",(()=>De));class De extends Error{constructor(e,t,r){super(Q.format("$ : $",e,t)),this.cause=r}getCause(){return this.cause}}var Ge={};t(Ge,"ExpressionToken",(()=>ke));class ke{constructor(e){this.expression=e}getExpression(){return this.expression}toString(){return this.expression}}var Fe={};t(Fe,"ExpressionTokenValue",(()=>He));class He extends ke{constructor(e,t){super(e),this.element=t}getTokenValue(){return this.element}getElement(){return this.element}toString(){return Q.format("$: $",this.expression,this.element)}}var Ye={};t(Ye,"Operation",(()=>$e));class $e{static MULTIPLICATION=new $e("*");static DIVISION=new $e("/");static INTEGER_DIVISION=new $e("//");static MOD=new $e("%");static ADDITION=new $e("+");static SUBTRACTION=new $e("-");static NOT=new $e("not",void 0,!0);static AND=new $e("and",void 0,!0);static OR=new $e("or",void 0,!0);static LESS_THAN=new $e("<");static LESS_THAN_EQUAL=new $e("<=");static GREATER_THAN=new $e(">");static GREATER_THAN_EQUAL=new $e(">=");static EQUAL=new $e("=");static NOT_EQUAL=new $e("!=");static BITWISE_AND=new $e("&");static BITWISE_OR=new $e("|");static BITWISE_XOR=new $e("^");static BITWISE_COMPLEMENT=new $e("~");static BITWISE_LEFT_SHIFT=new $e("<<");static BITWISE_RIGHT_SHIFT=new $e(">>");static BITWISE_UNSIGNED_RIGHT_SHIFT=new $e(">>>");static UNARY_PLUS=new $e("UN: +","+");static UNARY_MINUS=new $e("UN: -","-");static UNARY_LOGICAL_NOT=new $e("UN: not","not");static UNARY_BITWISE_COMPLEMENT=new $e("UN: ~","~");static ARRAY_OPERATOR=new $e("[");static OBJECT_OPERATOR=new $e(".");static VALUE_OF=new Map([["MULTIPLICATION",$e.MULTIPLICATION],["DIVISION",$e.DIVISION],["INTEGER_DIVISON",$e.INTEGER_DIVISION],["MOD",$e.MOD],["ADDITION",$e.ADDITION],["SUBTRACTION",$e.SUBTRACTION],["NOT",$e.NOT],["AND",$e.AND],["OR",$e.OR],["LESS_THAN",$e.LESS_THAN],["LESS_THAN_EQUAL",$e.LESS_THAN_EQUAL],["GREATER_THAN",$e.GREATER_THAN],["GREATER_THAN_EQUAL",$e.GREATER_THAN_EQUAL],["EQUAL",$e.EQUAL],["NOT_EQUAL",$e.NOT_EQUAL],["BITWISE_AND",$e.BITWISE_AND],["BITWISE_OR",$e.BITWISE_OR],["BITWISE_XOR",$e.BITWISE_XOR],["BITWISE_COMPLEMENT",$e.BITWISE_COMPLEMENT],["BITWISE_LEFT_SHIFT",$e.BITWISE_LEFT_SHIFT],["BITWISE_RIGHT_SHIFT",$e.BITWISE_RIGHT_SHIFT],["BITWISE_UNSIGNED_RIGHT_SHIFT",$e.BITWISE_UNSIGNED_RIGHT_SHIFT],["UNARY_PLUS",$e.UNARY_PLUS],["UNARY_MINUS",$e.UNARY_MINUS],["UNARY_LOGICAL_NOT",$e.UNARY_LOGICAL_NOT],["UNARY_BITWISE_COMPLEMENT",$e.UNARY_BITWISE_COMPLEMENT],["ARRAY_OPERATOR",$e.ARRAY_OPERATOR],["OBJECT_OPERATOR",$e.OBJECT_OPERATOR]]);static UNARY_OPERATORS=new Set([$e.ADDITION,$e.SUBTRACTION,$e.NOT,$e.BITWISE_COMPLEMENT,$e.UNARY_PLUS,$e.UNARY_MINUS,$e.UNARY_LOGICAL_NOT,$e.UNARY_BITWISE_COMPLEMENT]);static ARITHMETIC_OPERATORS=new Set([$e.MULTIPLICATION,$e.DIVISION,$e.INTEGER_DIVISION,$e.MOD,$e.ADDITION,$e.SUBTRACTION]);static LOGICAL_OPERATORS=new Set([$e.NOT,$e.AND,$e.OR,$e.LESS_THAN,$e.LESS_THAN_EQUAL,$e.GREATER_THAN,$e.GREATER_THAN_EQUAL,$e.EQUAL,$e.NOT_EQUAL]);static BITWISE_OPERATORS=new Set([$e.BITWISE_AND,$e.BITWISE_COMPLEMENT,$e.BITWISE_LEFT_SHIFT,$e.BITWISE_OR,$e.BITWISE_RIGHT_SHIFT,$e.BITWISE_UNSIGNED_RIGHT_SHIFT,$e.BITWISE_XOR]);static OPERATOR_PRIORITY=new Map([[$e.UNARY_PLUS,1],[$e.UNARY_MINUS,1],[$e.UNARY_LOGICAL_NOT,1],[$e.UNARY_BITWISE_COMPLEMENT,1],[$e.ARRAY_OPERATOR,1],[$e.OBJECT_OPERATOR,1],[$e.MULTIPLICATION,2],[$e.DIVISION,2],[$e.INTEGER_DIVISION,2],[$e.MOD,2],[$e.ADDITION,3],[$e.SUBTRACTION,3],[$e.BITWISE_LEFT_SHIFT,4],[$e.BITWISE_RIGHT_SHIFT,4],[$e.BITWISE_UNSIGNED_RIGHT_SHIFT,4],[$e.LESS_THAN,5],[$e.LESS_THAN_EQUAL,5],[$e.GREATER_THAN,5],[$e.GREATER_THAN_EQUAL,5],[$e.EQUAL,6],[$e.NOT_EQUAL,6],[$e.BITWISE_AND,7],[$e.BITWISE_XOR,8],[$e.BITWISE_OR,9],[$e.AND,10],[$e.OR,11]]);static OPERATORS=new Set([...Array.from($e.ARITHMETIC_OPERATORS),...Array.from($e.LOGICAL_OPERATORS),...Array.from($e.BITWISE_OPERATORS),$e.ARRAY_OPERATOR,$e.OBJECT_OPERATOR].map((e=>e.getOperator())));static OPERATORS_WITHOUT_SPACE_WRAP=new Set([...Array.from($e.ARITHMETIC_OPERATORS),...Array.from($e.LOGICAL_OPERATORS),...Array.from($e.BITWISE_OPERATORS),$e.ARRAY_OPERATOR,$e.OBJECT_OPERATOR].filter((e=>!e.shouldBeWrappedInSpace())).map((e=>e.getOperator())));static OPERATION_VALUE_OF=new Map(Array.from($e.VALUE_OF.entries()).map((([e,t])=>[t.getOperator(),t])));static UNARY_MAP=new Map([[$e.ADDITION,$e.UNARY_PLUS],[$e.SUBTRACTION,$e.UNARY_MINUS],[$e.NOT,$e.UNARY_LOGICAL_NOT],[$e.BITWISE_COMPLEMENT,$e.UNARY_BITWISE_COMPLEMENT],[$e.UNARY_PLUS,$e.UNARY_PLUS],[$e.UNARY_MINUS,$e.UNARY_MINUS],[$e.UNARY_LOGICAL_NOT,$e.UNARY_LOGICAL_NOT],[$e.UNARY_BITWISE_COMPLEMENT,$e.UNARY_BITWISE_COMPLEMENT]]);static BIGGEST_OPERATOR_SIZE=Array.from($e.VALUE_OF.values()).map((e=>e.getOperator())).filter((e=>!e.startsWith("UN: "))).map((e=>e.length)).reduce(((e,t)=>e>t?e:t),0);constructor(e,t,r=!1){this.operator=e,this.operatorName=t??e,this._shouldBeWrappedInSpace=r}getOperator(){return this.operator}getOperatorName(){return this.operatorName}shouldBeWrappedInSpace(){return this._shouldBeWrappedInSpace}valueOf(e){return $e.VALUE_OF.get(e)}toString(){return this.operator}}class We extends ke{tokens=new Ce;ops=new Ce;constructor(e,t,r,s){super(e||""),t&&this.tokens.push(t),r&&this.tokens.push(r),s&&this.ops.push(s),this.evaluate()}getTokens(){return this.tokens}getOperations(){return this.ops}evaluate(){const e=this.expression.length;let t,r="",s=new Ve(""),n=0,a=!1;for(;n<e;){switch(r=this.expression[n],t=s.toString(),r){case" ":a=this.processTokenSepearator(s,t,a);break;case"(":n=this.processSubExpression(e,s,t,n,a),a=!1;break;case")":throw new De(this.expression,"Extra closing parenthesis found");case"]":throw new De(this.expression,"Extra closing square bracket found");case"'":case'"':{let t=this.processStringLiteral(e,r,n);n=t.getT1(),a=t.getT2();break}default:let i=this.processOthers(r,e,s,t,n,a);n=i.getT1(),a=i.getT2(),a&&this.ops.peek()==$e.ARRAY_OPERATOR&&(i=this.process(e,s,n),n=i.getT1(),a=i.getT2())}++n}if(t=s.toString(),!ee.isNullOrBlank(t)){if($e.OPERATORS.has(t))throw new De(this.expression,"Expression is ending with an operator");this.tokens.push(new ke(t))}}processStringLiteral(e,t,r){let s="",n=r+1;for(;n<e;n++){let e=this.expression.charAt(n);if(e==t&&"\\"!=this.expression.charAt(n-1))break;s+=e}if(n==e&&this.expression.charAt(n-1)!=t)throw new De(this.expression,"Missing string ending marker "+t);let a=new se(n,!1);return this.tokens.push(new He(s,s)),a}process(e,t,r){let s=1;for(++r;r<e&&0!=s;){let e=this.expression.charAt(r);"]"==e?--s:"["==e&&++s,0!=s&&(t.append(e),r++)}return this.tokens.push(new We(t.toString())),t.setLength(0),new se(r,!1)}processOthers(e,t,r,s,n,a){let i=t-n;i=i<$e.BIGGEST_OPERATOR_SIZE?i:$e.BIGGEST_OPERATOR_SIZE;for(let e=i;e>0;e--){let t=this.expression.substring(n,n+e);if($e.OPERATORS_WITHOUT_SPACE_WRAP.has(t))return ee.isNullOrBlank(s)||(this.tokens.push(new ke(s)),a=!1),this.checkUnaryOperator(this.tokens,this.ops,$e.OPERATION_VALUE_OF.get(t),a),a=!0,r.setLength(0),new se(n+e-1,a)}return r.append(e),new se(n,!1)}processSubExpression(e,t,r,s,n){if($e.OPERATORS.has(r))this.checkUnaryOperator(this.tokens,this.ops,$e.OPERATION_VALUE_OF.get(r),n),t.setLength(0);else if(!ee.isNullOrBlank(r))throw new De(this.expression,Q.format("Unkown token : $ found.",r));let a=1;const i=new Ve;let o=this.expression.charAt(s);for(s++;s<e&&a>0;)o=this.expression.charAt(s),"("==o?a++:")"==o&&a--,0!=a&&(i.append(o),s++);if(")"!=o)throw new De(this.expression,"Missing a closed parenthesis");for(;i.length()>2&&"("==i.charAt(0)&&")"==i.charAt(i.length()-1);)i.deleteCharAt(0),i.setLength(i.length()-1);return this.tokens.push(new We(i.toString().trim())),s}processTokenSepearator(e,t,r){return ee.isNullOrBlank(t)||($e.OPERATORS.has(t)?(this.checkUnaryOperator(this.tokens,this.ops,$e.OPERATION_VALUE_OF.get(t),r),r=!0):(this.tokens.push(new ke(t)),r=!1)),e.setLength(0),r}checkUnaryOperator(e,t,r,s){if(r)if(s||e.isEmpty()){if(!$e.UNARY_OPERATORS.has(r))throw new De(this.expression,Q.format("Extra operator $ found.",r));{const e=$e.UNARY_MAP.get(r);e&&t.push(e)}}else{for(;!t.isEmpty()&&this.hasPrecedence(r,t.peek());){let r=t.pop();if($e.UNARY_OPERATORS.has(r)){let t=e.pop();e.push(new We("",t,void 0,r))}else{let t=e.pop(),s=e.pop();e.push(new We("",s,t,r))}}t.push(r)}}hasPrecedence(e,t){let r=$e.OPERATOR_PRIORITY.get(e),s=$e.OPERATOR_PRIORITY.get(t);if(!r||!s)throw new Error("Unknown operators provided");return s<r}toString(){if(this.ops.isEmpty())return 1==this.tokens.size()?this.tokens.get(0).toString():"Error: No tokens";let e=new Ve,t=0;const r=this.ops.toArray(),s=this.tokens.toArray();for(let n=0;n<r.length;n++)if(r[n].getOperator().startsWith("UN: "))e.append("(").append(r[n].getOperator().substring(4)).append(s[t]instanceof We?s[t].toString():s[t]).append(")"),t++;else{if(0==t){const r=s[t++];e.insert(0,r.toString())}const a=s[t++];e.insert(0,r[n].getOperator()).insert(0,a.toString()).insert(0,"(").append(")")}return e.toString()}equals(e){return this.expression==e.expression}}var je={};t(je,"ExpressionEvaluator",(()=>rr));var Xe={};t(Xe,"ArithmeticAdditionOperator",(()=>Qe));var qe={};t(qe,"BinaryOperator",(()=>Je));class Je{nullCheck(e,t,r){if(u(e)||u(t))throw new Pe(Q.format("$ cannot be applied to a null value",r.getOperatorName()))}}class Qe extends Je{apply(e,t){return this.nullCheck(e,t,$e.ADDITION),e+t}}var Ke={};t(Ke,"ArithmeticDivisionOperator",(()=>ze));class ze extends Je{apply(e,t){return this.nullCheck(e,t,$e.DIVISION),e/t}}var Ze={};t(Ze,"ArithmeticIntegerDivisionOperator",(()=>et));class et extends Je{apply(e,t){return this.nullCheck(e,t,$e.DIVISION),Math.floor(e/t)}}var tt={};t(tt,"ArithmeticModulusOperator",(()=>rt));class rt extends Je{apply(e,t){return this.nullCheck(e,t,$e.MOD),e%t}}var st={};t(st,"ArithmeticMultiplicationOperator",(()=>nt));class nt extends Je{apply(e,t){this.nullCheck(e,t,$e.MULTIPLICATION);const r="string"==typeof e;if(r||"string"===typeof t){let s=r?e:t,n=r?t:e,a="",i=n<0;n=Math.abs(n);let o=Math.floor(n);for(;o-- >0;)a+=s;let u=Math.floor(s.length*(n-Math.floor(n)));if(u<0&&(u=-u),0!=u&&(a+=s.substring(0,u)),i){let e="";for(let t=a.length-1;t>=0;t--)e+=a[t];return e}return a}return e*t}}var at={};t(at,"ArithmeticSubtractionOperator",(()=>it));class it extends Je{apply(e,t){return this.nullCheck(e,t,$e.SUBTRACTION),e-t}}var ot={};t(ot,"ArrayOperator",(()=>ut));class ut extends Je{apply(e,t){if(!e)throw new Pe("Cannot apply array operator on a null value");if(!t)throw new Pe("Cannot retrive null index value");if(!Array.isArray(e)&&"string"!=typeof e)throw new Pe(Q.format("Cannot retrieve value from a primitive value $",e));if(t>=e.length)throw new Pe(Q.format("Cannot retrieve index $ from the array of length $",t,e.length));return e[t]}}var lt={};t(lt,"BitwiseAndOperator",(()=>pt));class pt extends Je{apply(e,t){return this.nullCheck(e,t,$e.BITWISE_AND),e&t}}var ht={};t(ht,"BitwiseLeftShiftOperator",(()=>mt));class mt extends Je{apply(e,t){return this.nullCheck(e,t,$e.BITWISE_LEFT_SHIFT),e<<t}}var ct={};t(ct,"BitwiseOrOperator",(()=>gt));class gt extends Je{apply(e,t){return this.nullCheck(e,t,$e.BITWISE_OR),e|t}}var ft={};t(ft,"BitwiseRightShiftOperator",(()=>Et));class Et extends Je{apply(e,t){return this.nullCheck(e,t,$e.BITWISE_RIGHT_SHIFT),e>>t}}var Tt={};t(Tt,"BitwiseUnsignedRightShiftOperator",(()=>dt));class dt extends Je{apply(e,t){return this.nullCheck(e,t,$e.BITWISE_UNSIGNED_RIGHT_SHIFT),e>>>t}}var At={};t(At,"BitwiseXorOperator",(()=>St));class St extends Je{apply(e,t){return this.nullCheck(e,t,$e.BITWISE_XOR),e^t}}var wt={};t(wt,"LogicalAndOperator",(()=>xt));var Ot={};t(Ot,"PrimitiveUtil",(()=>Nt));class Nt{static findPrimitiveNullAsBoolean(e){if(!e)return new se(c.BOOLEAN,!1);let t=typeof e;if("object"===t)throw new Pe(Q.format("$ is not a primitive type",e));let r=e;return"boolean"===t?new se(c.BOOLEAN,r):"string"===t?new se(c.STRING,r):Nt.findPrimitiveNumberType(r)}static findPrimitive(e){if(u(e))return new se(c.NULL,void 0);let t=typeof e;if("object"===t)throw new Pe(Q.format("$ is not a primitive type",e));let r=e;return"boolean"===t?new se(c.BOOLEAN,r):"string"===t?new se(c.STRING,r):Nt.findPrimitiveNumberType(r)}static findPrimitiveNumberType(e){if(u(e)||Array.isArray(e)||"object"==typeof e)throw new Pe(Q.format("Unable to convert $ to a number.",e));let t=e;try{let e=t;return Number.isInteger(e)?new se(c.LONG,e):new se(c.DOUBLE,e)}catch(e){throw new Pe(Q.format("Unable to convert $ to a number.",t),e)}}static compare(e,t){if(e==t)return 0;if(u(e)||u(t))return u(e)?-1:1;if(Array.isArray(e)||Array.isArray(t)){if(Array.isArray(e)&&Array.isArray(t)){if(e.length!=t.length)return e.length-t.length;for(let r=0;r<e.length;r++){let s=this.compare(e[r],t[r]);if(0!=s)return s}return 0}return Array.isArray(e)?-1:1}const r=typeof e,s=typeof t;return"object"===r||"object"===s?("object"===r&&"object"===s&&Object.keys(e).forEach((r=>{let s=this.compare(e[r],t[r]);if(0!=s)return s})),"object"===r?-1:1):this.comparePrimitive(e,t)}static comparePrimitive(e,t){return u(e)||u(t)?u(e)&&u(t)?0:u(e)?-1:1:e==t?0:"boolean"==typeof e||"boolean"==typeof t?e?-1:1:"string"==typeof e||"string"==typeof t?e+""<t+""?-1:1:"number"==typeof e||"number"==typeof t?e-t:0}static baseNumberType(e){return Number.isInteger(e)?c.LONG:c.DOUBLE}static toPrimitiveType(e){return e}constructor(){}}class xt extends Je{apply(e,t){const r=Nt.findPrimitiveNullAsBoolean(e),s=Nt.findPrimitiveNullAsBoolean(t);if(r.getT1()!=c.BOOLEAN)throw new Pe(Q.format("Boolean value expected but found $",r.getT2()));if(s.getT1()!=c.BOOLEAN)throw new Pe(Q.format("Boolean value expected but found $",s.getT2()));return r.getT2()&&s.getT2()}}var Rt={};t(Rt,"LogicalEqualOperator",(()=>vt));class vt extends Je{apply(e,t){const r=Nt.findPrimitiveNullAsBoolean(e),s=Nt.findPrimitiveNullAsBoolean(t);return r.getT2()==s.getT2()}}var It={};t(It,"LogicalGreaterThanEqualOperator",(()=>yt));class yt extends Je{apply(e,t){const r=Nt.findPrimitiveNullAsBoolean(e),s=Nt.findPrimitiveNullAsBoolean(t);if(r.getT1()==c.BOOLEAN||s.getT1()==c.BOOLEAN)throw new Pe(Q.format("Cannot compare >= with the values $ and $",r.getT2(),s.getT2()));return r.getT2()>=s.getT2()}}var Mt={};t(Mt,"LogicalGreaterThanOperator",(()=>Pt));class Pt extends Je{apply(e,t){const r=Nt.findPrimitiveNullAsBoolean(e),s=Nt.findPrimitiveNullAsBoolean(t);if(r.getT1()==c.BOOLEAN||s.getT1()==c.BOOLEAN)throw new Pe(Q.format("Cannot compare > with the values $ and $",r.getT2(),s.getT2()));return r.getT2()>s.getT2()}}var _t={};t(_t,"LogicalLessThanEqualOperator",(()=>Lt));class Lt extends Je{apply(e,t){const r=Nt.findPrimitiveNullAsBoolean(e),s=Nt.findPrimitiveNullAsBoolean(t);if(r.getT1()==c.BOOLEAN||s.getT1()==c.BOOLEAN)throw new Pe(Q.format("Cannot compare <= with the values $ and $",r.getT2(),s.getT2()));return r.getT2()<=s.getT2()}}var Ct={};t(Ct,"LogicalLessThanOperator",(()=>bt));class bt extends Je{apply(e,t){const r=Nt.findPrimitiveNullAsBoolean(e),s=Nt.findPrimitiveNullAsBoolean(t);if(r.getT1()==c.BOOLEAN||s.getT1()==c.BOOLEAN)throw new Pe(Q.format("Cannot compare < with the values $ and $",r.getT2(),s.getT2()));return r.getT2()<s.getT2()}}var Ut={};t(Ut,"LogicalNotEqualOperator",(()=>Vt));class Vt extends Je{apply(e,t){const r=Nt.findPrimitiveNullAsBoolean(e),s=Nt.findPrimitiveNullAsBoolean(t);return r.getT2()!=s.getT2()}}var Bt={};t(Bt,"LogicalOrOperator",(()=>Dt));class Dt extends Je{apply(e,t){const r=Nt.findPrimitiveNullAsBoolean(e),s=Nt.findPrimitiveNullAsBoolean(t);if(r.getT1()!=c.BOOLEAN)throw new Pe(Q.format("Boolean value expected but found $",r.getT2()));if(s.getT1()!=c.BOOLEAN)throw new Pe(Q.format("Boolean value expected but found $",s.getT2()));return r.getT2()||s.getT2()}}var Gt={};t(Gt,"ObjectOperator",(()=>kt));class kt extends Je{apply(e,t){if(!e)throw new Pe("Cannot apply array operator on a null value");if(!t)throw new Pe("Cannot retrive null property value");const r=typeof e;if(!Array.isArray(e)&&"string"!=r&&"object"!=r)throw new Pe(Q.format("Cannot retrieve value from a primitive value $",e));return e[t]}}var Ft={};t(Ft,"ArithmeticUnaryMinusOperator",(()=>$t));var Ht={};t(Ht,"UnaryOperator",(()=>Yt));class Yt{nullCheck(e,t){if(u(e))throw new Pe(Q.format("$ cannot be applied to a null value",t.getOperatorName()))}}class $t extends Yt{apply(e){return this.nullCheck(e,$e.UNARY_MINUS),Nt.findPrimitiveNumberType(e),-e}}var Wt={};t(Wt,"ArithmeticUnaryPlusOperator",(()=>jt));class jt extends Yt{apply(e){return this.nullCheck(e,$e.UNARY_PLUS),Nt.findPrimitiveNumberType(e),e}}var Xt={};t(Xt,"BitwiseComplementOperator",(()=>qt));class qt extends Yt{apply(e){this.nullCheck(e,$e.UNARY_BITWISE_COMPLEMENT);let t=Nt.findPrimitiveNumberType(e);if(t.getT1()!=c.INTEGER&&t.getT1()!=c.LONG)throw new Pe(Q.format("Unable to apply bitwise operator on $",e));return~e}}var Jt={};t(Jt,"LogicalNotOperator",(()=>Qt));class Qt extends Yt{apply(e){if(this.nullCheck(e,$e.UNARY_LOGICAL_NOT),Nt.findPrimitiveNumberType(e).getT1()!=c.BOOLEAN)throw new Pe(Q.format("Unable to apply bitwise operator on $",e));return!e}}var Kt={};t(Kt,"LiteralTokenValueExtractor",(()=>tr));var zt={};t(zt,"TokenValueExtractor",(()=>Zt));class Zt{static REGEX_SQUARE_BRACKETS=/[\[\]]/;static REGEX_DOT=/\./;getValue(e){let t=this.getPrefix();if(!e.startsWith(t))throw new U(Q.format("Token $ doesn't start with $",e,t));return this.getValueInternal(e)}retrieveElementFrom(e,t,r,s){if(u(s))return;if(t.length==r)return s;let n=t[r].split(Zt.REGEX_SQUARE_BRACKETS).map((e=>e.trim())).filter((e=>!ee.isNullOrBlank(e))).reduce(((s,n,a)=>this.resolveForEachPartOfTokenWithBrackets(e,t,r,n,s,a)),s);return this.retrieveElementFrom(e,t,r+1,n)}resolveForEachPartOfTokenWithBrackets(e,t,r,s,n,a){if(!u(n)){if(0===a){if(Array.isArray(n)){if("length"===s)return n.length;try{let e=parseInt(s);if(isNaN(e))throw new Error(Q.format("$ is not a number",e));if(e>=n.length)return;return n[e]}catch(t){throw new De(e,Q.format("$ couldn't be parsed into integer in $",s,e),t)}}return this.checkIfObject(e,t,r,n),n[s]}if(s?.startsWith('"')){if(!s.endsWith('"')||1==s.length||2==s.length)throw new De(e,Q.format("$ is missing a double quote or empty key found",e));return this.checkIfObject(e,t,r,n),n[s.substring(1,s.length-1)]}try{let t=parseInt(s);if(isNaN(t))throw new Error(Q.format("$ is not a number",t));if(!Array.isArray(n))throw new De(e,Q.format("Expecting an array with index $ while processing the expression",t,e));if(t>=n.length)return;return n[t]}catch(t){throw new De(e,Q.format("$ couldn't be parsed into integer in $",s,e),t)}}}checkIfObject(e,t,r,s){if("object"!=typeof s||Array.isArray(s))throw new De(e,Q.format("Unable to retrive $ from $ in the path $",t[r],s.toString(),e))}}const er=new Map([["true",!0],["false",!1],["null",void 0]]);class tr extends Zt{static INSTANCE=new tr;getValueInternal(e){if(!ee.isNullOrBlank(e))return e=e.trim(),er.has(e)?er.get(e):e.startsWith('"')?this.processString(e):this.processNumbers(e)}processNumbers(e){try{let t;if(t=-1==e.indexOf(".")?parseInt(e):parseFloat(e),isNaN(t))throw new Error("Parse number error");return t}catch(t){throw new De(e,Q.format("Unable to parse the literal or expression $",e),t)}}processString(e){if(!e.endsWith('"'))throw new De(e,Q.format("String literal $ is not closed properly",e));return e.substring(1,e.length-1)}getPrefix(){return""}}class rr{static UNARY_OPERATORS_MAP=new Map([[$e.UNARY_BITWISE_COMPLEMENT,new qt],[$e.UNARY_LOGICAL_NOT,new Qt],[$e.UNARY_MINUS,new $t],[$e.UNARY_PLUS,new jt]]);static BINARY_OPERATORS_MAP=new Map([[$e.ADDITION,new Qe],[$e.DIVISION,new ze],[$e.INTEGER_DIVISION,new et],[$e.MOD,new rt],[$e.MULTIPLICATION,new nt],[$e.SUBTRACTION,new it],[$e.BITWISE_AND,new pt],[$e.BITWISE_LEFT_SHIFT,new mt],[$e.BITWISE_OR,new gt],[$e.BITWISE_RIGHT_SHIFT,new Et],[$e.BITWISE_UNSIGNED_RIGHT_SHIFT,new dt],[$e.BITWISE_XOR,new St],[$e.AND,new xt],[$e.EQUAL,new vt],[$e.GREATER_THAN,new Pt],[$e.GREATER_THAN_EQUAL,new yt],[$e.LESS_THAN,new bt],[$e.LESS_THAN_EQUAL,new Lt],[$e.OR,new Dt],[$e.NOT_EQUAL,new Vt],[$e.ARRAY_OPERATOR,new ut],[$e.OBJECT_OPERATOR,new kt]]);static UNARY_OPERATORS_MAP_KEY_SET=new Set(rr.UNARY_OPERATORS_MAP.keys());constructor(e){e instanceof We?(this.exp=e,this.expression=this.exp.getExpression()):this.expression=e}evaluate(e){return this.exp||(this.exp=new We(this.expression)),this.evaluateExpression(this.exp,e)}getExpression(){return this.exp||(this.exp=new We(this.expression)),this.exp}getExpressionString(){return this.expression}evaluateExpression(e,t){let r=e.getOperations(),s=e.getTokens();for(;!r.isEmpty();){let e=r.pop(),i=s.pop();if(rr.UNARY_OPERATORS_MAP_KEY_SET.has(e))s.push(this.applyUnaryOperation(e,this.getValueFromToken(t,i)));else if(e==$e.OBJECT_OPERATOR||e==$e.ARRAY_OPERATOR)this.processObjectOrArrayOperator(t,r,s,e,i);else{const r=s.pop();var n=this.getValueFromToken(t,r),a=this.getValueFromToken(t,i);s.push(this.applyBinaryOperation(e,n,a))}}if(s.isEmpty())throw new Pe(Q.format("Expression : $ evaluated to null",e));if(1!=s.size())throw new Pe(Q.format("Expression : $ evaluated multiple values $",e,s));const i=s.get(0);if(i instanceof He)return i.getElement();if(!(i instanceof We))return this.getValueFromToken(t,i);throw new Pe(Q.format("Expression : $ evaluated to $",e,s.get(0)))}processObjectOrArrayOperator(e,t,r,s,n){const a=new Ce,i=new Ce;if(!s||!n)return;do{i.push(s),n instanceof We?a.push(new He(n.toString(),this.evaluateExpression(n,e))):n&&a.push(n),n=r.isEmpty()?void 0:r.pop(),s=t.isEmpty()?void 0:t.pop()}while(s==$e.OBJECT_OPERATOR||s==$e.ARRAY_OPERATOR);n&&(n instanceof We?a.push(new He(n.toString(),this.evaluateExpression(n,e))):a.push(n)),s&&t.push(s);let o=a.pop(),u=new Ve(o instanceof He?o.getTokenValue():o.toString());for(;!a.isEmpty();)o=a.pop(),s=i.pop(),u.append(s.getOperator()).append(o instanceof He?o.getTokenValue():o.toString()),s==$e.ARRAY_OPERATOR&&u.append("]");let l=u.toString(),p=l.substring(0,l.indexOf(".")+1);if(p.length>2&&e.has(p))r.push(new He(l,this.getValue(l,e)));else{let e;try{e=tr.INSTANCE.getValue(l)}catch(t){e=l}r.push(new He(l,e))}}applyBinaryOperation(e,t,r){if("object"===typeof t||"object"===typeof r||Array.isArray(t)||Array.isArray(r))throw new De(this.expression,Q.format("Cannot evaluate expression $ $ $",t,e.getOperator(),r));let s=rr.BINARY_OPERATORS_MAP.get(e);if(!s)throw new De(this.expression,Q.format("No operator found to evaluate $ $ $",t,e.getOperator(),r));return new He(e.toString(),s.apply(t,r))}applyUnaryOperation(e,t){if("object"===typeof t||Array.isArray(t))throw new De(this.expression,Q.format("The operator $ cannot be applied to $",e.getOperator(),t));let r=rr.UNARY_OPERATORS_MAP.get(e);if(!r)throw new De(this.expression,Q.format("No Unary operator $ is found to apply on $",e.getOperator(),t));return new He(e.toString(),r.apply(t))}getValueFromToken(e,t){return t instanceof We?this.evaluateExpression(t,e):t instanceof He?t.getElement():this.getValue(t.getExpression(),e)}getValue(e,t){if(e.length<=5)return tr.INSTANCE.getValue(e);const r=e.substring(0,e.indexOf(".")+1);return(t.get(r)??tr.INSTANCE).getValue(e)}}const sr=new j("Set").setNamespace(a.SYSTEM_CTX).setParameters(new Map([P.ofEntry("name",(new N).setName("name").setType(O.of(c.STRING)).setMinLength(1),!1,y.CONSTANT),P.ofEntry("value",N.ofAny("value"))])).setEvents(new Map([k.outputEventMapEntry(new Map)]));const nr=new j("GenerateEvent").setNamespace(a.SYSTEM).setParameters(new Map([P.ofEntry("eventName",N.ofString("eventName")),P.ofEntry("results",N.ofObject("results").setProperties(new Map([["name",N.ofString("name")],["value",P.EXPRESSION]])),!0)])).setEvents(new Map([k.outputEventMapEntry(new Map)]));class ar extends ve{static CONDITION="condition";static SIGNATURE=new j("If").setNamespace(a.SYSTEM).setParameters(new Map([P.ofEntry(ar.CONDITION,N.of(ar.CONDITION,c.BOOLEAN))])).setEvents(new Map([k.eventMapEntry(k.TRUE,new Map),k.eventMapEntry(k.FALSE,new Map),k.outputEventMapEntry(new Map)]));getSignature(){return ar.SIGNATURE}async internalExecute(e){var t=e.getArguments()?.get(ar.CONDITION);return new $([H.of(t?k.TRUE:k.FALSE,new Map),H.outputOf(new Map)])}}const ir=new j("CountLoop").setNamespace(a.SYSTEM_LOOP).setParameters(new Map([P.ofEntry("count",N.of("count",c.INTEGER).setDefaultValue(1))])).setEvents(new Map([k.eventMapEntry(k.ITERATION,new Map([["index",N.of("index",c.INTEGER)]])),k.outputEventMapEntry(new Map([["value",N.of("value",c.INTEGER)]]))]));const or=new j("RangeLoop").setNamespace(a.SYSTEM_LOOP).setParameters(new Map([P.ofEntry("from",N.of("from",c.INTEGER,c.LONG,c.FLOAT,c.DOUBLE).setDefaultValue(0)),P.ofEntry("to",N.of("to",c.INTEGER,c.LONG,c.FLOAT,c.DOUBLE).setDefaultValue(1)),P.ofEntry("step",N.of("step",c.INTEGER,c.LONG,c.FLOAT,c.DOUBLE).setDefaultValue(1).setNot((new N).setConstant(0)))])).setEvents(new Map([k.eventMapEntry(k.ITERATION,new Map([["index",N.of("index",c.INTEGER,c.LONG,c.FLOAT,c.DOUBLE)]])),k.outputEventMapEntry(new Map([["value",N.of("value",c.INTEGER,c.LONG,c.FLOAT,c.DOUBLE)]]))]));const ur=new j("Add").setNamespace(a.MATH).setParameters(new Map([["value",new P("value",N.ofNumber("value")).setVariableArgument(!0)]])).setEvents(new Map([k.outputEventMapEntry(new Map([["value",N.ofNumber("value")]]))]));const lr=[()=>new Map([["value",new P("value",N.ofNumber("value"))]]),()=>new Map([["value1",new P("value1",N.ofNumber("value1"))],["value2",new P("value2",N.ofNumber("value2"))]])];class pr extends ve{constructor(e,t,r=1,...s){super(),s&&s.length||(s=[c.DOUBLE]),this.parametersNumber=r,this.mathFunction=t,this.signature=new j(e).setNamespace(a.MATH).setParameters(lr[r-1]()).setEvents(new Map([k.outputEventMapEntry(new Map([["value",(new N).setType(O.of(...s)).setName("value")]]))]))}getSignature(){return this.signature}async internalExecute(e){let t,r=Nt.findPrimitiveNumberType(e.getArguments()?.get(1==this.parametersNumber?"value":"value1")).getT2();return 2==this.parametersNumber&&(t=Nt.findPrimitiveNumberType(e.getArguments()?.get("value2")).getT2()),new $([H.outputOf(new Map([["value",this.mathFunction.call(this,r,t)]]))])}}class hr extends ve{static SIGNATURE=new j("Hypotenuse").setNamespace(a.MATH).setParameters(new Map([["value",new P("value",N.ofNumber("value")).setVariableArgument(!0)]])).setEvents(new Map([k.outputEventMapEntry(new Map([["value",(new N).setType(O.of(c.DOUBLE)).setName("value")]]))]));constructor(){super()}getSignature(){return hr.SIGNATURE}async internalExecute(e){let t=e.getArguments()?.get("value");return new $([H.outputOf(new Map([["value",Math.sqrt(t.reduce(((e,t)=>e+t*t),0))]]))])}}const mr=new j("Maximum").setNamespace(a.MATH).setParameters(new Map([["value",new P("value",N.ofNumber("value")).setVariableArgument(!0)]])).setEvents(new Map([k.outputEventMapEntry(new Map([["value",N.ofNumber("value")]]))]));const cr=new j("Minimum").setNamespace(a.MATH).setParameters(new Map([["value",new P("value",N.ofNumber("value")).setVariableArgument(!0)]])).setEvents(new Map([k.outputEventMapEntry(new Map([["value",N.ofNumber("value")]]))]));var gr={};t(gr,"MapUtil",(()=>fr)),t(gr,"MapEntry",(()=>Er));class fr{static of(e,t,r,s,n,a,i,o,l,p,h,m,c,g,f,E,T,d,A,S){const w=new Map;return u(e)||u(t)||w.set(e,t),u(r)||u(s)||w.set(r,s),u(n)||u(a)||w.set(n,a),u(i)||u(o)||w.set(i,o),u(l)||u(p)||w.set(l,p),u(h)||u(m)||w.set(h,m),u(c)||u(g)||w.set(c,g),u(f)||u(E)||w.set(f,E),u(T)||u(d)||w.set(T,d),u(A)||u(S)||w.set(A,S),w}static ofArrayEntries(...e){const t=new Map;for(const[r,s]of e)t.set(r,s);return t}static entry(e,t){return new Er(e,t)}static ofEntries(...e){const t=new Map;for(const r of e)t.set(r.k,r.v);return t}constructor(){}}class Er{constructor(e,t){this.k=e,this.v=t}}class Tr extends ve{static SIGNATURE=new j("Random").setNamespace(a.MATH).setEvents(new Map([k.outputEventMapEntry(fr.of("value",N.ofDouble("value")))]));getSignature(){return Tr.SIGNATURE}async internalExecute(e){return new $([H.outputOf(new Map([["value",Math.random()]]))])}}const dr={Absolute:new pr("Absolute",(e=>Math.abs(e)),1,c.INTEGER,c.LONG,c.FLOAT,c.DOUBLE),ACosine:new pr("ArcCosine",(e=>Math.acos(e))),ASine:new pr("ArcSine",(e=>Math.asin(e))),ATangent:new pr("ArcTangent",(e=>Math.atan(e))),Ceiling:new pr("Ceiling",(e=>Math.ceil(e))),Cosine:new pr("Cosine",(e=>Math.cos(e))),CosineH:new pr("HyperbolicCosine",(e=>Math.cosh(e))),CubeRoot:new pr("CubeRoot",(e=>Math.cbrt(e))),Exponential:new pr("Exponential",(e=>Math.exp(e))),Expm1:new pr("ExponentialMinus1",(e=>Math.expm1(e))),Floor:new pr("Floor",(e=>Math.floor(e))),Log:new pr("LogNatural",(e=>Math.log(e))),Log10:new pr("Log10",(e=>Math.log10(e))),Round:new pr("Round",(e=>Math.round(e)),1,c.INTEGER,c.LONG),Sine:new pr("Sine",(e=>Math.sin(e))),SineH:new pr("HyperbolicSine",(e=>Math.sinh(e))),Tangent:new pr("Tangent",(e=>Math.tan(e))),TangentH:new pr("HyperbolicTangent",(e=>Math.tanh(e))),ToDegrees:new pr("ToDegrees",(e=>e*(Math.PI/180))),ToRadians:new pr("ToRadians",(e=>e*(180/Math.PI))),SquareRoot:new pr("SquareRoot",(e=>Math.sqrt(e))),ArcTangent:new pr("ArcTangent2",((e,t)=>Math.atan2(e,t)),2),Power:new pr("Power",((e,t)=>Math.pow(e,t)),2),Add:new class extends ve{getSignature(){return ur}async internalExecute(e){let t=e.getArguments()?.get("value");return new $([H.outputOf(new Map([["value",t.reduce(((e,t)=>e+t),0)]]))])}},Hypotenuse:new hr,Maximum:new class extends ve{getSignature(){return mr}async internalExecute(e){let t=e.getArguments()?.get("value");return new $([H.outputOf(new Map([["value",t.reduce(((e,t)=>!e&&0!==e||t>e?t:e))]]))])}},Minimum:new class extends ve{getSignature(){return cr}async internalExecute(e){let t=e.getArguments()?.get("value");return new $([H.outputOf(new Map([["value",t.reduce(((e,t)=>!e&&0!==e||t<e?t:e))]]))])}},Random:new Tr};class Ar{find(e,t){if(e==a.MATH)return dr[t]}}var Sr={};t(Sr,"HybridRepository",(()=>wr));class wr{constructor(...e){this.repos=e}find(e,t){for(let r of this.repos){let s=r.find(e,t);if(s)return s}}}function Or(e){return[e.getSignature().getName(),e]}const Nr=new Map([[a.SYSTEM_CTX,new Map([Or(new class extends ve{getSignature(){return Ie}async internalExecute(e){const t=e?.getArguments()?.get("name");if(e?.getContext()?.has(t))throw new U(Q.format("Context already has an element for '$' ",t));let r=N.from(e?.getArguments()?.get("schema"));if(!r)throw new U("Schema is not supplied.");return e.getContext().set(t,new q(r,u(r.getDefaultValue())?void 0:r.getDefaultValue())),new $([H.outputOf(new Map)])}}),Or(new class extends ve{getSignature(){return ye}async internalExecute(e){const t=e?.getArguments()?.get("name");if(!e.getContext()?.has(t))throw new U(Q.format("Context don't have an element for '$' ",t));return new $([H.outputOf(new Map(["value",e.getContext()?.get(t)?.getElement()]))])}}),Or(new class extends ve{getSignature(){return sr}async internalExecute(e){let t=e?.getArguments()?.get("name");if(ee.isNullOrBlank(t))throw new U("Empty string is not a valid name for the context element");let r=e?.getArguments()?.get("value");const s=new We(t),n=s.getTokens().peekLast();if(!n.getExpression().startsWith("Context")||n instanceof We||n instanceof He&&!n.getElement().toString().startsWith("Context"))throw new Pe(Q.format("The context path $ is not a valid path in context",t));for(const e of s.getOperations().toArray())if(e!=$e.ARRAY_OPERATOR&&e!=$e.OBJECT_OPERATOR)throw new Pe(Q.format("Expected a reference to the context location, but found an expression $",t));for(let r=0;r<s.getTokens().size();r++){let n=s.getTokens().get(r);n instanceof We&&s.getTokens().set(r,new He(t,new rr(n).evaluate(e.getValuesMap())))}return this.modifyContext(e,t,r,s)}modifyContext(e,t,r,s){const n=s.getTokens();n.removeLast();const a=s.getOperations();a.removeLast();let i=e.getContext()?.get(n.removeLast().getExpression());if(u(i))throw new U(Q.format("Context doesn't have any element with name '$' ",t));if(a.isEmpty())return i.setElement(r),new $([H.outputOf(new Map)]);let o=i.getElement(),l=a.removeLast(),p=n.removeLast(),h=p instanceof He?p.getElement():p.getExpression();for(u(o)&&(o=l==$e.OBJECT_OPERATOR?{}:[],i.setElement(o));!a.isEmpty();)o=l==$e.OBJECT_OPERATOR?this.getDataFromObject(o,h,a.peekLast()):this.getDataFromArray(o,h,a.peekLast()),l=a.removeLast(),p=n.removeLast(),h=p instanceof He?p.getElement():p.getExpression();return l==$e.OBJECT_OPERATOR?this.putDataInObject(o,h,r):this.putDataInArray(o,h,r),new $([H.outputOf(new Map)])}getDataFromArray(e,t,r){if(!Array.isArray(e))throw new U(Q.format("Expected an array but found $",e));const s=parseInt(t);if(isNaN(s))throw new U(Q.format("Expected an array index but found $",t));if(s<0)throw new U(Q.format("Array index is out of bound - $",t));let n=e[s];return u(n)&&(n=r==$e.OBJECT_OPERATOR?{}:[],e[s]=n),n}getDataFromObject(e,t,r){if(Array.isArray(e)||"object"!=typeof e)throw new U(Q.format("Expected an object but found $",e));let s=e[t];return u(s)&&(s=r==$e.OBJECT_OPERATOR?{}:[],e[t]=s),s}putDataInArray(e,t,r){if(!Array.isArray(e))throw new U(Q.format("Expected an array but found $",e));const s=parseInt(t);if(isNaN(s))throw new U(Q.format("Expected an array index but found $",t));if(s<0)throw new U(Q.format("Array index is out of bound - $",t));e[s]=r}putDataInObject(e,t,r){if(Array.isArray(e)||"object"!=typeof e)throw new U(Q.format("Expected an object but found $",e));e[t]=r}})])],[a.SYSTEM_LOOP,new Map([Or(new class extends ve{getSignature(){return or}async internalExecute(e){let t=e.getArguments()?.get("from"),r=e.getArguments()?.get("to"),s=e.getArguments()?.get("step");const n=s>0;let a=t,i=!1;return new $({next(){if(i)return;if(n&&a>=r||!n&&a<=r)return i=!0,H.outputOf(new Map([["value",a]]));const e=H.of(k.ITERATION,new Map([["index",a]]));return a+=s,e}})}}),Or(new class extends ve{getSignature(){return ir}async internalExecute(e){let t=e.getArguments()?.get("count"),r=0;return new $({next(){if(r>=t)return H.outputOf(new Map([["value",r]]));const e=H.of(k.ITERATION,new Map([["index",r]]));return++r,e}})}})])],[a.SYSTEM,new Map([Or(new ar),Or(new class extends ve{getSignature(){return nr}async internalExecute(e){const t=e.getEvents(),r=e.getArguments()?.get("eventName"),s=e?.getArguments()?.get("results").map((t=>{let r=t.value;if(u(r))throw new U("Expect a value object");let s=r.value;return r.isExpression&&(s=new rr(s).evaluate(e.getValuesMap())),[t.name,s]})).reduce(((e,t)=>(e.set(t[0],t[1]),e)),new Map);return t?.has(r)||t?.set(r,[]),t?.get(r)?.push(s),new $([H.outputOf(new Map)])}})])]]);class xr extends wr{constructor(){super({find:(e,t)=>Nr.get(e)?.get(t)},new Ar)}}var Rr={};t(Rr,"ArrayUtil",(()=>vr));class vr{static removeAListFrom(e,t){if(!(t&&e&&e.length&&t.length))return;const r=new Set(t);for(let t=0;t<e.length;t++)r.has(e[t])&&(e.splice(t,1),t--)}static of(...e){const t=new Array(e.length);for(let r=0;r<e.length;r++)t[r]=e[r];return t}constructor(){}}var Ir={};t(Ir,"StatementExecution",(()=>Pr));var yr={};t(yr,"StatementMessage",(()=>Mr));class Mr{constructor(e,t){this.message=t,this.messageType=e}getMessageType(){return this.messageType}setMessageType(e){return this.messageType=e,this}getMessage(){return this.message}setMessage(e){return this.message=e,this}toString(){return`${this.messageType} : ${this.message}`}}class Pr{messages=new Array;dependencies=new Set;constructor(e){this.statement=e}getStatement(){return this.statement}setStatement(e){return this.statement=e,this}getMessages(){return this.messages}setMessages(e){return this.messages=e,this}getDependencies(){return this.dependencies}setDependencies(e){return this.dependencies=e,this}getUniqueKey(){return this.statement.getStatementName()}addMessage(e,t){this.messages.push(new Mr(e,t))}addDependency(e){this.dependencies.add(e)}getDepenedencies(){return this.dependencies}equals(e){if(!(e instanceof Pr))return!1;return e.statement.equals(this.statement)}}var _r={};t(_r,"ContextTokenValueExtractor",(()=>Lr));class Lr extends Zt{static PREFIX="Context.";constructor(e){super(),this.context=e}getValueInternal(e){let t=e.split(Zt.REGEX_DOT),r=t[1],s=r.indexOf("["),n=2;return-1!=s&&(r=t[1].substring(0,s),t[1]=t[1].substring(s),n=1),this.retrieveElementFrom(e,t,n,this.context.get(r)?.getElement())}getPrefix(){return Lr.PREFIX}}var Cr={};t(Cr,"OutputMapTokenValueExtractor",(()=>br));class br extends Zt{static PREFIX="Steps.";constructor(e){super(),this.output=e}getValueInternal(e){let t=e.split(Zt.REGEX_DOT),r=1,s=this.output.get(t[r++]);if(!s||r>=t.length)return;let n=s.get(t[r++]);if(!n||r>=t.length)return;let a=n.get(t[r++]);return this.retrieveElementFrom(e,t,r,a)}getPrefix(){return br.PREFIX}}var Ur={};t(Ur,"ArgumentsTokenValueExtractor",(()=>Vr));class Vr extends Zt{static PREFIX="Arguments.";constructor(e){super(),this.args=e}getValueInternal(e){let t=e.split(Zt.REGEX_DOT);return this.retrieveElementFrom(e,t,2,this.args.get(t[1]))}getPrefix(){return Vr.PREFIX}}var Br={};t(Br,"GraphVertex",(()=>kr));var Dr={};t(Dr,"ExecutionGraph",(()=>Gr));class Gr{nodeMap=new Map;constructor(e=!1){this.isSubGrph=e}getVerticesData(){return Array.from(this.nodeMap.values()).map((e=>e.getData()))}addVertex(e){if(!this.nodeMap.has(e.getUniqueKey())){let t=new kr(this,e);this.nodeMap.set(e.getUniqueKey(),t)}return this.nodeMap.get(e.getUniqueKey())}getVertex(e){return this.nodeMap.get(e)}getVertexData(e){if(this.nodeMap.has(e))return this.nodeMap.get(e).getData()}getVerticesWithNoIncomingEdges(){return Array.from(this.nodeMap.values()).filter((e=>!e.hasIncomingEdges()))}isCyclic(){let e,t=new Ce(this.getVerticesWithNoIncomingEdges()),r=new Set;for(;!t.isEmpty();){if(r.has(t.getFirst().getKey()))return!0;e=t.removeFirst(),r.add(e.getKey()),e.hasOutgoingEdges()&&t.addAll(Array.from(e.getOutVertices().values()).flatMap((e=>Array.from(e))))}return!1}addVertices(e){for(const t of e)this.addVertex(t)}getNodeMap(){return this.nodeMap}isSubGraph(){return this.isSubGrph}toString(){return"Execution Graph : \n"+Array.from(this.nodeMap.values()).map((e=>e.toString())).join("\n")}}class kr{outVertices=new Map;inVertices=new Set;constructor(e,t){this.data=t,this.graph=e}getData(){return this.data}setData(e){return this.data=e,this}getOutVertices(){return this.outVertices}setOutVertices(e){return this.outVertices=e,this}getInVertices(){return this.inVertices}setInVertices(e){return this.inVertices=e,this}getGraph(){return this.graph}setGraph(e){return this.graph=e,this}getKey(){return this.data.getUniqueKey()}addOutEdgeTo(e,t){return this.outVertices.has(e)||this.outVertices.set(e,new Set),this.outVertices.get(e).add(t),t.inVertices.add(new se(this,e)),t}addInEdgeTo(e,t){return this.inVertices.add(new se(e,t)),e.outVertices.has(t)||e.outVertices.set(t,new Set),e.outVertices.get(t).add(this),e}hasIncomingEdges(){return!!this.inVertices.size}hasOutgoingEdges(){return!!this.outVertices.size}getSubGraphOfType(e){let t=new Gr(!0);var r=new Ce(Array.from(this.outVertices.get(e)??[]));for(r.map((e=>e.getData())).forEach((e=>t.addVertex(e)));!r.isEmpty();){var s=r.pop();Array.from(s.outVertices.values()).flatMap((e=>Array.from(e))).forEach((e=>{t.addVertex(e.getData()),r.add(e)}))}return t}toString(){var e=Array.from(this.getInVertices()).map((e=>e.getT1().getKey()+"("+e.getT2()+")")).join(", "),t=Array.from(this.outVertices.entries()).map((([e,t])=>e+": "+Array.from(t).map((e=>e.getKey())).join(","))).join("\n\t\t");return this.getKey()+":\n\tIn: "+e+"\n\tOut: \n\t\t"+t}}var Fr={};t(Fr,"KIRuntime",(()=>zr));var Hr={};t(Hr,"JsonExpression",(()=>Yr));class Yr{constructor(e){this.expression=e}getExpression(){return this.expression}}var $r={};let Wr;var jr;t($r,"ParameterReferenceType",(()=>Wr)),(jr=Wr||(Wr={})).VALUE="VALUE",jr.EXPRESSION="EXPRESSION";var Xr={};t(Xr,"FunctionExecutionParameters",(()=>qr));class qr{count=0;valueExtractors=new Map;constructor(e,t,r){var s;this.functionRepository=e,this.schemaRepository=t,this.executionId=r??(s=(new Date).getTime(),"xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g,(function(e){var t=(s+16*Math.random())%16|0;return s=Math.floor(s/16),("x"==e?t:3&t|8).toString(16)})))}getExecutionId(){return this.executionId}getContext(){return this.context}setContext(e){this.context=e;let t=new Lr(e);return this.valueExtractors.set(t.getPrefix(),t),this}getArguments(){return this.args}setArguments(e){this.args=e;let t=new Vr(e);return this.valueExtractors.set(t.getPrefix(),t),this}getEvents(){return this.events}setEvents(e){return this.events=e,this}getStatementExecution(){return this.statementExecution}setStatementExecution(e){return this.statementExecution=e,this}getSteps(){return this.steps}setSteps(e){this.steps=e;let t=new br(e);return this.valueExtractors.set(t.getPrefix(),t),this}getCount(){return this.count}setCount(e){return this.count=e,this}getValuesMap(){return this.valueExtractors}getFunctionRepository(){return this.functionRepository}setFunctionRepository(e){return this.functionRepository=e,this}getSchemaRepository(){return this.schemaRepository}setSchemaRepository(e){return this.schemaRepository=e,this}addTokenValueExtractor(...e){for(const t of e)this.valueExtractors.set(t.getPrefix(),t);return this}setValuesMap(e){for(const[t,r]of e.entries())this.valueExtractors.set(t,r);return this}}var Jr={};let Qr;var Kr;t(Jr,"StatementMessageType",(()=>Qr)),(Kr=Qr||(Qr={})).ERROR="ERROR",Kr.WARNING="WARNING",Kr.MESSAGE="MESSAGE";class zr extends ve{static PARAMETER_NEEDS_A_VALUE='Parameter "$" needs a value';static STEP_REGEX_PATTERN=new RegExp("Steps\\.([a-zA-Z0-9\\\\-]{1,})\\.([a-zA-Z0-9\\\\-]{1,})","g");static VERSION=1;static MAX_EXECUTION_ITERATIONS=1e7;constructor(e){if(super(),this.fd=e,this.fd.getVersion()>zr.VERSION)throw new U("Runtime is at a lower version "+zr.VERSION+" and trying to run code from version "+this.fd.getVersion()+".")}getSignature(){return this.fd}async getExecutionPlan(e){let t=new Gr;for(let r of Array.from(this.fd.getSteps().values()))t.addVertex(this.prepareStatementExecution(r,e.getFunctionRepository(),e.getSchemaRepository()));return new se(this.makeEdges(t),t)}async internalExecute(e){e.getContext()||e.setContext(new Map),e.getEvents()||e.setEvents(new Map),e.getSteps()||e.setSteps(new Map);let t=await this.getExecutionPlan(e),r=t.getT1();if(r.length)throw new U(Q.format("Found these unresolved dependencies : $ ",r.map((e=>Q.format("Steps.$.$",e.getT1(),e.getT2())))));let s=t.getT2().getVerticesData().filter((e=>e.getMessages().length)).map((e=>e.getStatement().getStatementName()+": \n"+e.getMessages().join(",")));if(s?.length)throw new U("Please fix the errors in the function definition before execution : \n"+s.join(",\n"));return await this.executeGraph(t.getT2(),e)}async executeGraph(e,t){let r=new Ce;r.addAll(e.getVerticesWithNoIncomingEdges());let s=new Ce;for(;!(r.isEmpty()&&s.isEmpty()||t.getEvents()?.has(k.OUTPUT));)if(await this.processBranchQue(t,r,s),await this.processExecutionQue(t,r,s),t.setCount(t.getCount()+1),t.getCount()==zr.MAX_EXECUTION_ITERATIONS)throw new U("Execution locked in an infinite loop");if(!e.isSubGraph()&&!t.getEvents()?.size)throw new U("No events raised");return new $(Array.from(t.getEvents()?.entries()??[]).flatMap((e=>e[1].map((t=>H.of(e[0],t))))))}async processExecutionQue(e,t,r){if(!t.isEmpty()){let s=t.pop();await this.allDependenciesResolvedVertex(s,e.getSteps())?await this.executeVertex(s,e,r,t,e.getFunctionRepository()):t.add(s)}}async processBranchQue(e,t,r){if(r.length){let s=r.pop();await this.allDependenciesResolvedTuples(s.getT2(),e.getSteps())?await this.executeBranch(e,t,s):r.add(s)}}async executeBranch(e,t,r){let s,n=r.getT4();do{await this.executeGraph(r.getT1(),e),s=r.getT3().next(),s&&(e.getSteps()?.has(n.getData().getStatement().getStatementName())||e.getSteps()?.set(n.getData().getStatement().getStatementName(),new Map),e.getSteps()?.get(n.getData().getStatement().getStatementName())?.set(s.getName(),await this.resolveInternalExpressions(s.getResult(),e)))}while(s&&s.getName()!=k.OUTPUT);s?.getName()==k.OUTPUT&&n.getOutVertices().has(k.OUTPUT)&&(n?.getOutVertices()?.get(k.OUTPUT)??[]).forEach((e=>t.add(e)))}async executeVertex(e,t,r,s,n){let a=e.getData().getStatement(),i=n.find(a.getNamespace(),a.getName());if(!i)throw new U(Q.format("$.$ function is not found.",a.getNamespace(),a.getName()));let o=i?.getSignature().getParameters(),u=this.getArgumentsFromParametersMap(t,a,o??new Map),l=t.getContext(),p=await i.execute(new qr(t.getFunctionRepository(),t.getSchemaRepository(),t.getExecutionId()).setValuesMap(t.getValuesMap()).setContext(l).setArguments(u).setEvents(t.getEvents()).setSteps(t.getSteps()).setStatementExecution(e.getData()).setCount(t.getCount())),h=p.next();if(!h)throw new U(Q.format("Executing $ returned no events",a.getStatementName()));let m=h.getName()==k.OUTPUT;if(t.getSteps()?.has(a.getStatementName())||t.getSteps().set(a.getStatementName(),new Map),t.getSteps().get(a.getStatementName()).set(h.getName(),this.resolveInternalExpressions(h.getResult(),t)),m){let t=e.getOutVertices().get(k.OUTPUT);t&&t.forEach((e=>s.add(e)))}else{let t=e.getSubGraphOfType(h.getName()),s=this.makeEdges(t);r.push(new ae(t,s,p,e))}}resolveInternalExpressions(e,t){return e?Array.from(e.entries()).map((e=>new se(e[0],this.resolveInternalExpression(e[1],t)))).reduce(((e,t)=>(e.set(t.getT1(),t.getT2()),e)),new Map):e}resolveInternalExpression(e,t){if(u(e)||"object"!=typeof e)return e;if(e instanceof Yr){return new rr(e.getExpression()).evaluate(t.getValuesMap())}if(Array.isArray(e)){let r=[];for(let s of e)r.push(this.resolveInternalExpression(s,t));return r}if("object"==typeof e){let r={};for(let s of Object.entries(e))r[s[0]]=this.resolveInternalExpression(s[1],t);return r}}allDependenciesResolvedTuples(e,t){for(let r of e){if(!t.has(r.getT1()))return!1;if(!t.get(r.getT1())?.get(r.getT2()))return!1}return!0}allDependenciesResolvedVertex(e,t){return!e.getInVertices().size||0==Array.from(e.getInVertices()).filter((e=>{let r=e.getT1().getData().getStatement().getStatementName(),s=e.getT2();return!(t.has(r)&&t.get(r)?.has(s))})).length}getArgumentsFromParametersMap(e,t,r){return Array.from(t.getParameterMap().entries()).map((t=>{let s,n=t[1];if(!n?.length)return new se(t[0],s);let a=r.get(t[0]);return a?(s=a.isVariableArgument()?n.map((t=>this.parameterReferenceEvaluation(e,t))).flatMap((e=>Array.isArray(e)?e:[e])):this.parameterReferenceEvaluation(e,n[0]),new se(t[0],s)):new se(t[0],void 0)})).filter((e=>!u(e.getT2()))).reduce(((e,t)=>(e.set(t.getT1(),t.getT2()),e)),new Map)}parameterReferenceEvaluation(e,t){let r;if(t.getType()==Wr.VALUE)r=this.resolveInternalExpression(t.getValue(),e);else if(t.getType()==Wr.EXPRESSION&&!ee.isNullOrBlank(t.getExpression())){r=new rr(t.getExpression()??"").evaluate(e.getValuesMap())}return r}prepareStatementExecution(e,t,r){let s=new Pr(e),n=t.find(e.getNamespace(),e.getName());if(!n)throw new U(Q.format("$.$ was not available",e.getNamespace(),e.getName()));let a=new Map(n.getSignature().getParameters());for(let t of Array.from(e.getParameterMap().entries())){let e=a.get(t[0]);if(!e)continue;let n=t[1];if(n.length){if(e.isVariableArgument())for(let t of n)this.parameterReferenceValidation(s,e,t,r);else{let t=n[0];this.parameterReferenceValidation(s,e,t,r)}a.delete(e.getParameterName())}else u(ue.getDefaultValue(e.getSchema(),r))&&s.addMessage(Qr.ERROR,Q.format(zr.PARAMETER_NEEDS_A_VALUE,e.getParameterName())),a.delete(e.getParameterName())}if(!u(s.getStatement().getDependentStatements()))for(let e of s.getStatement().getDependentStatements())s.addDependency(e);if(a.size)for(let e of Array.from(a.values()))u(ue.getDefaultValue(e.getSchema(),r))&&s.addMessage(Qr.ERROR,Q.format(zr.PARAMETER_NEEDS_A_VALUE,e.getParameterName()));return s}parameterReferenceValidation(e,t,r,s){if(r){if(r.getType()==Wr.VALUE){u(r.getValue())&&u(ue.getDefaultValue(t.getSchema(),s))&&e.addMessage(Qr.ERROR,Q.format(zr.PARAMETER_NEEDS_A_VALUE,t.getParameterName()));let n=new Ce;for(n.push(new se(t.getSchema(),r.getValue()));!n.isEmpty();){let t=n.pop();if(t.getT2()instanceof Yr)this.addDependencies(e,t.getT2().getExpression());else{if(u(t.getT1())||u(t.getT1().getType()))continue;if(t.getT1().getType()?.contains(c.ARRAY)&&Array.isArray(t.getT2())){let e=t.getT1().getItems();if(!e)continue;if(e.isSingleType())for(let r of t.getT2())n.push(new se(e.getSingleSchema(),r));else{let r=t.getT2();for(let t=0;t<r.length;t++)n.push(new se(e.getTupleSchema()[t],r[t]))}}else if(t.getT1().getType()?.contains(c.OBJECT)&&"object"==typeof t.getT2()){let r=t.getT1();if(r.getName()===P.EXPRESSION.getName()&&r.getNamespace()===P.EXPRESSION.getNamespace()){let r=t.getT2();r.isExpression&&this.addDependencies(e,r.value)}else if(r.getProperties())for(let e of Object.entries(t.getT2()))r.getProperties().has(e[0])&&n.push(new se(r.getProperties().get(e[0]),e[1]))}}}}else if(r.getType()==Wr.EXPRESSION)if(ee.isNullOrBlank(r.getExpression()))u(ue.getDefaultValue(t.getSchema(),s))&&e.addMessage(Qr.ERROR,Q.format(zr.PARAMETER_NEEDS_A_VALUE,t.getParameterName()));else try{this.addDependencies(e,r.getExpression())}catch(t){e.addMessage(Qr.ERROR,Q.format("Error evaluating $ : $",r.getExpression(),t))}}else u(ue.getDefaultValue(t.getSchema(),s))&&e.addMessage(Qr.ERROR,Q.format(zr.PARAMETER_NEEDS_A_VALUE,t.getParameterName()))}addDependencies(e,t){t&&Array.from(t.match(zr.STEP_REGEX_PATTERN)??[]).forEach((t=>e.addDependency(t)))}makeEdges(e){let t=e.getNodeMap().values(),r=[];for(let s of Array.from(t))for(let t of s.getData().getDependencies()){let n=t.indexOf(".",6),a=t.substring(6,n),i=t.indexOf(".",n+1),o=-1==i?t.substring(n+1):t.substring(n+1,i);e.getNodeMap().has(a)||r.push(new se(a,o));let u=e.getNodeMap().get(a);u&&s.addInEdgeTo(u,o)}return r}}var Zr={};t(Zr,"KIRunConstants",(()=>es));class es{static NAMESPACE="namespace";static NAME="name";static ID="id";constructor(){}}var ts={};t(ts,"Position",(()=>rs));class rs{static SCHEMA_NAME="Position";static SCHEMA=(new N).setNamespace(a.SYSTEM).setName(rs.SCHEMA_NAME).setType(O.of(c.OBJECT)).setProperties(new Map([["left",N.ofFloat("left")],["top",N.ofFloat("top")]]));constructor(e,t){this.left=e,this.top=t}getLeft(){return this.left}setLeft(e){return this.left=e,this}getTop(){return this.top}setTop(e){return this.top=e,this}static from(e){return e?new rs(e.left,e.top):new rs(-1,-1)}}var ss={};t(ss,"FunctionDefinition",(()=>cs));var ns={};t(ns,"Statement",(()=>ls));var as={};t(as,"AbstractStatement",(()=>is));class is{override=!1;getComment(){return this.comment}setComment(e){return this.comment=e,this}isOverride(){return this.override}setOverride(e){return this.override=e,this}getDescription(){return this.description}setDescription(e){return this.description=e,this}getPosition(){return this.position}setPosition(e){return this.position=e,this}}var os={};t(os,"ParameterReference",(()=>us));class us{static SCHEMA_NAME="ParameterReference";static SCHEMA=(new N).setNamespace(a.SYSTEM).setName(us.SCHEMA_NAME).setType(O.of(c.OBJECT)).setProperties(new Map([["value",N.ofAny("value")],["expression",N.ofString("expression")],["type",N.ofString("type").setEnums(["EXPRESSION","VALUE"])]]));constructor(e){this.type=e}getType(){return this.type}setType(e){return this.type=e,this}getValue(){return this.value}setValue(e){return this.value=e,this}getExpression(){return this.expression}setExpression(e){return this.expression=e,this}static ofExpression(e){return new us(Wr.EXPRESSION).setExpression(e)}static ofValue(e){return new us(Wr.VALUE).setValue(e)}static from(e){return e?Array.from(e).map((e=>new us(e.type).setValue(e.value).setExpression(e.expression))):[]}}class ls extends is{static SCHEMA_NAME="Statement";static SCHEMA=(new N).setNamespace(a.SYSTEM).setName(ls.SCHEMA_NAME).setType(O.of(c.OBJECT)).setProperties(new Map([["statementName",N.ofString("statementName")],["comment",N.ofString("comment")],["description",N.ofString("description")],["namespace",N.ofString("namespace")],["name",N.ofString("name")],["dependentStatements",N.ofArray("dependentstatement",N.ofString("dependentstatement"))],["parameterMap",(new N).setName("parameterMap").setAdditionalProperties((new h).setSchemaValue(N.ofArray("parameterReference",us.SCHEMA)))],["position",rs.SCHEMA]]));constructor(e,t,r){super(),this.statementName=e,this.namespace=t,this.name=r}getStatementName(){return this.statementName}setStatementName(e){return this.statementName=e,this}getNamespace(){return this.namespace}setNamespace(e){return this.namespace=e,this}getName(){return this.name}setName(e){return this.name=e,this}getParameterMap(){return this.parameterMap||(this.parameterMap=new Map),this.parameterMap}setParameterMap(e){return this.parameterMap=e,this}getDependentStatements(){return this.dependentStatements??[]}setDependentStatements(e){return this.dependentStatements=e,this}equals(e){if(!(e instanceof ls))return!1;return e.statementName==this.statementName}static ofEntry(e){return[e.statementName,e]}static from(e){return new ls(e.statementName,e.namespace,e.name).setParameterMap(new Map(Object.entries(e.parameterMap??{}).map((([e,t])=>[e,us.from(t)])))).setDependentStatements(e.dependentStatements).setPosition(rs.from(e.position)).setComment(e.comment).setDescription(e.description)}}var ps={};t(ps,"StatementGroup",(()=>hs));class hs extends is{static SCHEMA_NAME="StatementGroup";static SCHEMA=(new N).setNamespace(a.SYSTEM).setName(hs.SCHEMA_NAME).setType(O.of(c.OBJECT)).setProperties(new Map([["statementGroupName",N.ofString("statementGroupName")],["comment",N.ofString("comment")],["description",N.ofString("description")],["position",rs.SCHEMA]]));constructor(e){super(),this.statementGroupName=e}getStatementGroupName(){return this.statementGroupName}setStatementGroupName(e){return this.statementGroupName=e,this}static from(e){return new hs(e.statementGroupName).setPosition(rs.from(e.position)).setComment(e.comment).setDescription(e.description)}}const ms=(new N).setNamespace(a.SYSTEM).setName("FunctionDefinition").setProperties(new Map([["name",N.ofString("name")],["namespace",N.ofString("namespace")],["parameters",N.ofArray("parameters",P.SCHEMA)],["events",N.ofObject("events").setAdditionalProperties((new h).setSchemaValue(k.SCHEMA))],["steps",N.ofObject("steps").setAdditionalProperties((new h).setSchemaValue(ls.SCHEMA))]]));ms.getProperties()?.set("parts",N.ofArray("parts",ms));class cs extends j{static SCHEMA=ms;version=1;constructor(e){super(e)}getVersion(){return this.version}setVersion(e){return this.version=e,this}getSteps(){return this.steps??new Map}setSteps(e){return this.steps=e,this}getStepGroups(){return this.stepGroups}setStepGroups(e){return this.stepGroups=e,this}getParts(){return this.parts}setParts(e){return this.parts=e,this}static from(e){return e?new cs(e.name).setSteps(new Map(Object.values(e.steps??{}).filter((e=>!!e)).map((e=>[e.statementName,ls.from(e)])))).setStepGroups(new Map(Object.values(e.stepGroups??{}).filter((e=>!!e)).map((e=>[e.statementGroupName,hs.from(e)])))).setParts(Array.from(e.parts??[]).filter((e=>!!e)).map((e=>cs.from(e)))).setVersion(e.version??1).setEvents(new Map(Object.values(e.events??{}).filter((e=>!!e)).map((e=>[e.name,k.from(e)])))).setParameters(new Map(Object.values(e.parameters??{}).filter((e=>!!e)).map((e=>[e.parameterName,P.from(e)])))):new cs("unknown")}}var gs={};t(gs,"Argument",(()=>fs));class fs{argumentIndex=0;constructor(e,t,r){this.argumentIndex=e,this.name=t,this.value=r}getArgumentIndex(){return this.argumentIndex}setArgumentIndex(e){return this.argumentIndex=e,this}getName(){return this.name}setName(e){return this.name=e,this}getValue(){return this.value}setValue(e){return this.value=e,this}static of(e,t){return new fs(0,e,t)}}var Es={};e(Es,Ft),e(Es,Wt),e(Es,Xt),e(Es,Jt),e(Es,Ht);var Ts={};e(Ts,Xe),e(Ts,Ke),e(Ts,Ze),e(Ts,tt),e(Ts,st),e(Ts,at),e(Ts,ot),e(Ts,qe),e(Ts,lt),e(Ts,ht),e(Ts,ct),e(Ts,ft),e(Ts,Tt),e(Ts,At),e(Ts,wt),e(Ts,Rt),e(Ts,It),e(Ts,Mt),e(Ts,_t),e(Ts,Ut),e(Ts,Ct),e(Ts,Bt),e(Ts,Gt),e(module.exports,r),e(module.exports,C),e(module.exports,{}),e(module.exports,Ot),e(module.exports,gr),e(module.exports,o),e(module.exports,Le),e(module.exports,Ue),e(module.exports,J),e(module.exports,Z),e(module.exports,re),e(module.exports,Rr),e(module.exports,Ir),e(module.exports,yr),e(module.exports,X),e(module.exports,_r),e(module.exports,Cr),e(module.exports,Ur),e(module.exports,Br),e(module.exports,{}),e(module.exports,Dr),e(module.exports,Fr),e(module.exports,Jr),e(module.exports,Xr),e(module.exports,_e),e(module.exports,zt),e(module.exports,Kt),e(module.exports,je),e(module.exports,Ye),e(module.exports,Ge),e(module.exports,Be),e(module.exports,Fe),e(module.exports,{}),e(module.exports,K),e(module.exports,n),e(module.exports,Hr),e(module.exports,s),e(module.exports,de),e(module.exports,ge),e(module.exports,Ee),e(module.exports,me),e(module.exports,le),e(module.exports,Oe),e(module.exports,Se),e(module.exports,z),e(module.exports,ie),e(module.exports,R),e(module.exports,he),e(module.exports,i),e(module.exports,S),e(module.exports,f),e(module.exports,E),e(module.exports,T),e(module.exports,m),e(module.exports,p),e(module.exports,te),e(module.exports,V),e(module.exports,Sr),e(module.exports,Zr),e(module.exports,x),e(module.exports,Y),e(module.exports,ts),e(module.exports,ss),e(module.exports,$r),e(module.exports,F),e(module.exports,as),e(module.exports,ns),e(module.exports,{}),e(module.exports,ps),e(module.exports,W),e(module.exports,G),e(module.exports,I),e(module.exports,gs),e(module.exports,os),e(module.exports,Me),e(module.exports,b),e(module.exports,Es),e(module.exports,Ts);
1
+ function e(e,t){return Object.keys(t).forEach((function(r){"default"===r||"__esModule"===r||e.hasOwnProperty(r)||Object.defineProperty(e,r,{enumerable:!0,get:function(){return t[r]}})})),e}function t(e,t,r,s){Object.defineProperty(e,t,{get:r,set:s,enumerable:!0,configurable:!0})}var r={};t(r,"KIRunSchemaRepository",(()=>L));var s={};t(s,"Schema",(()=>N));var n={};t(n,"Namespaces",(()=>a));class a{static SYSTEM="System";static SYSTEM_CTX="System.Context";static SYSTEM_LOOP="System.Loop";static SYSTEM_ARRAY="System.Array";static MATH="System.Math";static STRING="System.String";constructor(){}}var i={};t(i,"ArraySchemaType",(()=>p));var o={};function u(e){return null==e}t(o,"isNullValue",(()=>u));class p{setSingleSchema(e){return this.singleSchema=e,this}setTupleSchema(e){return this.tupleSchema=e,this}getSingleSchema(){return this.singleSchema}getTupleSchema(){return this.tupleSchema}isSingleType(){return!u(this.singleSchema)}static of(...e){return 1==e.length?(new p).setSingleSchema(e[0]):(new p).setTupleSchema(e)}static from(e){if(!e)return;Array.isArray(e)&&p.of(...N.fromListOfSchemas(e));let t=N.from(e);return t?p.of(t):void 0}}var l={};t(l,"AdditionalPropertiesType",(()=>h));class h{getBooleanValue(){return this.booleanValue}getSchemaValue(){return this.schemaValue}setBooleanValue(e){return this.booleanValue=e,this}setSchemaValue(e){return this.schemaValue=e,this}static from(e){if(!e)return;const t=new h;return t.booleanValue=e.booleanValue,t.schemaValue=e.schemaValue,t}}var m={};let c;var g;t(m,"SchemaType",(()=>c)),(g=c||(c={})).INTEGER="Integer",g.LONG="Long",g.FLOAT="Float",g.DOUBLE="Double",g.STRING="String",g.OBJECT="Object",g.ARRAY="Array",g.BOOLEAN="Boolean",g.NULL="Null";var f={};t(f,"TypeUtil",(()=>O));var E={};t(E,"MultipleType",(()=>d));var T={};t(T,"Type",(()=>A));class A{}class d extends A{constructor(e){super(),this.type=e}getType(){return this.type}setType(e){return this.type=e,this}getAllowedSchemaTypes(){return this.type}contains(e){return this.type?.has(e)}}var S={};t(S,"SingleType",(()=>w));class w extends A{constructor(e){super(),this.type=e}getType(){return this.type}getAllowedSchemaTypes(){return new Set([this.type])}contains(e){return this.type==e}}class O{static of(...e){return 1==e.length?new w(e[0]):new d(new Set(e))}static from(e){return"string"==typeof e?new w(e):Array.isArray(e)?new d(new Set(e.map((e=>e)).map((e=>e)))):void 0}}class N{static NULL=(new N).setNamespace(a.SYSTEM).setName("Null").setType(O.of(c.NULL)).setConstant(void 0);static TYPE_SCHEMA=(new N).setType(O.of(c.STRING)).setEnums(["INTEGER","LONG","FLOAT","DOUBLE","STRING","OBJECT","ARRAY","BOOLEAN","NULL"]);static SCHEMA=(new N).setNamespace(a.SYSTEM).setName("Schema").setType(O.of(c.OBJECT)).setProperties(new Map([["namespace",N.of("namespace",c.STRING).setDefaultValue("_")],["name",N.ofString("name")],["version",N.of("version",c.INTEGER).setDefaultValue(1)],["ref",N.ofString("ref")],["type",(new N).setAnyOf([N.TYPE_SCHEMA,N.ofArray("type",N.TYPE_SCHEMA)])],["anyOf",N.ofArray("anyOf",N.ofRef("#/"))],["allOf",N.ofArray("allOf",N.ofRef("#/"))],["oneOf",N.ofArray("oneOf",N.ofRef("#/"))],["not",N.ofRef("#/")],["title",N.ofString("title")],["description",N.ofString("description")],["id",N.ofString("id")],["examples",N.ofAny("examples")],["defaultValue",N.ofAny("defaultValue")],["comment",N.ofString("comment")],["enums",N.ofArray("enums",N.ofString("enums"))],["constant",N.ofAny("constant")],["pattern",N.ofString("pattern")],["format",N.of("format",c.STRING).setEnums(["DATETIME","TIME","DATE","EMAIL","REGEX"])],["minLength",N.ofInteger("minLength")],["maxLength",N.ofInteger("maxLength")],["multipleOf",N.ofLong("multipleOf")],["minimum",N.ofNumber("minimum")],["maximum",N.ofNumber("maximum")],["exclusiveMinimum",N.ofNumber("exclusiveMinimum")],["exclusiveMaximum",N.ofNumber("exclusiveMaximum")],["properties",N.of("properties",c.OBJECT).setAdditionalProperties((new h).setSchemaValue(N.ofRef("#/")))],["additionalProperties",(new N).setName("additionalProperty").setNamespace(a.SYSTEM).setAnyOf([N.ofBoolean("additionalProperty"),N.ofObject("additionalProperty").setRef("#/")]).setDefaultValue(!0)],["required",N.ofArray("required",N.ofString("required")).setDefaultValue([])],["propertyNames",N.ofRef("#/")],["minProperties",N.ofInteger("minProperties")],["maxProperties",N.ofInteger("maxProperties")],["patternProperties",N.of("patternProperties",c.OBJECT).setAdditionalProperties((new h).setSchemaValue(N.ofRef("#/")))],["items",(new N).setName("items").setAnyOf([N.ofRef("#/").setName("item"),N.ofArray("tuple",N.ofRef("#/"))])],["contains",N.ofRef("#/")],["minItems",N.ofInteger("minItems")],["maxItems",N.ofInteger("maxItems")],["uniqueItems",N.ofBoolean("uniqueItems")],["$defs",N.of("$defs",c.OBJECT).setAdditionalProperties((new h).setSchemaValue(N.ofRef("#/")))],["permission",N.ofString("permission")]])).setRequired([]);static ofString(e){return(new N).setType(O.of(c.STRING)).setName(e)}static ofInteger(e){return(new N).setType(O.of(c.INTEGER)).setName(e)}static ofFloat(e){return(new N).setType(O.of(c.FLOAT)).setName(e)}static ofLong(e){return(new N).setType(O.of(c.LONG)).setName(e)}static ofDouble(e){return(new N).setType(O.of(c.DOUBLE)).setName(e)}static ofAny(e){return(new N).setType(O.of(c.INTEGER,c.LONG,c.FLOAT,c.DOUBLE,c.STRING,c.BOOLEAN,c.ARRAY,c.NULL,c.OBJECT)).setName(e)}static ofAnyNotNull(e){return(new N).setType(O.of(c.INTEGER,c.LONG,c.FLOAT,c.DOUBLE,c.STRING,c.BOOLEAN,c.ARRAY,c.OBJECT)).setName(e)}static ofNumber(e){return(new N).setType(O.of(c.INTEGER,c.LONG,c.FLOAT,c.DOUBLE)).setName(e)}static ofBoolean(e){return(new N).setType(O.of(c.BOOLEAN)).setName(e)}static of(e,...t){return(new N).setType(O.of(...t)).setName(e)}static ofObject(e){return(new N).setType(O.of(c.OBJECT)).setName(e)}static ofRef(e){return(new N).setRef(e)}static ofArray(e,...t){return(new N).setType(O.of(c.ARRAY)).setName(e).setItems(p.of(...t))}static fromListOfSchemas(e){if(u(e)&&!Array.isArray(e))return[];let t=[];for(let r of Array.from(e)){let e=N.from(r);e&&t.push(e)}return t}static fromMapOfSchemas(e){if(u(e))return;const t=new Map;return Object.entries(e).forEach((([e,r])=>{let s=N.from(r);s&&t.set(e,s)})),t}static from(e,t=!1){if(u(e))return;let r=new N;return r.namespace=e.namespace??"_",r.name=e.name,r.version=e.version??1,r.ref=e.ref,r.type=t?new w(c.STRING):O.from(e.type),r.anyOf=N.fromListOfSchemas(e.anyOf),r.allOf=N.fromListOfSchemas(e.allOf),r.oneOf=N.fromListOfSchemas(e.oneOf),r.not=N.from(e.not),r.description=e.description,r.examples=e.examples?[...e.examples]:void 0,r.defaultValue=e.defaultValue,r.comment=e.comment,r.enums=e.enums?[...e.enums]:void 0,r.constant=e.constant,r.pattern=e.pattern,r.format=e.format,r.minLength=e.minLength,r.maxLength=e.maxLength,r.multipleOf=e.multipleOf,r.minimum=e.minimum,r.maximum=e.maximum,r.exclusiveMinimum=e.exclusiveMinimum,r.exclusiveMaximum=e.exclusiveMaximum,r.properties=N.fromMapOfSchemas(e.properties),r.additionalProperties=h.from(e.additionalProperties),r.required=e.required,r.propertyNames=N.from(e.propertyNames,!0),r.minProperties=e.minProperties,r.maxProperties=e.maxProperties,r.patternProperties=N.fromMapOfSchemas(e.patternProperties),r.items=p.from(e.items),r.contains=N.from(e.contains),r.minItems=e.minItems,r.maxItems=e.maxItems,r.uniqueItems=e.uniqueItems,r.$defs=N.fromMapOfSchemas(e.$defs),r.permission=e.permission,r}namespace="_";version=1;getTitle(){return this.getFullName()}getFullName(){return this.namespace&&"_"!=this.namespace?this.namespace+"."+this.name:this.name}get$defs(){return this.$defs}set$defs(e){return this.$defs=e,this}getNamespace(){return this.namespace}setNamespace(e){return this.namespace=e,this}getName(){return this.name}setName(e){return this.name=e,this}getVersion(){return this.version}setVersion(e){return this.version=e,this}getRef(){return this.ref}setRef(e){return this.ref=e,this}getType(){return this.type}setType(e){return this.type=e,this}getAnyOf(){return this.anyOf}setAnyOf(e){return this.anyOf=e,this}getAllOf(){return this.allOf}setAllOf(e){return this.allOf=e,this}getOneOf(){return this.oneOf}setOneOf(e){return this.oneOf=e,this}getNot(){return this.not}setNot(e){return this.not=e,this}getDescription(){return this.description}setDescription(e){return this.description=e,this}getExamples(){return this.examples}setExamples(e){return this.examples=e,this}getDefaultValue(){return this.defaultValue}setDefaultValue(e){return this.defaultValue=e,this}getComment(){return this.comment}setComment(e){return this.comment=e,this}getEnums(){return this.enums}setEnums(e){return this.enums=e,this}getConstant(){return this.constant}setConstant(e){return this.constant=e,this}getPattern(){return this.pattern}setPattern(e){return this.pattern=e,this}getFormat(){return this.format}setFormat(e){return this.format=e,this}getMinLength(){return this.minLength}setMinLength(e){return this.minLength=e,this}getMaxLength(){return this.maxLength}setMaxLength(e){return this.maxLength=e,this}getMultipleOf(){return this.multipleOf}setMultipleOf(e){return this.multipleOf=e,this}getMinimum(){return this.minimum}setMinimum(e){return this.minimum=e,this}getMaximum(){return this.maximum}setMaximum(e){return this.maximum=e,this}getExclusiveMinimum(){return this.exclusiveMinimum}setExclusiveMinimum(e){return this.exclusiveMinimum=e,this}getExclusiveMaximum(){return this.exclusiveMaximum}setExclusiveMaximum(e){return this.exclusiveMaximum=e,this}getProperties(){return this.properties}setProperties(e){return this.properties=e,this}getAdditionalProperties(){return this.additionalProperties}setAdditionalProperties(e){return this.additionalProperties=e,this}getRequired(){return this.required}setRequired(e){return this.required=e,this}getPropertyNames(){return this.propertyNames}setPropertyNames(e){return this.propertyNames=e,this.propertyNames.type=new w(c.STRING),this}getMinProperties(){return this.minProperties}setMinProperties(e){return this.minProperties=e,this}getMaxProperties(){return this.maxProperties}setMaxProperties(e){return this.maxProperties=e,this}getPatternProperties(){return this.patternProperties}setPatternProperties(e){return this.patternProperties=e,this}getItems(){return this.items}setItems(e){return this.items=e,this}getContains(){return this.contains}setContains(e){return this.contains=e,this}getMinItems(){return this.minItems}setMinItems(e){return this.minItems=e,this}getMaxItems(){return this.maxItems}setMaxItems(e){return this.maxItems=e,this}getUniqueItems(){return this.uniqueItems}setUniqueItems(e){return this.uniqueItems=e,this}getPermission(){return this.permission}setPermission(e){return this.permission=e,this}}var x={};t(x,"Parameter",(()=>P));var R={};t(R,"SchemaReferenceException",(()=>I));class I extends Error{constructor(e,t,r){super(e.trim()?e+"-"+t:t),this.schemaPath=e,this.cause=r}getSchemaPath(){return this.schemaPath}getCause(){return this.cause}}var y={};let v;var M;t(y,"ParameterType",(()=>v)),(M=v||(v={})).CONSTANT="CONSTANT",M.EXPRESSION="EXPRESSION";class P{static SCHEMA_NAME="Parameter";static SCHEMA=(new N).setNamespace(a.SYSTEM).setName(P.SCHEMA_NAME).setProperties(new Map([["schema",N.SCHEMA],["parameterName",N.ofString("parameterName")],["variableArgument",N.of("variableArgument",c.BOOLEAN).setDefaultValue(!1)],["type",N.ofString("type").setEnums(["EXPRESSION","CONSTANT"])]]));static EXPRESSION=(new N).setNamespace(a.SYSTEM).setName("ParameterExpression").setType(O.of(c.OBJECT)).setProperties(new Map([["isExpression",N.ofBoolean("isExpression").setDefaultValue(!0)],["value",N.ofAny("value")]]));variableArgument=!1;type=v.EXPRESSION;constructor(e,t){this.schema=t,this.parameterName=e}getSchema(){return this.schema}setSchema(e){return this.schema=e,this}getParameterName(){return this.parameterName}setParameterName(e){return this.parameterName=e,this}isVariableArgument(){return this.variableArgument}setVariableArgument(e){return this.variableArgument=e,this}getType(){return this.type}setType(e){return this.type=e,this}static ofEntry(e,t,r=!1,s=v.EXPRESSION){return[e,new P(e,t).setType(s).setVariableArgument(r)]}static of(e,t,r=!1,s=v.EXPRESSION){return new P(e,t).setType(s).setVariableArgument(r)}static from(e){const t=N.from(e.schema);if(!t)throw new I("","Parameter requires Schema");return new P(e.parameterName,t).setVariableArgument(!!e.variableArguments).setType(e.type??v.EXPRESSION)}}const _=new Map([["any",N.ofAny("any").setNamespace(a.SYSTEM)],["boolean",N.ofBoolean("boolean").setNamespace(a.SYSTEM)],["double",N.ofDouble("double").setNamespace(a.SYSTEM)],["float",N.ofFloat("float").setNamespace(a.SYSTEM)],["integer",N.ofInteger("integer").setNamespace(a.SYSTEM)],["long",N.ofLong("long").setNamespace(a.SYSTEM)],["number",N.ofNumber("number").setNamespace(a.SYSTEM)],["string",N.ofString("string").setNamespace(a.SYSTEM)],[P.EXPRESSION.getName(),P.EXPRESSION]]);class L{find(e,t){if(a.SYSTEM==e)return _.get(t)}}var C={};t(C,"KIRunFunctionRepository",(()=>vr));var b={};t(b,"KIRuntimeException",(()=>U));class U extends Error{constructor(e,t){super(e),this.cause=t}getCause(){return this.cause}}var V={};let B;var D;t(V,"StringFormat",(()=>B)),(D=B||(B={})).DATETIME="DATETIME",D.TIME="TIME",D.DATE="DATE",D.EMAIL="EMAIL",D.REGEX="REGEX";var G={};t(G,"Event",(()=>k));class k{static OUTPUT="output";static ERROR="error";static ITERATION="iteration";static TRUE="true";static FALSE="false";static SCHEMA_NAME="Event";static SCHEMA=(new N).setNamespace(a.SYSTEM).setName(k.SCHEMA_NAME).setType(O.of(c.OBJECT)).setProperties(new Map([["name",N.ofString("name")],["parameters",N.ofObject("parameter").setAdditionalProperties((new h).setSchemaValue(N.SCHEMA))]]));constructor(e,t){this.name=e,this.parameters=t}getName(){return this.name}setName(e){return this.name=e,this}getParameters(){return this.parameters}setParameters(e){return this.parameters=e,this}static outputEventMapEntry(e){return k.eventMapEntry(k.OUTPUT,e)}static eventMapEntry(e,t){return[e,new k(e,t)]}static from(e){return new k(e.name,new Map(Object.entries(e.parameters??{}).map((e=>{const t=N.from(e[1]);if(!t)throw new I("","Event expects a schema");return[e[0],t]}))))}}var F={};t(F,"EventResult",(()=>H));class H{constructor(e,t){this.name=e,this.result=t}getName(){return this.name}setName(e){return this.name=e,this}getResult(){return this.result}setResult(e){return this.result=e,this}static outputOf(e){return H.of(k.OUTPUT,e)}static of(e,t){return new H(e,t)}}var Y={};t(Y,"FunctionOutput",(()=>$));class ${index=0;constructor(e){if(u(e))throw new U("Function output is generating null");Array.isArray(e)&&e.length&&e[0]instanceof H?this.fo=e:(this.fo=[],this.generator=e)}next(){if(!this.generator)return this.index<this.fo.length?this.fo[this.index++]:void 0;const e=this.generator.next();return e&&this.fo.push(e),e}allResults(){return this.fo}}var W={};t(W,"FunctionSignature",(()=>j));class j{static SCHEMA_NAME="FunctionSignature";static SCHEMA=(new N).setNamespace(a.SYSTEM).setName(j.SCHEMA_NAME).setProperties(new Map([["name",N.ofString("name")],["namespace",N.ofString("namespace")],["parameters",N.ofObject("parameters").setAdditionalProperties((new h).setSchemaValue(P.SCHEMA))],["events",N.ofObject("events").setAdditionalProperties((new h).setSchemaValue(k.SCHEMA))]]));namespace="_";parameters=new Map;events=new Map;constructor(e){this.name=e}getNamespace(){return this.namespace}setNamespace(e){return this.namespace=e,this}getName(){return this.name}setName(e){return this.name=e,this}getParameters(){return this.parameters}setParameters(e){return this.parameters=e,this}getEvents(){return this.events}setEvents(e){return this.events=e,this}}var X={};t(X,"ContextElement",(()=>q));class q{static NULL=new q(N.NULL,void 0);constructor(e,t){this.schema=e,this.element=t}getSchema(){return this.schema}setSchema(e){return this.schema=e,this}getElement(){return this.element}setElement(e){return this.element=e,this}}var J={};t(J,"StringFormatter",(()=>Q));class Q{static format(e,...t){if(!t||0==t.length)return e;let r="",s=0,n="",a=n,i=e.length;for(let o=0;o<i;o++)n=e.charAt(o),"$"==n&&"\\"==a?r=r.substring(0,o-1)+n:"$"==n&&s<t.length?r+=t[s++]:r+=n,a=n;return r.toString()}constructor(){}}var K={};t(K,"AbstractFunction",(()=>Ie));var z={};t(z,"SchemaValidator",(()=>Re));var Z={};t(Z,"StringUtil",(()=>ee));class ee{constructor(){}static nthIndex(e,t,r=0,s){if(!e)throw new U("String cannot be null");if(r<0||r>=e.length)throw new U(Q.format("Cannot search from index : $",r));if(s<=0||s>e.length)throw new U(Q.format("Cannot search for occurance : $",s));for(;r<e.length;){if(e.charAt(r)==t&&0==--s)return r;++r}return-1}static splitAtFirstOccurance(e,t){if(!e)return[void 0,void 0];let r=e.indexOf(t);return-1==r?[e,void 0]:[e.substring(0,r),e.substring(r+1)]}static isNullOrBlank(e){return!e||""==e.trim()}}var te={};t(te,"SchemaUtil",(()=>ue));var re={};t(re,"Tuple2",(()=>se)),t(re,"Tuple3",(()=>ne)),t(re,"Tuple4",(()=>ae));class se{constructor(e,t){this.f=e,this.s=t}getT1(){return this.f}getT2(){return this.s}setT1(e){return this.f=e,this}setT2(e){return this.s=e,this}}class ne extends se{constructor(e,t,r){super(e,t),this.t=r}getT3(){return this.t}setT1(e){return this.f=e,this}setT2(e){return this.s=e,this}setT3(e){return this.t=e,this}}class ae extends ne{constructor(e,t,r,s){super(e,t,r),this.fr=s}getT4(){return this.fr}setT1(e){return this.f=e,this}setT2(e){return this.s=e,this}setT3(e){return this.t=e,this}setT4(e){return this.fr=e,this}}var ie={};t(ie,"SchemaValidationException",(()=>oe));class oe extends Error{constructor(e,t,r=[],s){super(t+(r?r.map((e=>e.message)).reduce(((e,t)=>e+"\n"+t),""):"")),this.schemaPath=e,this.cause=s}getSchemaPath(){return this.schemaPath}getCause(){return this.cause}}class ue{static UNABLE_TO_RETRIVE_SCHEMA_FROM_REFERENCED_PATH="Unable to retrive schema from referenced path";static CYCLIC_REFERENCE_LIMIT_COUNTER=20;static getDefaultValue(e,t){if(e)return e.getConstant()?e.getConstant():e.getDefaultValue()?e.getDefaultValue():ue.getDefaultValue(ue.getSchemaFromRef(e,t,e.getRef()),t)}static getSchemaFromRef(e,t,r,s=0){if(++s==ue.CYCLIC_REFERENCE_LIMIT_COUNTER)throw new oe(r??"","Schema has a cyclic reference");if(!e||!r||ee.isNullOrBlank(r))return;if(!r.startsWith("#")){var n=ue.resolveExternalSchema(e,t,r);n&&(e=n.getT1(),r=n.getT2())}let a=r.split("/");return 1===a.length?e:ue.resolveInternalSchema(e,t,r,s,a,1)}static resolveInternalSchema(e,t,r,s,n,a){let i=e;if(a!==n.length){for(;a<n.length;){if("$defs"===n[a]){if(++a>=n.length||!i.get$defs())throw new I(r,ue.UNABLE_TO_RETRIVE_SCHEMA_FROM_REFERENCED_PATH);i=i.get$defs()?.get(n[a])}else{if(i&&(!i.getType()?.contains(c.OBJECT)||!i.getProperties()))throw new I(r,"Cannot retrievie schema from non Object type schemas");i=i.getProperties()?.get(n[a])}if(a++,!i)throw new I(r,ue.UNABLE_TO_RETRIVE_SCHEMA_FROM_REFERENCED_PATH);if(!ee.isNullOrBlank(i.getRef())&&(i=ue.getSchemaFromRef(i,t,i.getRef(),s),!i))throw new I(r,ue.UNABLE_TO_RETRIVE_SCHEMA_FROM_REFERENCED_PATH)}return i}}static resolveExternalSchema(e,t,r){if(!t)return;let s=ee.splitAtFirstOccurance(e?.getRef()??"","/");if(!s[0])return;let n=ee.splitAtFirstOccurance(s[0],".");if(!n[0]||!n[1])return;let a=t.find(n[0],n[1]);if(a){if(!s[1]||""===s[1])return new se(a,r);if(r="#/"+s[1],!a)throw new I(r,ue.UNABLE_TO_RETRIVE_SCHEMA_FROM_REFERENCED_PATH);return new se(a,r)}}constructor(){}}var pe={};t(pe,"AnyOfAllOfOneOfValidator",(()=>le));class le{static validate(e,t,r,s){let n=[];return t.getOneOf()&&!t.getOneOf()?le.oneOf(e,t,r,s,n):t.getAllOf()&&!t.getAllOf()?le.allOf(e,t,r,s,n):t.getAnyOf()&&!t.getAnyOf()&&le.anyOf(e,t,r,s,n),s}static anyOf(e,t,r,s,n){let a=!1;for(let i of t.getAnyOf()??[])try{le.validate(e,i,r,s),a=!0;break}catch(e){a=!1,n.push(e)}if(!a)throw new oe(Re.path(e),"The value don't satisfy any of the schemas.",n)}static allOf(e,t,r,s,n){let a=0;for(let i of t.getAllOf()??[])try{le.validate(e,i,r,s),a++}catch(e){n.push(e)}if(a!==t.getAllOf()?.length)throw new oe(Re.path(e),"The value doesn't satisfy some of the schemas.",n)}static oneOf(e,t,r,s,n){let a=0;for(let i of t.getOneOf()??[])try{le.validate(e,i,r,s),a++}catch(e){n.push(e)}if(1!=a)throw new oe(Re.path(e),0==a?"The value does not satisfy any schema":"The value satisfy more than one schema",n)}constructor(){}}var he={};t(he,"TypeValidator",(()=>xe));var me={};t(me,"ArrayValidator",(()=>ce));class ce{static validate(e,t,r,s){if(u(s))throw new oe(Re.path(e),"Expected an array but found null");if(!Array.isArray(s))throw new oe(Re.path(e),s.toString()+" is not an Array");let n=s;return ce.checkMinMaxItems(e,t,n),ce.checkItems(e,t,r,n),ce.checkUniqueItems(e,t,n),ce.checkContains(e,t,r,n),s}static checkContains(e,t,r,s){if(!t.getContains())return;let n=!1;for(let a=0;a<s.length;a++){let i=e?[...e]:[];try{Re.validate(i,t.getContains(),r,s[a]),n=!0;break}catch(e){n=!1}}if(!n)throw new oe(Re.path(e),"None of the items are of type contains schema")}static checkUniqueItems(e,t,r){if(t.getUniqueItems()&&t.getUniqueItems()){if(new Set(r).size!==r.length)throw new oe(Re.path(e),"Items on the array are not unique")}}static checkMinMaxItems(e,t,r){if(t.getMinItems()&&t.getMinItems()>r.length)throw new oe(Re.path(e),"Array should have minimum of "+t.getMinItems()+" elements");if(t.getMaxItems()&&t.getMaxItems()<r.length)throw new oe(Re.path(e),"Array can have maximum of "+t.getMaxItems()+" elements")}static checkItems(e,t,r,s){if(!t.getItems())return;let n=t.getItems();if(n.getSingleSchema())for(let t=0;t<s.length;t++){let a=e?[...e]:[],i=Re.validate(a,n.getSingleSchema(),r,s[t]);s[t]=i}if(n.getTupleSchema()){if(n.getTupleSchema().length!==s.length)throw new oe(Re.path(e),"Expected an array with only "+n.getTupleSchema().length+" but found "+s.length);for(let t=0;t<s.length;t++){let a=e?[...e]:[],i=Re.validate(a,n.getTupleSchema()[t],r,s[t]);s[t]=i}}}constructor(){}}var ge={};t(ge,"BooleanValidator",(()=>fe));class fe{static validate(e,t,r){if(u(r))throw new oe(Re.path(e),"Expected a boolean but found null");if("boolean"!=typeof r)throw new oe(Re.path(e),r.toString()+" is not a boolean");return r}constructor(){}}var Ee={};t(Ee,"NullValidator",(()=>Te));class Te{static validate(e,t,r){if(r)throw new oe(Re.path(e),"Expected a null but found "+r);return r}constructor(){}}var Ae={};t(Ae,"NumberValidator",(()=>de));class de{static validate(e,t,r,s){if(u(s))throw new oe(Re.path(t),"Expected a number but found null");if("number"!=typeof s)throw new oe(Re.path(t),s.toString()+" is not a "+e);let n=de.extractNumber(e,t,r,s);return de.checkRange(t,r,s,n),de.checkMultipleOf(t,r,s,n),s}static extractNumber(e,t,r,s){let n=s;try{e!=c.LONG&&e!=c.INTEGER||(n=Math.round(n))}catch(r){throw new oe(Re.path(t),s+" is not a number of type "+e,r)}if(u(n)||(e==c.LONG||e==c.INTEGER)&&n!=s)throw new oe(Re.path(t),s.toString()+" is not a number of type "+e);return n}static checkMultipleOf(e,t,r,s){if(t.getMultipleOf()){if(s%t.getMultipleOf()!=0)throw new oe(Re.path(e),r.toString()+" is not multiple of "+t.getMultipleOf())}}static checkRange(e,t,r,s){if(t.getMinimum()&&de.numberCompare(s,t.getMinimum())<0)throw new oe(Re.path(e),r.toString()+" should be greater than or equal to "+t.getMinimum());if(t.getMaximum()&&de.numberCompare(s,t.getMaximum())>0)throw new oe(Re.path(e),r.toString()+" should be less than or equal to "+t.getMaximum());if(t.getExclusiveMinimum()&&de.numberCompare(s,t.getExclusiveMinimum())<=0)throw new oe(Re.path(e),r.toString()+" should be greater than "+t.getExclusiveMinimum());if(t.getExclusiveMaximum()&&de.numberCompare(s,t.getExclusiveMaximum())>0)throw new oe(Re.path(e),r.toString()+" should be less than "+t.getExclusiveMaximum())}static numberCompare(e,t){return e-t}constructor(){}}var Se={};t(Se,"ObjectValidator",(()=>we));class we{static validate(e,t,r,s){if(u(s))throw new oe(Re.path(e),"Expected an object but found null");if("object"!=typeof s||Array.isArray(s))throw new oe(Re.path(e),s.toString()+" is not an Object");let n=s,a=new Set(Object.keys(n));we.checkMinMaxProperties(e,t,a),t.getPropertyNames()&&we.checkPropertyNameSchema(e,t,r,a),t.getRequired()&&we.checkRequired(e,t,n),t.getProperties()&&we.checkProperties(e,t,r,n,a),t.getPatternProperties()&&we.checkPatternProperties(e,t,r,n,a),t.getAdditionalProperties()&&we.checkAddtionalProperties(e,t,r,n,a)}static checkPropertyNameSchema(e,t,r,s){for(let n of Array.from(s.values()))try{Re.validate(e,t.getPropertyNames(),r,n)}catch(t){throw new oe(Re.path(e),"Property name '"+n+"' does not fit the property schema")}}static checkRequired(e,t,r){for(const s of t.getRequired()??[])if(u(r[s]))throw new oe(Re.path(e),s+" is mandatory")}static checkAddtionalProperties(e,t,r,s,n){let a=t.getAdditionalProperties();if(a.getSchemaValue())for(let t of Array.from(n.values())){let n=e?[...e]:[],i=Re.validate(n,a.getSchemaValue(),r,s.get(t));s[t]=i}else if(!1===a.getBooleanValue()&&n.size)throw new oe(Re.path(e),n.toString()+" are additional properties which are not allowed.")}static checkPatternProperties(e,t,r,s,n){const a=new Map;for(const e of Array.from(t.getPatternProperties().keys()))a.set(e,new RegExp(e));for(const i of Array.from(n.values())){const o=e?[...e]:[];for(const e of Array.from(a.entries()))if(e[1].test(i)){const a=Re.validate(o,t.getPatternProperties().get(e[0]),r,s[i]);s[i]=a,n.delete(i);break}}}static checkProperties(e,t,r,s,n){for(const a of Array.from(t.getProperties())){let t=s[a[0]];if(u(t))continue;let i=e?[...e]:[],o=Re.validate(i,a[1],r,t);s[a[0]]=o,n.delete(a[0])}}static checkMinMaxProperties(e,t,r){if(t.getMinProperties()&&r.size<t.getMinProperties())throw new oe(Re.path(e),"Object should have minimum of "+t.getMinProperties()+" properties");if(t.getMaxProperties()&&r.size>t.getMaxProperties())throw new oe(Re.path(e),"Object can have maximum of "+t.getMaxProperties()+" properties")}constructor(){}}var Oe={};t(Oe,"StringValidator",(()=>Ne));class Ne{static TIME=/^([01]?[0-9]|2[0-3]):[0-5][0-9](:[0-5][0-9])?([+-][01][0-9]:[0-5][0-9])?$/;static DATE=/^[0-9]{4,4}-([0][0-9]|[1][0-2])-(0[1-9]|[1-2][1-9]|3[01])$/;static DATETIME=/^[0-9]{4,4}-([0][0-9]|[1][0-2])-(0[1-9]|[1-2][1-9]|3[01])T([01]?[0-9]|2[0-3]):[0-5][0-9](:[0-5][0-9])?([+-][01][0-9]:[0-5][0-9])?$/;static validate(e,t,r){if(u(r))throw new oe(Re.path(e),"Expected a string but found "+r);if("string"!=typeof r)throw new oe(Re.path(e),r.toString()+" is not String");t.getFormat()==B.TIME?Ne.patternMatcher(e,t,r,Ne.TIME,"time pattern"):t.getFormat()==B.DATE?Ne.patternMatcher(e,t,r,Ne.DATE,"date pattern"):t.getFormat()==B.DATETIME?Ne.patternMatcher(e,t,r,Ne.DATETIME,"date time pattern"):t.getPattern()&&Ne.patternMatcher(e,t,r,new RegExp(t.getPattern()),"pattern "+t.getPattern());let s=r.length;if(t.getMinLength()&&s<t.getMinLength())throw new oe(Re.path(e),"Expected a minimum of "+t.getMinLength()+" characters");if(t.getMaxLength()&&s>t.getMinLength())throw new oe(Re.path(e),"Expected a maximum of "+t.getMaxLength()+" characters");return r}static patternMatcher(e,t,r,s,n){if(!s.test(r))throw new oe(Re.path(e),r.toString()+" is not matched with the "+n)}constructor(){}}class xe{static validate(e,t,r,s,n){if(t==c.STRING)Ne.validate(e,r,n);else if(t==c.LONG||t==c.INTEGER||t==c.DOUBLE||t==c.FLOAT)de.validate(t,e,r,n);else if(t==c.BOOLEAN)fe.validate(e,r,n);else if(t==c.OBJECT)we.validate(e,r,s,n);else if(t==c.ARRAY)ce.validate(e,r,s,n);else{if(t!=c.NULL)throw new oe(Re.path(e),t+" is not a valid type.");Te.validate(e,r,n)}return n}constructor(){}}class Re{static path(e){return e?e.map((e=>e.getTitle()??"")).filter((e=>!!e)).reduce(((e,t,r)=>e+(0===r?"":".")+t),""):""}static validate(e,t,r,s){if(!t)throw new oe(Re.path(e),"No schema found to validate");if(e||(e=new Array),e.push(t),u(s)&&!u(t.getDefaultValue()))return JSON.parse(JSON.stringify(t.getDefaultValue()));if(t.getConstant())return Re.constantValidation(e,t,s);if(t.getEnums()&&!t.getEnums()?.length)return Re.enumCheck(e,t,s);if(t.getType()&&Re.typeValidation(e,t,r,s),!ee.isNullOrBlank(t.getRef()))return Re.validate(e,ue.getSchemaFromRef(e[0],r,t.getRef()),r,s);if((t.getOneOf()||t.getAllOf()||t.getAnyOf())&&le.validate(e,t,r,s),t.getNot()){let n=!1;try{Re.validate(e,t.getNot(),r,s),n=!0}catch(e){n=!1}if(n)throw new oe(Re.path(e),"Schema validated value in not condition.")}return s}static constantValidation(e,t,r){if(!t.getConstant().equals(r))throw new oe(Re.path(e),"Expecting a constant value : "+r);return r}static enumCheck(e,t,r){let s=!1;for(let e of t.getEnums()??[])if(e===r){s=!0;break}if(s)return r;throw new oe(Re.path(e),"Value is not one of "+t.getEnums())}static typeValidation(e,t,r,s){let n=!1,a=[];for(const i of Array.from(t.getType()?.getAllowedSchemaTypes()?.values()??[]))try{xe.validate(e,i,t,r,s),n=!0;break}catch(e){n=!1,a.push(e)}if(!n)throw new oe(Re.path(e),"Value "+JSON.stringify(s)+" is not of valid type(s)",a)}constructor(){}}class Ie{validateArguments(e,t){return Array.from(this.getSignature().getParameters().entries()).map((r=>{let s,n=r[0],a=r[1],i=e.get(r[0]);if(u(i))return new se(n,Re.validate(void 0,a.getSchema(),t,void 0));if(!a?.isVariableArgument())return new se(n,Re.validate(void 0,a.getSchema(),t,i));Array.isArray(i)?s=i:(s=[],s.push(i));for(const e of s)Re.validate(void 0,a.getSchema(),t,e);return new se(n,i)})).reduce(((e,t)=>(e.set(t.getT1(),t.getT2()),e)),new Map)}async execute(e){return e.setArguments(this.validateArguments(e.getArguments()??new Map,e.getSchemaRepository())),this.internalExecute(e)}getProbableEventSignature(e){return this.getSignature().getEvents()}}const ye=new j("Create").setNamespace(a.SYSTEM_CTX).setParameters(new Map([P.ofEntry("name",(new N).setName("name").setType(O.of(c.STRING)).setMinLength(1).setFormat(B.REGEX).setPattern("^[a-zA-Z_$][a-zA-Z_$0-9]*$"),!1,v.CONSTANT),P.ofEntry("schema",N.SCHEMA,!1,v.CONSTANT)])).setEvents(new Map([k.outputEventMapEntry(new Map)]));const ve=new j("Get").setNamespace(a.SYSTEM_CTX).setParameters(new Map([P.ofEntry("name",(new N).setName("name").setType(O.of(c.STRING)).setMinLength(1).setFormat(B.REGEX).setPattern("^[a-zA-Z_$][a-zA-Z_$0-9]*$"),!1,v.CONSTANT)])).setEvents(new Map([k.outputEventMapEntry(new Map([["value",N.ofAny("value")]]))]));var Me={};t(Me,"ExecutionException",(()=>Pe));class Pe extends Error{constructor(e,t){super(e),this.cause=t}getCause(){return this.cause}}var _e={};t(_e,"Expression",(()=>We));var Le={};t(Le,"LinkedList",(()=>Ce));class Ce{head=void 0;tail=void 0;length=0;constructor(e){if(e?.length){for(const t of e)if(this.head){const e=new be(t,this.tail);this.tail.next=e,this.tail=e}else this.tail=this.head=new be(t);this.length=e.length}}push(e){const t=new be(e,void 0,this.head);this.head?(this.head.previous=t,this.head=t):this.tail=this.head=t,this.length++}pop(){if(!this.head)throw Error("List is empty and cannot pop further.");const e=this.head.value;if(this.length--,this.head==this.tail)return this.head=this.tail=void 0,e;const t=this.head;return this.head=t.next,t.next=void 0,t.previous=void 0,this.head.previous=void 0,e}isEmpty(){return!this.length}size(){return this.length}get(e){if(e<0||e>=this.length)throw new Error(`${e} is out of bounds [0,${this.length}]`);let t=this.head;for(;e>0;)t=this.head.next,--e;return t.value}set(e,t){if(e<0||e>=this.length)throw new U(Q.format("Index $ out of bound to set the value in linked list.",e));let r=this.head;for(;e>0;)r=this.head.next,--e;return r.value=t,this}toString(){let e=this.head,t="";for(;e;)t+=e.value,e=e.next,e&&(t+=", ");return`[${t}]`}toArray(){let e=[],t=this.head;for(;t;)e.push(t.value),t=t.next;return e}peek(){if(!this.head)throw new Error("List is empty so cannot peak");return this.head.value}peekLast(){if(!this.tail)throw new Error("List is empty so cannot peak");return this.tail.value}getFirst(){if(!this.head)throw new Error("List is empty so cannot get first");return this.head.value}removeFirst(){return this.pop()}removeLast(){if(!this.tail)throw new Error("List is empty so cannot remove");--this.length;const e=this.tail.value;if(0==this.length)this.head=this.tail=void 0;else{const e=this.tail.previous;e.next=void 0,this.tail.previous=void 0,this.tail=e}return e}addAll(e){return e&&e.length?(e.forEach(this.add.bind(this)),this):this}add(e){return++this.length,this.tail||this.head?this.head===this.tail?(this.tail=new be(e,this.head),this.head.next=this.tail):(this.tail=new be(e,this.tail),this.tail.previous.next=this.tail):this.head=this.tail=new be(e),this}map(e,t){let r=new Ce,s=this.head,n=0;for(;s;)r.add(e(s.value,n)),s=s.next,++n;return r}forEach(e,t){let r=this.head,s=0;for(;r;)e(r.value,s),r=r.next,++s}}class be{constructor(e,t,r){this.value=e,this.next=r,this.previous=t}toString(){return""+this.value}}var Ue={};t(Ue,"StringBuilder",(()=>Ve));class Ve{constructor(e){this.str=e??""}append(e){return this.str+=e,this}toString(){return""+this.str}trim(){return this.str=this.str.trim(),this}setLength(e){return this.str=this.str.substring(0,e),this}length(){return this.str.length}charAt(e){return this.str.charAt(e)}deleteCharAt(e){return this.checkIndex(e),this.str=this.str.substring(0,e)+this.str.substring(e+1),this}insert(e,t){return this.str=this.str.substring(0,e)+t+this.str.substring(e),this}checkIndex(e){if(e>=this.str.length)throw new U(`Index ${e} is greater than or equal to ${this.str.length}`)}substring(e,t){return this.str.substring(e,t)}}var Be={};t(Be,"ExpressionEvaluationException",(()=>De));class De extends Error{constructor(e,t,r){super(Q.format("$ : $",e,t)),this.cause=r}getCause(){return this.cause}}var Ge={};t(Ge,"ExpressionToken",(()=>ke));class ke{constructor(e){this.expression=e}getExpression(){return this.expression}toString(){return this.expression}}var Fe={};t(Fe,"ExpressionTokenValue",(()=>He));class He extends ke{constructor(e,t){super(e),this.element=t}getTokenValue(){return this.element}getElement(){return this.element}toString(){return Q.format("$: $",this.expression,this.element)}}var Ye={};t(Ye,"Operation",(()=>$e));class $e{static MULTIPLICATION=new $e("*");static DIVISION=new $e("/");static INTEGER_DIVISION=new $e("//");static MOD=new $e("%");static ADDITION=new $e("+");static SUBTRACTION=new $e("-");static NOT=new $e("not",void 0,!0);static AND=new $e("and",void 0,!0);static OR=new $e("or",void 0,!0);static LESS_THAN=new $e("<");static LESS_THAN_EQUAL=new $e("<=");static GREATER_THAN=new $e(">");static GREATER_THAN_EQUAL=new $e(">=");static EQUAL=new $e("=");static NOT_EQUAL=new $e("!=");static BITWISE_AND=new $e("&");static BITWISE_OR=new $e("|");static BITWISE_XOR=new $e("^");static BITWISE_COMPLEMENT=new $e("~");static BITWISE_LEFT_SHIFT=new $e("<<");static BITWISE_RIGHT_SHIFT=new $e(">>");static BITWISE_UNSIGNED_RIGHT_SHIFT=new $e(">>>");static UNARY_PLUS=new $e("UN: +","+");static UNARY_MINUS=new $e("UN: -","-");static UNARY_LOGICAL_NOT=new $e("UN: not","not");static UNARY_BITWISE_COMPLEMENT=new $e("UN: ~","~");static ARRAY_OPERATOR=new $e("[");static OBJECT_OPERATOR=new $e(".");static NULLISH_COALESCING_OPERATOR=new $e("??");static VALUE_OF=new Map([["MULTIPLICATION",$e.MULTIPLICATION],["DIVISION",$e.DIVISION],["INTEGER_DIVISON",$e.INTEGER_DIVISION],["MOD",$e.MOD],["ADDITION",$e.ADDITION],["SUBTRACTION",$e.SUBTRACTION],["NOT",$e.NOT],["AND",$e.AND],["OR",$e.OR],["LESS_THAN",$e.LESS_THAN],["LESS_THAN_EQUAL",$e.LESS_THAN_EQUAL],["GREATER_THAN",$e.GREATER_THAN],["GREATER_THAN_EQUAL",$e.GREATER_THAN_EQUAL],["EQUAL",$e.EQUAL],["NOT_EQUAL",$e.NOT_EQUAL],["BITWISE_AND",$e.BITWISE_AND],["BITWISE_OR",$e.BITWISE_OR],["BITWISE_XOR",$e.BITWISE_XOR],["BITWISE_COMPLEMENT",$e.BITWISE_COMPLEMENT],["BITWISE_LEFT_SHIFT",$e.BITWISE_LEFT_SHIFT],["BITWISE_RIGHT_SHIFT",$e.BITWISE_RIGHT_SHIFT],["BITWISE_UNSIGNED_RIGHT_SHIFT",$e.BITWISE_UNSIGNED_RIGHT_SHIFT],["UNARY_PLUS",$e.UNARY_PLUS],["UNARY_MINUS",$e.UNARY_MINUS],["UNARY_LOGICAL_NOT",$e.UNARY_LOGICAL_NOT],["UNARY_BITWISE_COMPLEMENT",$e.UNARY_BITWISE_COMPLEMENT],["ARRAY_OPERATOR",$e.ARRAY_OPERATOR],["OBJECT_OPERATOR",$e.OBJECT_OPERATOR],["NULLISH_COALESCING_OPERATOR",$e.NULLISH_COALESCING_OPERATOR]]);static UNARY_OPERATORS=new Set([$e.ADDITION,$e.SUBTRACTION,$e.NOT,$e.BITWISE_COMPLEMENT,$e.UNARY_PLUS,$e.UNARY_MINUS,$e.UNARY_LOGICAL_NOT,$e.UNARY_BITWISE_COMPLEMENT]);static ARITHMETIC_OPERATORS=new Set([$e.MULTIPLICATION,$e.DIVISION,$e.INTEGER_DIVISION,$e.MOD,$e.ADDITION,$e.SUBTRACTION]);static LOGICAL_OPERATORS=new Set([$e.NOT,$e.AND,$e.OR,$e.LESS_THAN,$e.LESS_THAN_EQUAL,$e.GREATER_THAN,$e.GREATER_THAN_EQUAL,$e.EQUAL,$e.NOT_EQUAL,$e.NULLISH_COALESCING_OPERATOR]);static BITWISE_OPERATORS=new Set([$e.BITWISE_AND,$e.BITWISE_COMPLEMENT,$e.BITWISE_LEFT_SHIFT,$e.BITWISE_OR,$e.BITWISE_RIGHT_SHIFT,$e.BITWISE_UNSIGNED_RIGHT_SHIFT,$e.BITWISE_XOR]);static OPERATOR_PRIORITY=new Map([[$e.UNARY_PLUS,1],[$e.UNARY_MINUS,1],[$e.UNARY_LOGICAL_NOT,1],[$e.UNARY_BITWISE_COMPLEMENT,1],[$e.ARRAY_OPERATOR,1],[$e.OBJECT_OPERATOR,1],[$e.MULTIPLICATION,2],[$e.DIVISION,2],[$e.INTEGER_DIVISION,2],[$e.MOD,2],[$e.ADDITION,3],[$e.SUBTRACTION,3],[$e.BITWISE_LEFT_SHIFT,4],[$e.BITWISE_RIGHT_SHIFT,4],[$e.BITWISE_UNSIGNED_RIGHT_SHIFT,4],[$e.LESS_THAN,5],[$e.LESS_THAN_EQUAL,5],[$e.GREATER_THAN,5],[$e.GREATER_THAN_EQUAL,5],[$e.EQUAL,6],[$e.NOT_EQUAL,6],[$e.BITWISE_AND,7],[$e.BITWISE_XOR,8],[$e.BITWISE_OR,9],[$e.AND,10],[$e.OR,11],[$e.NULLISH_COALESCING_OPERATOR,11]]);static OPERATORS=new Set([...Array.from($e.ARITHMETIC_OPERATORS),...Array.from($e.LOGICAL_OPERATORS),...Array.from($e.BITWISE_OPERATORS),$e.ARRAY_OPERATOR,$e.OBJECT_OPERATOR].map((e=>e.getOperator())));static OPERATORS_WITHOUT_SPACE_WRAP=new Set([...Array.from($e.ARITHMETIC_OPERATORS),...Array.from($e.LOGICAL_OPERATORS),...Array.from($e.BITWISE_OPERATORS),$e.ARRAY_OPERATOR,$e.OBJECT_OPERATOR].filter((e=>!e.shouldBeWrappedInSpace())).map((e=>e.getOperator())));static OPERATION_VALUE_OF=new Map(Array.from($e.VALUE_OF.entries()).map((([e,t])=>[t.getOperator(),t])));static UNARY_MAP=new Map([[$e.ADDITION,$e.UNARY_PLUS],[$e.SUBTRACTION,$e.UNARY_MINUS],[$e.NOT,$e.UNARY_LOGICAL_NOT],[$e.BITWISE_COMPLEMENT,$e.UNARY_BITWISE_COMPLEMENT],[$e.UNARY_PLUS,$e.UNARY_PLUS],[$e.UNARY_MINUS,$e.UNARY_MINUS],[$e.UNARY_LOGICAL_NOT,$e.UNARY_LOGICAL_NOT],[$e.UNARY_BITWISE_COMPLEMENT,$e.UNARY_BITWISE_COMPLEMENT]]);static BIGGEST_OPERATOR_SIZE=Array.from($e.VALUE_OF.values()).map((e=>e.getOperator())).filter((e=>!e.startsWith("UN: "))).map((e=>e.length)).reduce(((e,t)=>e>t?e:t),0);constructor(e,t,r=!1){this.operator=e,this.operatorName=t??e,this._shouldBeWrappedInSpace=r}getOperator(){return this.operator}getOperatorName(){return this.operatorName}shouldBeWrappedInSpace(){return this._shouldBeWrappedInSpace}valueOf(e){return $e.VALUE_OF.get(e)}toString(){return this.operator}}class We extends ke{tokens=new Ce;ops=new Ce;constructor(e,t,r,s){super(e||""),t&&this.tokens.push(t),r&&this.tokens.push(r),s&&this.ops.push(s),this.evaluate()}getTokens(){return this.tokens}getOperations(){return this.ops}evaluate(){const e=this.expression.length;let t,r="",s=new Ve(""),n=0,a=!1;for(;n<e;){switch(r=this.expression[n],t=s.toString(),r){case" ":a=this.processTokenSepearator(s,t,a);break;case"(":n=this.processSubExpression(e,s,t,n,a),a=!1;break;case")":throw new De(this.expression,"Extra closing parenthesis found");case"]":throw new De(this.expression,"Extra closing square bracket found");case"'":case'"':{let t=this.processStringLiteral(e,r,n);n=t.getT1(),a=t.getT2();break}default:let i=this.processOthers(r,e,s,t,n,a);n=i.getT1(),a=i.getT2(),a&&this.ops.peek()==$e.ARRAY_OPERATOR&&(i=this.process(e,s,n),n=i.getT1(),a=i.getT2())}++n}if(t=s.toString(),!ee.isNullOrBlank(t)){if($e.OPERATORS.has(t))throw new De(this.expression,"Expression is ending with an operator");this.tokens.push(new ke(t))}}processStringLiteral(e,t,r){let s="",n=r+1;for(;n<e;n++){let e=this.expression.charAt(n);if(e==t&&"\\"!=this.expression.charAt(n-1))break;s+=e}if(n==e&&this.expression.charAt(n-1)!=t)throw new De(this.expression,"Missing string ending marker "+t);let a=new se(n,!1);return this.tokens.push(new He(s,s)),a}process(e,t,r){let s=1;for(++r;r<e&&0!=s;){let e=this.expression.charAt(r);"]"==e?--s:"["==e&&++s,0!=s&&(t.append(e),r++)}return this.tokens.push(new We(t.toString())),t.setLength(0),new se(r,!1)}processOthers(e,t,r,s,n,a){let i=t-n;i=i<$e.BIGGEST_OPERATOR_SIZE?i:$e.BIGGEST_OPERATOR_SIZE;for(let e=i;e>0;e--){let t=this.expression.substring(n,n+e);if($e.OPERATORS_WITHOUT_SPACE_WRAP.has(t))return ee.isNullOrBlank(s)||(this.tokens.push(new ke(s)),a=!1),this.checkUnaryOperator(this.tokens,this.ops,$e.OPERATION_VALUE_OF.get(t),a),a=!0,r.setLength(0),new se(n+e-1,a)}return r.append(e),new se(n,!1)}processSubExpression(e,t,r,s,n){if($e.OPERATORS.has(r))this.checkUnaryOperator(this.tokens,this.ops,$e.OPERATION_VALUE_OF.get(r),n),t.setLength(0);else if(!ee.isNullOrBlank(r))throw new De(this.expression,Q.format("Unkown token : $ found.",r));let a=1;const i=new Ve;let o=this.expression.charAt(s);for(s++;s<e&&a>0;)o=this.expression.charAt(s),"("==o?a++:")"==o&&a--,0!=a&&(i.append(o),s++);if(")"!=o)throw new De(this.expression,"Missing a closed parenthesis");for(;i.length()>2&&"("==i.charAt(0)&&")"==i.charAt(i.length()-1);)i.deleteCharAt(0),i.setLength(i.length()-1);return this.tokens.push(new We(i.toString().trim())),s}processTokenSepearator(e,t,r){return ee.isNullOrBlank(t)||($e.OPERATORS.has(t)?(this.checkUnaryOperator(this.tokens,this.ops,$e.OPERATION_VALUE_OF.get(t),r),r=!0):(this.tokens.push(new ke(t)),r=!1)),e.setLength(0),r}checkUnaryOperator(e,t,r,s){if(r)if(s||e.isEmpty()){if(!$e.UNARY_OPERATORS.has(r))throw new De(this.expression,Q.format("Extra operator $ found.",r));{const e=$e.UNARY_MAP.get(r);e&&t.push(e)}}else{for(;!t.isEmpty()&&this.hasPrecedence(r,t.peek());){let r=t.pop();if($e.UNARY_OPERATORS.has(r)){let t=e.pop();e.push(new We("",t,void 0,r))}else{let t=e.pop(),s=e.pop();e.push(new We("",s,t,r))}}t.push(r)}}hasPrecedence(e,t){let r=$e.OPERATOR_PRIORITY.get(e),s=$e.OPERATOR_PRIORITY.get(t);if(!r||!s)throw new Error("Unknown operators provided");return s<r}toString(){if(this.ops.isEmpty())return 1==this.tokens.size()?this.tokens.get(0).toString():"Error: No tokens";let e=new Ve,t=0;const r=this.ops.toArray(),s=this.tokens.toArray();for(let n=0;n<r.length;n++)if(r[n].getOperator().startsWith("UN: "))e.append("(").append(r[n].getOperator().substring(4)).append(s[t]instanceof We?s[t].toString():s[t]).append(")"),t++;else{if(0==t){const r=s[t++];e.insert(0,r.toString())}const a=s[t++];e.insert(0,r[n].getOperator()).insert(0,a.toString()).insert(0,"(").append(")")}return e.toString()}equals(e){return this.expression==e.expression}}var je={};t(je,"ExpressionEvaluator",(()=>ir));var Xe={};t(Xe,"LogicalNullishCoalescingOperator",(()=>Qe));var qe={};t(qe,"BinaryOperator",(()=>Je));class Je{nullCheck(e,t,r){if(u(e)||u(t))throw new Pe(Q.format("$ cannot be applied to a null value",r.getOperatorName()))}}class Qe extends Je{apply(e,t){return u(e)?t:e}}var Ke={};t(Ke,"ArithmeticAdditionOperator",(()=>ze));class ze extends Je{apply(e,t){return this.nullCheck(e,t,$e.ADDITION),e+t}}var Ze={};t(Ze,"ArithmeticDivisionOperator",(()=>et));class et extends Je{apply(e,t){return this.nullCheck(e,t,$e.DIVISION),e/t}}var tt={};t(tt,"ArithmeticIntegerDivisionOperator",(()=>rt));class rt extends Je{apply(e,t){return this.nullCheck(e,t,$e.DIVISION),Math.floor(e/t)}}var st={};t(st,"ArithmeticModulusOperator",(()=>nt));class nt extends Je{apply(e,t){return this.nullCheck(e,t,$e.MOD),e%t}}var at={};t(at,"ArithmeticMultiplicationOperator",(()=>it));class it extends Je{apply(e,t){this.nullCheck(e,t,$e.MULTIPLICATION);const r="string"==typeof e;if(r||"string"===typeof t){let s=r?e:t,n=r?t:e,a="",i=n<0;n=Math.abs(n);let o=Math.floor(n);for(;o-- >0;)a+=s;let u=Math.floor(s.length*(n-Math.floor(n)));if(u<0&&(u=-u),0!=u&&(a+=s.substring(0,u)),i){let e="";for(let t=a.length-1;t>=0;t--)e+=a[t];return e}return a}return e*t}}var ot={};t(ot,"ArithmeticSubtractionOperator",(()=>ut));class ut extends Je{apply(e,t){return this.nullCheck(e,t,$e.SUBTRACTION),e-t}}var pt={};t(pt,"ArrayOperator",(()=>lt));class lt extends Je{apply(e,t){if(!e)throw new Pe("Cannot apply array operator on a null value");if(!t)throw new Pe("Cannot retrive null index value");if(!Array.isArray(e)&&"string"!=typeof e)throw new Pe(Q.format("Cannot retrieve value from a primitive value $",e));if(t>=e.length)throw new Pe(Q.format("Cannot retrieve index $ from the array of length $",t,e.length));return e[t]}}var ht={};t(ht,"BitwiseAndOperator",(()=>mt));class mt extends Je{apply(e,t){return this.nullCheck(e,t,$e.BITWISE_AND),e&t}}var ct={};t(ct,"BitwiseLeftShiftOperator",(()=>gt));class gt extends Je{apply(e,t){return this.nullCheck(e,t,$e.BITWISE_LEFT_SHIFT),e<<t}}var ft={};t(ft,"BitwiseOrOperator",(()=>Et));class Et extends Je{apply(e,t){return this.nullCheck(e,t,$e.BITWISE_OR),e|t}}var Tt={};t(Tt,"BitwiseRightShiftOperator",(()=>At));class At extends Je{apply(e,t){return this.nullCheck(e,t,$e.BITWISE_RIGHT_SHIFT),e>>t}}var dt={};t(dt,"BitwiseUnsignedRightShiftOperator",(()=>St));class St extends Je{apply(e,t){return this.nullCheck(e,t,$e.BITWISE_UNSIGNED_RIGHT_SHIFT),e>>>t}}var wt={};t(wt,"BitwiseXorOperator",(()=>Ot));class Ot extends Je{apply(e,t){return this.nullCheck(e,t,$e.BITWISE_XOR),e^t}}var Nt={};t(Nt,"LogicalAndOperator",(()=>It));var xt={};t(xt,"PrimitiveUtil",(()=>Rt));class Rt{static findPrimitiveNullAsBoolean(e){if(!e)return new se(c.BOOLEAN,!1);let t=typeof e;if("object"===t)throw new Pe(Q.format("$ is not a primitive type",e));let r=e;return"boolean"===t?new se(c.BOOLEAN,r):"string"===t?new se(c.STRING,r):Rt.findPrimitiveNumberType(r)}static findPrimitive(e){if(u(e))return new se(c.NULL,void 0);let t=typeof e;if("object"===t)throw new Pe(Q.format("$ is not a primitive type",e));let r=e;return"boolean"===t?new se(c.BOOLEAN,r):"string"===t?new se(c.STRING,r):Rt.findPrimitiveNumberType(r)}static findPrimitiveNumberType(e){if(u(e)||Array.isArray(e)||"object"==typeof e)throw new Pe(Q.format("Unable to convert $ to a number.",e));let t=e;try{let e=t;return Number.isInteger(e)?new se(c.LONG,e):new se(c.DOUBLE,e)}catch(e){throw new Pe(Q.format("Unable to convert $ to a number.",t),e)}}static compare(e,t){if(e==t)return 0;if(u(e)||u(t))return u(e)?-1:1;if(Array.isArray(e)||Array.isArray(t)){if(Array.isArray(e)&&Array.isArray(t)){if(e.length!=t.length)return e.length-t.length;for(let r=0;r<e.length;r++){let s=this.compare(e[r],t[r]);if(0!=s)return s}return 0}return Array.isArray(e)?-1:1}const r=typeof e,s=typeof t;return"object"===r||"object"===s?("object"===r&&"object"===s&&Object.keys(e).forEach((r=>{let s=this.compare(e[r],t[r]);if(0!=s)return s})),"object"===r?-1:1):this.comparePrimitive(e,t)}static comparePrimitive(e,t){return u(e)||u(t)?u(e)&&u(t)?0:u(e)?-1:1:e==t?0:"boolean"==typeof e||"boolean"==typeof t?e?-1:1:"string"==typeof e||"string"==typeof t?e+""<t+""?-1:1:"number"==typeof e||"number"==typeof t?e-t:0}static baseNumberType(e){return Number.isInteger(e)?c.LONG:c.DOUBLE}static toPrimitiveType(e){return e}constructor(){}}class It extends Je{apply(e,t){const r=Rt.findPrimitiveNullAsBoolean(e),s=Rt.findPrimitiveNullAsBoolean(t);if(r.getT1()!=c.BOOLEAN)throw new Pe(Q.format("Boolean value expected but found $",r.getT2()));if(s.getT1()!=c.BOOLEAN)throw new Pe(Q.format("Boolean value expected but found $",s.getT2()));return r.getT2()&&s.getT2()}}var yt={};t(yt,"LogicalEqualOperator",(()=>Pt));var vt={};function Mt(e,t){let r=new Ce;r.push(e);let s=new Ce;for(s.push(t);!r.isEmpty()&&!s.isEmpty();){const e=r.pop(),t=s.pop();if(e===t)continue;const n=typeof e,a=typeof t;if("undefined"===n||"undefined"===a){if(!e&&!t)continue;return!1}if(n!==a)return!1;if(Array.isArray(e)){if(!Array.isArray(t)||e.length!=t.length)return!1;for(let n=0;n<e.length;n++)r.push(e[n]),s.push(t[n])}else{if("object"!==n)return!1;{const n=Object.entries(e),a=Object.entries(t);if(n.length!==a.length)return!1;for(const[e,a]of n)r.push(a),s.push(t[e])}}}return!0}t(vt,"deepEqual",(()=>Mt));class Pt extends Je{apply(e,t){return Mt(e,t)}}var _t={};t(_t,"LogicalGreaterThanEqualOperator",(()=>Lt));class Lt extends Je{apply(e,t){const r=Rt.findPrimitiveNullAsBoolean(e),s=Rt.findPrimitiveNullAsBoolean(t);if(r.getT1()==c.BOOLEAN||s.getT1()==c.BOOLEAN)throw new Pe(Q.format("Cannot compare >= with the values $ and $",r.getT2(),s.getT2()));return r.getT2()>=s.getT2()}}var Ct={};t(Ct,"LogicalGreaterThanOperator",(()=>bt));class bt extends Je{apply(e,t){const r=Rt.findPrimitiveNullAsBoolean(e),s=Rt.findPrimitiveNullAsBoolean(t);if(r.getT1()==c.BOOLEAN||s.getT1()==c.BOOLEAN)throw new Pe(Q.format("Cannot compare > with the values $ and $",r.getT2(),s.getT2()));return r.getT2()>s.getT2()}}var Ut={};t(Ut,"LogicalLessThanEqualOperator",(()=>Vt));class Vt extends Je{apply(e,t){const r=Rt.findPrimitiveNullAsBoolean(e),s=Rt.findPrimitiveNullAsBoolean(t);if(r.getT1()==c.BOOLEAN||s.getT1()==c.BOOLEAN)throw new Pe(Q.format("Cannot compare <= with the values $ and $",r.getT2(),s.getT2()));return r.getT2()<=s.getT2()}}var Bt={};t(Bt,"LogicalLessThanOperator",(()=>Dt));class Dt extends Je{apply(e,t){const r=Rt.findPrimitiveNullAsBoolean(e),s=Rt.findPrimitiveNullAsBoolean(t);if(r.getT1()==c.BOOLEAN||s.getT1()==c.BOOLEAN)throw new Pe(Q.format("Cannot compare < with the values $ and $",r.getT2(),s.getT2()));return r.getT2()<s.getT2()}}var Gt={};t(Gt,"LogicalNotEqualOperator",(()=>kt));class kt extends Je{apply(e,t){return!Mt(e,t)}}var Ft={};t(Ft,"LogicalOrOperator",(()=>Ht));class Ht extends Je{apply(e,t){const r=Rt.findPrimitiveNullAsBoolean(e),s=Rt.findPrimitiveNullAsBoolean(t);if(r.getT1()!=c.BOOLEAN)throw new Pe(Q.format("Boolean value expected but found $",r.getT2()));if(s.getT1()!=c.BOOLEAN)throw new Pe(Q.format("Boolean value expected but found $",s.getT2()));return r.getT2()||s.getT2()}}var Yt={};t(Yt,"ObjectOperator",(()=>$t));class $t extends Je{apply(e,t){if(!e)throw new Pe("Cannot apply array operator on a null value");if(!t)throw new Pe("Cannot retrive null property value");const r=typeof e;if(!Array.isArray(e)&&"string"!=r&&"object"!=r)throw new Pe(Q.format("Cannot retrieve value from a primitive value $",e));return e[t]}}var Wt={};t(Wt,"ArithmeticUnaryMinusOperator",(()=>qt));var jt={};t(jt,"UnaryOperator",(()=>Xt));class Xt{nullCheck(e,t){if(u(e))throw new Pe(Q.format("$ cannot be applied to a null value",t.getOperatorName()))}}class qt extends Xt{apply(e){return this.nullCheck(e,$e.UNARY_MINUS),Rt.findPrimitiveNumberType(e),-e}}var Jt={};t(Jt,"ArithmeticUnaryPlusOperator",(()=>Qt));class Qt extends Xt{apply(e){return this.nullCheck(e,$e.UNARY_PLUS),Rt.findPrimitiveNumberType(e),e}}var Kt={};t(Kt,"BitwiseComplementOperator",(()=>zt));class zt extends Xt{apply(e){this.nullCheck(e,$e.UNARY_BITWISE_COMPLEMENT);let t=Rt.findPrimitiveNumberType(e);if(t.getT1()!=c.INTEGER&&t.getT1()!=c.LONG)throw new Pe(Q.format("Unable to apply bitwise operator on $",e));return~e}}var Zt={};t(Zt,"LogicalNotOperator",(()=>er));class er extends Xt{apply(e){if(this.nullCheck(e,$e.UNARY_LOGICAL_NOT),Rt.findPrimitiveNumberType(e).getT1()!=c.BOOLEAN)throw new Pe(Q.format("Unable to apply bitwise operator on $",e));return!e}}var tr={};t(tr,"LiteralTokenValueExtractor",(()=>ar));var rr={};t(rr,"TokenValueExtractor",(()=>sr));class sr{static REGEX_SQUARE_BRACKETS=/[\[\]]/;static REGEX_DOT=/\./;getValue(e){let t=this.getPrefix();if(!e.startsWith(t))throw new U(Q.format("Token $ doesn't start with $",e,t));return this.getValueInternal(e)}retrieveElementFrom(e,t,r,s){if(u(s))return;if(t.length==r)return s;let n=t[r].split(sr.REGEX_SQUARE_BRACKETS).map((e=>e.trim())).filter((e=>!ee.isNullOrBlank(e))).reduce(((s,n,a)=>this.resolveForEachPartOfTokenWithBrackets(e,t,r,n,s,a)),s);return this.retrieveElementFrom(e,t,r+1,n)}resolveForEachPartOfTokenWithBrackets(e,t,r,s,n,a){if(!u(n)){if(0===a){if(Array.isArray(n)){if("length"===s)return n.length;try{let e=parseInt(s);if(isNaN(e))throw new Error(Q.format("$ is not a number",e));if(e>=n.length)return;return n[e]}catch(t){throw new De(e,Q.format("$ couldn't be parsed into integer in $",s,e),t)}}return this.checkIfObject(e,t,r,n),n[s]}if(s?.startsWith('"')){if(!s.endsWith('"')||1==s.length||2==s.length)throw new De(e,Q.format("$ is missing a double quote or empty key found",e));return this.checkIfObject(e,t,r,n),n[s.substring(1,s.length-1)]}try{let t=parseInt(s);if(isNaN(t))throw new Error(Q.format("$ is not a number",t));if(!Array.isArray(n))throw new De(e,Q.format("Expecting an array with index $ while processing the expression",t,e));if(t>=n.length)return;return n[t]}catch(t){throw new De(e,Q.format("$ couldn't be parsed into integer in $",s,e),t)}}}checkIfObject(e,t,r,s){if("object"!=typeof s||Array.isArray(s))throw new De(e,Q.format("Unable to retrive $ from $ in the path $",t[r],s.toString(),e))}}const nr=new Map([["true",!0],["false",!1],["null",void 0]]);class ar extends sr{static INSTANCE=new ar;getValueInternal(e){if(!ee.isNullOrBlank(e))return e=e.trim(),nr.has(e)?nr.get(e):e.startsWith('"')?this.processString(e):this.processNumbers(e)}processNumbers(e){try{let t;if(t=-1==e.indexOf(".")?parseInt(e):parseFloat(e),isNaN(t))throw new Error("Parse number error");return t}catch(t){throw new De(e,Q.format("Unable to parse the literal or expression $",e),t)}}processString(e){if(!e.endsWith('"'))throw new De(e,Q.format("String literal $ is not closed properly",e));return e.substring(1,e.length-1)}getPrefix(){return""}}class ir{static UNARY_OPERATORS_MAP=new Map([[$e.UNARY_BITWISE_COMPLEMENT,new zt],[$e.UNARY_LOGICAL_NOT,new er],[$e.UNARY_MINUS,new qt],[$e.UNARY_PLUS,new Qt]]);static BINARY_OPERATORS_MAP=new Map([[$e.ADDITION,new ze],[$e.DIVISION,new et],[$e.INTEGER_DIVISION,new rt],[$e.MOD,new nt],[$e.MULTIPLICATION,new it],[$e.SUBTRACTION,new ut],[$e.BITWISE_AND,new mt],[$e.BITWISE_LEFT_SHIFT,new gt],[$e.BITWISE_OR,new Et],[$e.BITWISE_RIGHT_SHIFT,new At],[$e.BITWISE_UNSIGNED_RIGHT_SHIFT,new St],[$e.BITWISE_XOR,new Ot],[$e.AND,new It],[$e.EQUAL,new Pt],[$e.GREATER_THAN,new bt],[$e.GREATER_THAN_EQUAL,new Lt],[$e.LESS_THAN,new Dt],[$e.LESS_THAN_EQUAL,new Vt],[$e.OR,new Ht],[$e.NOT_EQUAL,new kt],[$e.NULLISH_COALESCING_OPERATOR,new Qe],[$e.ARRAY_OPERATOR,new lt],[$e.OBJECT_OPERATOR,new $t]]);static UNARY_OPERATORS_MAP_KEY_SET=new Set(ir.UNARY_OPERATORS_MAP.keys());constructor(e){e instanceof We?(this.exp=e,this.expression=this.exp.getExpression()):this.expression=e}evaluate(e){const t=this.processNestingExpression(this.expression,e);return this.expression=t.getT1(),this.exp=t.getT2(),this.evaluateExpression(this.exp,e)}processNestingExpression(e,t){let r=0,s=0;const n=new Ce;for(;s<e.length-1;){if("{"==e.charAt(s)&&"{"==e.charAt(s+1))0==r&&n.push(new se(s+2,-1)),r++,s++;else if("}"==e.charAt(s)&&"}"==e.charAt(s+1)){if(r--,r<0)throw new De(e,"Expecting {{ nesting path operator to be started before closing");0==r&&n.push(n.pop().setT2(s)),s++}s++}let a=this.replaceNestingExpression(e,t,n);return new se(a,new We(a))}replaceNestingExpression(e,t,r){let s=e;for(var n of r.toArray()){if(-1==n.getT2())throw new De(e,"Expecting }} nesting path operator to be closed");let r=new ir(s.substring(n.getT1(),n.getT2())).evaluate(t);s=s.substring(0,n.getT1()-2)+r+s.substring(n.getT2()+2)}return s}getExpression(){return this.exp||(this.exp=new We(this.expression)),this.exp}getExpressionString(){return this.expression}evaluateExpression(e,t){let r=e.getOperations(),s=e.getTokens();for(;!r.isEmpty();){let e=r.pop(),i=s.pop();if(ir.UNARY_OPERATORS_MAP_KEY_SET.has(e))s.push(this.applyUnaryOperation(e,this.getValueFromToken(t,i)));else if(e==$e.OBJECT_OPERATOR||e==$e.ARRAY_OPERATOR)this.processObjectOrArrayOperator(t,r,s,e,i);else{const r=s.pop();var n=this.getValueFromToken(t,r),a=this.getValueFromToken(t,i);s.push(this.applyBinaryOperation(e,n,a))}}if(s.isEmpty())throw new Pe(Q.format("Expression : $ evaluated to null",e));if(1!=s.size())throw new Pe(Q.format("Expression : $ evaluated multiple values $",e,s));const i=s.get(0);if(i instanceof He)return i.getElement();if(!(i instanceof We))return this.getValueFromToken(t,i);throw new Pe(Q.format("Expression : $ evaluated to $",e,s.get(0)))}processObjectOrArrayOperator(e,t,r,s,n){const a=new Ce,i=new Ce;if(!s||!n)return;do{i.push(s),n instanceof We?a.push(new He(n.toString(),this.evaluateExpression(n,e))):n&&a.push(n),n=r.isEmpty()?void 0:r.pop(),s=t.isEmpty()?void 0:t.pop()}while(s==$e.OBJECT_OPERATOR||s==$e.ARRAY_OPERATOR);n&&(n instanceof We?a.push(new He(n.toString(),this.evaluateExpression(n,e))):a.push(n)),s&&t.push(s);let o=a.pop(),u=new Ve(o instanceof He?o.getTokenValue():o.toString());for(;!a.isEmpty();)o=a.pop(),s=i.pop(),u.append(s.getOperator()).append(o instanceof He?o.getTokenValue():o.toString()),s==$e.ARRAY_OPERATOR&&u.append("]");let p=u.toString(),l=p.substring(0,p.indexOf(".")+1);if(l.length>2&&e.has(l))r.push(new He(p,this.getValue(p,e)));else{let e;try{e=ar.INSTANCE.getValue(p)}catch(t){e=p}r.push(new He(p,e))}}applyBinaryOperation(e,t,r){let s=typeof t,n=typeof r,a=ir.BINARY_OPERATORS_MAP.get(e);if(("object"===s||"object"===n)&&e!==$e.EQUAL&&e!==$e.NOT_EQUAL)throw new De(this.expression,Q.format("Cannot evaluate expression $ $ $",t,e.getOperator(),r));if(!a)throw new De(this.expression,Q.format("No operator found to evaluate $ $ $",t,e.getOperator(),r));return new He(e.toString(),a.apply(t,r))}applyUnaryOperation(e,t){if("object"===typeof t||Array.isArray(t))throw new De(this.expression,Q.format("The operator $ cannot be applied to $",e.getOperator(),t));let r=ir.UNARY_OPERATORS_MAP.get(e);if(!r)throw new De(this.expression,Q.format("No Unary operator $ is found to apply on $",e.getOperator(),t));return new He(e.toString(),r.apply(t))}getValueFromToken(e,t){return t instanceof We?this.evaluateExpression(t,e):t instanceof He?t.getElement():this.getValue(t.getExpression(),e)}getValue(e,t){if(e.length<=5)return ar.INSTANCE.getValue(e);const r=e.substring(0,e.indexOf(".")+1);return(t.get(r)??ar.INSTANCE).getValue(e)}}const or=new j("Set").setNamespace(a.SYSTEM_CTX).setParameters(new Map([P.ofEntry("name",(new N).setName("name").setType(O.of(c.STRING)).setMinLength(1),!1,v.CONSTANT),P.ofEntry("value",N.ofAny("value"))])).setEvents(new Map([k.outputEventMapEntry(new Map)]));const ur=new j("GenerateEvent").setNamespace(a.SYSTEM).setParameters(new Map([P.ofEntry("eventName",N.ofString("eventName")),P.ofEntry("results",N.ofObject("results").setProperties(new Map([["name",N.ofString("name")],["value",P.EXPRESSION]])),!0)])).setEvents(new Map([k.outputEventMapEntry(new Map)]));class pr extends Ie{static CONDITION="condition";static SIGNATURE=new j("If").setNamespace(a.SYSTEM).setParameters(new Map([P.ofEntry(pr.CONDITION,N.of(pr.CONDITION,c.BOOLEAN))])).setEvents(new Map([k.eventMapEntry(k.TRUE,new Map),k.eventMapEntry(k.FALSE,new Map),k.outputEventMapEntry(new Map)]));getSignature(){return pr.SIGNATURE}async internalExecute(e){var t=e.getArguments()?.get(pr.CONDITION);return new $([H.of(t?k.TRUE:k.FALSE,new Map),H.outputOf(new Map)])}}const lr=new j("CountLoop").setNamespace(a.SYSTEM_LOOP).setParameters(new Map([P.ofEntry("count",N.of("count",c.INTEGER).setDefaultValue(1))])).setEvents(new Map([k.eventMapEntry(k.ITERATION,new Map([["index",N.of("index",c.INTEGER)]])),k.outputEventMapEntry(new Map([["value",N.of("value",c.INTEGER)]]))]));const hr=new j("RangeLoop").setNamespace(a.SYSTEM_LOOP).setParameters(new Map([P.ofEntry("from",N.of("from",c.INTEGER,c.LONG,c.FLOAT,c.DOUBLE).setDefaultValue(0)),P.ofEntry("to",N.of("to",c.INTEGER,c.LONG,c.FLOAT,c.DOUBLE).setDefaultValue(1)),P.ofEntry("step",N.of("step",c.INTEGER,c.LONG,c.FLOAT,c.DOUBLE).setDefaultValue(1).setNot((new N).setConstant(0)))])).setEvents(new Map([k.eventMapEntry(k.ITERATION,new Map([["index",N.of("index",c.INTEGER,c.LONG,c.FLOAT,c.DOUBLE)]])),k.outputEventMapEntry(new Map([["value",N.of("value",c.INTEGER,c.LONG,c.FLOAT,c.DOUBLE)]]))]));const mr=new j("Add").setNamespace(a.MATH).setParameters(new Map([["value",new P("value",N.ofNumber("value")).setVariableArgument(!0)]])).setEvents(new Map([k.outputEventMapEntry(new Map([["value",N.ofNumber("value")]]))]));const cr=[()=>new Map([["value",new P("value",N.ofNumber("value"))]]),()=>new Map([["value1",new P("value1",N.ofNumber("value1"))],["value2",new P("value2",N.ofNumber("value2"))]])];class gr extends Ie{constructor(e,t,r=1,...s){super(),s&&s.length||(s=[c.DOUBLE]),this.parametersNumber=r,this.mathFunction=t,this.signature=new j(e).setNamespace(a.MATH).setParameters(cr[r-1]()).setEvents(new Map([k.outputEventMapEntry(new Map([["value",(new N).setType(O.of(...s)).setName("value")]]))]))}getSignature(){return this.signature}async internalExecute(e){let t,r=Rt.findPrimitiveNumberType(e.getArguments()?.get(1==this.parametersNumber?"value":"value1")).getT2();return 2==this.parametersNumber&&(t=Rt.findPrimitiveNumberType(e.getArguments()?.get("value2")).getT2()),new $([H.outputOf(new Map([["value",this.mathFunction.call(this,r,t)]]))])}}class fr extends Ie{static SIGNATURE=new j("Hypotenuse").setNamespace(a.MATH).setParameters(new Map([["value",new P("value",N.ofNumber("value")).setVariableArgument(!0)]])).setEvents(new Map([k.outputEventMapEntry(new Map([["value",(new N).setType(O.of(c.DOUBLE)).setName("value")]]))]));constructor(){super()}getSignature(){return fr.SIGNATURE}async internalExecute(e){let t=e.getArguments()?.get("value");return new $([H.outputOf(new Map([["value",Math.sqrt(t.reduce(((e,t)=>e+t*t),0))]]))])}}const Er=new j("Maximum").setNamespace(a.MATH).setParameters(new Map([["value",new P("value",N.ofNumber("value")).setVariableArgument(!0)]])).setEvents(new Map([k.outputEventMapEntry(new Map([["value",N.ofNumber("value")]]))]));const Tr=new j("Minimum").setNamespace(a.MATH).setParameters(new Map([["value",new P("value",N.ofNumber("value")).setVariableArgument(!0)]])).setEvents(new Map([k.outputEventMapEntry(new Map([["value",N.ofNumber("value")]]))]));var Ar={};t(Ar,"MapUtil",(()=>dr)),t(Ar,"MapEntry",(()=>Sr));class dr{static of(e,t,r,s,n,a,i,o,p,l,h,m,c,g,f,E,T,A,d,S){const w=new Map;return u(e)||u(t)||w.set(e,t),u(r)||u(s)||w.set(r,s),u(n)||u(a)||w.set(n,a),u(i)||u(o)||w.set(i,o),u(p)||u(l)||w.set(p,l),u(h)||u(m)||w.set(h,m),u(c)||u(g)||w.set(c,g),u(f)||u(E)||w.set(f,E),u(T)||u(A)||w.set(T,A),u(d)||u(S)||w.set(d,S),w}static ofArrayEntries(...e){const t=new Map;for(const[r,s]of e)t.set(r,s);return t}static entry(e,t){return new Sr(e,t)}static ofEntries(...e){const t=new Map;for(const r of e)t.set(r.k,r.v);return t}constructor(){}}class Sr{constructor(e,t){this.k=e,this.v=t}}class wr extends Ie{static SIGNATURE=new j("Random").setNamespace(a.MATH).setEvents(new Map([k.outputEventMapEntry(dr.of("value",N.ofDouble("value")))]));getSignature(){return wr.SIGNATURE}async internalExecute(e){return new $([H.outputOf(new Map([["value",Math.random()]]))])}}const Or={Absolute:new gr("Absolute",(e=>Math.abs(e)),1,c.INTEGER,c.LONG,c.FLOAT,c.DOUBLE),ACosine:new gr("ArcCosine",(e=>Math.acos(e))),ASine:new gr("ArcSine",(e=>Math.asin(e))),ATangent:new gr("ArcTangent",(e=>Math.atan(e))),Ceiling:new gr("Ceiling",(e=>Math.ceil(e))),Cosine:new gr("Cosine",(e=>Math.cos(e))),CosineH:new gr("HyperbolicCosine",(e=>Math.cosh(e))),CubeRoot:new gr("CubeRoot",(e=>Math.cbrt(e))),Exponential:new gr("Exponential",(e=>Math.exp(e))),Expm1:new gr("ExponentialMinus1",(e=>Math.expm1(e))),Floor:new gr("Floor",(e=>Math.floor(e))),Log:new gr("LogNatural",(e=>Math.log(e))),Log10:new gr("Log10",(e=>Math.log10(e))),Round:new gr("Round",(e=>Math.round(e)),1,c.INTEGER,c.LONG),Sine:new gr("Sine",(e=>Math.sin(e))),SineH:new gr("HyperbolicSine",(e=>Math.sinh(e))),Tangent:new gr("Tangent",(e=>Math.tan(e))),TangentH:new gr("HyperbolicTangent",(e=>Math.tanh(e))),ToDegrees:new gr("ToDegrees",(e=>e*(Math.PI/180))),ToRadians:new gr("ToRadians",(e=>e*(180/Math.PI))),SquareRoot:new gr("SquareRoot",(e=>Math.sqrt(e))),ArcTangent:new gr("ArcTangent2",((e,t)=>Math.atan2(e,t)),2),Power:new gr("Power",((e,t)=>Math.pow(e,t)),2),Add:new class extends Ie{getSignature(){return mr}async internalExecute(e){let t=e.getArguments()?.get("value");return new $([H.outputOf(new Map([["value",t.reduce(((e,t)=>e+t),0)]]))])}},Hypotenuse:new fr,Maximum:new class extends Ie{getSignature(){return Er}async internalExecute(e){let t=e.getArguments()?.get("value");return new $([H.outputOf(new Map([["value",t.reduce(((e,t)=>!e&&0!==e||t>e?t:e))]]))])}},Minimum:new class extends Ie{getSignature(){return Tr}async internalExecute(e){let t=e.getArguments()?.get("value");return new $([H.outputOf(new Map([["value",t.reduce(((e,t)=>!e&&0!==e||t<e?t:e))]]))])}},Random:new wr};class Nr{find(e,t){if(e==a.MATH)return Or[t]}}var xr={};t(xr,"HybridRepository",(()=>Rr));class Rr{constructor(...e){this.repos=e}find(e,t){for(let r of this.repos){let s=r.find(e,t);if(s)return s}}}function Ir(e){return[e.getSignature().getName(),e]}const yr=new Map([[a.SYSTEM_CTX,new Map([Ir(new class extends Ie{getSignature(){return ye}async internalExecute(e){const t=e?.getArguments()?.get("name");if(e?.getContext()?.has(t))throw new U(Q.format("Context already has an element for '$' ",t));let r=N.from(e?.getArguments()?.get("schema"));if(!r)throw new U("Schema is not supplied.");return e.getContext().set(t,new q(r,u(r.getDefaultValue())?void 0:r.getDefaultValue())),new $([H.outputOf(new Map)])}}),Ir(new class extends Ie{getSignature(){return ve}async internalExecute(e){const t=e?.getArguments()?.get("name");if(!e.getContext()?.has(t))throw new U(Q.format("Context don't have an element for '$' ",t));return new $([H.outputOf(new Map(["value",e.getContext()?.get(t)?.getElement()]))])}}),Ir(new class extends Ie{getSignature(){return or}async internalExecute(e){let t=e?.getArguments()?.get("name");if(ee.isNullOrBlank(t))throw new U("Empty string is not a valid name for the context element");let r=e?.getArguments()?.get("value");const s=new We(t),n=s.getTokens().peekLast();if(!n.getExpression().startsWith("Context")||n instanceof We||n instanceof He&&!n.getElement().toString().startsWith("Context"))throw new Pe(Q.format("The context path $ is not a valid path in context",t));for(const e of s.getOperations().toArray())if(e!=$e.ARRAY_OPERATOR&&e!=$e.OBJECT_OPERATOR)throw new Pe(Q.format("Expected a reference to the context location, but found an expression $",t));for(let r=0;r<s.getTokens().size();r++){let n=s.getTokens().get(r);n instanceof We&&s.getTokens().set(r,new He(t,new ir(n).evaluate(e.getValuesMap())))}return this.modifyContext(e,t,r,s)}modifyContext(e,t,r,s){const n=s.getTokens();n.removeLast();const a=s.getOperations();a.removeLast();let i=e.getContext()?.get(n.removeLast().getExpression());if(u(i))throw new U(Q.format("Context doesn't have any element with name '$' ",t));if(a.isEmpty())return i.setElement(r),new $([H.outputOf(new Map)]);let o=i.getElement(),p=a.removeLast(),l=n.removeLast(),h=l instanceof He?l.getElement():l.getExpression();for(u(o)&&(o=p==$e.OBJECT_OPERATOR?{}:[],i.setElement(o));!a.isEmpty();)o=p==$e.OBJECT_OPERATOR?this.getDataFromObject(o,h,a.peekLast()):this.getDataFromArray(o,h,a.peekLast()),p=a.removeLast(),l=n.removeLast(),h=l instanceof He?l.getElement():l.getExpression();return p==$e.OBJECT_OPERATOR?this.putDataInObject(o,h,r):this.putDataInArray(o,h,r),new $([H.outputOf(new Map)])}getDataFromArray(e,t,r){if(!Array.isArray(e))throw new U(Q.format("Expected an array but found $",e));const s=parseInt(t);if(isNaN(s))throw new U(Q.format("Expected an array index but found $",t));if(s<0)throw new U(Q.format("Array index is out of bound - $",t));let n=e[s];return u(n)&&(n=r==$e.OBJECT_OPERATOR?{}:[],e[s]=n),n}getDataFromObject(e,t,r){if(Array.isArray(e)||"object"!=typeof e)throw new U(Q.format("Expected an object but found $",e));let s=e[t];return u(s)&&(s=r==$e.OBJECT_OPERATOR?{}:[],e[t]=s),s}putDataInArray(e,t,r){if(!Array.isArray(e))throw new U(Q.format("Expected an array but found $",e));const s=parseInt(t);if(isNaN(s))throw new U(Q.format("Expected an array index but found $",t));if(s<0)throw new U(Q.format("Array index is out of bound - $",t));e[s]=r}putDataInObject(e,t,r){if(Array.isArray(e)||"object"!=typeof e)throw new U(Q.format("Expected an object but found $",e));e[t]=r}})])],[a.SYSTEM_LOOP,new Map([Ir(new class extends Ie{getSignature(){return hr}async internalExecute(e){let t=e.getArguments()?.get("from"),r=e.getArguments()?.get("to"),s=e.getArguments()?.get("step");const n=s>0;let a=t,i=!1;return new $({next(){if(i)return;if(n&&a>=r||!n&&a<=r)return i=!0,H.outputOf(new Map([["value",a]]));const e=H.of(k.ITERATION,new Map([["index",a]]));return a+=s,e}})}}),Ir(new class extends Ie{getSignature(){return lr}async internalExecute(e){let t=e.getArguments()?.get("count"),r=0;return new $({next(){if(r>=t)return H.outputOf(new Map([["value",r]]));const e=H.of(k.ITERATION,new Map([["index",r]]));return++r,e}})}})])],[a.SYSTEM,new Map([Ir(new pr),Ir(new class extends Ie{getSignature(){return ur}async internalExecute(e){const t=e.getEvents(),r=e.getArguments()?.get("eventName"),s=e?.getArguments()?.get("results").map((t=>{let r=t.value;if(u(r))throw new U("Expect a value object");let s=r.value;return r.isExpression&&(s=new ir(s).evaluate(e.getValuesMap())),[t.name,s]})).reduce(((e,t)=>(e.set(t[0],t[1]),e)),new Map);return t?.has(r)||t?.set(r,[]),t?.get(r)?.push(s),new $([H.outputOf(new Map)])}})])]]);class vr extends Rr{constructor(){super({find:(e,t)=>yr.get(e)?.get(t)},new Nr)}}var Mr={};t(Mr,"ArrayUtil",(()=>Pr));class Pr{static removeAListFrom(e,t){if(!(t&&e&&e.length&&t.length))return;const r=new Set(t);for(let t=0;t<e.length;t++)r.has(e[t])&&(e.splice(t,1),t--)}static of(...e){const t=new Array(e.length);for(let r=0;r<e.length;r++)t[r]=e[r];return t}constructor(){}}var _r={};t(_r,"StatementExecution",(()=>br));var Lr={};t(Lr,"StatementMessage",(()=>Cr));class Cr{constructor(e,t){this.message=t,this.messageType=e}getMessageType(){return this.messageType}setMessageType(e){return this.messageType=e,this}getMessage(){return this.message}setMessage(e){return this.message=e,this}toString(){return`${this.messageType} : ${this.message}`}}class br{messages=new Array;dependencies=new Set;constructor(e){this.statement=e}getStatement(){return this.statement}setStatement(e){return this.statement=e,this}getMessages(){return this.messages}setMessages(e){return this.messages=e,this}getDependencies(){return this.dependencies}setDependencies(e){return this.dependencies=e,this}getUniqueKey(){return this.statement.getStatementName()}addMessage(e,t){this.messages.push(new Cr(e,t))}addDependency(e){this.dependencies.add(e)}getDepenedencies(){return this.dependencies}equals(e){if(!(e instanceof br))return!1;return e.statement.equals(this.statement)}}var Ur={};t(Ur,"ContextTokenValueExtractor",(()=>Vr));class Vr extends sr{static PREFIX="Context.";constructor(e){super(),this.context=e}getValueInternal(e){let t=e.split(sr.REGEX_DOT),r=t[1],s=r.indexOf("["),n=2;return-1!=s&&(r=t[1].substring(0,s),t[1]=t[1].substring(s),n=1),this.retrieveElementFrom(e,t,n,this.context.get(r)?.getElement())}getPrefix(){return Vr.PREFIX}}var Br={};t(Br,"OutputMapTokenValueExtractor",(()=>Dr));class Dr extends sr{static PREFIX="Steps.";constructor(e){super(),this.output=e}getValueInternal(e){let t=e.split(sr.REGEX_DOT),r=1,s=this.output.get(t[r++]);if(!s||r>=t.length)return;let n=s.get(t[r++]);if(!n||r>=t.length)return;let a=n.get(t[r++]);return this.retrieveElementFrom(e,t,r,a)}getPrefix(){return Dr.PREFIX}}var Gr={};t(Gr,"ArgumentsTokenValueExtractor",(()=>kr));class kr extends sr{static PREFIX="Arguments.";constructor(e){super(),this.args=e}getValueInternal(e){let t=e.split(sr.REGEX_DOT);return this.retrieveElementFrom(e,t,2,this.args.get(t[1]))}getPrefix(){return kr.PREFIX}}var Fr={};t(Fr,"GraphVertex",(()=>$r));var Hr={};t(Hr,"ExecutionGraph",(()=>Yr));class Yr{nodeMap=new Map;constructor(e=!1){this.isSubGrph=e}getVerticesData(){return Array.from(this.nodeMap.values()).map((e=>e.getData()))}addVertex(e){if(!this.nodeMap.has(e.getUniqueKey())){let t=new $r(this,e);this.nodeMap.set(e.getUniqueKey(),t)}return this.nodeMap.get(e.getUniqueKey())}getVertex(e){return this.nodeMap.get(e)}getVertexData(e){if(this.nodeMap.has(e))return this.nodeMap.get(e).getData()}getVerticesWithNoIncomingEdges(){return Array.from(this.nodeMap.values()).filter((e=>!e.hasIncomingEdges()))}isCyclic(){let e,t=new Ce(this.getVerticesWithNoIncomingEdges()),r=new Set;for(;!t.isEmpty();){if(r.has(t.getFirst().getKey()))return!0;e=t.removeFirst(),r.add(e.getKey()),e.hasOutgoingEdges()&&t.addAll(Array.from(e.getOutVertices().values()).flatMap((e=>Array.from(e))))}return!1}addVertices(e){for(const t of e)this.addVertex(t)}getNodeMap(){return this.nodeMap}isSubGraph(){return this.isSubGrph}toString(){return"Execution Graph : \n"+Array.from(this.nodeMap.values()).map((e=>e.toString())).join("\n")}}class $r{outVertices=new Map;inVertices=new Set;constructor(e,t){this.data=t,this.graph=e}getData(){return this.data}setData(e){return this.data=e,this}getOutVertices(){return this.outVertices}setOutVertices(e){return this.outVertices=e,this}getInVertices(){return this.inVertices}setInVertices(e){return this.inVertices=e,this}getGraph(){return this.graph}setGraph(e){return this.graph=e,this}getKey(){return this.data.getUniqueKey()}addOutEdgeTo(e,t){return this.outVertices.has(e)||this.outVertices.set(e,new Set),this.outVertices.get(e).add(t),t.inVertices.add(new se(this,e)),t}addInEdgeTo(e,t){return this.inVertices.add(new se(e,t)),e.outVertices.has(t)||e.outVertices.set(t,new Set),e.outVertices.get(t).add(this),e}hasIncomingEdges(){return!!this.inVertices.size}hasOutgoingEdges(){return!!this.outVertices.size}getSubGraphOfType(e){let t=new Yr(!0);var r=new Ce(Array.from(this.outVertices.get(e)??[]));for(r.map((e=>e.getData())).forEach((e=>t.addVertex(e)));!r.isEmpty();){var s=r.pop();Array.from(s.outVertices.values()).flatMap((e=>Array.from(e))).forEach((e=>{t.addVertex(e.getData()),r.add(e)}))}return t}toString(){var e=Array.from(this.getInVertices()).map((e=>e.getT1().getKey()+"("+e.getT2()+")")).join(", "),t=Array.from(this.outVertices.entries()).map((([e,t])=>e+": "+Array.from(t).map((e=>e.getKey())).join(","))).join("\n\t\t");return this.getKey()+":\n\tIn: "+e+"\n\tOut: \n\t\t"+t}}var Wr={};t(Wr,"KIRuntime",(()=>rs));var jr={};t(jr,"JsonExpression",(()=>Xr));class Xr{constructor(e){this.expression=e}getExpression(){return this.expression}}var qr={};let Jr;var Qr;t(qr,"ParameterReferenceType",(()=>Jr)),(Qr=Jr||(Jr={})).VALUE="VALUE",Qr.EXPRESSION="EXPRESSION";var Kr={};t(Kr,"FunctionExecutionParameters",(()=>zr));class zr{count=0;valueExtractors=new Map;constructor(e,t,r){var s;this.functionRepository=e,this.schemaRepository=t,this.executionId=r??(s=(new Date).getTime(),"xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g,(function(e){var t=(s+16*Math.random())%16|0;return s=Math.floor(s/16),("x"==e?t:3&t|8).toString(16)})))}getExecutionId(){return this.executionId}getContext(){return this.context}setContext(e){this.context=e;let t=new Vr(e);return this.valueExtractors.set(t.getPrefix(),t),this}getArguments(){return this.args}setArguments(e){this.args=e;let t=new kr(e);return this.valueExtractors.set(t.getPrefix(),t),this}getEvents(){return this.events}setEvents(e){return this.events=e,this}getStatementExecution(){return this.statementExecution}setStatementExecution(e){return this.statementExecution=e,this}getSteps(){return this.steps}setSteps(e){this.steps=e;let t=new Dr(e);return this.valueExtractors.set(t.getPrefix(),t),this}getCount(){return this.count}setCount(e){return this.count=e,this}getValuesMap(){return this.valueExtractors}getFunctionRepository(){return this.functionRepository}setFunctionRepository(e){return this.functionRepository=e,this}getSchemaRepository(){return this.schemaRepository}setSchemaRepository(e){return this.schemaRepository=e,this}addTokenValueExtractor(...e){for(const t of e)this.valueExtractors.set(t.getPrefix(),t);return this}setValuesMap(e){for(const[t,r]of e.entries())this.valueExtractors.set(t,r);return this}}var Zr={};let es;var ts;t(Zr,"StatementMessageType",(()=>es)),(ts=es||(es={})).ERROR="ERROR",ts.WARNING="WARNING",ts.MESSAGE="MESSAGE";class rs extends Ie{static PARAMETER_NEEDS_A_VALUE='Parameter "$" needs a value';static STEP_REGEX_PATTERN=new RegExp("Steps\\.([a-zA-Z0-9\\\\-]{1,})\\.([a-zA-Z0-9\\\\-]{1,})","g");static VERSION=1;static MAX_EXECUTION_ITERATIONS=1e7;constructor(e){if(super(),this.fd=e,this.fd.getVersion()>rs.VERSION)throw new U("Runtime is at a lower version "+rs.VERSION+" and trying to run code from version "+this.fd.getVersion()+".")}getSignature(){return this.fd}async getExecutionPlan(e){let t=new Yr;for(let r of Array.from(this.fd.getSteps().values()))t.addVertex(this.prepareStatementExecution(r,e.getFunctionRepository(),e.getSchemaRepository()));return new se(this.makeEdges(t),t)}async internalExecute(e){e.getContext()||e.setContext(new Map),e.getEvents()||e.setEvents(new Map),e.getSteps()||e.setSteps(new Map);let t=await this.getExecutionPlan(e),r=t.getT1();if(r.length)throw new U(Q.format("Found these unresolved dependencies : $ ",r.map((e=>Q.format("Steps.$.$",e.getT1(),e.getT2())))));let s=t.getT2().getVerticesData().filter((e=>e.getMessages().length)).map((e=>e.getStatement().getStatementName()+": \n"+e.getMessages().join(",")));if(s?.length)throw new U("Please fix the errors in the function definition before execution : \n"+s.join(",\n"));return await this.executeGraph(t.getT2(),e)}async executeGraph(e,t){let r=new Ce;r.addAll(e.getVerticesWithNoIncomingEdges());let s=new Ce;for(;!(r.isEmpty()&&s.isEmpty()||t.getEvents()?.has(k.OUTPUT));)if(await this.processBranchQue(t,r,s),await this.processExecutionQue(t,r,s),t.setCount(t.getCount()+1),t.getCount()==rs.MAX_EXECUTION_ITERATIONS)throw new U("Execution locked in an infinite loop");if(!e.isSubGraph()&&!t.getEvents()?.size)throw new U("No events raised");return new $(Array.from(t.getEvents()?.entries()??[]).flatMap((e=>e[1].map((t=>H.of(e[0],t))))))}async processExecutionQue(e,t,r){if(!t.isEmpty()){let s=t.pop();await this.allDependenciesResolvedVertex(s,e.getSteps())?await this.executeVertex(s,e,r,t,e.getFunctionRepository()):t.add(s)}}async processBranchQue(e,t,r){if(r.length){let s=r.pop();await this.allDependenciesResolvedTuples(s.getT2(),e.getSteps())?await this.executeBranch(e,t,s):r.add(s)}}async executeBranch(e,t,r){let s,n=r.getT4();do{await this.executeGraph(r.getT1(),e),s=r.getT3().next(),s&&(e.getSteps()?.has(n.getData().getStatement().getStatementName())||e.getSteps()?.set(n.getData().getStatement().getStatementName(),new Map),e.getSteps()?.get(n.getData().getStatement().getStatementName())?.set(s.getName(),await this.resolveInternalExpressions(s.getResult(),e)))}while(s&&s.getName()!=k.OUTPUT);s?.getName()==k.OUTPUT&&n.getOutVertices().has(k.OUTPUT)&&(n?.getOutVertices()?.get(k.OUTPUT)??[]).forEach((e=>t.add(e)))}async executeVertex(e,t,r,s,n){let a=e.getData().getStatement(),i=n.find(a.getNamespace(),a.getName());if(!i)throw new U(Q.format("$.$ function is not found.",a.getNamespace(),a.getName()));let o=i?.getSignature().getParameters(),u=this.getArgumentsFromParametersMap(t,a,o??new Map),p=t.getContext(),l=await i.execute(new zr(t.getFunctionRepository(),t.getSchemaRepository(),t.getExecutionId()).setValuesMap(t.getValuesMap()).setContext(p).setArguments(u).setEvents(t.getEvents()).setSteps(t.getSteps()).setStatementExecution(e.getData()).setCount(t.getCount())),h=l.next();if(!h)throw new U(Q.format("Executing $ returned no events",a.getStatementName()));let m=h.getName()==k.OUTPUT;if(t.getSteps()?.has(a.getStatementName())||t.getSteps().set(a.getStatementName(),new Map),t.getSteps().get(a.getStatementName()).set(h.getName(),this.resolveInternalExpressions(h.getResult(),t)),m){let t=e.getOutVertices().get(k.OUTPUT);t&&t.forEach((e=>s.add(e)))}else{let t=e.getSubGraphOfType(h.getName()),s=this.makeEdges(t);r.push(new ae(t,s,l,e))}}resolveInternalExpressions(e,t){return e?Array.from(e.entries()).map((e=>new se(e[0],this.resolveInternalExpression(e[1],t)))).reduce(((e,t)=>(e.set(t.getT1(),t.getT2()),e)),new Map):e}resolveInternalExpression(e,t){if(u(e)||"object"!=typeof e)return e;if(e instanceof Xr){return new ir(e.getExpression()).evaluate(t.getValuesMap())}if(Array.isArray(e)){let r=[];for(let s of e)r.push(this.resolveInternalExpression(s,t));return r}if("object"==typeof e){let r={};for(let s of Object.entries(e))r[s[0]]=this.resolveInternalExpression(s[1],t);return r}}allDependenciesResolvedTuples(e,t){for(let r of e){if(!t.has(r.getT1()))return!1;if(!t.get(r.getT1())?.get(r.getT2()))return!1}return!0}allDependenciesResolvedVertex(e,t){return!e.getInVertices().size||0==Array.from(e.getInVertices()).filter((e=>{let r=e.getT1().getData().getStatement().getStatementName(),s=e.getT2();return!(t.has(r)&&t.get(r)?.has(s))})).length}getArgumentsFromParametersMap(e,t,r){return Array.from(t.getParameterMap().entries()).map((t=>{let s,n=t[1];if(!n?.length)return new se(t[0],s);let a=r.get(t[0]);return a?(s=a.isVariableArgument()?n.map((t=>this.parameterReferenceEvaluation(e,t))).flatMap((e=>Array.isArray(e)?e:[e])):this.parameterReferenceEvaluation(e,n[0]),new se(t[0],s)):new se(t[0],void 0)})).filter((e=>!u(e.getT2()))).reduce(((e,t)=>(e.set(t.getT1(),t.getT2()),e)),new Map)}parameterReferenceEvaluation(e,t){let r;if(t.getType()==Jr.VALUE)r=this.resolveInternalExpression(t.getValue(),e);else if(t.getType()==Jr.EXPRESSION&&!ee.isNullOrBlank(t.getExpression())){r=new ir(t.getExpression()??"").evaluate(e.getValuesMap())}return r}prepareStatementExecution(e,t,r){let s=new br(e),n=t.find(e.getNamespace(),e.getName());if(!n)throw new U(Q.format("$.$ was not available",e.getNamespace(),e.getName()));let a=new Map(n.getSignature().getParameters());for(let t of Array.from(e.getParameterMap().entries())){let e=a.get(t[0]);if(!e)continue;let n=t[1];if(n.length){if(e.isVariableArgument())for(let t of n)this.parameterReferenceValidation(s,e,t,r);else{let t=n[0];this.parameterReferenceValidation(s,e,t,r)}a.delete(e.getParameterName())}else u(ue.getDefaultValue(e.getSchema(),r))&&s.addMessage(es.ERROR,Q.format(rs.PARAMETER_NEEDS_A_VALUE,e.getParameterName())),a.delete(e.getParameterName())}if(!u(s.getStatement().getDependentStatements()))for(let e of s.getStatement().getDependentStatements())s.addDependency(e);if(a.size)for(let e of Array.from(a.values()))u(ue.getDefaultValue(e.getSchema(),r))&&s.addMessage(es.ERROR,Q.format(rs.PARAMETER_NEEDS_A_VALUE,e.getParameterName()));return s}parameterReferenceValidation(e,t,r,s){if(r){if(r.getType()==Jr.VALUE){u(r.getValue())&&u(ue.getDefaultValue(t.getSchema(),s))&&e.addMessage(es.ERROR,Q.format(rs.PARAMETER_NEEDS_A_VALUE,t.getParameterName()));let n=new Ce;for(n.push(new se(t.getSchema(),r.getValue()));!n.isEmpty();){let t=n.pop();if(t.getT2()instanceof Xr)this.addDependencies(e,t.getT2().getExpression());else{if(u(t.getT1())||u(t.getT1().getType()))continue;if(t.getT1().getType()?.contains(c.ARRAY)&&Array.isArray(t.getT2())){let e=t.getT1().getItems();if(!e)continue;if(e.isSingleType())for(let r of t.getT2())n.push(new se(e.getSingleSchema(),r));else{let r=t.getT2();for(let t=0;t<r.length;t++)n.push(new se(e.getTupleSchema()[t],r[t]))}}else if(t.getT1().getType()?.contains(c.OBJECT)&&"object"==typeof t.getT2()){let r=t.getT1();if(r.getName()===P.EXPRESSION.getName()&&r.getNamespace()===P.EXPRESSION.getNamespace()){let r=t.getT2();r.isExpression&&this.addDependencies(e,r.value)}else if(r.getProperties())for(let e of Object.entries(t.getT2()))r.getProperties().has(e[0])&&n.push(new se(r.getProperties().get(e[0]),e[1]))}}}}else if(r.getType()==Jr.EXPRESSION)if(ee.isNullOrBlank(r.getExpression()))u(ue.getDefaultValue(t.getSchema(),s))&&e.addMessage(es.ERROR,Q.format(rs.PARAMETER_NEEDS_A_VALUE,t.getParameterName()));else try{this.addDependencies(e,r.getExpression())}catch(t){e.addMessage(es.ERROR,Q.format("Error evaluating $ : $",r.getExpression(),t))}}else u(ue.getDefaultValue(t.getSchema(),s))&&e.addMessage(es.ERROR,Q.format(rs.PARAMETER_NEEDS_A_VALUE,t.getParameterName()))}addDependencies(e,t){t&&Array.from(t.match(rs.STEP_REGEX_PATTERN)??[]).forEach((t=>e.addDependency(t)))}makeEdges(e){let t=e.getNodeMap().values(),r=[];for(let s of Array.from(t))for(let t of s.getData().getDependencies()){let n=t.indexOf(".",6),a=t.substring(6,n),i=t.indexOf(".",n+1),o=-1==i?t.substring(n+1):t.substring(n+1,i);e.getNodeMap().has(a)||r.push(new se(a,o));let u=e.getNodeMap().get(a);u&&s.addInEdgeTo(u,o)}return r}}var ss={};t(ss,"KIRunConstants",(()=>ns));class ns{static NAMESPACE="namespace";static NAME="name";static ID="id";constructor(){}}var as={};t(as,"Position",(()=>is));class is{static SCHEMA_NAME="Position";static SCHEMA=(new N).setNamespace(a.SYSTEM).setName(is.SCHEMA_NAME).setType(O.of(c.OBJECT)).setProperties(new Map([["left",N.ofFloat("left")],["top",N.ofFloat("top")]]));constructor(e,t){this.left=e,this.top=t}getLeft(){return this.left}setLeft(e){return this.left=e,this}getTop(){return this.top}setTop(e){return this.top=e,this}static from(e){return e?new is(e.left,e.top):new is(-1,-1)}}var os={};t(os,"FunctionDefinition",(()=>Ts));var us={};t(us,"Statement",(()=>cs));var ps={};t(ps,"AbstractStatement",(()=>ls));class ls{override=!1;getComment(){return this.comment}setComment(e){return this.comment=e,this}isOverride(){return this.override}setOverride(e){return this.override=e,this}getDescription(){return this.description}setDescription(e){return this.description=e,this}getPosition(){return this.position}setPosition(e){return this.position=e,this}}var hs={};t(hs,"ParameterReference",(()=>ms));class ms{static SCHEMA_NAME="ParameterReference";static SCHEMA=(new N).setNamespace(a.SYSTEM).setName(ms.SCHEMA_NAME).setType(O.of(c.OBJECT)).setProperties(new Map([["value",N.ofAny("value")],["expression",N.ofString("expression")],["type",N.ofString("type").setEnums(["EXPRESSION","VALUE"])]]));constructor(e){this.type=e}getType(){return this.type}setType(e){return this.type=e,this}getValue(){return this.value}setValue(e){return this.value=e,this}getExpression(){return this.expression}setExpression(e){return this.expression=e,this}static ofExpression(e){return new ms(Jr.EXPRESSION).setExpression(e)}static ofValue(e){return new ms(Jr.VALUE).setValue(e)}static from(e){return e?Array.from(e).map((e=>new ms(e.type).setValue(e.value).setExpression(e.expression))):[]}}class cs extends ls{static SCHEMA_NAME="Statement";static SCHEMA=(new N).setNamespace(a.SYSTEM).setName(cs.SCHEMA_NAME).setType(O.of(c.OBJECT)).setProperties(new Map([["statementName",N.ofString("statementName")],["comment",N.ofString("comment")],["description",N.ofString("description")],["namespace",N.ofString("namespace")],["name",N.ofString("name")],["dependentStatements",N.ofArray("dependentstatement",N.ofString("dependentstatement"))],["parameterMap",(new N).setName("parameterMap").setAdditionalProperties((new h).setSchemaValue(N.ofArray("parameterReference",ms.SCHEMA)))],["position",is.SCHEMA]]));constructor(e,t,r){super(),this.statementName=e,this.namespace=t,this.name=r}getStatementName(){return this.statementName}setStatementName(e){return this.statementName=e,this}getNamespace(){return this.namespace}setNamespace(e){return this.namespace=e,this}getName(){return this.name}setName(e){return this.name=e,this}getParameterMap(){return this.parameterMap||(this.parameterMap=new Map),this.parameterMap}setParameterMap(e){return this.parameterMap=e,this}getDependentStatements(){return this.dependentStatements??[]}setDependentStatements(e){return this.dependentStatements=e,this}equals(e){if(!(e instanceof cs))return!1;return e.statementName==this.statementName}static ofEntry(e){return[e.statementName,e]}static from(e){return new cs(e.statementName,e.namespace,e.name).setParameterMap(new Map(Object.entries(e.parameterMap??{}).map((([e,t])=>[e,ms.from(t)])))).setDependentStatements(e.dependentStatements).setPosition(is.from(e.position)).setComment(e.comment).setDescription(e.description)}}var gs={};t(gs,"StatementGroup",(()=>fs));class fs extends ls{static SCHEMA_NAME="StatementGroup";static SCHEMA=(new N).setNamespace(a.SYSTEM).setName(fs.SCHEMA_NAME).setType(O.of(c.OBJECT)).setProperties(new Map([["statementGroupName",N.ofString("statementGroupName")],["comment",N.ofString("comment")],["description",N.ofString("description")],["position",is.SCHEMA]]));constructor(e){super(),this.statementGroupName=e}getStatementGroupName(){return this.statementGroupName}setStatementGroupName(e){return this.statementGroupName=e,this}static from(e){return new fs(e.statementGroupName).setPosition(is.from(e.position)).setComment(e.comment).setDescription(e.description)}}const Es=(new N).setNamespace(a.SYSTEM).setName("FunctionDefinition").setProperties(new Map([["name",N.ofString("name")],["namespace",N.ofString("namespace")],["parameters",N.ofArray("parameters",P.SCHEMA)],["events",N.ofObject("events").setAdditionalProperties((new h).setSchemaValue(k.SCHEMA))],["steps",N.ofObject("steps").setAdditionalProperties((new h).setSchemaValue(cs.SCHEMA))]]));Es.getProperties()?.set("parts",N.ofArray("parts",Es));class Ts extends j{static SCHEMA=Es;version=1;constructor(e){super(e)}getVersion(){return this.version}setVersion(e){return this.version=e,this}getSteps(){return this.steps??new Map}setSteps(e){return this.steps=e,this}getStepGroups(){return this.stepGroups}setStepGroups(e){return this.stepGroups=e,this}getParts(){return this.parts}setParts(e){return this.parts=e,this}static from(e){return e?new Ts(e.name).setSteps(new Map(Object.values(e.steps??{}).filter((e=>!!e)).map((e=>[e.statementName,cs.from(e)])))).setStepGroups(new Map(Object.values(e.stepGroups??{}).filter((e=>!!e)).map((e=>[e.statementGroupName,fs.from(e)])))).setParts(Array.from(e.parts??[]).filter((e=>!!e)).map((e=>Ts.from(e)))).setVersion(e.version??1).setEvents(new Map(Object.values(e.events??{}).filter((e=>!!e)).map((e=>[e.name,k.from(e)])))).setParameters(new Map(Object.values(e.parameters??{}).filter((e=>!!e)).map((e=>[e.parameterName,P.from(e)])))):new Ts("unknown")}}var As={};t(As,"Argument",(()=>ds));class ds{argumentIndex=0;constructor(e,t,r){this.argumentIndex=e,this.name=t,this.value=r}getArgumentIndex(){return this.argumentIndex}setArgumentIndex(e){return this.argumentIndex=e,this}getName(){return this.name}setName(e){return this.name=e,this}getValue(){return this.value}setValue(e){return this.value=e,this}static of(e,t){return new ds(0,e,t)}}var Ss={};e(Ss,Wt),e(Ss,Jt),e(Ss,Kt),e(Ss,Zt),e(Ss,jt);var ws={};e(ws,Ke),e(ws,Ze),e(ws,tt),e(ws,st),e(ws,at),e(ws,ot),e(ws,pt),e(ws,qe),e(ws,ht),e(ws,ct),e(ws,ft),e(ws,Tt),e(ws,dt),e(ws,wt),e(ws,Nt),e(ws,yt),e(ws,_t),e(ws,Ct),e(ws,Ut),e(ws,Gt),e(ws,Bt),e(ws,Ft),e(ws,Yt),e(ws,Xe),e(module.exports,r),e(module.exports,C),e(module.exports,{}),e(module.exports,xt),e(module.exports,Ar),e(module.exports,o),e(module.exports,Le),e(module.exports,Ue),e(module.exports,J),e(module.exports,Z),e(module.exports,re),e(module.exports,Mr),e(module.exports,vt),e(module.exports,_r),e(module.exports,Lr),e(module.exports,X),e(module.exports,Ur),e(module.exports,Br),e(module.exports,Gr),e(module.exports,Fr),e(module.exports,{}),e(module.exports,Hr),e(module.exports,Wr),e(module.exports,Zr),e(module.exports,Kr),e(module.exports,_e),e(module.exports,rr),e(module.exports,tr),e(module.exports,je),e(module.exports,Ye),e(module.exports,Ge),e(module.exports,Be),e(module.exports,Fe),e(module.exports,{}),e(module.exports,K),e(module.exports,n),e(module.exports,jr),e(module.exports,s),e(module.exports,Ae),e(module.exports,ge),e(module.exports,Ee),e(module.exports,me),e(module.exports,pe),e(module.exports,Oe),e(module.exports,Se),e(module.exports,z),e(module.exports,ie),e(module.exports,R),e(module.exports,he),e(module.exports,i),e(module.exports,S),e(module.exports,f),e(module.exports,E),e(module.exports,T),e(module.exports,m),e(module.exports,l),e(module.exports,te),e(module.exports,V),e(module.exports,xr),e(module.exports,ss),e(module.exports,x),e(module.exports,Y),e(module.exports,as),e(module.exports,os),e(module.exports,qr),e(module.exports,F),e(module.exports,ps),e(module.exports,us),e(module.exports,{}),e(module.exports,gs),e(module.exports,W),e(module.exports,G),e(module.exports,y),e(module.exports,As),e(module.exports,hs),e(module.exports,Me),e(module.exports,b),e(module.exports,Ss),e(module.exports,ws);
2
2
  //# sourceMappingURL=index.js.map