@player-ui/check-path-plugin 0.12.1-next.0 → 0.13.0-next.1

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 CheckPathPlugin = 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();
@@ -3534,8 +3583,19 @@ var CheckPathPlugin = function() {
3534
3583
  },
3535
3584
  setDataVal: function() {
3536
3585
  return setDataVal;
3586
+ },
3587
+ waitFor: function() {
3588
+ return waitFor;
3537
3589
  }
3538
3590
  });
3591
+ var AwaitableSymbol = Symbol("Awaitable");
3592
+ function makeAwaitable(promise) {
3593
+ promise[AwaitableSymbol] = AwaitableSymbol;
3594
+ promise.awaitableThen = function(arg) {
3595
+ return makeAwaitable(promise.then(arg));
3596
+ };
3597
+ return promise;
3598
+ }
3539
3599
  var setDataVal = function(_context, binding, value) {
3540
3600
  _context.model.set([
3541
3601
  [
@@ -3551,8 +3611,19 @@ var CheckPathPlugin = function() {
3551
3611
  return _context.model.delete(binding);
3552
3612
  };
3553
3613
  var conditional = function(ctx, condition, ifTrue, ifFalse) {
3554
- var resolution = ctx.evaluate(condition);
3555
- if (resolution) {
3614
+ var testResult = ctx.evaluate(condition);
3615
+ if (isAwaitable(testResult)) {
3616
+ return testResult.awaitableThen(function(resolvedTest) {
3617
+ if (resolvedTest) {
3618
+ return ctx.evaluate(ifTrue);
3619
+ }
3620
+ if (ifFalse) {
3621
+ return ctx.evaluate(ifFalse);
3622
+ }
3623
+ return null;
3624
+ });
3625
+ }
3626
+ if (testResult) {
3556
3627
  return ctx.evaluate(ifTrue);
3557
3628
  }
3558
3629
  if (ifFalse) {
@@ -3561,12 +3632,15 @@ var CheckPathPlugin = function() {
3561
3632
  return null;
3562
3633
  };
3563
3634
  conditional.resolveParams = false;
3564
- var andandOperator = function(ctx, a, b) {
3565
- return ctx.evaluate(a) && ctx.evaluate(b);
3635
+ var waitFor = function(ctx, promise) {
3636
+ return makeAwaitable(promise);
3637
+ };
3638
+ var andandOperator = function(ctx, a, b, async) {
3639
+ return LogicalOperators.and(ctx, a, b, async);
3566
3640
  };
3567
3641
  andandOperator.resolveParams = false;
3568
- var ororOperator = function(ctx, a, b) {
3569
- return ctx.evaluate(a) || ctx.evaluate(b);
3642
+ var ororOperator = function(ctx, a, b, async) {
3643
+ return LogicalOperators.or(ctx, a, b, async);
3570
3644
  };
3571
3645
  ororOperator.resolveParams = false;
3572
3646
  var DEFAULT_BINARY_OPERATORS = {
@@ -3586,34 +3660,35 @@ var CheckPathPlugin = function() {
3586
3660
  "%": function(a, b) {
3587
3661
  return a % b;
3588
3662
  },
3663
+ // Promise-aware comparison operators
3589
3664
  // eslint-disable-next-line
3590
- "==": function(a, b) {
3665
+ "==": makePromiseAwareBinaryOp(function(a, b) {
3591
3666
  return a == b;
3592
- },
3667
+ }),
3593
3668
  // eslint-disable-next-line
3594
- "!=": function(a, b) {
3669
+ "!=": makePromiseAwareBinaryOp(function(a, b) {
3595
3670
  return a != b;
3596
- },
3597
- ">": function(a, b) {
3671
+ }),
3672
+ ">": makePromiseAwareBinaryOp(function(a, b) {
3598
3673
  return a > b;
3599
- },
3600
- ">=": function(a, b) {
3674
+ }),
3675
+ ">=": makePromiseAwareBinaryOp(function(a, b) {
3601
3676
  return a >= b;
3602
- },
3603
- "<": function(a, b) {
3677
+ }),
3678
+ "<": makePromiseAwareBinaryOp(function(a, b) {
3604
3679
  return a < b;
3605
- },
3606
- "<=": function(a, b) {
3680
+ }),
3681
+ "<=": makePromiseAwareBinaryOp(function(a, b) {
3607
3682
  return a <= b;
3608
- },
3609
- "&&": andandOperator,
3610
- "||": ororOperator,
3611
- "!==": function(a, b) {
3683
+ }),
3684
+ "!==": makePromiseAwareBinaryOp(function(a, b) {
3612
3685
  return a !== b;
3613
- },
3614
- "===": function(a, b) {
3686
+ }),
3687
+ "===": makePromiseAwareBinaryOp(function(a, b) {
3615
3688
  return a === b;
3616
- },
3689
+ }),
3690
+ "&&": andandOperator,
3691
+ "||": ororOperator,
3617
3692
  // eslint-disable-next-line
3618
3693
  "|": function(a, b) {
3619
3694
  return a | b;
@@ -3644,8 +3719,73 @@ var CheckPathPlugin = function() {
3644
3719
  "+": function(a) {
3645
3720
  return Number(a);
3646
3721
  },
3647
- "!": function(a) {
3722
+ "!": makePromiseAwareUnaryOp(function(a) {
3648
3723
  return !a;
3724
+ })
3725
+ };
3726
+ var PromiseCollectionHandler = {
3727
+ /**
3728
+ * Handle array with potential Promise elements
3729
+ */ handleArray: function handleArray(items, async) {
3730
+ if (!async) {
3731
+ return items;
3732
+ }
3733
+ var hasPromises = items.some(function(item) {
3734
+ return isAwaitable(item);
3735
+ });
3736
+ return hasPromises ? collateAwaitable(items) : items;
3737
+ },
3738
+ /**
3739
+ * Handle object with potential Promise keys/values
3740
+ */ handleObject: function handleObject(attributes, resolveNode, async) {
3741
+ var resolvedAttributes = {};
3742
+ var promises = [];
3743
+ var hasPromises = false;
3744
+ attributes.forEach(function(attr) {
3745
+ var key = resolveNode(attr.key);
3746
+ var value = resolveNode(attr.value);
3747
+ if (async && (isAwaitable(key) || isAwaitable(value))) {
3748
+ hasPromises = true;
3749
+ var keyPromise = Promise.resolve(key);
3750
+ var valuePromise = Promise.resolve(value);
3751
+ promises.push(collateAwaitable([
3752
+ keyPromise,
3753
+ valuePromise
3754
+ ]).awaitableThen(function(param) {
3755
+ var _param = _sliced_to_array(param, 2), resolvedKey = _param[0], resolvedValue = _param[1];
3756
+ resolvedAttributes[resolvedKey] = resolvedValue;
3757
+ }));
3758
+ } else {
3759
+ resolvedAttributes[key] = value;
3760
+ }
3761
+ });
3762
+ return hasPromises ? collateAwaitable(promises).awaitableThen(function() {
3763
+ return resolvedAttributes;
3764
+ }) : resolvedAttributes;
3765
+ }
3766
+ };
3767
+ var LogicalOperators = {
3768
+ and: function(ctx, leftNode, rightNode, async) {
3769
+ var leftResult = ctx.evaluate(leftNode);
3770
+ if (async && isAwaitable(leftResult)) {
3771
+ return leftResult.awaitableThen(function(awaitedLeft) {
3772
+ if (!awaitedLeft) return awaitedLeft;
3773
+ var rightResult = ctx.evaluate(rightNode);
3774
+ return isAwaitable(rightResult) ? rightResult : Promise.resolve(rightResult);
3775
+ });
3776
+ }
3777
+ return leftResult && ctx.evaluate(rightNode);
3778
+ },
3779
+ or: function(ctx, leftNode, rightNode, async) {
3780
+ var leftResult = ctx.evaluate(leftNode);
3781
+ if (async && isAwaitable(leftResult)) {
3782
+ return leftResult.awaitableThen(function(awaitedLeft) {
3783
+ if (awaitedLeft) return awaitedLeft;
3784
+ var rightResult = ctx.evaluate(rightNode);
3785
+ return isAwaitable(rightResult) ? rightResult : Promise.resolve(rightResult);
3786
+ });
3787
+ }
3788
+ return leftResult || ctx.evaluate(rightNode);
3649
3789
  }
3650
3790
  };
3651
3791
  var ExpressionEvaluator = /*#__PURE__*/ function() {
@@ -3666,7 +3806,12 @@ var CheckPathPlugin = function() {
3666
3806
  this.operators = {
3667
3807
  binary: new Map(Object.entries(DEFAULT_BINARY_OPERATORS)),
3668
3808
  unary: new Map(Object.entries(DEFAULT_UNARY_OPERATORS)),
3669
- expressions: new Map(Object.entries(evaluator_functions_exports))
3809
+ expressions: new Map(_to_consumable_array(Object.entries(evaluator_functions_exports)).concat([
3810
+ [
3811
+ "await",
3812
+ waitFor
3813
+ ]
3814
+ ]))
3670
3815
  };
3671
3816
  this.defaultHookOptions = _object_spread_props(_object_spread({}, defaultOptions), {
3672
3817
  evaluate: function(expr) {
@@ -3676,7 +3821,9 @@ var CheckPathPlugin = function() {
3676
3821
  return _this._execAST(node, _this.defaultHookOptions);
3677
3822
  }
3678
3823
  });
3679
- this.hooks.resolve.tap("ExpressionEvaluator", this._resolveNode.bind(this));
3824
+ this.hooks.resolve.tap("ExpressionEvaluator", function(result, node, options) {
3825
+ return _this._resolveNode(result, node, options);
3826
+ });
3680
3827
  this.evaluate = this.evaluate.bind(this);
3681
3828
  }
3682
3829
  _create_class(ExpressionEvaluator, [
@@ -3714,6 +3861,38 @@ var CheckPathPlugin = function() {
3714
3861
  return this._execString(String(expression), resolvedOpts);
3715
3862
  }
3716
3863
  },
3864
+ {
3865
+ /**
3866
+ * Evaluate functions in an async context
3867
+ * @experimental These Player APIs are in active development and may change. Use with caution
3868
+ */ key: "evaluateAsync",
3869
+ value: function evaluateAsync(expr, options) {
3870
+ if (Array.isArray(expr)) {
3871
+ var _this = this;
3872
+ return collateAwaitable(expr.map(function() {
3873
+ var _ref = _async_to_generator(function(exp) {
3874
+ return _ts_generator(this, function(_state) {
3875
+ return [
3876
+ 2,
3877
+ _this.evaluate(exp, _object_spread_props(_object_spread({}, options), {
3878
+ async: true
3879
+ }))
3880
+ ];
3881
+ });
3882
+ });
3883
+ return function(exp) {
3884
+ return _ref.apply(this, arguments);
3885
+ };
3886
+ }())).awaitableThen(function(values) {
3887
+ return values.pop();
3888
+ });
3889
+ } else {
3890
+ return this.evaluate(expr, _object_spread_props(_object_spread({}, options), {
3891
+ async: true
3892
+ }));
3893
+ }
3894
+ }
3895
+ },
3717
3896
  {
3718
3897
  key: "addExpressionFunction",
3719
3898
  value: function addExpressionFunction(name, handler) {
@@ -3759,8 +3938,10 @@ var CheckPathPlugin = function() {
3759
3938
  var matches = exp.match(/^@\[(.*)\]@$/);
3760
3939
  var matchedExp = exp;
3761
3940
  if (matches) {
3762
- var ref;
3763
- ref = _sliced_to_array(Array.from(matches), 2), matchedExp = ref[1], ref;
3941
+ var _Array_from = _sliced_to_array(Array.from(matches), 2), matched = _Array_from[1];
3942
+ if (matched) {
3943
+ matchedExp = matched;
3944
+ }
3764
3945
  }
3765
3946
  var storedAST;
3766
3947
  try {
@@ -3789,6 +3970,8 @@ var CheckPathPlugin = function() {
3789
3970
  value: function _resolveNode(_currentValue, node, options) {
3790
3971
  var _this = this;
3791
3972
  var resolveNode = options.resolveNode, model = options.model;
3973
+ var _options_async;
3974
+ var isAsync = (_options_async = options.async) !== null && _options_async !== void 0 ? _options_async : false;
3792
3975
  var expressionContext = _object_spread_props(_object_spread({}, options), {
3793
3976
  evaluate: function(expr) {
3794
3977
  return _this.evaluate(expr, options);
@@ -3808,11 +3991,33 @@ var CheckPathPlugin = function() {
3808
3991
  if (operator) {
3809
3992
  if ("resolveParams" in operator) {
3810
3993
  if (operator.resolveParams === false) {
3811
- return operator(expressionContext, node.left, node.right);
3994
+ return operator(expressionContext, node.left, node.right, isAsync);
3995
+ }
3996
+ var left2 = resolveNode(node.left);
3997
+ var right2 = resolveNode(node.right);
3998
+ if (options.async && (isAwaitable(left2) || isAwaitable(right2))) {
3999
+ return collateAwaitable([
4000
+ left2,
4001
+ right2
4002
+ ]).awaitableThen(function(param) {
4003
+ var _param = _sliced_to_array(param, 2), leftVal = _param[0], rightVal = _param[1];
4004
+ return operator(expressionContext, leftVal, rightVal, isAsync);
4005
+ });
3812
4006
  }
3813
- return operator(expressionContext, resolveNode(node.left), resolveNode(node.right));
4007
+ return operator(expressionContext, left2, right2, isAsync);
4008
+ }
4009
+ var left = resolveNode(node.left);
4010
+ var right = resolveNode(node.right);
4011
+ if (options.async && (isAwaitable(left) || isAwaitable(right))) {
4012
+ return collateAwaitable([
4013
+ left,
4014
+ right
4015
+ ]).awaitableThen(function(param) {
4016
+ var _param = _sliced_to_array(param, 2), leftVal = _param[0], rightVal = _param[1];
4017
+ return operator(leftVal, rightVal, isAsync);
4018
+ });
3814
4019
  }
3815
- return operator(resolveNode(node.left), resolveNode(node.right));
4020
+ return operator(left, right, isAsync);
3816
4021
  }
3817
4022
  return;
3818
4023
  }
@@ -3820,21 +4025,29 @@ var CheckPathPlugin = function() {
3820
4025
  var operator1 = this.operators.unary.get(node.operator);
3821
4026
  if (operator1) {
3822
4027
  if ("resolveParams" in operator1) {
3823
- return operator1(expressionContext, operator1.resolveParams === false ? node.argument : resolveNode(node.argument));
4028
+ if (operator1.resolveParams === false) {
4029
+ return operator1(expressionContext, node.argument, isAsync);
4030
+ }
4031
+ var arg2 = resolveNode(node.argument);
4032
+ if (options.async && isAwaitable(arg2)) {
4033
+ return arg2.awaitableThen(function(argVal) {
4034
+ return operator1(expressionContext, argVal, isAsync);
4035
+ });
4036
+ }
4037
+ return operator1(expressionContext, arg2, isAsync);
4038
+ }
4039
+ var arg = resolveNode(node.argument);
4040
+ if (options.async && isAwaitable(arg)) {
4041
+ return arg.awaitableThen(function(argVal) {
4042
+ return operator1(argVal, isAsync);
4043
+ });
3824
4044
  }
3825
- return operator1(resolveNode(node.argument));
4045
+ return operator1(arg, isAsync);
3826
4046
  }
3827
4047
  return;
3828
4048
  }
3829
4049
  if (node.type === "Object") {
3830
- var attributes = node.attributes;
3831
- var resolvedAttributes = {};
3832
- attributes.forEach(function(attr) {
3833
- var key = resolveNode(attr.key);
3834
- var value = resolveNode(attr.value);
3835
- resolvedAttributes[key] = value;
3836
- });
3837
- return resolvedAttributes;
4050
+ return PromiseCollectionHandler.handleObject(node.attributes, resolveNode, options.async || false);
3838
4051
  }
3839
4052
  if (node.type === "CallExpression") {
3840
4053
  var expressionName = node.callTarget.name;
@@ -3842,6 +4055,9 @@ var CheckPathPlugin = function() {
3842
4055
  if (!operator2) {
3843
4056
  throw new Error("Unknown expression function: ".concat(expressionName));
3844
4057
  }
4058
+ if (operator2.name === waitFor.name && !options.async) {
4059
+ throw new Error("Usage of await outside of async context");
4060
+ }
3845
4061
  if ("resolveParams" in operator2 && operator2.resolveParams === false) {
3846
4062
  return operator2.apply(void 0, [
3847
4063
  expressionContext
@@ -3850,6 +4066,16 @@ var CheckPathPlugin = function() {
3850
4066
  var args = node.args.map(function(n) {
3851
4067
  return resolveNode(n);
3852
4068
  });
4069
+ if (options.async) {
4070
+ var hasPromises = args.some(isAwaitable);
4071
+ if (hasPromises) {
4072
+ return collateAwaitable(args).awaitableThen(function(resolvedArgs) {
4073
+ return operator2.apply(void 0, [
4074
+ expressionContext
4075
+ ].concat(_to_consumable_array(resolvedArgs)));
4076
+ });
4077
+ }
4078
+ }
3853
4079
  return operator2.apply(void 0, [
3854
4080
  expressionContext
3855
4081
  ].concat(_to_consumable_array(args)));
@@ -3864,11 +4090,36 @@ var CheckPathPlugin = function() {
3864
4090
  if (node.type === "MemberExpression") {
3865
4091
  var obj = resolveNode(node.object);
3866
4092
  var prop = resolveNode(node.property);
4093
+ if (options.async && (isAwaitable(obj) || isAwaitable(prop))) {
4094
+ return collateAwaitable([
4095
+ obj,
4096
+ prop
4097
+ ]).awaitableThen(function(param) {
4098
+ var _param = _sliced_to_array(param, 2), objVal = _param[0], propVal = _param[1];
4099
+ return objVal[propVal];
4100
+ });
4101
+ }
3867
4102
  return obj[prop];
3868
4103
  }
3869
4104
  if (node.type === "Assignment") {
3870
4105
  if (node.left.type === "ModelRef") {
3871
4106
  var value = resolveNode(node.right);
4107
+ if (isPromiseLike(value)) {
4108
+ if (options.async && isAwaitable(value)) {
4109
+ return value.awaitableThen(function(resolvedValue) {
4110
+ model.set([
4111
+ [
4112
+ node.left.ref,
4113
+ resolvedValue
4114
+ ]
4115
+ ]);
4116
+ return resolvedValue;
4117
+ });
4118
+ } else {
4119
+ var _options_logger;
4120
+ (_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");
4121
+ }
4122
+ }
3872
4123
  model.set([
3873
4124
  [
3874
4125
  node.left.ref,
@@ -3879,19 +4130,30 @@ var CheckPathPlugin = function() {
3879
4130
  }
3880
4131
  if (node.left.type === "Identifier") {
3881
4132
  var value1 = resolveNode(node.right);
4133
+ if (options.async && isAwaitable(value1)) {
4134
+ return value1.awaitableThen(function(resolvedValue) {
4135
+ _this.vars[node.left.name] = resolvedValue;
4136
+ return resolvedValue;
4137
+ });
4138
+ }
3882
4139
  this.vars[node.left.name] = value1;
3883
4140
  return value1;
3884
4141
  }
3885
4142
  return;
3886
4143
  }
3887
4144
  if (node.type === "ConditionalExpression") {
3888
- var result = resolveNode(node.test) ? node.consequent : node.alternate;
3889
- return resolveNode(result);
4145
+ var testResult = resolveNode(node.test);
4146
+ return handleConditionalBranching(testResult, function() {
4147
+ return node.consequent;
4148
+ }, function() {
4149
+ return node.alternate;
4150
+ }, resolveNode, isAsync);
3890
4151
  }
3891
4152
  if (node.type === "ArrayExpression") {
3892
- return node.elements.map(function(ele) {
4153
+ var results = node.elements.map(function(ele) {
3893
4154
  return resolveNode(ele);
3894
4155
  });
4156
+ return PromiseCollectionHandler.handleArray(results, isAsync);
3895
4157
  }
3896
4158
  if (node.type === "Modification") {
3897
4159
  var operation = this.operators.binary.get(node.operator);
@@ -3899,14 +4161,49 @@ var CheckPathPlugin = function() {
3899
4161
  var newValue;
3900
4162
  if ("resolveParams" in operation) {
3901
4163
  if (operation.resolveParams === false) {
3902
- newValue = operation(expressionContext, node.left, node.right);
4164
+ newValue = operation(expressionContext, node.left, node.right, isAsync);
3903
4165
  } else {
3904
- newValue = operation(expressionContext, resolveNode(node.left), resolveNode(node.right));
4166
+ var left1 = resolveNode(node.left);
4167
+ var right1 = resolveNode(node.right);
4168
+ if (options.async && (isAwaitable(left1) || isAwaitable(right1))) {
4169
+ newValue = collateAwaitable([
4170
+ left1,
4171
+ right1
4172
+ ]).awaitableThen(function(param) {
4173
+ var _param = _sliced_to_array(param, 2), leftVal = _param[0], rightVal = _param[1];
4174
+ return operation(expressionContext, leftVal, rightVal, isAsync);
4175
+ });
4176
+ } else {
4177
+ newValue = operation(expressionContext, left1, right1, isAsync);
4178
+ }
3905
4179
  }
3906
4180
  } else {
3907
- newValue = operation(resolveNode(node.left), resolveNode(node.right));
4181
+ var left3 = resolveNode(node.left);
4182
+ var right3 = resolveNode(node.right);
4183
+ if (options.async && (isAwaitable(left3) || isAwaitable(right3))) {
4184
+ newValue = collateAwaitable([
4185
+ left3,
4186
+ right3
4187
+ ]).awaitableThen(function(param) {
4188
+ var _param = _sliced_to_array(param, 2), leftVal = _param[0], rightVal = _param[1];
4189
+ return operation(leftVal, rightVal, isAsync);
4190
+ });
4191
+ } else {
4192
+ newValue = operation(left3, right3, isAsync);
4193
+ }
3908
4194
  }
3909
4195
  if (node.left.type === "ModelRef") {
4196
+ if (options.async && isAwaitable(newValue)) {
4197
+ return newValue.awaitableThen(function(resolvedValue) {
4198
+ model.set([
4199
+ [
4200
+ node.left.ref,
4201
+ resolvedValue
4202
+ ]
4203
+ ]);
4204
+ return resolvedValue;
4205
+ });
4206
+ }
3910
4207
  model.set([
3911
4208
  [
3912
4209
  node.left.ref,
@@ -3914,6 +4211,12 @@ var CheckPathPlugin = function() {
3914
4211
  ]
3915
4212
  ]);
3916
4213
  } else if (node.left.type === "Identifier") {
4214
+ if (options.async && isAwaitable(newValue)) {
4215
+ return newValue.awaitableThen(function(resolvedValue) {
4216
+ _this.vars[node.left.name] = resolvedValue;
4217
+ return resolvedValue;
4218
+ });
4219
+ }
3917
4220
  this.vars[node.left.name] = newValue;
3918
4221
  }
3919
4222
  return newValue;
@@ -4792,20 +5095,15 @@ var CheckPathPlugin = function() {
4792
5095
  }();
4793
5096
  var ViewInstance = /*#__PURE__*/ function() {
4794
5097
  function ViewInstance(initialView, resolverOptions) {
4795
- var _this = this;
4796
5098
  _class_call_check(this, ViewInstance);
4797
5099
  this.hooks = {
4798
5100
  onUpdate: new SyncHook(),
4799
5101
  parser: new SyncHook(),
4800
5102
  resolver: new SyncHook(),
4801
- onTemplatePluginCreated: new SyncHook(),
4802
5103
  templatePlugin: new SyncHook()
4803
5104
  };
4804
5105
  this.initialView = initialView;
4805
5106
  this.resolverOptions = resolverOptions;
4806
- this.hooks.onTemplatePluginCreated.tap("view", function(templatePlugin) {
4807
- _this.templatePlugin = templatePlugin;
4808
- });
4809
5107
  }
4810
5108
  _create_class(ViewInstance, [
4811
5109
  {
@@ -4852,6 +5150,12 @@ var CheckPathPlugin = function() {
4852
5150
  var _this_validationProvider;
4853
5151
  return (_this_validationProvider = this.validationProvider) === null || _this_validationProvider === void 0 ? void 0 : _this_validationProvider.getValidationsForBinding(binding);
4854
5152
  }
5153
+ },
5154
+ {
5155
+ key: "setTemplatePlugin",
5156
+ value: function setTemplatePlugin(plugin) {
5157
+ this.templatePlugin = plugin;
5158
+ }
4855
5159
  }
4856
5160
  ]);
4857
5161
  return ViewInstance;
@@ -5023,6 +5327,7 @@ var CheckPathPlugin = function() {
5023
5327
  value: function apply(view) {
5024
5328
  view.hooks.parser.tap("template", this.applyParser.bind(this));
5025
5329
  view.hooks.resolver.tap("template", this.applyResolverHooks.bind(this));
5330
+ view.setTemplatePlugin(this);
5026
5331
  }
5027
5332
  }
5028
5333
  ]);
@@ -6631,8 +6936,7 @@ var CheckPathPlugin = function() {
6631
6936
  var _this1 = this;
6632
6937
  _class_call_check(this, ViewController);
6633
6938
  this.hooks = {
6634
- /** Do any processing before the `View` instance is created */ resolveView: new SyncWaterfallHook(),
6635
- // The hook right before the View starts resolving. Attach anything custom here
6939
+ resolveView: new SyncWaterfallHook(),
6636
6940
  view: new SyncHook()
6637
6941
  };
6638
6942
  this.transformRegistry = new Registry();
@@ -6680,6 +6984,7 @@ var CheckPathPlugin = function() {
6680
6984
  ]));
6681
6985
  }
6682
6986
  });
6987
+ this.viewPlugins = this.createViewPlugins();
6683
6988
  }
6684
6989
  _create_class(ViewController, [
6685
6990
  {
@@ -6735,9 +7040,50 @@ var CheckPathPlugin = function() {
6735
7040
  }
6736
7041
  var view = new ViewInstance(source, this.viewOptions);
6737
7042
  this.currentView = view;
7043
+ this.applyViewPlugins(view);
6738
7044
  this.hooks.view.call(view);
6739
7045
  view.update();
6740
7046
  }
7047
+ },
7048
+ {
7049
+ key: "applyViewPlugins",
7050
+ value: function applyViewPlugins(view) {
7051
+ var _iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = undefined;
7052
+ try {
7053
+ for(var _iterator = this.viewPlugins[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true){
7054
+ var plugin = _step.value;
7055
+ plugin.apply(view);
7056
+ }
7057
+ } catch (err) {
7058
+ _didIteratorError = true;
7059
+ _iteratorError = err;
7060
+ } finally{
7061
+ try {
7062
+ if (!_iteratorNormalCompletion && _iterator.return != null) {
7063
+ _iterator.return();
7064
+ }
7065
+ } finally{
7066
+ if (_didIteratorError) {
7067
+ throw _iteratorError;
7068
+ }
7069
+ }
7070
+ }
7071
+ }
7072
+ },
7073
+ {
7074
+ key: "createViewPlugins",
7075
+ value: function createViewPlugins() {
7076
+ var pluginOptions = toNodeResolveOptions(this.viewOptions);
7077
+ return [
7078
+ new AssetPlugin(),
7079
+ new SwitchPlugin(pluginOptions),
7080
+ new ApplicabilityPlugin(),
7081
+ new AssetTransformCorePlugin(this.transformRegistry),
7082
+ new StringResolverPlugin(),
7083
+ new TemplatePlugin(pluginOptions),
7084
+ new MultiNodePlugin()
7085
+ ];
7086
+ }
6741
7087
  }
6742
7088
  ]);
6743
7089
  return ViewController;
@@ -7110,35 +7456,6 @@ var CheckPathPlugin = function() {
7110
7456
  ref: Symbol("not-started"),
7111
7457
  status: "not-started"
7112
7458
  };
7113
- var DefaultViewPlugin = /*#__PURE__*/ function() {
7114
- function DefaultViewPlugin() {
7115
- _class_call_check(this, DefaultViewPlugin);
7116
- this.name = "default-view-plugin";
7117
- }
7118
- _create_class(DefaultViewPlugin, [
7119
- {
7120
- key: "apply",
7121
- value: function apply(player) {
7122
- var _this = this;
7123
- player.hooks.viewController.tap(this.name, function(viewController) {
7124
- viewController.hooks.view.tap(_this.name, function(view) {
7125
- var pluginOptions = toNodeResolveOptions(view.resolverOptions);
7126
- new AssetPlugin().apply(view);
7127
- new SwitchPlugin(pluginOptions).apply(view);
7128
- new ApplicabilityPlugin().apply(view);
7129
- new AssetTransformCorePlugin(viewController.transformRegistry).apply(view);
7130
- new StringResolverPlugin().apply(view);
7131
- var templatePlugin = new TemplatePlugin(pluginOptions);
7132
- templatePlugin.apply(view);
7133
- view.hooks.onTemplatePluginCreated.call(templatePlugin);
7134
- new MultiNodePlugin().apply(view);
7135
- });
7136
- });
7137
- }
7138
- }
7139
- ]);
7140
- return DefaultViewPlugin;
7141
- }();
7142
7459
  var PLAYER_VERSION = "__VERSION__";
7143
7460
  var COMMIT = "__GIT_COMMIT__";
7144
7461
  var _Player = /*#__PURE__*/ function() {
@@ -7150,26 +7467,25 @@ var CheckPathPlugin = function() {
7150
7467
  this.constantsController = new ConstantsController();
7151
7468
  this.state = NOT_STARTED_STATE;
7152
7469
  this.hooks = {
7153
- /** The hook that fires every time we create a new flowController (a new Content blob is passed in) */ flowController: new SyncHook(),
7154
- /** The hook that updates/handles views */ viewController: new SyncHook(),
7155
- /** A hook called every-time there's a new view. This is equivalent to the view hook on the view-controller */ view: new SyncHook(),
7156
- /** Called when an expression evaluator was created */ expressionEvaluator: new SyncHook(),
7157
- /** The hook that creates and manages data */ dataController: new SyncHook(),
7158
- /** Called after the schema is created for a flow */ schema: new SyncHook(),
7159
- /** Manages validations (schema and x-field ) */ validationController: new SyncHook(),
7160
- /** Manages parsing binding */ bindingParser: new SyncHook(),
7161
- /** A that's called for state changes in the flow execution */ state: new SyncHook(),
7162
- /** A hook to access the current flow */ onStart: new SyncHook(),
7163
- /** A hook for when the flow ends either in success or failure */ onEnd: new SyncHook(),
7164
- /** Mutate the Content flow before starting */ resolveFlowContent: new SyncWaterfallHook()
7470
+ flowController: new SyncHook(),
7471
+ viewController: new SyncHook(),
7472
+ view: new SyncHook(),
7473
+ expressionEvaluator: new SyncHook(),
7474
+ dataController: new SyncHook(),
7475
+ schema: new SyncHook(),
7476
+ validationController: new SyncHook(),
7477
+ bindingParser: new SyncHook(),
7478
+ state: new SyncHook(),
7479
+ onStart: new SyncHook(),
7480
+ onEnd: new SyncHook(),
7481
+ resolveFlowContent: new SyncWaterfallHook()
7165
7482
  };
7166
7483
  if (config === null || config === void 0 ? void 0 : config.logger) {
7167
7484
  this.logger.addHandler(config.logger);
7168
7485
  }
7169
7486
  this.config = config || {};
7170
7487
  this.config.plugins = [
7171
- new DefaultExpPlugin(),
7172
- new DefaultViewPlugin()
7488
+ new DefaultExpPlugin()
7173
7489
  ].concat(_to_consumable_array(this.config.plugins || []), [
7174
7490
  new FlowExpPlugin()
7175
7491
  ]);
@@ -7361,10 +7677,90 @@ var CheckPathPlugin = function() {
7361
7677
  var value = (_flowInstance_currentState = flowInstance.currentState) === null || _flowInstance_currentState === void 0 ? void 0 : _flowInstance_currentState.value;
7362
7678
  if (value && value.state_type === "ACTION") {
7363
7679
  var exp = value.exp;
7364
- flowController === null || flowController === void 0 ? void 0 : flowController.transition(String(expressionEvaluator === null || expressionEvaluator === void 0 ? void 0 : expressionEvaluator.evaluate(exp)));
7680
+ var result = expressionEvaluator.evaluate(exp);
7681
+ if (isPromiseLike(result)) {
7682
+ _this.logger.warn("Async expression used as return value in in non-async context, transitioning with '*' value");
7683
+ }
7684
+ flowController === null || flowController === void 0 ? void 0 : flowController.transition(String(result));
7365
7685
  }
7366
7686
  expressionEvaluator.reset();
7367
7687
  });
7688
+ var _this1 = _this;
7689
+ flow.hooks.afterTransition.tap("player", function() {
7690
+ var _ref = _async_to_generator(function(flowInstance) {
7691
+ var _flowInstance_currentState, value, exp, result, e;
7692
+ return _ts_generator(this, function(_state) {
7693
+ switch(_state.label){
7694
+ case 0:
7695
+ value = (_flowInstance_currentState = flowInstance.currentState) === null || _flowInstance_currentState === void 0 ? void 0 : _flowInstance_currentState.value;
7696
+ if (!(value && value.state_type === "ASYNC_ACTION")) return [
7697
+ 3,
7698
+ 8
7699
+ ];
7700
+ exp = value.exp;
7701
+ _state.label = 1;
7702
+ case 1:
7703
+ _state.trys.push([
7704
+ 1,
7705
+ 7,
7706
+ ,
7707
+ 8
7708
+ ]);
7709
+ result = expressionEvaluator.evaluateAsync(exp);
7710
+ if (!isPromiseLike(result)) return [
7711
+ 3,
7712
+ 5
7713
+ ];
7714
+ if (!value.await) return [
7715
+ 3,
7716
+ 3
7717
+ ];
7718
+ return [
7719
+ 4,
7720
+ result
7721
+ ];
7722
+ case 2:
7723
+ result = _state.sent();
7724
+ return [
7725
+ 3,
7726
+ 4
7727
+ ];
7728
+ case 3:
7729
+ _this1.logger.warn("Unawaited promise used as return value in in non-async context, transitioning with '*' value");
7730
+ _state.label = 4;
7731
+ case 4:
7732
+ return [
7733
+ 3,
7734
+ 6
7735
+ ];
7736
+ case 5:
7737
+ _this1.logger.warn("Non async expression used in async action node");
7738
+ _state.label = 6;
7739
+ case 6:
7740
+ flowController === null || flowController === void 0 ? void 0 : flowController.transition(String(result));
7741
+ return [
7742
+ 3,
7743
+ 8
7744
+ ];
7745
+ case 7:
7746
+ e = _state.sent();
7747
+ flowResultDeferred.reject(e);
7748
+ return [
7749
+ 3,
7750
+ 8
7751
+ ];
7752
+ case 8:
7753
+ expressionEvaluator.reset();
7754
+ return [
7755
+ 2
7756
+ ];
7757
+ }
7758
+ });
7759
+ });
7760
+ return function(flowInstance) {
7761
+ return _ref.apply(this, arguments);
7762
+ };
7763
+ }());
7368
7764
  });
7369
7765
  this.hooks.dataController.call(dataController);
7370
7766
  validationController.setOptions({
@@ -7402,11 +7798,9 @@ var CheckPathPlugin = function() {
7402
7798
  }),
7403
7799
  constants: this.constantsController
7404
7800
  });
7405
- this.hooks.viewController.tap("player", function(vc) {
7406
- vc.hooks.view.tap("player", function(view) {
7407
- validationController.onView(view);
7408
- _this.hooks.view.call(view);
7409
- });
7801
+ viewController.hooks.view.tap("player", function(view) {
7802
+ validationController.onView(view);
7803
+ _this.hooks.view.call(view);
7410
7804
  });
7411
7805
  this.hooks.viewController.call(viewController);
7412
7806
  return {