@player-ui/markdown-plugin 0.12.1-next.0 → 0.13.0-next.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.
@@ -1184,12 +1184,61 @@ var MarkdownPlugin = function() {
1184
1184
  };
1185
1185
  }
1186
1186
  };
1187
+ var isPromiseLike = function isPromiseLike(value) {
1188
+ var // Check for standard Promise constructor name
1189
+ _value_constructor;
1190
+ return value != null && typeof value === "object" && typeof value.then === "function" && // Additional safeguards against false positives
1191
+ (_instanceof(value, Promise) || ((_value_constructor = value.constructor) === null || _value_constructor === void 0 ? void 0 : _value_constructor.name) === "Promise" || // Verify it has other Promise-like methods to reduce false positives
1192
+ typeof value.catch === "function" && typeof value.finally === "function");
1193
+ };
1194
+ var isAwaitable = function isAwaitable(val) {
1195
+ return isPromiseLike(val) && val[AwaitableSymbol] !== void 0;
1196
+ };
1197
+ var collateAwaitable = function collateAwaitable(promises) {
1198
+ var result = Promise.all(promises);
1199
+ return makeAwaitable(result);
1200
+ };
1187
1201
  var isObjectExpression = function isObjectExpression(expr) {
1188
1202
  if (isExpressionNode(expr)) {
1189
1203
  return false;
1190
1204
  }
1191
1205
  return typeof expr === "object" && expr !== null && !Array.isArray(expr) && "value" in expr;
1192
1206
  };
1207
+ var makePromiseAwareBinaryOp = function makePromiseAwareBinaryOp(operation) {
1208
+ return function(a, b, async) {
1209
+ if (async && (isAwaitable(a) || isAwaitable(b))) {
1210
+ return collateAwaitable([
1211
+ Promise.resolve(a),
1212
+ Promise.resolve(b)
1213
+ ]).awaitableThen(function(param) {
1214
+ var _param = _sliced_to_array(param, 2), resolvedA = _param[0], resolvedB = _param[1];
1215
+ return operation(resolvedA, resolvedB);
1216
+ });
1217
+ }
1218
+ return operation(a, b);
1219
+ };
1220
+ };
1221
+ var makePromiseAwareUnaryOp = function makePromiseAwareUnaryOp(operation) {
1222
+ return function(a, async) {
1223
+ if (async && isAwaitable(a)) {
1224
+ return a.awaitableThen(function(resolved) {
1225
+ return operation(resolved);
1226
+ });
1227
+ }
1228
+ return operation(a);
1229
+ };
1230
+ };
1231
+ var handleConditionalBranching = function handleConditionalBranching(testValue, getTrueBranch, getFalseBranch, resolveNode, async) {
1232
+ if (async && isAwaitable(testValue)) {
1233
+ return testValue.awaitableThen(function(resolved) {
1234
+ var branch2 = resolved ? getTrueBranch() : getFalseBranch();
1235
+ var branchResult = resolveNode(branch2);
1236
+ return isAwaitable(branchResult) ? Promise.resolve(branchResult) : branchResult;
1237
+ });
1238
+ }
1239
+ var branch = testValue ? getTrueBranch() : getFalseBranch();
1240
+ return resolveNode(branch);
1241
+ };
1193
1242
  var parse2 = function parse2(schema) {
1194
1243
  var _loop = function() {
1195
1244
  var next = parseQueue.shift();
@@ -7831,8 +7880,19 @@ var MarkdownPlugin = function() {
7831
7880
  },
7832
7881
  setDataVal: function() {
7833
7882
  return setDataVal;
7883
+ },
7884
+ waitFor: function() {
7885
+ return waitFor;
7834
7886
  }
7835
7887
  });
