@player-ui/common-types-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 CommonTypesPlugin = 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();
@@ -3626,8 +3675,19 @@ var CommonTypesPlugin = function() {
3626
3675
  },
3627
3676
  setDataVal: function() {
3628
3677
  return setDataVal;
3678
+ },
3679
+ waitFor: function() {
3680
+ return waitFor;
3629
3681
  }
3630
3682
  });
3683
+ var AwaitableSymbol = Symbol("Awaitable");
3684
+ function makeAwaitable(promise) {
3685
+ promise[AwaitableSymbol] = AwaitableSymbol;
3686
+ promise.awaitableThen = function(arg) {
3687
+ return makeAwaitable(promise.then(arg));
3688
+ };
3689
+ return promise;
3690
+ }
3631
3691
  var setDataVal = function(_context, binding, value) {
3632
3692
  _context.model.set([
3633
3693
  [
@@ -3643,8 +3703,19 @@ var CommonTypesPlugin = function() {
3643
3703
  return _context.model.delete(binding);
3644
3704
  };
3645
3705
  var conditional = function(ctx, condition, ifTrue, ifFalse) {
3646
- var resolution = ctx.evaluate(condition);
3647
- if (resolution) {
3706
+ var testResult = ctx.evaluate(condition);
3707
+ if (isAwaitable(testResult)) {
3708
+ return testResult.awaitableThen(function(resolvedTest) {
3709
+ if (resolvedTest) {
3710
+ return ctx.evaluate(ifTrue);
3711
+ }
3712
+ if (ifFalse) {
3713
+ return ctx.evaluate(ifFalse);
3714
+ }
3715
+ return null;
3716
+ });
3717
+ }
3718
+ if (testResult) {
3648
3719
  return ctx.evaluate(ifTrue);
3649
3720
  }
3650
3721
  if (ifFalse) {
@@ -3653,12 +3724,15 @@ var CommonTypesPlugin = function() {
3653
3724
  return null;
3654
3725
  };
3655
3726
  conditional.resolveParams = false;
3656
- var andandOperator = function(ctx, a, b) {
3657
- return ctx.evaluate(a) && ctx.evaluate(b);
3727
+ var waitFor = function(ctx, promise) {
3728
+ return makeAwaitable(promise);
3729
+ };
3730
+ var andandOperator = function(ctx, a, b, async) {
3731
+ return LogicalOperators.and(ctx, a, b, async);
3658
3732
  };
3659
3733
  andandOperator.resolveParams = false;
3660
- var ororOperator = function(ctx, a, b) {
3661
- return ctx.evaluate(a) || ctx.evaluate(b);
3734
+ var ororOperator = function(ctx, a, b, async) {
3735
+ return LogicalOperators.or(ctx, a, b, async);
3662
3736
  };
3663
3737
  ororOperator.resolveParams = false;
3664
3738
  var DEFAULT_BINARY_OPERATORS = {
@@ -3678,34 +3752,35 @@ var CommonTypesPlugin = function() {
3678
3752
  "%": function(a, b) {
3679
3753
  return a % b;
3680
3754
  },
3755
+ // Promise-aware comparison operators
3681
3756
  // eslint-disable-next-line
3682
- "==": function(a, b) {
3757
+ "==": makePromiseAwareBinaryOp(function(a, b) {
3683
3758
  return a == b;
3684
- },
3759
+ }),
3685
3760
  // eslint-disable-next-line
3686
- "!=": function(a, b) {
3761
+ "!=": makePromiseAwareBinaryOp(function(a, b) {
3687
3762
  return a != b;
3688
- },
3689
- ">": function(a, b) {
3763
+ }),
3764
+ ">": makePromiseAwareBinaryOp(function(a, b) {
3690
3765
  return a > b;
3691
- },
3692
- ">=": function(a, b) {
3766
+ }),
3767
+ ">=": makePromiseAwareBinaryOp(function(a, b) {
3693
3768
  return a >= b;
3694
- },
3695
- "<": function(a, b) {
3769
+ }),
3770
+ "<": makePromiseAwareBinaryOp(function(a, b) {
3696
3771
  return a < b;
3697
- },
3698
- "<=": function(a, b) {
3772
+ }),
3773
+ "<=": makePromiseAwareBinaryOp(function(a, b) {
3699
3774
  return a <= b;
3700
- },
3701
- "&&": andandOperator,
3702
- "||": ororOperator,
3703
- "!==": function(a, b) {
3775
+ }),
3776
+ "!==": makePromiseAwareBinaryOp(function(a, b) {
3704
3777
  return a !== b;
3705
- },
3706
- "===": function(a, b) {
3778
+ }),
3779
+ "===": makePromiseAwareBinaryOp(function(a, b) {
3707
3780
  return a === b;
3708
- },
3781
+ }),
3782
+ "&&": andandOperator,
3783
+ "||": ororOperator,
3709
3784
  // eslint-disable-next-line
3710
3785
  "|": function(a, b) {
3711
3786
  return a | b;
@@ -3736,8 +3811,73 @@ var CommonTypesPlugin = function() {
3736
3811
  "+": function(a) {
3737
3812
  return Number(a);
3738
3813
  },
3739
- "!": function(a) {
3814
+ "!": makePromiseAwareUnaryOp(function(a) {
3740
3815
  return !a;
3816
+ })
3817
+ };
3818
+ var PromiseCollectionHandler = {
3819
+ /**
3820
+ * Handle array with potential Promise elements
3821
+ */ handleArray: function handleArray(items, async) {
3822
+ if (!async) {
3823
+ return items;
3824
+ }
3825
+ var hasPromises = items.some(function(item) {
3826
+ return isAwaitable(item);
3827
+ });
3828
+ return hasPromises ? collateAwaitable(items) : items;
3829
+ },
3830
+ /**
3831
+ * Handle object with potential Promise keys/values
3832
+ */ handleObject: function handleObject(attributes, resolveNode, async) {
3833
+ var resolvedAttributes = {};
3834
+ var promises = [];
3835
+ var hasPromises = false;
3836
+ attributes.forEach(function(attr) {
3837
+ var key = resolveNode(attr.key);
3838
+ var value = resolveNode(attr.value);
3839
+ if (async && (isAwaitable(key) || isAwaitable(value))) {
3840
+ hasPromises = true;
3841
+ var keyPromise = Promise.resolve(key);
3842
+ var valuePromise = Promise.resolve(value);
3843
+ promises.push(collateAwaitable([
3844
+ keyPromise,
3845
+ valuePromise
3846
+ ]).awaitableThen(function(param) {
3847
+ var _param = _sliced_to_array(param, 2), resolvedKey = _param[0], resolvedValue = _param[1];
3848
+ resolvedAttributes[resolvedKey] = resolvedValue;
3849
+ }));
3850
+ } else {
3851
+ resolvedAttributes[key] = value;
3852
+ }
3853
+ });
3854
+ return hasPromises ? collateAwaitable(promises).awaitableThen(function() {
3855
+ return resolvedAttributes;
3856
+ }) : resolvedAttributes;
3857
+ }
3858
+ };
3859
+ var LogicalOperators = {
3860
+ and: function(ctx, leftNode, rightNode, async) {
3861
+ var leftResult = ctx.evaluate(leftNode);
3862
+ if (async && isAwaitable(leftResult)) {
3863
+ return leftResult.awaitableThen(function(awaitedLeft) {
3864
+ if (!awaitedLeft) return awaitedLeft;
3865
+ var rightResult = ctx.evaluate(rightNode);
3866
+ return isAwaitable(rightResult) ? rightResult : Promise.resolve(rightResult);
3867
+ });
3868
+ }
3869
+ return leftResult && ctx.evaluate(rightNode);
3870
+ },
3871
+ or: function(ctx, leftNode, rightNode, async) {
3872
+ var leftResult = ctx.evaluate(leftNode);
3873
+ if (async && isAwaitable(leftResult)) {
3874
+ return leftResult.awaitableThen(function(awaitedLeft) {
3875
+ if (awaitedLeft) return awaitedLeft;
3876
+ var rightResult = ctx.evaluate(rightNode);
3877
+ return isAwaitable(rightResult) ? rightResult : Promise.resolve(rightResult);
3878
+ });
3879
+ }
3880
+ return leftResult || ctx.evaluate(rightNode);
3741
3881
  }
3742
3882
  };
3743
3883
  var ExpressionEvaluator = /*#__PURE__*/ function() {
@@ -3758,7 +3898,12 @@ var CommonTypesPlugin = function() {
3758
3898
  this.operators = {
3759
3899
  binary: new Map(Object.entries(DEFAULT_BINARY_OPERATORS)),
3760
3900
  unary: new Map(Object.entries(DEFAULT_UNARY_OPERATORS)),
3761
- expressions: new Map(Object.entries(evaluator_functions_exports))
3901
+ expressions: new Map(_to_consumable_array(Object.entries(evaluator_functions_exports)).concat([
3902
+ [
3903
+ "await",
3904
+ waitFor
3905
+ ]
3906
+ ]))
3762
3907
  };
3763
3908
  this.defaultHookOptions = _object_spread_props(_object_spread({}, defaultOptions), {
3764
3909
  evaluate: function(expr) {
@@ -3768,7 +3913,9 @@ var CommonTypesPlugin = function() {
3768
3913
  return _this._execAST(node, _this.defaultHookOptions);
3769
3914
  }
3770
3915
  });
3771
- this.hooks.resolve.tap("ExpressionEvaluator", this._resolveNode.bind(this));
3916
+ this.hooks.resolve.tap("ExpressionEvaluator", function(result, node, options) {
3917
+ return _this._resolveNode(result, node, options);
3918
+ });
3772
3919
  this.evaluate = this.evaluate.bind(this);
3773
3920
  }
3774
3921
  _create_class(ExpressionEvaluator, [
@@ -3806,6 +3953,38 @@ var CommonTypesPlugin = function() {
3806
3953
  return this._execString(String(expression2), resolvedOpts);
3807
3954
  }
3808
3955
  },
3956
+ {
3957
+ /**
3958
+ * Evaluate functions in an async context
3959
+ * @experimental These Player APIs are in active development and may change. Use with caution
3960
+ */ key: "evaluateAsync",
3961
+ value: function evaluateAsync(expr, options) {
3962
+ if (Array.isArray(expr)) {
3963
+ var _this = this;
3964
+ return collateAwaitable(expr.map(function() {
3965
+ var _ref = _async_to_generator(function(exp) {
3966
+ return _ts_generator(this, function(_state) {
3967
+ return [
3968
+ 2,
3969
+ _this.evaluate(exp, _object_spread_props(_object_spread({}, options), {
3970
+ async: true
3971
+ }))
3972
+ ];
3973
+ });
3974
+ });
3975
+ return function(exp) {
3976
+ return _ref.apply(this, arguments);
3977
+ };
3978
+ }())).awaitableThen(function(values) {
3979
+ return values.pop();
3980
+ });
3981
+ } else {
3982
+ return this.evaluate(expr, _object_spread_props(_object_spread({}, options), {
3983
+ async: true
3984
+ }));
3985
+ }
3986
+ }
3987
+ },
3809
3988
  {
3810
3989
  key: "addExpressionFunction",
3811
3990
  value: function addExpressionFunction(name, handler) {
@@ -3851,8 +4030,10 @@ var CommonTypesPlugin = function() {
3851
4030
  var matches = exp.match(/^@\[(.*)\]@$/);
3852
4031
  var matchedExp = exp;
3853
4032
  if (matches) {
3854
- var ref;
3855
- ref = _sliced_to_array(Array.from(matches), 2), matchedExp = ref[1], ref;
4033
+ var _Array_from = _sliced_to_array(Array.from(matches), 2), matched = _Array_from[1];
4034
+ if (matched) {
4035
+ matchedExp = matched;
4036
+ }
3856
4037
  }
3857
4038
  var storedAST;
3858
4039
  try {
@@ -3881,6 +4062,8 @@ var CommonTypesPlugin = function() {
3881
4062
  value: function _resolveNode(_currentValue, node, options) {
3882
4063
  var _this = this;
3883
4064
  var resolveNode = options.resolveNode, model = options.model;
4065
+ var _options_async;
4066
+ var isAsync = (_options_async = options.async) !== null && _options_async !== void 0 ? _options_async : false;
3884
4067
  var expressionContext = _object_spread_props(_object_spread({}, options), {
3885
4068
  evaluate: function(expr) {
3886
4069
  return _this.evaluate(expr, options);
@@ -3900,11 +4083,33 @@ var CommonTypesPlugin = function() {
3900
4083
  if (operator) {
3901
4084
  if ("resolveParams" in operator) {
3902
4085
  if (operator.resolveParams === false) {
3903
- return operator(expressionContext, node.left, node.right);
4086
+ return operator(expressionContext, node.left, node.right, isAsync);
4087
+ }
4088
+ var left2 = resolveNode(node.left);
4089
+ var right2 = resolveNode(node.right);
4090
+ if (options.async && (isAwaitable(left2) || isAwaitable(right2))) {
4091
+ return collateAwaitable([
4092
+ left2,
4093
+ right2
4094
+ ]).awaitableThen(function(param) {
4095
+ var _param = _sliced_to_array(param, 2), leftVal = _param[0], rightVal = _param[1];
4096
+ return operator(expressionContext, leftVal, rightVal, isAsync);
4097
+ });
3904
4098
  }
3905
- return operator(expressionContext, resolveNode(node.left), resolveNode(node.right));
4099
+ return operator(expressionContext, left2, right2, isAsync);
3906
4100
  }
3907
- return operator(resolveNode(node.left), resolveNode(node.right));
4101
+ var left = resolveNode(node.left);
4102
+ var right = resolveNode(node.right);
4103
+ if (options.async && (isAwaitable(left) || isAwaitable(right))) {
4104
+ return collateAwaitable([
4105
+ left,
4106
+ right
4107
+ ]).awaitableThen(function(param) {
4108
+ var _param = _sliced_to_array(param, 2), leftVal = _param[0], rightVal = _param[1];
4109
+ return operator(leftVal, rightVal, isAsync);
4110
+ });
4111
+ }
4112
+ return operator(left, right, isAsync);
3908
4113
  }
3909
4114
  return;
3910
4115
  }
@@ -3912,21 +4117,29 @@ var CommonTypesPlugin = function() {
3912
4117
  var operator1 = this.operators.unary.get(node.operator);
3913
4118
  if (operator1) {
3914
4119
  if ("resolveParams" in operator1) {
3915
- return operator1(expressionContext, operator1.resolveParams === false ? node.argument : resolveNode(node.argument));
4120
+ if (operator1.resolveParams === false) {
4121
+ return operator1(expressionContext, node.argument, isAsync);
4122
+ }
4123
+ var arg2 = resolveNode(node.argument);
4124
+ if (options.async && isAwaitable(arg2)) {
4125
+ return arg2.awaitableThen(function(argVal) {
4126
+ return operator1(expressionContext, argVal, isAsync);
4127
+ });
4128
+ }
4129
+ return operator1(expressionContext, arg2, isAsync);
4130
+ }
4131
+ var arg = resolveNode(node.argument);
4132
+ if (options.async && isAwaitable(arg)) {
4133
+ return arg.awaitableThen(function(argVal) {
4134
+ return operator1(argVal, isAsync);
4135
+ });
3916
4136
  }
3917
- return operator1(resolveNode(node.argument));
4137
+ return operator1(arg, isAsync);
3918
4138
  }
3919
4139
  return;
3920
4140
  }
3921
4141
  if (node.type === "Object") {
3922
- var attributes = node.attributes;
3923
- var resolvedAttributes = {};
3924
- attributes.forEach(function(attr) {
3925
- var key = resolveNode(attr.key);
3926
- var value = resolveNode(attr.value);
3927
- resolvedAttributes[key] = value;
3928
- });
3929
- return resolvedAttributes;
4142
+ return PromiseCollectionHandler.handleObject(node.attributes, resolveNode, options.async || false);
3930
4143
  }
3931
4144
  if (node.type === "CallExpression") {
3932
4145
  var expressionName = node.callTarget.name;
@@ -3934,6 +4147,9 @@ var CommonTypesPlugin = function() {
3934
4147
  if (!operator2) {
3935
4148
  throw new Error("Unknown expression function: ".concat(expressionName));
3936
4149
  }
4150
+ if (operator2.name === waitFor.name && !options.async) {
4151
+ throw new Error("Usage of await outside of async context");
4152
+ }
3937
4153
  if ("resolveParams" in operator2 && operator2.resolveParams === false) {
3938
4154
  return operator2.apply(void 0, [
3939
4155
  expressionContext
@@ -3942,6 +4158,16 @@ var CommonTypesPlugin = function() {
3942
4158
  var args = node.args.map(function(n) {
3943
4159
  return resolveNode(n);
3944
4160
  });
4161
+ if (options.async) {
4162
+ var hasPromises = args.some(isAwaitable);
4163
+ if (hasPromises) {
4164
+ return collateAwaitable(args).awaitableThen(function(resolvedArgs) {
4165
+ return operator2.apply(void 0, [
4166
+ expressionContext
4167
+ ].concat(_to_consumable_array(resolvedArgs)));
4168
+ });
4169
+ }
4170
+ }
3945
4171
  return operator2.apply(void 0, [
3946
4172
  expressionContext
3947
4173
  ].concat(_to_consumable_array(args)));
@@ -3956,11 +4182,36 @@ var CommonTypesPlugin = function() {
3956
4182
  if (node.type === "MemberExpression") {
3957
4183
  var obj = resolveNode(node.object);
3958
4184
  var prop = resolveNode(node.property);
4185
+ if (options.async && (isAwaitable(obj) || isAwaitable(prop))) {
4186
+ return collateAwaitable([
4187
+ obj,
4188
+ prop
4189
+ ]).awaitableThen(function(param) {
4190
+ var _param = _sliced_to_array(param, 2), objVal = _param[0], propVal = _param[1];
4191
+ return objVal[propVal];
4192
+ });
4193
+ }
3959
4194
  return obj[prop];
3960
4195
  }
3961
4196
  if (node.type === "Assignment") {
3962
4197
  if (node.left.type === "ModelRef") {
3963
4198
  var value = resolveNode(node.right);
4199
+ if (isPromiseLike(value)) {
4200
+ if (options.async && isAwaitable(value)) {
4201
+ return value.awaitableThen(function(resolvedValue) {
4202
+ model.set([
4203
+ [
4204
+ node.left.ref,
4205
+ resolvedValue
4206
+ ]
4207
+ ]);
4208
+ return resolvedValue;
4209
+ });
4210
+ } else {
4211
+ var _options_logger;
4212
+ (_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");
4213
+ }
4214
+ }
3964
4215
  model.set([
3965
4216
  [
3966
4217
  node.left.ref,
@@ -3971,19 +4222,30 @@ var CommonTypesPlugin = function() {
3971
4222
  }
3972
4223
  if (node.left.type === "Identifier") {
3973
4224
  var value1 = resolveNode(node.right);
4225
+ if (options.async && isAwaitable(value1)) {
4226
+ return value1.awaitableThen(function(resolvedValue) {
4227
+ _this.vars[node.left.name] = resolvedValue;
4228
+ return resolvedValue;
4229
+ });
4230
+ }
3974
4231
  this.vars[node.left.name] = value1;
3975
4232
  return value1;
3976
4233
  }
3977
4234
  return;
3978
4235
  }
3979
4236
  if (node.type === "ConditionalExpression") {
3980
- var result = resolveNode(node.test) ? node.consequent : node.alternate;
3981
- return resolveNode(result);
4237
+ var testResult = resolveNode(node.test);
4238
+ return handleConditionalBranching(testResult, function() {
4239
+ return node.consequent;
4240
+ }, function() {
4241
+ return node.alternate;
4242
+ }, resolveNode, isAsync);
3982
4243
  }
3983
4244
  if (node.type === "ArrayExpression") {
3984
- return node.elements.map(function(ele) {
4245
+ var results = node.elements.map(function(ele) {
3985
4246
  return resolveNode(ele);
3986
4247
  });
4248
+ return PromiseCollectionHandler.handleArray(results, isAsync);
3987
4249
  }
3988
4250
  if (node.type === "Modification") {
3989
4251
  var operation = this.operators.binary.get(node.operator);
@@ -3991,14 +4253,49 @@ var CommonTypesPlugin = function() {
3991
4253
  var newValue;
3992
4254
  if ("resolveParams" in operation) {
3993
4255
  if (operation.resolveParams === false) {
3994
- newValue = operation(expressionContext, node.left, node.right);
4256
+ newValue = operation(expressionContext, node.left, node.right, isAsync);
3995
4257
  } else {
3996
- newValue = operation(expressionContext, resolveNode(node.left), resolveNode(node.right));
4258
+ var left1 = resolveNode(node.left);
4259
+ var right1 = resolveNode(node.right);
4260
+ if (options.async && (isAwaitable(left1) || isAwaitable(right1))) {
4261
+ newValue = collateAwaitable([
4262
+ left1,
4263
+ right1
4264
+ ]).awaitableThen(function(param) {
4265
+ var _param = _sliced_to_array(param, 2), leftVal = _param[0], rightVal = _param[1];
4266
+ return operation(expressionContext, leftVal, rightVal, isAsync);
4267
+ });
4268
+ } else {
4269
+ newValue = operation(expressionContext, left1, right1, isAsync);
4270
+ }
3997
4271
  }
3998
4272
  } else {
3999
- newValue = operation(resolveNode(node.left), resolveNode(node.right));
4273
+ var left3 = resolveNode(node.left);
4274
+ var right3 = resolveNode(node.right);
4275
+ if (options.async && (isAwaitable(left3) || isAwaitable(right3))) {
4276
+ newValue = collateAwaitable([
4277
+ left3,
4278
+ right3
4279
+ ]).awaitableThen(function(param) {
4280
+ var _param = _sliced_to_array(param, 2), leftVal = _param[0], rightVal = _param[1];
4281
+ return operation(leftVal, rightVal, isAsync);
4282
+ });
4283
+ } else {
4284
+ newValue = operation(left3, right3, isAsync);
4285
+ }
4000
4286
  }
4001
4287
  if (node.left.type === "ModelRef") {
4288
+ if (options.async && isAwaitable(newValue)) {
4289
+ return newValue.awaitableThen(function(resolvedValue) {
4290
+ model.set([
4291
+ [
4292
+ node.left.ref,
4293
+ resolvedValue
4294
+ ]
4295
+ ]);
4296
+ return resolvedValue;
4297
+ });
4298
+ }
4002
4299
  model.set([
4003
4300
  [
4004
4301
  node.left.ref,
@@ -4006,6 +4303,12 @@ var CommonTypesPlugin = function() {
4006
4303
  ]
4007
4304
  ]);
4008
4305
  } else if (node.left.type === "Identifier") {
4306
+ if (options.async && isAwaitable(newValue)) {
4307
+ return newValue.awaitableThen(function(resolvedValue) {
4308
+ _this.vars[node.left.name] = resolvedValue;
4309
+ return resolvedValue;
4310
+ });
4311
+ }
4009
4312
  this.vars[node.left.name] = newValue;
4010
4313
  }
4011
4314
  return newValue;
@@ -7229,18 +7532,18 @@ var CommonTypesPlugin = function() {
7229
7532
  this.constantsController = new ConstantsController();
7230
7533
  this.state = NOT_STARTED_STATE;
7231
7534
  this.hooks = {
7232
- /** The hook that fires every time we create a new flowController (a new Content blob is passed in) */ flowController: new SyncHook(),
7233
- /** The hook that updates/handles views */ viewController: new SyncHook(),
7234
- /** A hook called every-time there's a new view. This is equivalent to the view hook on the view-controller */ view: new SyncHook(),
7235
- /** Called when an expression evaluator was created */ expressionEvaluator: new SyncHook(),
7236
- /** The hook that creates and manages data */ dataController: new SyncHook(),
7237
- /** Called after the schema is created for a flow */ schema: new SyncHook(),
7238
- /** Manages validations (schema and x-field ) */ validationController: new SyncHook(),
7239
- /** Manages parsing binding */ bindingParser: new SyncHook(),
7240
- /** A that's called for state changes in the flow execution */ state: new SyncHook(),
7241
- /** A hook to access the current flow */ onStart: new SyncHook(),
7242
- /** A hook for when the flow ends either in success or failure */ onEnd: new SyncHook(),
7243
- /** Mutate the Content flow before starting */ resolveFlowContent: new SyncWaterfallHook()
7535
+ flowController: new SyncHook(),
7536
+ viewController: new SyncHook(),
7537
+ view: new SyncHook(),
7538
+ expressionEvaluator: new SyncHook(),
7539
+ dataController: new SyncHook(),
7540
+ schema: new SyncHook(),
7541
+ validationController: new SyncHook(),
7542
+ bindingParser: new SyncHook(),
7543
+ state: new SyncHook(),
7544
+ onStart: new SyncHook(),
7545
+ onEnd: new SyncHook(),
7546
+ resolveFlowContent: new SyncWaterfallHook()
7244
7547
  };
7245
7548
  if (config === null || config === void 0 ? void 0 : config.logger) {
7246
7549
  this.logger.addHandler(config.logger);
@@ -7440,10 +7743,90 @@ var CommonTypesPlugin = function() {
7440
7743
  var value = (_flowInstance_currentState = flowInstance.currentState) === null || _flowInstance_currentState === void 0 ? void 0 : _flowInstance_currentState.value;
7441
7744
  if (value && value.state_type === "ACTION") {
7442
7745
  var exp = value.exp;
7443
- flowController === null || flowController === void 0 ? void 0 : flowController.transition(String(expressionEvaluator === null || expressionEvaluator === void 0 ? void 0 : expressionEvaluator.evaluate(exp)));
7746
+ var result = expressionEvaluator.evaluate(exp);
7747
+ if (isPromiseLike(result)) {
7748
+ _this.logger.warn("Async expression used as return value in in non-async context, transitioning with '*' value");
7749
+ }
7750
+ flowController === null || flowController === void 0 ? void 0 : flowController.transition(String(result));
7444
7751
  }
7445
7752
  expressionEvaluator.reset();
7446
7753
  });
7754
+ var _this1 = _this;
7755
+ flow.hooks.afterTransition.tap("player", function() {
7756
+ var _ref = _async_to_generator(function(flowInstance) {
7757
+ var _flowInstance_currentState, value, exp, result, e;
7758
+ return _ts_generator(this, function(_state) {
7759
+ switch(_state.label){
7760
+ case 0:
7761
+ value = (_flowInstance_currentState = flowInstance.currentState) === null || _flowInstance_currentState === void 0 ? void 0 : _flowInstance_currentState.value;
7762
+ if (!(value && value.state_type === "ASYNC_ACTION")) return [
7763
+ 3,
7764
+ 8
7765
+ ];
7766
+ exp = value.exp;
7767
+ _state.label = 1;
7768
+ case 1:
7769
+ _state.trys.push([
7770
+ 1,
7771
+ 7,
7772
+ ,
7773
+ 8
7774
+ ]);
7775
+ result = expressionEvaluator.evaluateAsync(exp);
7776
+ if (!isPromiseLike(result)) return [
7777
+ 3,
7778
+ 5
7779
+ ];
7780
+ if (!value.await) return [
7781
+ 3,
7782
+ 3
7783
+ ];
7784
+ return [
7785
+ 4,
7786
+ result
7787
+ ];
7788
+ case 2:
7789
+ result = _state.sent();
7790
+ return [
7791
+ 3,
7792
+ 4
7793
+ ];
7794
+ case 3:
7795
+ _this1.logger.warn("Unawaited promise used as return value in in non-async context, transitioning with '*' value");
7796
+ _state.label = 4;
7797
+ case 4:
7798
+ return [
7799
+ 3,
7800
+ 6
7801
+ ];
7802
+ case 5:
7803
+ _this1.logger.warn("Non async expression used in async action node");
7804
+ _state.label = 6;
7805
+ case 6:
7806
+ flowController === null || flowController === void 0 ? void 0 : flowController.transition(String(result));
7807
+ return [
7808
+ 3,
7809
+ 8
7810
+ ];
7811
+ case 7:
7812
+ e = _state.sent();
7813
+ flowResultDeferred.reject(e);
7814
+ return [
7815
+ 3,
7816
+ 8
7817
+ ];
7818
+ case 8:
7819
+ expressionEvaluator.reset();
7820
+ return [
7821
+ 2
7822
+ ];
7823
+ }
7824
+ });
7825
+ });
7826
+ return function(flowInstance) {
7827
+ return _ref.apply(this, arguments);
7828
+ };
7829
+ }());
7447
7830
  });
7448
7831
  this.hooks.dataController.call(dataController);
7449
7832
  validationController.setOptions({