@flowgram.ai/runtime-js 0.4.13 → 0.4.15

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/esm/index.js CHANGED
@@ -187,6 +187,8 @@ var WorkflowVariableType = /* @__PURE__ */ ((WorkflowVariableType2) => {
187
187
  WorkflowVariableType2["Boolean"] = "boolean";
188
188
  WorkflowVariableType2["Object"] = "object";
189
189
  WorkflowVariableType2["Array"] = "array";
190
+ WorkflowVariableType2["Map"] = "map";
191
+ WorkflowVariableType2["DateTime"] = "date-time";
190
192
  WorkflowVariableType2["Null"] = "null";
191
193
  return WorkflowVariableType2;
192
194
  })(WorkflowVariableType || {});
@@ -207,23 +209,23 @@ var FlowGramNode = /* @__PURE__ */ ((FlowGramNode22) => {
207
209
  FlowGramNode22["Continue"] = "continue";
208
210
  return FlowGramNode22;
209
211
  })(FlowGramNode || {});
210
- var ConditionOperation = /* @__PURE__ */ ((ConditionOperation2) => {
211
- ConditionOperation2["EQ"] = "eq";
212
- ConditionOperation2["NEQ"] = "neq";
213
- ConditionOperation2["GT"] = "gt";
214
- ConditionOperation2["GTE"] = "gte";
215
- ConditionOperation2["LT"] = "lt";
216
- ConditionOperation2["LTE"] = "lte";
217
- ConditionOperation2["IN"] = "in";
218
- ConditionOperation2["NIN"] = "nin";
219
- ConditionOperation2["CONTAINS"] = "contains";
220
- ConditionOperation2["NOT_CONTAINS"] = "not_contains";
221
- ConditionOperation2["IS_EMPTY"] = "is_empty";
222
- ConditionOperation2["IS_NOT_EMPTY"] = "is_not_empty";
223
- ConditionOperation2["IS_TRUE"] = "is_true";
224
- ConditionOperation2["IS_FALSE"] = "is_false";
225
- return ConditionOperation2;
226
- })(ConditionOperation || {});
212
+ var ConditionOperator = /* @__PURE__ */ ((ConditionOperator22) => {
213
+ ConditionOperator22["EQ"] = "eq";
214
+ ConditionOperator22["NEQ"] = "neq";
215
+ ConditionOperator22["GT"] = "gt";
216
+ ConditionOperator22["GTE"] = "gte";
217
+ ConditionOperator22["LT"] = "lt";
218
+ ConditionOperator22["LTE"] = "lte";
219
+ ConditionOperator22["IN"] = "in";
220
+ ConditionOperator22["NIN"] = "nin";
221
+ ConditionOperator22["CONTAINS"] = "contains";
222
+ ConditionOperator22["NOT_CONTAINS"] = "not_contains";
223
+ ConditionOperator22["IS_EMPTY"] = "is_empty";
224
+ ConditionOperator22["IS_NOT_EMPTY"] = "is_not_empty";
225
+ ConditionOperator22["IS_TRUE"] = "is_true";
226
+ ConditionOperator22["IS_FALSE"] = "is_false";
227
+ return ConditionOperator22;
228
+ })(ConditionOperator || {});
227
229
  var HTTPBodyType = /* @__PURE__ */ ((HTTPBodyType2) => {
228
230
  HTTPBodyType2["None"] = "none";
229
231
  HTTPBodyType2["FormData"] = "form-data";
@@ -280,6 +282,13 @@ var WorkflowRuntimeType;
280
282
  return WorkflowVariableType.Null;
281
283
  }
282
284
  if (typeof value === "string") {
285
+ const iso8601Regex = /^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}(\.\d{3})?Z?$/;
286
+ if (iso8601Regex.test(value)) {
287
+ const date = new Date(value);
288
+ if (!isNaN(date.getTime())) {
289
+ return WorkflowVariableType.DateTime;
290
+ }
291
+ }
283
292
  return WorkflowVariableType.String;
284
293
  }
285
294
  if (typeof value === "boolean") {
@@ -306,11 +315,11 @@ var WorkflowRuntimeType;
306
315
  }
307
316
  return workflowType === type;
308
317
  };