7888
+ var AwaitableSymbol = Symbol("Awaitable");
7889
+ function makeAwaitable(promise) {
7890
+ promise[AwaitableSymbol] = AwaitableSymbol;
7891
+ promise.awaitableThen = function(arg) {
7892
+ return makeAwaitable(promise.then(arg));
7893
+ };
7894
+ return promise;
7895
+ }
7836
7896
  var setDataVal = function(_context, binding, value) {
7837
7897
  _context.model.set([
7838
7898
  [
@@ -7848,8 +7908,19 @@ var MarkdownPlugin = function() {
7848
7908
  return _context.model.delete(binding);
7849
7909
  };
7850
7910
  var conditional = function(ctx, condition, ifTrue, ifFalse) {
7851
- var resolution = ctx.evaluate(condition);
7852
- if (resolution) {
7911
+ var testResult = ctx.evaluate(condition);
7912
+ if (isAwaitable(testResult)) {
7913
+ return testResult.awaitableThen(function(resolvedTest) {
7914
+ if (resolvedTest) {
7915
+ return ctx.evaluate(ifTrue);
7916
+ }
7917
+ if (ifFalse) {
7918
+ return ctx.evaluate(ifFalse);
7919
+ }
7920
+ return null;
7921
+ });
7922
+ }
7923
+ if (testResult) {
7853
7924
  return ctx.evaluate(ifTrue);
7854
7925
  }
7855
7926
  if (ifFalse) {
@@ -7858,12 +7929,15 @@ var MarkdownPlugin = function() {
7858
7929
  return null;
7859
7930
  };
7860
7931
  conditional.resolveParams = false;
7861
- var andandOperator = function(ctx, a, b) {
7862
- return ctx.evaluate(a) && ctx.evaluate(b);
7932
+ var waitFor = function(ctx, promise) {
7933
+ return makeAwaitable(promise);
7934
+ };
7935
+ var andandOperator = function(ctx, a, b, async) {
7936
+ return LogicalOperators.and(ctx, a, b, async);
7863
7937
  };
7864
7938
  andandOperator.resolveParams = false;
7865
- var ororOperator = function(ctx, a, b) {
7866
- return ctx.evaluate(a) || ctx.evaluate(b);
7939
+ var ororOperator = function(ctx, a, b, async) {
7940
+ return LogicalOperators.or(ctx, a, b, async);
7867
7941
  };
7868
7942
  ororOperator.resolveParams = false;
7869
7943
  var DEFAULT_BINARY_OPERATORS = {
@@ -7883,34 +7957,35 @@ var MarkdownPlugin = function() {
7883
7957
  "%": function(a, b) {
7884
7958
  return a % b;
7885
7959
  },
7960
+ // Promise-aware comparison operators
7886
7961
  // eslint-disable-next-line
7887
- "==": function(a, b) {
7962
+ "==": makePromiseAwareBinaryOp(function(a, b) {
7888
7963
  return a == b;
7889
- },
7964
+ }),
7890
7965
  // eslint-disable-next-line
7891
- "!=": function(a, b) {
7966
+ "!=": makePromiseAwareBinaryOp(function(a, b) {
7892
7967
  return a != b;
7893
- },
7894
- ">": function(a, b) {
7968
+ }),
7969
+ ">": makePromiseAwareBinaryOp(function(a, b) {
7895
7970
  return a > b;
7896
- },
7897
- ">=": function(a, b) {
7971
+ }),
7972
+ ">=": makePromiseAwareBinaryOp(function(a, b) {
7898
7973
  return a >= b;
7899
- },
7900
- "<": function(a, b) {
7974
+ }),
7975
+ "<": makePromiseAwareBinaryOp(function(a, b) {
7901
7976
  return a < b;
7902
- },
7903
- "<=": function(a, b) {
7977
+ }),
7978
+ "<=": makePromiseAwareBinaryOp(function(a, b) {
7904
7979
  return a <= b;
7905
- },
7906
- "&&": andandOperator,
7907
- "||": ororOperator,
7908
- "!==": function(a, b) {
7980
+ }),
7981
+ "!==": makePromiseAwareBinaryOp(function(a, b) {
7909
7982
  return a !== b;
7910
- },
7911
- "===": function(a, b) {
7983
+ }),
7984
+ "===": makePromiseAwareBinaryOp(function(a, b) {
7912
7985
  return a === b;
7913
- },
7986
+ }),
7987
+ "&&": andandOperator,
7988
+ "||": ororOperator,
7914
7989
  // eslint-disable-next-line
7915
7990
  "|": function(a, b) {
7916
7991
  return a | b;
@@ -7941,8 +8016,73 @@ var MarkdownPlugin = function() {
7941
8016
  "+": function(a) {
7942
8017
  return Number(a);
7943
8018
  },
7944
- "!": function(a) {
8019
+ "!": makePromiseAwareUnaryOp(function(a) {
7945
8020
  return !a;
8021
+ })
8022
+ };
8023
+ var PromiseCollectionHandler = {
8024
+ /**
8025
+ * Handle array with potential Promise elements
8026
+ */ handleArray: function handleArray(items, async) {
8027
+ if (!async) {
8028
+ return items;
8029
+ }
8030
+ var hasPromises = items.some(function(item) {
8031
+ return isAwaitable(item);
8032
+ });
8033
+ return hasPromises ? collateAwaitable(items) : items;
8034
+ },
8035
+ /**
8036
+ * Handle object with potential Promise keys/values
8037
+ */ handleObject: function handleObject(attributes, resolveNode, async) {
8038
+ var resolvedAttributes = {};
8039
+ var promises = [];
8040
+ var hasPromises = false;
8041
+ attributes.forEach(function(attr) {
8042
+ var key = resolveNode(attr.key);
8043
+ var value = resolveNode(attr.value);
8044
+ if (async && (isAwaitable(key) || isAwaitable(value))) {
8045
+ hasPromises = true;
8046
+ var keyPromise = Promise.resolve(key);
8047
+ var valuePromise = Promise.resolve(value);
8048
+ promises.push(collateAwaitable([
8049
+ keyPromise,
8050
+ valuePromise
8051
+ ]).awaitableThen(function(param) {
8052
+ var _param = _sliced_to_array(param, 2), resolvedKey = _param[0], resolvedValue = _param[1];
8053
+ resolvedAttributes[resolvedKey] = resolvedValue;
8054
+ }));
8055
+ } else {
8056
+ resolvedAttributes[key] = value;
8057
+ }
8058
+ });
8059
+ return hasPromises ? collateAwaitable(promises).awaitableThen(function() {
8060
+ return resolvedAttributes;
8061
+ }) : resolvedAttributes;
8062
+ }
8063
+ };
8064
+ var LogicalOperators = {
8065
+ and: function(ctx, leftNode, rightNode, async) {
8066
+ var leftResult = ctx.evaluate(leftNode);
8067
+ if (async && isAwaitable(leftResult)) {
8068
+ return leftResult.awaitableThen(function(awaitedLeft) {
8069
+ if (!awaitedLeft) return awaitedLeft;
8070
+ var rightResult = ctx.evaluate(rightNode);
8071
+ return isAwaitable(rightResult) ? rightResult : Promise.resolve(rightResult);
8072
+ });
8073
+ }
8074
+ return leftResult && ctx.evaluate(rightNode);
8075
+ },
8076
+ or: function(ctx, leftNode, rightNode, async) {
8077
+ var leftResult = ctx.evaluate(leftNode);
8078
+ if (async && isAwaitable(leftResult)) {
8079
+ return leftResult.awaitableThen(function(awaitedLeft) {
8080
+ if (awaitedLeft) return awaitedLeft;
8081
+ var rightResult = ctx.evaluate(rightNode);
8082
+ return isAwaitable(rightResult) ? rightResult : Promise.resolve(rightResult);
8083
+ });
8084
+ }
8085
+ return leftResult || ctx.evaluate(rightNode);
7946
8086
  }
7947
8087
  };
7948
8088
  var ExpressionEvaluator = /*#__PURE__*/ function() {
@@ -7963,7 +8103,12 @@ var MarkdownPlugin = function() {
7963
8103
  this.operators = {
7964
8104
  binary: new Map(Object.entries(DEFAULT_BINARY_OPERATORS)),
7965
8105
  unary: new Map(Object.entries(DEFAULT_UNARY_OPERATORS)),
7966
- expressions: new Map(Object.entries(evaluator_functions_exports))
8106
+ expressions: new Map(_to_consumable_array(Object.entries(evaluator_functions_exports)).concat([
8107
+ [
8108
+ "await",
8109
+ waitFor
8110
+ ]
8111
+ ]))
7967
8112
  };
7968
8113
  this.defaultHookOptions = _object_spread_props(_object_spread({}, defaultOptions), {
7969
8114
  evaluate: function(expr) {
@@ -7973,7 +8118,9 @@ var MarkdownPlugin = function() {
7973
8118
  return _this._execAST(node2, _this.defaultHookOptions);
7974
8119
  }
7975
8120
  });
7976
- this.hooks.resolve.tap("ExpressionEvaluator", this._resolveNode.bind(this));
8121
+ this.hooks.resolve.tap("ExpressionEvaluator", function(result, node2, options) {
8122
+ return _this._resolveNode(result, node2, options);
8123
+ });
7977
8124
  this.evaluate = this.evaluate.bind(this);
7978
8125
  }
7979
8126
  _create_class(ExpressionEvaluator, [
@@ -8011,6 +8158,38 @@ var MarkdownPlugin = function() {
8011
8158
  return this._execString(String(expression), resolvedOpts);
8012
8159
  }
8013
8160
  },
8161
+ {
8162
+ /**
8163
+ * Evaluate functions in an async context
8164
+ * @experimental These Player APIs are in active development and may change. Use with caution
8165
+ */ key: "evaluateAsync",
8166
+ value: function evaluateAsync(expr, options) {
8167
+ if (Array.isArray(expr)) {
8168
+ var _this = this;
8169
+ return collateAwaitable(expr.map(function() {
8170
+ var _ref = _async_to_generator(function(exp) {
8171
+ return _ts_generator(this, function(_state) {
8172
+ return [
8173
+ 2,
8174
+ _this.evaluate(exp, _object_spread_props(_object_spread({}, options), {
8175
+ async: true
8176
+ }))
8177
+ ];
8178
+ });
8179
+ });
8180
+ return function(exp) {
8181
+ return _ref.apply(this, arguments);
8182
+ };
8183
+ }())).awaitableThen(function(values) {
8184
+ return values.pop();
8185
+ });
8186
+ } else {
8187
+ return this.evaluate(expr, _object_spread_props(_object_spread({}, options), {
8188
+ async: true
8189
+ }));
8190
+ }
8191
+ }
8192
+ },
8014
8193
  {
8015
8194
  key: "addExpressionFunction",
8016
8195
  value: function addExpressionFunction(name, handler) {
@@ -8056,8 +8235,10 @@ var MarkdownPlugin = function() {
8056
8235
  var matches = exp.match(/^@\[(.*)\]@$/);
8057
8236
  var matchedExp = exp;
8058
8237
  if (matches) {
8059
- var ref;
8060
- ref = _sliced_to_array(Array.from(matches), 2), matchedExp = ref[1], ref;
8238
+ var _Array_from = _sliced_to_array(Array.from(matches), 2), matched = _Array_from[1];
8239
+ if (matched) {
8240
+ matchedExp = matched;
8241
+ }
8061
8242
  }
8062
8243
  var storedAST;
8063
8244
  try {
@@ -8086,6 +8267,8 @@ var MarkdownPlugin = function() {
8086
8267
  value: function _resolveNode(_currentValue, node2, options) {
8087
8268
  var _this = this;
8088
8269
  var resolveNode = options.resolveNode, model = options.model;
8270
+ var _options_async;
8271
+ var isAsync = (_options_async = options.async) !== null && _options_async !== void 0 ? _options_async : false;
8089
8272
  var expressionContext = _object_spread_props(_object_spread({}, options), {
8090
8273
  evaluate: function(expr) {
8091
8274
  return _this.evaluate(expr, options);
@@ -8105,11 +8288,33 @@ var MarkdownPlugin = function() {
8105
8288
  if (operator) {
8106
8289
  if ("resolveParams" in operator) {
8107
8290
  if (operator.resolveParams === false) {
8108
- return operator(expressionContext, node2.left, node2.right);
8291
+ return operator(expressionContext, node2.left, node2.right, isAsync);
8292
+ }
8293
+ var left2 = resolveNode(node2.left);
8294
+ var right2 = resolveNode(node2.right);
8295
+ if (options.async && (isAwaitable(left2) || isAwaitable(right2))) {
8296
+ return collateAwaitable([
8297
+ left2,
8298
+ right2
8299
+ ]).awaitableThen(function(param) {
8300
+ var _param = _sliced_to_array(param, 2), leftVal = _param[0], rightVal = _param[1];
8301
+ return operator(expressionContext, leftVal, rightVal, isAsync);
8302
+ });
8109
8303
  }
8110
- return operator(expressionContext, resolveNode(node2.left), resolveNode(node2.right));
8304
+ return operator(expressionContext, left2, right2, isAsync);
8111
8305
  }
8112
- return operator(resolveNode(node2.left), resolveNode(node2.right));
8306
+ var left = resolveNode(node2.left);
8307
+ var right = resolveNode(node2.right);
8308
+ if (options.async && (isAwaitable(left) || isAwaitable(right))) {
8309
+ return collateAwaitable([
8310
+ left,
8311
+ right
8312
+ ]).awaitableThen(function(param) {
8313
+ var _param = _sliced_to_array(param, 2), leftVal = _param[0], rightVal = _param[1];
8314
+ return operator(leftVal, rightVal, isAsync);
8315
+ });
8316
+ }
8317
+ return operator(left, right, isAsync);
8113
8318
  }
8114
8319
  return;
8115
8320
  }
@@ -8117,21 +8322,29 @@ var MarkdownPlugin = function() {
8117
8322
  var operator1 = this.operators.unary.get(node2.operator);
8118
8323
  if (operator1) {
8119
8324
  if ("resolveParams" in operator1) {
8120
- return operator1(expressionContext, operator1.resolveParams === false ? node2.argument : resolveNode(node2.argument));
8325
+ if (operator1.resolveParams === false) {
8326
+ return operator1(expressionContext, node2.argument, isAsync);
8327
+ }
8328
+ var arg2 = resolveNode(node2.argument);
8329
+ if (options.async && isAwaitable(arg2)) {
8330
+ return arg2.awaitableThen(function(argVal) {
8331
+ return operator1(expressionContext, argVal, isAsync);
8332
+ });
8333
+ }
8334
+ return operator1(expressionContext, arg2, isAsync);
8335
+ }
8336
+ var arg = resolveNode(node2.argument);
8337
+ if (options.async && isAwaitable(arg)) {
8338
+ return arg.awaitableThen(function(argVal) {
8339
+ return operator1(argVal, isAsync);
8340
+ });
8121
8341
  }
8122
- return operator1(resolveNode(node2.argument));
8342
+ return operator1(arg, isAsync);
8123
8343
  }
8124
8344
  return;
8125
8345
  }
8126
8346
  if (node2.type === "Object") {
8127
- var attributes = node2.attributes;
8128
- var resolvedAttributes = {};
8129
- attributes.forEach(function(attr) {
8130
- var key = resolveNode(attr.key);
8131
- var value = resolveNode(attr.value);
8132
- resolvedAttributes[key] = value;
8133
- });
8134
- return resolvedAttributes;
8347
+ return PromiseCollectionHandler.handleObject(node2.attributes, resolveNode, options.async || false);
8135
8348
  }
8136
8349
  if (node2.type === "CallExpression") {
8137
8350
  var expressionName = node2.callTarget.name;
@@ -8139,6 +8352,9 @@ var MarkdownPlugin = function() {
8139
8352
  if (!operator2) {
8140
8353
  throw new Error("Unknown expression function: ".concat(expressionName));
8141
8354
  }
8355
+ if (operator2.name === waitFor.name && !options.async) {
8356
+ throw new Error("Usage of await outside of async context");
8357
+ }
8142
8358
  if ("resolveParams" in operator2 && operator2.resolveParams === false) {
8143
8359
  return operator2.apply(void 0, [
8144
8360
  expressionContext
@@ -8147,6 +8363,16 @@ var MarkdownPlugin = function() {
8147
8363
  var args = node2.args.map(function(n) {
8148
8364
  return resolveNode(n);
8149
8365
  });
8366
+ if (options.async) {
8367
+ var hasPromises = args.some(isAwaitable);
8368
+ if (hasPromises) {
8369
+ return collateAwaitable(args).awaitableThen(function(resolvedArgs) {
8370
+ return operator2.apply(void 0, [
8371
+ expressionContext
8372
+ ].concat(_to_consumable_array(resolvedArgs)));
8373
+ });
8374
+ }
8375
+ }
8150
8376
  return operator2.apply(void 0, [
8151
8377
  expressionContext
8152
8378
  ].concat(_to_consumable_array(args)));
@@ -8161,11 +8387,36 @@ var MarkdownPlugin = function() {
8161
8387
  if (node2.type === "MemberExpression") {
8162
8388
  var obj = resolveNode(node2.object);
8163
8389
  var prop = resolveNode(node2.property);
8390
+ if (options.async && (isAwaitable(obj) || isAwaitable(prop))) {
8391
+ return collateAwaitable([
8392
+ obj,
8393
+ prop
8394
+ ]).awaitableThen(function(param) {
8395
+ var _param = _sliced_to_array(param, 2), objVal = _param[0], propVal = _param[1];
8396
+ return objVal[propVal];
8397
+ });
8398
+ }
8164
8399
  return obj[prop];
8165
8400
  }
8166
8401
  if (node2.type === "Assignment") {
8167
8402
  if (node2.left.type === "ModelRef") {
8168
8403
  var value = resolveNode(node2.right);
8404
+ if (isPromiseLike(value)) {
8405
+ if (options.async && isAwaitable(value)) {
8406
+ return value.awaitableThen(function(resolvedValue) {
8407
+ model.set([
8408
+ [
8409
+ node2.left.ref,
8410
+ resolvedValue
8411
+ ]
8412
+ ]);
8413
+ return resolvedValue;
8414
+ });
8415
+ } else {
8416
+ var _options_logger;
8417
+ (_options_logger = options.logger) === null || _options_logger === void 0 ? void 0 : _options_logger.warn("Unawaited promise written to mode, this behavior is undefined and may change in future releases");
8418
+ }
8419
+ }
8169
8420
  model.set([
8170
8421
  [
8171
8422
  node2.left.ref,
@@ -8176,19 +8427,30 @@ var MarkdownPlugin = function() {
8176
8427
  }
8177
8428
  if (node2.left.type === "Identifier") {
8178
8429
  var value1 = resolveNode(node2.right);
8430
+ if (options.async && isAwaitable(value1)) {
8431
+ return value1.awaitableThen(function(resolvedValue) {
8432
+ _this.vars[node2.left.name] = resolvedValue;
8433
+ return resolvedValue;
8434
+ });
8435
+ }
8179
8436
  this.vars[node2.left.name] = value1;
8180
8437
  return value1;
8181
8438
  }
8182
8439
  return;
8183
8440
  }
8184
8441
  if (node2.type === "ConditionalExpression") {
8185
- var result = resolveNode(node2.test) ? node2.consequent : node2.alternate;
8186
- return resolveNode(result);
8442
+ var testResult = resolveNode(node2.test);
8443
+ return handleConditionalBranching(testResult, function() {
8444
+ return node2.consequent;
8445
+ }, function() {
8446
+ return node2.alternate;
8447
+ }, resolveNode, isAsync);
8187
8448
  }
8188
8449
  if (node2.type === "ArrayExpression") {
8189
- return node2.elements.map(function(ele) {
8450
+ var results = node2.elements.map(function(ele) {
8190
8451
  return resolveNode(ele);
8191
8452
  });
8453
+ return PromiseCollectionHandler.handleArray(results, isAsync);
8192
8454
  }
8193
8455
  if (node2.type === "Modification") {
8194
8456
  var operation = this.operators.binary.get(node2.operator);
@@ -8196,14 +8458,49 @@ var MarkdownPlugin = function() {
8196
8458
  var newValue;
8197
8459
  if ("resolveParams" in operation) {
8198
8460
  if (operation.resolveParams === false) {
8199
- newValue = operation(expressionContext, node2.left, node2.right);
8461
+ newValue = operation(expressionContext, node2.left, node2.right, isAsync);
8200
8462
  } else {
8201
- newValue = operation(expressionContext, resolveNode(node2.left), resolveNode(node2.right));
8463
+ var left1 = resolveNode(node2.left);
8464
+ var right1 = resolveNode(node2.right);
8465
+ if (options.async && (isAwaitable(left1) || isAwaitable(right1))) {
8466
+ newValue = collateAwaitable([
8467
+ left1,
8468
+ right1
8469
+ ]).awaitableThen(function(param) {
8470
+ var _param = _sliced_to_array(param, 2), leftVal = _param[0], rightVal = _param[1];
8471
+ return operation(expressionContext, leftVal, rightVal, isAsync);
8472
+ });
8473
+ } else {
8474
+ newValue = operation(expressionContext, left1, right1, isAsync);
8475
+ }
8202
8476
  }
8203
8477
  } else {
8204
- newValue = operation(resolveNode(node2.left), resolveNode(node2.right));
8478
+ var left3 = resolveNode(node2.left);
8479
+ var right3 = resolveNode(node2.right);
8480
+ if (options.async && (isAwaitable(left3) || isAwaitable(right3))) {
8481
+ newValue = collateAwaitable([
8482
+ left3,
8483
+ right3
8484
+ ]).awaitableThen(function(param) {
8485
+ var _param = _sliced_to_array(param, 2), leftVal = _param[0], rightVal = _param[1];
8486
+ return operation(leftVal, rightVal, isAsync);
8487
+ });
8488
+ } else {
8489
+ newValue = operation(left3, right3, isAsync);
8490
+ }
8205
8491
  }
8206
8492
  if (node2.left.type === "ModelRef") {
8493
+ if (options.async && isAwaitable(newValue)) {
8494
+ return newValue.awaitableThen(function(resolvedValue) {
8495
+ model.set([
8496
+ [
8497
+ node2.left.ref,
8498
+ resolvedValue
8499
+ ]
8500
+ ]);
8501
+ return resolvedValue;
8502
+ });
8503
+ }
8207
8504
  model.set([
8208
8505
  [
8209
8506
  node2.left.ref,
@@ -8211,6 +8508,12 @@ var MarkdownPlugin = function() {
8211
8508
  ]
8212
8509
  ]);
8213
8510
  } else if (node2.left.type === "Identifier") {
8511
+ if (options.async && isAwaitable(newValue)) {
8512
+ return newValue.awaitableThen(function(resolvedValue) {
8513
+ _this.vars[node2.left.name] = resolvedValue;
8514
+ return resolvedValue;
8515
+ });
8516
+ }
8214
8517
  this.vars[node2.left.name] = newValue;
8215
8518
  }
8216
8519
  return newValue;
@@ -11447,18 +11750,18 @@ var MarkdownPlugin = function() {
11447
11750
  this.constantsController = new ConstantsController();
11448
11751
  this.state = NOT_STARTED_STATE;
11449
11752
  this.hooks = {
11450
- /** The hook that fires every time we create a new flowController (a new Content blob is passed in) */ flowController: new SyncHook(),
11451
- /** The hook that updates/handles views */ viewController: new SyncHook(),
11452
- /** A hook called every-time there's a new view. This is equivalent to the view hook on the view-controller */ view: new SyncHook(),
11453
- /** Called when an expression evaluator was created */ expressionEvaluator: new SyncHook(),
11454
- /** The hook that creates and manages data */ dataController: new SyncHook(),
11455
- /** Called after the schema is created for a flow */ schema: new SyncHook(),
11456
- /** Manages validations (schema and x-field ) */ validationController: new SyncHook(),
11457
- /** Manages parsing binding */ bindingParser: new SyncHook(),
11458
- /** A that's called for state changes in the flow execution */ state: new SyncHook(),
11459
- /** A hook to access the current flow */ onStart: new SyncHook(),
11460
- /** A hook for when the flow ends either in success or failure */ onEnd: new SyncHook(),
11461
- /** Mutate the Content flow before starting */ resolveFlowContent: new SyncWaterfallHook()
11753
+ flowController: new SyncHook(),
11754
+ viewController: new SyncHook(),
11755
+ view: new SyncHook(),
11756
+ expressionEvaluator: new SyncHook(),
11757
+ dataController: new SyncHook(),
11758
+ schema: new SyncHook(),
11759
+ validationController: new SyncHook(),
11760
+ bindingParser: new SyncHook(),
11761
+ state: new SyncHook(),
11762
+ onStart: new SyncHook(),
11763
+ onEnd: new SyncHook(),
11764
+ resolveFlowContent: new SyncWaterfallHook()
11462
11765
  };
11463
11766
  if (config === null || config === void 0 ? void 0 : config.logger) {
11464
11767
  this.logger.addHandler(config.logger);
@@ -11658,10 +11961,90 @@ var MarkdownPlugin = function() {
11658
11961
  var value = (_flowInstance_currentState = flowInstance.currentState) === null || _flowInstance_currentState === void 0 ? void 0 : _flowInstance_currentState.value;
11659
11962
  if (value && value.state_type === "ACTION") {
11660
11963
  var exp = value.exp;
11661
- flowController === null || flowController === void 0 ? void 0 : flowController.transition(String(expressionEvaluator === null || expressionEvaluator === void 0 ? void 0 : expressionEvaluator.evaluate(exp)));
11964
+ var result = expressionEvaluator.evaluate(exp);
11965
+ if (isPromiseLike(result)) {
11966
+ _this.logger.warn("Async expression used as return value in in non-async context, transitioning with '*' value");
11967
+ }
11968
+ flowController === null || flowController === void 0 ? void 0 : flowController.transition(String(result));
11662
11969
  }
11663
11970
  expressionEvaluator.reset();
11664
11971
  });
11972
+ var _this1 = _this;
11973
+ flow3.hooks.afterTransition.tap("player", function() {
11974
+ var _ref = _async_to_generator(function(flowInstance) {
11975
+ var _flowInstance_currentState, value, exp, result, e;
11976
+ return _ts_generator(this, function(_state) {
11977
+ switch(_state.label){
11978
+ case 0:
11979
+ value = (_flowInstance_currentState = flowInstance.currentState) === null || _flowInstance_currentState === void 0 ? void 0 : _flowInstance_currentState.value;
11980
+ if (!(value && value.state_type === "ASYNC_ACTION")) return [
11981
+ 3,
11982
+ 8
11983
+ ];
11984
+ exp = value.exp;
11985
+ _state.label = 1;
11986
+ case 1:
11987
+ _state.trys.push([
11988
+ 1,
11989
+ 7,
11990
+ ,
11991
+ 8
11992
+ ]);
11993
+ result = expressionEvaluator.evaluateAsync(exp);
11994
+ if (!isPromiseLike(result)) return [
11995
+ 3,
11996
+ 5
11997
+ ];
11998
+ if (!value.await) return [
11999
+ 3,
12000
+ 3
12001
+ ];
12002
+ return [
12003
+ 4,
12004
+ result
12005
+ ];
12006
+ case 2:
12007
+ result = _state.sent();
12008
+ return [
12009
+ 3,
12010
+ 4
12011
+ ];
12012
+ case 3:
12013
+ _this1.logger.warn("Unawaited promise used as return value in in non-async context, transitioning with '*' value");
12014
+ _state.label = 4;
12015
+ case 4:
12016
+ return [
12017
+ 3,
12018
+ 6
12019
+ ];
12020
+ case 5:
12021
+ _this1.logger.warn("Non async expression used in async action node");
12022
+ _state.label = 6;
12023
+ case 6:
12024
+ flowController === null || flowController === void 0 ? void 0 : flowController.transition(String(result));
12025
+ return [
12026
+ 3,
12027
+ 8
12028
+ ];
12029
+ case 7:
12030
+ e = _state.sent();
12031
+ flowResultDeferred.reject(e);
12032
+ return [
12033
+ 3,
12034
+ 8
12035
+ ];
12036
+ case 8:
12037
+ expressionEvaluator.reset();
12038
+ return [
12039
+ 2
12040
+ ];
12041
+ }
12042
+ });
12043
+ });
12044
+ return function(flowInstance) {
12045
+ return _ref.apply(this, arguments);
12046
+ };
12047
+ }());
11665
12048
  });
11666
12049
  this.hooks.dataController.call(dataController);
11667
12050
  validationController.setOptions({