309
- WorkflowRuntimeType2.isTypeEqual = (leftType, rightType) => {
310
- if (leftType === WorkflowVariableType.Number && rightType === WorkflowVariableType.Integer || leftType === WorkflowVariableType.Integer && rightType === WorkflowVariableType.Number) {
318
+ WorkflowRuntimeType2.isTypeEqual = (typeA, typeB) => {
319
+ if (typeA === WorkflowVariableType.Number && typeB === WorkflowVariableType.Integer || typeA === WorkflowVariableType.Integer && typeB === WorkflowVariableType.Number) {
311
320
  return true;
312
321
  }
313
- return leftType === rightType;
322
+ return typeA === typeB;
314
323
  };
315
324
  WorkflowRuntimeType2.getArrayItemsType = (types) => {
316
325
  const expectedType = types[0];
@@ -1045,66 +1054,80 @@ var ContinueExecutor = class {
1045
1054
  };
1046
1055
 
1047
1056
  // src/nodes/condition/index.ts
1048
- import { isNil as isNil9 } from "lodash-es";
1057
+ import { isNil as isNil11 } from "lodash-es";
1049
1058
 
1050
1059
  // src/nodes/condition/rules.ts
1051
1060
  var conditionRules = {
1052
1061
  [WorkflowVariableType.String]: {
1053
- [ConditionOperation.EQ]: WorkflowVariableType.String,
1054
- [ConditionOperation.NEQ]: WorkflowVariableType.String,
1055
- [ConditionOperation.CONTAINS]: WorkflowVariableType.String,
1056
- [ConditionOperation.NOT_CONTAINS]: WorkflowVariableType.String,
1057
- [ConditionOperation.IN]: WorkflowVariableType.Array,
1058
- [ConditionOperation.NIN]: WorkflowVariableType.Array,
1059
- [ConditionOperation.IS_EMPTY]: WorkflowVariableType.String,
1060
- [ConditionOperation.IS_NOT_EMPTY]: WorkflowVariableType.String
1062
+ [ConditionOperator.EQ]: WorkflowVariableType.String,
1063
+ [ConditionOperator.NEQ]: WorkflowVariableType.String,
1064
+ [ConditionOperator.CONTAINS]: WorkflowVariableType.String,
1065
+ [ConditionOperator.NOT_CONTAINS]: WorkflowVariableType.String,
1066
+ [ConditionOperator.IN]: WorkflowVariableType.Array,
1067
+ [ConditionOperator.NIN]: WorkflowVariableType.Array,
1068
+ [ConditionOperator.IS_EMPTY]: WorkflowVariableType.String,
1069
+ [ConditionOperator.IS_NOT_EMPTY]: WorkflowVariableType.String
1061
1070
  },
1062
1071
  [WorkflowVariableType.Number]: {
1063
- [ConditionOperation.EQ]: WorkflowVariableType.Number,
1064
- [ConditionOperation.NEQ]: WorkflowVariableType.Number,
1065
- [ConditionOperation.GT]: WorkflowVariableType.Number,
1066
- [ConditionOperation.GTE]: WorkflowVariableType.Number,
1067
- [ConditionOperation.LT]: WorkflowVariableType.Number,
1068
- [ConditionOperation.LTE]: WorkflowVariableType.Number,
1069
- [ConditionOperation.IN]: WorkflowVariableType.Array,
1070
- [ConditionOperation.NIN]: WorkflowVariableType.Array,
1071
- [ConditionOperation.IS_EMPTY]: WorkflowVariableType.Null,
1072
- [ConditionOperation.IS_NOT_EMPTY]: WorkflowVariableType.Null
1072
+ [ConditionOperator.EQ]: WorkflowVariableType.Number,
1073
+ [ConditionOperator.NEQ]: WorkflowVariableType.Number,
1074
+ [ConditionOperator.GT]: WorkflowVariableType.Number,
1075
+ [ConditionOperator.GTE]: WorkflowVariableType.Number,
1076
+ [ConditionOperator.LT]: WorkflowVariableType.Number,
1077
+ [ConditionOperator.LTE]: WorkflowVariableType.Number,
1078
+ [ConditionOperator.IN]: WorkflowVariableType.Array,
1079
+ [ConditionOperator.NIN]: WorkflowVariableType.Array,
1080
+ [ConditionOperator.IS_EMPTY]: WorkflowVariableType.Null,
1081
+ [ConditionOperator.IS_NOT_EMPTY]: WorkflowVariableType.Null
1073
1082
  },
1074
1083
  [WorkflowVariableType.Integer]: {
1075
- [ConditionOperation.EQ]: WorkflowVariableType.Integer,
1076
- [ConditionOperation.NEQ]: WorkflowVariableType.Integer,
1077
- [ConditionOperation.GT]: WorkflowVariableType.Integer,
1078
- [ConditionOperation.GTE]: WorkflowVariableType.Integer,
1079
- [ConditionOperation.LT]: WorkflowVariableType.Integer,
1080
- [ConditionOperation.LTE]: WorkflowVariableType.Integer,
1081
- [ConditionOperation.IN]: WorkflowVariableType.Array,
1082
- [ConditionOperation.NIN]: WorkflowVariableType.Array,
1083
- [ConditionOperation.IS_EMPTY]: WorkflowVariableType.Null,
1084
- [ConditionOperation.IS_NOT_EMPTY]: WorkflowVariableType.Null
1084
+ [ConditionOperator.EQ]: WorkflowVariableType.Integer,
1085
+ [ConditionOperator.NEQ]: WorkflowVariableType.Integer,
1086
+ [ConditionOperator.GT]: WorkflowVariableType.Integer,
1087
+ [ConditionOperator.GTE]: WorkflowVariableType.Integer,
1088
+ [ConditionOperator.LT]: WorkflowVariableType.Integer,
1089
+ [ConditionOperator.LTE]: WorkflowVariableType.Integer,
1090
+ [ConditionOperator.IN]: WorkflowVariableType.Array,
1091
+ [ConditionOperator.NIN]: WorkflowVariableType.Array,
1092
+ [ConditionOperator.IS_EMPTY]: WorkflowVariableType.Null,
1093
+ [ConditionOperator.IS_NOT_EMPTY]: WorkflowVariableType.Null
1085
1094
  },
1086
1095
  [WorkflowVariableType.Boolean]: {
1087
- [ConditionOperation.EQ]: WorkflowVariableType.Boolean,
1088
- [ConditionOperation.NEQ]: WorkflowVariableType.Boolean,
1089
- [ConditionOperation.IS_TRUE]: WorkflowVariableType.Null,
1090
- [ConditionOperation.IS_FALSE]: WorkflowVariableType.Null,
1091
- [ConditionOperation.IN]: WorkflowVariableType.Array,
1092
- [ConditionOperation.NIN]: WorkflowVariableType.Array,
1093
- [ConditionOperation.IS_EMPTY]: WorkflowVariableType.Null,
1094
- [ConditionOperation.IS_NOT_EMPTY]: WorkflowVariableType.Null
1096
+ [ConditionOperator.EQ]: WorkflowVariableType.Boolean,
1097
+ [ConditionOperator.NEQ]: WorkflowVariableType.Boolean,
1098
+ [ConditionOperator.IS_TRUE]: WorkflowVariableType.Null,
1099
+ [ConditionOperator.IS_FALSE]: WorkflowVariableType.Null,
1100
+ [ConditionOperator.IN]: WorkflowVariableType.Array,
1101
+ [ConditionOperator.NIN]: WorkflowVariableType.Array,
1102
+ [ConditionOperator.IS_EMPTY]: WorkflowVariableType.Null,
1103
+ [ConditionOperator.IS_NOT_EMPTY]: WorkflowVariableType.Null
1095
1104
  },
1096
1105
  [WorkflowVariableType.Object]: {
1097
- [ConditionOperation.IS_EMPTY]: WorkflowVariableType.Null,
1098
- [ConditionOperation.IS_NOT_EMPTY]: WorkflowVariableType.Null
1106
+ [ConditionOperator.IS_EMPTY]: WorkflowVariableType.Null,
1107
+ [ConditionOperator.IS_NOT_EMPTY]: WorkflowVariableType.Null
1108
+ },
1109
+ [WorkflowVariableType.Map]: {
1110
+ [ConditionOperator.IS_EMPTY]: WorkflowVariableType.Null,
1111
+ [ConditionOperator.IS_NOT_EMPTY]: WorkflowVariableType.Null
1112
+ },
1113
+ [WorkflowVariableType.DateTime]: {
1114
+ [ConditionOperator.EQ]: WorkflowVariableType.DateTime,
1115
+ [ConditionOperator.NEQ]: WorkflowVariableType.DateTime,
1116
+ [ConditionOperator.GT]: WorkflowVariableType.DateTime,
1117
+ [ConditionOperator.GTE]: WorkflowVariableType.DateTime,
1118
+ [ConditionOperator.LT]: WorkflowVariableType.DateTime,
1119
+ [ConditionOperator.LTE]: WorkflowVariableType.DateTime,
1120
+ [ConditionOperator.IS_EMPTY]: WorkflowVariableType.Null,
1121
+ [ConditionOperator.IS_NOT_EMPTY]: WorkflowVariableType.Null
1099
1122
  },
1100
1123
  [WorkflowVariableType.Array]: {
1101
- [ConditionOperation.IS_EMPTY]: WorkflowVariableType.Null,
1102
- [ConditionOperation.IS_NOT_EMPTY]: WorkflowVariableType.Null
1124
+ [ConditionOperator.IS_EMPTY]: WorkflowVariableType.Null,
1125
+ [ConditionOperator.IS_NOT_EMPTY]: WorkflowVariableType.Null
1103
1126
  },
1104
1127
  [WorkflowVariableType.Null]: {
1105
- [ConditionOperation.EQ]: WorkflowVariableType.Null,
1106
- [ConditionOperation.IS_EMPTY]: WorkflowVariableType.Null,
1107
- [ConditionOperation.IS_NOT_EMPTY]: WorkflowVariableType.Null
1128
+ [ConditionOperator.EQ]: WorkflowVariableType.Null,
1129
+ [ConditionOperator.IS_EMPTY]: WorkflowVariableType.Null,
1130
+ [ConditionOperator.IS_NOT_EMPTY]: WorkflowVariableType.Null
1108
1131
  }
1109
1132
  };
1110
1133
 
@@ -1113,34 +1136,34 @@ import { isNil as isNil3 } from "lodash-es";
1113
1136
  var conditionStringHandler = (condition) => {
1114
1137
  const { operator } = condition;
1115
1138
  const leftValue = condition.leftValue;
1116
- if (operator === ConditionOperation.EQ) {
1139
+ if (operator === ConditionOperator.EQ) {
1117
1140
  const rightValue = condition.rightValue;
1118
1141
  return leftValue === rightValue;
1119
1142
  }
1120
- if (operator === ConditionOperation.NEQ) {
1143
+ if (operator === ConditionOperator.NEQ) {
1121
1144
  const rightValue = condition.rightValue;
1122
1145
  return leftValue !== rightValue;
1123
1146
  }
1124
- if (operator === ConditionOperation.CONTAINS) {
1147
+ if (operator === ConditionOperator.CONTAINS) {
1125
1148
  const rightValue = condition.rightValue;
1126
1149
  return leftValue.includes(rightValue);
1127
1150
  }
1128
- if (operator === ConditionOperation.NOT_CONTAINS) {
1151
+ if (operator === ConditionOperator.NOT_CONTAINS) {
1129
1152
  const rightValue = condition.rightValue;
1130
1153
  return !leftValue.includes(rightValue);
1131
1154
  }
1132
- if (operator === ConditionOperation.IN) {
1155
+ if (operator === ConditionOperator.IN) {
1133
1156
  const rightValue = condition.rightValue;
1134
1157
  return rightValue.includes(leftValue);
1135
1158
  }
1136
- if (operator === ConditionOperation.NIN) {
1159
+ if (operator === ConditionOperator.NIN) {
1137
1160
  const rightValue = condition.rightValue;
1138
1161
  return !rightValue.includes(leftValue);
1139
1162
  }
1140
- if (operator === ConditionOperation.IS_EMPTY) {
1163
+ if (operator === ConditionOperator.IS_EMPTY) {
1141
1164
  return isNil3(leftValue);
1142
1165
  }
1143
- if (operator === ConditionOperation.IS_NOT_EMPTY) {
1166
+ if (operator === ConditionOperator.IS_NOT_EMPTY) {
1144
1167
  return !isNil3(leftValue);
1145
1168
  }
1146
1169
  return false;
@@ -1151,10 +1174,10 @@ import { isNil as isNil4 } from "lodash-es";
1151
1174
  var conditionObjectHandler = (condition) => {
1152
1175
  const { operator } = condition;
1153
1176
  const leftValue = condition.leftValue;
1154
- if (operator === ConditionOperation.IS_EMPTY) {
1177
+ if (operator === ConditionOperator.IS_EMPTY) {
1155
1178
  return isNil4(leftValue);
1156
1179
  }
1157
- if (operator === ConditionOperation.IS_NOT_EMPTY) {
1180
+ if (operator === ConditionOperator.IS_NOT_EMPTY) {
1158
1181
  return !isNil4(leftValue);
1159
1182
  }
1160
1183
  return false;
@@ -1165,42 +1188,42 @@ import { isNil as isNil5 } from "lodash-es";
1165
1188
  var conditionNumberHandler = (condition) => {
1166
1189
  const { operator } = condition;
1167
1190
  const leftValue = condition.leftValue;
1168
- if (operator === ConditionOperation.EQ) {
1191
+ if (operator === ConditionOperator.EQ) {
1169
1192
  const rightValue = condition.rightValue;
1170
1193
  return leftValue === rightValue;
1171
1194
  }
1172
- if (operator === ConditionOperation.NEQ) {
1195
+ if (operator === ConditionOperator.NEQ) {
1173
1196
  const rightValue = condition.rightValue;
1174
1197
  return leftValue !== rightValue;
1175
1198
  }
1176
- if (operator === ConditionOperation.GT) {
1199
+ if (operator === ConditionOperator.GT) {
1177
1200
  const rightValue = condition.rightValue;
1178
1201
  return leftValue > rightValue;
1179
1202
  }
1180
- if (operator === ConditionOperation.GTE) {
1203
+ if (operator === ConditionOperator.GTE) {
1181
1204
  const rightValue = condition.rightValue;
1182
1205
  return leftValue >= rightValue;
1183
1206
  }
1184
- if (operator === ConditionOperation.LT) {
1207
+ if (operator === ConditionOperator.LT) {
1185
1208
  const rightValue = condition.rightValue;
1186
1209
  return leftValue < rightValue;
1187
1210
  }
1188
- if (operator === ConditionOperation.LTE) {
1211
+ if (operator === ConditionOperator.LTE) {
1189
1212
  const rightValue = condition.rightValue;
1190
1213
  return leftValue <= rightValue;
1191
1214
  }
1192
- if (operator === ConditionOperation.IN) {
1215
+ if (operator === ConditionOperator.IN) {
1193
1216
  const rightValue = condition.rightValue;
1194
1217
  return rightValue.includes(leftValue);
1195
1218
  }
1196
- if (operator === ConditionOperation.NIN) {
1219
+ if (operator === ConditionOperator.NIN) {
1197
1220
  const rightValue = condition.rightValue;
1198
1221
  return !rightValue.includes(leftValue);
1199
1222
  }
1200
- if (operator === ConditionOperation.IS_EMPTY) {
1223
+ if (operator === ConditionOperator.IS_EMPTY) {
1201
1224
  return isNil5(leftValue);
1202
1225
  }
1203
- if (operator === ConditionOperation.IS_NOT_EMPTY) {
1226
+ if (operator === ConditionOperator.IS_NOT_EMPTY) {
1204
1227
  return !isNil5(leftValue);
1205
1228
  }
1206
1229
  return false;
@@ -1211,64 +1234,119 @@ import { isNil as isNil6 } from "lodash-es";
1211
1234
  var conditionNullHandler = (condition) => {
1212
1235
  const { operator } = condition;
1213
1236
  const leftValue = condition.leftValue;
1214
- if (operator === ConditionOperation.EQ) {
1237
+ if (operator === ConditionOperator.EQ) {
1215
1238
  return isNil6(leftValue) && isNil6(condition.rightValue);
1216
1239
  }
1217
- if (operator === ConditionOperation.IS_EMPTY) {
1240
+ if (operator === ConditionOperator.IS_EMPTY) {
1218
1241
  return isNil6(leftValue);
1219
1242
  }
1220
- if (operator === ConditionOperation.IS_NOT_EMPTY) {
1243
+ if (operator === ConditionOperator.IS_NOT_EMPTY) {
1221
1244
  return !isNil6(leftValue);
1222
1245
  }
1223
1246
  return false;
1224
1247
  };
1225
1248
 
1226
- // src/nodes/condition/handlers/boolean.ts
1249
+ // src/nodes/condition/handlers/map.ts
1227
1250
  import { isNil as isNil7 } from "lodash-es";
1251
+ var conditionMapHandler = (condition) => {
1252
+ const { operator } = condition;
1253
+ const leftValue = condition.leftValue;
1254
+ if (operator === ConditionOperator.IS_EMPTY) {
1255
+ return isNil7(leftValue);
1256
+ }
1257
+ if (operator === ConditionOperator.IS_NOT_EMPTY) {
1258
+ return !isNil7(leftValue);
1259
+ }
1260
+ return false;
1261
+ };
1262
+
1263
+ // src/nodes/condition/handlers/datetime.ts
1264
+ import { isNil as isNil8 } from "lodash-es";
1265
+ var parseDateTime = (value) => {
1266
+ if (value instanceof Date) {
1267
+ return value;
1268
+ }
1269
+ return new Date(value);
1270
+ };
1271
+ var conditionDateTimeHandler = (condition) => {
1272
+ const { operator } = condition;
1273
+ const leftValue = condition.leftValue;
1274
+ if (operator === ConditionOperator.IS_EMPTY) {
1275
+ return isNil8(leftValue);
1276
+ }
1277
+ if (operator === ConditionOperator.IS_NOT_EMPTY) {
1278
+ return !isNil8(leftValue);
1279
+ }
1280
+ const leftTime = parseDateTime(leftValue).getTime();
1281
+ const rightValue = condition.rightValue;
1282
+ const rightTime = parseDateTime(rightValue).getTime();
1283
+ if (operator === ConditionOperator.EQ) {
1284
+ return leftTime === rightTime;
1285
+ }
1286
+ if (operator === ConditionOperator.NEQ) {
1287
+ return leftTime !== rightTime;
1288
+ }
1289
+ if (operator === ConditionOperator.GT) {
1290
+ return leftTime > rightTime;
1291
+ }
1292
+ if (operator === ConditionOperator.GTE) {
1293
+ return leftTime >= rightTime;
1294
+ }
1295
+ if (operator === ConditionOperator.LT) {
1296
+ return leftTime < rightTime;
1297
+ }
1298
+ if (operator === ConditionOperator.LTE) {
1299
+ return leftTime <= rightTime;
1300
+ }
1301
+ return false;
1302
+ };
1303
+
1304
+ // src/nodes/condition/handlers/boolean.ts
1305
+ import { isNil as isNil9 } from "lodash-es";
1228
1306
  var conditionBooleanHandler = (condition) => {
1229
1307
  const { operator } = condition;
1230
1308
  const leftValue = condition.leftValue;
1231
- if (operator === ConditionOperation.EQ) {
1309
+ if (operator === ConditionOperator.EQ) {
1232
1310
  const rightValue = condition.rightValue;
1233
1311
  return leftValue === rightValue;
1234
1312
  }
1235
- if (operator === ConditionOperation.NEQ) {
1313
+ if (operator === ConditionOperator.NEQ) {
1236
1314
  const rightValue = condition.rightValue;
1237
1315
  return leftValue !== rightValue;
1238
1316
  }
1239
- if (operator === ConditionOperation.IS_TRUE) {
1317
+ if (operator === ConditionOperator.IS_TRUE) {
1240
1318
  return leftValue === true;
1241
1319
  }
1242
- if (operator === ConditionOperation.IS_FALSE) {
1320
+ if (operator === ConditionOperator.IS_FALSE) {
1243
1321
  return leftValue === false;
1244
1322
  }
1245
- if (operator === ConditionOperation.IN) {
1323
+ if (operator === ConditionOperator.IN) {
1246
1324
  const rightValue = condition.rightValue;
1247
1325
  return rightValue.includes(leftValue);
1248
1326
  }
1249
- if (operator === ConditionOperation.NIN) {
1327
+ if (operator === ConditionOperator.NIN) {
1250
1328
  const rightValue = condition.rightValue;
1251
1329
  return !rightValue.includes(leftValue);
1252
1330
  }
1253
- if (operator === ConditionOperation.IS_EMPTY) {
1254
- return isNil7(leftValue);
1331
+ if (operator === ConditionOperator.IS_EMPTY) {
1332
+ return isNil9(leftValue);
1255
1333
  }
1256
- if (operator === ConditionOperation.IS_NOT_EMPTY) {
1257
- return !isNil7(leftValue);
1334
+ if (operator === ConditionOperator.IS_NOT_EMPTY) {
1335
+ return !isNil9(leftValue);
1258
1336
  }
1259
1337
  return false;
1260
1338
  };
1261
1339
 
1262
1340
  // src/nodes/condition/handlers/array.ts
1263
- import { isNil as isNil8 } from "lodash-es";
1341
+ import { isNil as isNil10 } from "lodash-es";
1264
1342
  var conditionArrayHandler = (condition) => {
1265
1343
  const { operator } = condition;
1266
1344
  const leftValue = condition.leftValue;
1267
- if (operator === ConditionOperation.IS_EMPTY) {
1268
- return isNil8(leftValue);
1345
+ if (operator === ConditionOperator.IS_EMPTY) {
1346
+ return isNil10(leftValue);
1269
1347
  }
1270
- if (operator === ConditionOperation.IS_NOT_EMPTY) {
1271
- return !isNil8(leftValue);
1348
+ if (operator === ConditionOperator.IS_NOT_EMPTY) {
1349
+ return !isNil10(leftValue);
1272
1350
  }
1273
1351
  return false;
1274
1352
  };
@@ -1280,7 +1358,9 @@ var conditionHandlers = {
1280
1358
  [WorkflowVariableType.Integer]: conditionNumberHandler,
1281
1359
  [WorkflowVariableType.Boolean]: conditionBooleanHandler,
1282
1360
  [WorkflowVariableType.Object]: conditionObjectHandler,
1361
+ [WorkflowVariableType.Map]: conditionMapHandler,
1283
1362
  [WorkflowVariableType.Array]: conditionArrayHandler,
1363
+ [WorkflowVariableType.DateTime]: conditionDateTimeHandler,
1284
1364
  [WorkflowVariableType.Null]: conditionNullHandler
1285
1365
  };
1286
1366
 
@@ -1299,7 +1379,10 @@ var ConditionExecutor = class {
1299
1379
  const parsedConditions = conditions.map((item) => this.parseCondition(item, context)).filter((item) => this.checkCondition(item));
1300
1380
  const activatedCondition = parsedConditions.find((item) => this.handleCondition(item));
1301
1381
  if (!activatedCondition) {
1302
- throw new Error("No condition is activated");
1382
+ return {
1383
+ outputs: {},
1384
+ branch: "else"
1385
+ };
1303
1386
  }
1304
1387
  return {
1305
1388
  outputs: {},
@@ -1312,7 +1395,11 @@ var ConditionExecutor = class {
1312
1395
  const parsedLeft = context.runtime.state.parseRef(left);
1313
1396
  const leftValue = parsedLeft?.value ?? null;
1314
1397
  const leftType = parsedLeft?.type ?? WorkflowVariableType.Null;
1315
- const parsedRight = Boolean(right) ? context.runtime.state.parseValue(right) : null;
1398
+ const expectedRightType = this.getRuleType({ leftType, operator });
1399
+ const parsedRight = Boolean(right) ? context.runtime.state.parseFlowValue({
1400
+ flowValue: right,
1401
+ declareType: expectedRightType
1402
+ }) : null;
1316
1403
  const rightValue = parsedRight?.value ?? null;
1317
1404
  const rightType = parsedRight?.type ?? WorkflowVariableType.Null;
1318
1405
  return {
@@ -1326,11 +1413,11 @@ var ConditionExecutor = class {
1326
1413
  }
1327
1414
  checkCondition(condition) {
1328
1415
  const rule = conditionRules[condition.leftType];
1329
- if (isNil9(rule)) {
1416
+ if (isNil11(rule)) {
1330
1417
  throw new Error(`Condition left type "${condition.leftType}" is not supported`);
1331
1418
  }
1332
1419
  const ruleType = rule[condition.operator];
1333
- if (isNil9(ruleType)) {
1420
+ if (isNil11(ruleType)) {
1334
1421
  throw new Error(
1335
1422
  `Condition left type "${condition.leftType}" has no operator "${condition.operator}"`
1336
1423
  );
@@ -1348,6 +1435,18 @@ var ConditionExecutor = class {
1348
1435
  const isActive = handler(condition);
1349
1436
  return isActive;
1350
1437
  }
1438
+ getRuleType(params) {
1439
+ const { leftType, operator } = params;
1440
+ const rule = conditionRules[leftType];
1441
+ if (isNil11(rule)) {
1442
+ return WorkflowVariableType.Null;
1443
+ }
1444
+ const ruleType = rule[operator];
1445
+ if (isNil11(ruleType)) {
1446
+ return WorkflowVariableType.Null;
1447
+ }
1448
+ return ruleType;
1449
+ }
1351
1450
  };
1352
1451
 
1353
1452
  // src/nodes/code/index.ts
@@ -2089,13 +2188,14 @@ var WorkflowRuntimeStatusCenter = class {
2089
2188
  };
2090
2189
 
2091
2190
  // src/domain/state/index.ts
2092
- import { isNil as isNil10 } from "lodash-es";
2191
+ import { isNil as isNil12 } from "lodash-es";
2093
2192
  var WorkflowRuntimeState = class {
2094
2193
  constructor(variableStore) {
2095
2194
  this.variableStore = variableStore;
2096
2195
  this.id = uuid();
2097
2196
  }
2098
- init() {
2197
+ init(schema) {
2198
+ this.setGlobalVariable(schema?.globalVariable);
2099
2199
  this.executedNodes = /* @__PURE__ */ new Set();
2100
2200
  }
2101
2201
  dispose() {
@@ -2112,16 +2212,17 @@ var WorkflowRuntimeState = class {
2112
2212
  setNodeOutputs(params) {
2113
2213
  const { node, outputs } = params;
2114
2214
  const outputsDeclare = node.declare.outputs;
2115
- if (!outputsDeclare) {
2215
+ if (outputsDeclare?.type !== "object" || !outputsDeclare.properties) {
2116
2216
  return;
2117
2217
  }
2118
- Object.entries(outputs).forEach(([key, value]) => {
2119
- const typeInfo = outputsDeclare.properties?.[key];
2120
- if (!typeInfo) {
2218
+ Object.entries(outputsDeclare.properties).forEach(([key, typeInfo]) => {
2219
+ if (!key || !typeInfo) {
2121
2220
  return;
2122
2221
  }
2123
2222
  const type = typeInfo.type;
2124
2223
  const itemsType = typeInfo.items?.type;
2224
+ const defaultValue = this.parseJSONContent(typeInfo.default, type);
2225
+ const value = outputs[key] ?? defaultValue;
2125
2226
  this.variableStore.setVariable({
2126
2227
  nodeID: node.id,
2127
2228
  key,
@@ -2136,18 +2237,18 @@ var WorkflowRuntimeState = class {
2136
2237
  if (!declare || !values) {
2137
2238
  return {};
2138
2239
  }
2139
- return Object.entries(values).reduce((prev, [key, inputValue]) => {
2240
+ return Object.entries(values).reduce((prev, [key, flowValue]) => {
2140
2241
  const typeInfo = declare.properties?.[key];
2141
2242
  if (!typeInfo) {
2142
2243
  return prev;
2143
2244
  }
2144
- const expectType = typeInfo.type;
2145
- const result = this.parseValue(inputValue);
2245
+ const declareType = typeInfo.type;
2246
+ const result = this.parseFlowValue({ flowValue, declareType });
2146
2247
  if (!result) {
2147
2248
  return prev;
2148
2249
  }
2149
2250
  const { value, type } = result;
2150
- if (!WorkflowRuntimeType.isTypeEqual(type, expectType)) {
2251
+ if (!WorkflowRuntimeType.isTypeEqual(type, declareType)) {
2151
2252
  return prev;
2152
2253
  }
2153
2254
  prev[key] = value;
@@ -2198,14 +2299,15 @@ var WorkflowRuntimeState = class {
2198
2299
  value: parsedValue
2199
2300
  };
2200
2301
  }
2201
- parseValue(flowValue) {
2302
+ parseFlowValue(params) {
2303
+ const { flowValue, declareType } = params;
2202
2304
  if (!flowValue?.type) {
2203
2305
  throw new Error(`Invalid flow value type: ${flowValue.type}`);
2204
2306
  }
2205
2307
  if (flowValue.type === "constant") {
2206
- const value = flowValue.content;
2207
- const type = WorkflowRuntimeType.getWorkflowType(value);
2208
- if (isNil10(value) || !type) {
2308
+ const value = this.parseJSONContent(flowValue.content, declareType);
2309
+ const type = declareType ?? WorkflowRuntimeType.getWorkflowType(value);
2310
+ if (isNil12(value) || !type) {
2209
2311
  return null;
2210
2312
  }
2211
2313
  return {
@@ -2227,6 +2329,41 @@ var WorkflowRuntimeState = class {
2227
2329
  addExecutedNode(node) {
2228
2330
  this.executedNodes.add(node.id);
2229
2331
  }
2332
+ parseJSONContent(jsonContent, declareType) {
2333
+ const JSONTypes = [
2334
+ WorkflowVariableType.Object,
2335
+ WorkflowVariableType.Array,
2336
+ WorkflowVariableType.Map
2337
+ ];
2338
+ if (declareType && JSONTypes.includes(declareType) && typeof jsonContent === "string") {
2339
+ try {
2340
+ return JSON.parse(jsonContent);
2341
+ } catch (e) {
2342
+ return jsonContent;
2343
+ }
2344
+ }
2345
+ return jsonContent;
2346
+ }
2347
+ setGlobalVariable(globalVariableDeclare) {
2348
+ if (globalVariableDeclare?.type !== "object" || !globalVariableDeclare.properties) {
2349
+ return;
2350
+ }
2351
+ Object.entries(globalVariableDeclare.properties).forEach(([key, typeInfo]) => {
2352
+ if (!key || !typeInfo) {
2353
+ return;
2354
+ }
2355
+ const type = typeInfo.type;
2356
+ const itemsType = typeInfo.items?.type;
2357
+ const defaultValue = this.parseJSONContent(typeInfo.default, type);
2358
+ this.variableStore.setVariable({
2359
+ nodeID: "global",
2360
+ key,
2361
+ value: defaultValue,
2362
+ type,
2363
+ itemsType
2364
+ });
2365
+ });
2366
+ }
2230
2367
  };
2231
2368
 
2232
2369
  // src/domain/snapshot/snapshot-entity/index.ts
@@ -2702,7 +2839,7 @@ var WorkflowRuntimeContext = class _WorkflowRuntimeContext {
2702
2839
  this.cache.init();
2703
2840
  this.document.init(schema);
2704
2841
  this.variableStore.init();
2705
- this.state.init();
2842
+ this.state.init(schema);
2706
2843
  this.ioCenter.init(inputs);
2707
2844
  this.snapshotCenter.init();
2708
2845
  this.statusCenter.init();
@@ -2888,7 +3025,7 @@ var WorkflowRuntimeEngine = class {
2888
3025
  }
2889
3026
  const targetPort = node.ports.outputs.find((port) => port.id === branch);
2890
3027
  if (!targetPort) {
2891
- throw new Error(`Engine branch ${branch} not found`);
3028
+ throw new Error(`Branch "${branch}" not found`);
2892
3029
  }
2893
3030
  const nextNodeIDs = new Set(targetPort.edges.map((edge) => edge.to.id));
2894
3031
  const nextNodes = allNextNodes.filter((nextNode) => nextNodeIDs.has(nextNode.id));
@@ -2913,7 +3050,7 @@ var WorkflowRuntimeEngine = class {
2913
3050
  return;
2914
3051
  }
2915
3052
  if (nextNodes.length === 0) {
2916
- throw new Error(`Node ${node.id} has no next nodes`);
3053
+ throw new Error(`Node "${node.id}" has no next nodes`);
2917
3054
  }
2918
3055
  await Promise.all(
2919
3056
  nextNodes.map(