@player-ui/reference-assets-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.
@@ -1276,12 +1276,61 @@ var ReferenceAssetsPlugin = function() {
1276
1276
  };
1277
1277
  }
1278
1278
  };
1279
+ var isPromiseLike = function isPromiseLike(value) {
1280
+ var // Check for standard Promise constructor name
1281
+ _value_constructor;
1282
+ return value != null && typeof value === "object" && typeof value.then === "function" && // Additional safeguards against false positives
1283
+ (_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
1284
+ typeof value.catch === "function" && typeof value.finally === "function");
1285
+ };
1286
+ var isAwaitable = function isAwaitable(val) {
1287
+ return isPromiseLike(val) && val[AwaitableSymbol] !== void 0;
1288
+ };
1289
+ var collateAwaitable = function collateAwaitable(promises) {
1290
+ var result = Promise.all(promises);
1291
+ return makeAwaitable(result);
1292
+ };
1279
1293
  var isObjectExpression = function isObjectExpression(expr) {
1280
1294
  if (isExpressionNode(expr)) {
1281
1295
  return false;
1282
1296
  }
1283
1297
  return typeof expr === "object" && expr !== null && !Array.isArray(expr) && "value" in expr;
1284
1298
  };
1299
+ var makePromiseAwareBinaryOp = function makePromiseAwareBinaryOp(operation) {
1300
+ return function(a, b, async) {
1301
+ if (async && (isAwaitable(a) || isAwaitable(b))) {
1302
+ return collateAwaitable([
1303
+ Promise.resolve(a),
1304
+ Promise.resolve(b)
1305
+ ]).awaitableThen(function(param) {
1306
+ var _param = _sliced_to_array(param, 2), resolvedA = _param[0], resolvedB = _param[1];
1307
+ return operation(resolvedA, resolvedB);
1308
+ });
1309
+ }
1310
+ return operation(a, b);
1311
+ };
1312
+ };
1313
+ var makePromiseAwareUnaryOp = function makePromiseAwareUnaryOp(operation) {
1314
+ return function(a, async) {
1315
+ if (async && isAwaitable(a)) {
1316
+ return a.awaitableThen(function(resolved) {
1317
+ return operation(resolved);
1318
+ });
1319
+ }
1320
+ return operation(a);
1321
+ };
1322
+ };
1323
+ var handleConditionalBranching = function handleConditionalBranching(testValue, getTrueBranch, getFalseBranch, resolveNode, async) {
1324
+ if (async && isAwaitable(testValue)) {
1325
+ return testValue.awaitableThen(function(resolved) {
1326
+ var branch2 = resolved ? getTrueBranch() : getFalseBranch();
1327
+ var branchResult = resolveNode(branch2);
1328
+ return isAwaitable(branchResult) ? Promise.resolve(branchResult) : branchResult;
1329
+ });
1330
+ }
1331
+ var branch = testValue ? getTrueBranch() : getFalseBranch();
1332
+ return resolveNode(branch);
1333
+ };
1285
1334
  var parse2 = function parse2(schema) {
1286
1335
  var _loop = function() {
1287
1336
  var next = parseQueue.shift();
@@ -3807,8 +3856,19 @@ var ReferenceAssetsPlugin = function() {
3807
3856
  },
3808
3857
  setDataVal: function() {
3809
3858
  return setDataVal;
3859
+ },
3860
+ waitFor: function() {
3861
+ return waitFor;
3810
3862
  }
3811
3863
  });
3864
+ var AwaitableSymbol = Symbol("Awaitable");
3865
+ function makeAwaitable(promise) {
3866
+ promise[AwaitableSymbol] = AwaitableSymbol;
3867
+ promise.awaitableThen = function(arg) {
3868
+ return makeAwaitable(promise.then(arg));
3869
+ };
3870
+ return promise;
3871
+ }
3812
3872
  var setDataVal = function(_context, binding, value) {
3813
3873
  _context.model.set([
3814
3874
  [
@@ -3824,8 +3884,19 @@ var ReferenceAssetsPlugin = function() {
3824
3884
  return _context.model.delete(binding);
3825
3885
  };
3826
3886
  var conditional = function(ctx, condition, ifTrue, ifFalse) {
3827
- var resolution = ctx.evaluate(condition);
3828
- if (resolution) {
3887
+ var testResult = ctx.evaluate(condition);
3888
+ if (isAwaitable(testResult)) {
3889
+ return testResult.awaitableThen(function(resolvedTest) {
3890
+ if (resolvedTest) {
3891
+ return ctx.evaluate(ifTrue);
3892
+ }
3893
+ if (ifFalse) {
3894
+ return ctx.evaluate(ifFalse);
3895
+ }
3896
+ return null;
3897
+ });
3898
+ }
3899
+ if (testResult) {
3829
3900
  return ctx.evaluate(ifTrue);
3830
3901
  }
3831
3902
  if (ifFalse) {
@@ -3834,12 +3905,15 @@ var ReferenceAssetsPlugin = function() {
3834
3905
  return null;
3835
3906
  };
3836
3907
  conditional.resolveParams = false;
3837
- var andandOperator = function(ctx, a, b) {
3838
- return ctx.evaluate(a) && ctx.evaluate(b);
3908
+ var waitFor = function(ctx, promise) {
3909
+ return makeAwaitable(promise);
3910
+ };
3911
+ var andandOperator = function(ctx, a, b, async) {
3912
+ return LogicalOperators.and(ctx, a, b, async);
3839
3913
  };
3840
3914
  andandOperator.resolveParams = false;
3841
- var ororOperator = function(ctx, a, b) {
3842
- return ctx.evaluate(a) || ctx.evaluate(b);
3915
+ var ororOperator = function(ctx, a, b, async) {
3916
+ return LogicalOperators.or(ctx, a, b, async);
3843
3917
  };
3844
3918
  ororOperator.resolveParams = false;
3845
3919
  var DEFAULT_BINARY_OPERATORS = {
@@ -3859,34 +3933,35 @@ var ReferenceAssetsPlugin = function() {
3859
3933
  "%": function(a, b) {
3860
3934
  return a % b;
3861
3935
  },
3936
+ // Promise-aware comparison operators
3862
3937
  // eslint-disable-next-line
3863
- "==": function(a, b) {
3938
+ "==": makePromiseAwareBinaryOp(function(a, b) {
3864
3939
  return a == b;
3865
- },
3940
+ }),
3866
3941
  // eslint-disable-next-line
3867
- "!=": function(a, b) {
3942
+ "!=": makePromiseAwareBinaryOp(function(a, b) {
3868
3943
  return a != b;
3869
- },
3870
- ">": function(a, b) {
3944
+ }),
3945
+ ">": makePromiseAwareBinaryOp(function(a, b) {
3871
3946
  return a > b;
3872
- },
3873
- ">=": function(a, b) {
3947
+ }),
3948
+ ">=": makePromiseAwareBinaryOp(function(a, b) {
3874
3949
  return a >= b;
3875
- },
3876
- "<": function(a, b) {
3950
+ }),
3951
+ "<": makePromiseAwareBinaryOp(function(a, b) {
3877
3952
  return a < b;
3878
- },
3879
- "<=": function(a, b) {
3953
+ }),
3954
+ "<=": makePromiseAwareBinaryOp(function(a, b) {
3880
3955
  return a <= b;
3881
- },
3882
- "&&": andandOperator,
3883
- "||": ororOperator,
3884
- "!==": function(a, b) {
3956
+ }),
3957
+ "!==": makePromiseAwareBinaryOp(function(a, b) {
3885
3958
  return a !== b;
3886
- },
3887
- "===": function(a, b) {
3959
+ }),
3960
+ "===": makePromiseAwareBinaryOp(function(a, b) {
3888
3961
  return a === b;
3889
- },
3962
+ }),
3963
+ "&&": andandOperator,
3964
+ "||": ororOperator,
3890
3965
  // eslint-disable-next-line
3891
3966
  "|": function(a, b) {
3892
3967
  return a | b;
@@ -3917,8 +3992,73 @@ var ReferenceAssetsPlugin = function() {
3917
3992
  "+": function(a) {
3918
3993
  return Number(a);
3919
3994
  },
3920
- "!": function(a) {
3995
+ "!": makePromiseAwareUnaryOp(function(a) {
3921
3996
  return !a;
3997
+ })
3998
+ };
3999
+ var PromiseCollectionHandler = {
4000
+ /**
4001
+ * Handle array with potential Promise elements
4002
+ */ handleArray: function handleArray(items, async) {
4003
+ if (!async) {
4004
+ return items;
4005
+ }
4006
+ var hasPromises = items.some(function(item) {
4007
+ return isAwaitable(item);
4008
+ });
4009
+ return hasPromises ? collateAwaitable(items) : items;
4010
+ },
4011
+ /**
4012
+ * Handle object with potential Promise keys/values
4013
+ */ handleObject: function handleObject(attributes, resolveNode, async) {
4014
+ var resolvedAttributes = {};
4015
+ var promises = [];
4016
+ var hasPromises = false;
4017
+ attributes.forEach(function(attr) {
4018
+ var key = resolveNode(attr.key);
4019
+ var value = resolveNode(attr.value);
4020
+ if (async && (isAwaitable(key) || isAwaitable(value))) {
4021
+ hasPromises = true;
4022
+ var keyPromise = Promise.resolve(key);
4023
+ var valuePromise = Promise.resolve(value);
4024
+ promises.push(collateAwaitable([
4025
+ keyPromise,
4026
+ valuePromise
4027
+ ]).awaitableThen(function(param) {
4028
+ var _param = _sliced_to_array(param, 2), resolvedKey = _param[0], resolvedValue = _param[1];
4029
+ resolvedAttributes[resolvedKey] = resolvedValue;
4030
+ }));
4031
+ } else {
4032
+ resolvedAttributes[key] = value;
4033
+ }
4034
+ });
4035
+ return hasPromises ? collateAwaitable(promises).awaitableThen(function() {
4036
+ return resolvedAttributes;
4037
+ }) : resolvedAttributes;
4038
+ }
4039
+ };
4040
+ var LogicalOperators = {
4041
+ and: function(ctx, leftNode, rightNode, async) {
4042
+ var leftResult = ctx.evaluate(leftNode);
4043
+ if (async && isAwaitable(leftResult)) {
4044
+ return leftResult.awaitableThen(function(awaitedLeft) {
4045
+ if (!awaitedLeft) return awaitedLeft;
4046
+ var rightResult = ctx.evaluate(rightNode);
4047
+ return isAwaitable(rightResult) ? rightResult : Promise.resolve(rightResult);
4048
+ });
4049
+ }
4050
+ return leftResult && ctx.evaluate(rightNode);
4051
+ },
4052
+ or: function(ctx, leftNode, rightNode, async) {
4053
+ var leftResult = ctx.evaluate(leftNode);
4054
+ if (async && isAwaitable(leftResult)) {
4055
+ return leftResult.awaitableThen(function(awaitedLeft) {
4056
+ if (awaitedLeft) return awaitedLeft;
4057
+ var rightResult = ctx.evaluate(rightNode);
4058
+ return isAwaitable(rightResult) ? rightResult : Promise.resolve(rightResult);
4059
+ });
4060
+ }
4061
+ return leftResult || ctx.evaluate(rightNode);
3922
4062
  }
3923
4063
  };
3924
4064
  var ExpressionEvaluator = /*#__PURE__*/ function() {
@@ -3939,7 +4079,12 @@ var ReferenceAssetsPlugin = function() {
3939
4079
  this.operators = {
3940
4080
  binary: new Map(Object.entries(DEFAULT_BINARY_OPERATORS)),
3941
4081
  unary: new Map(Object.entries(DEFAULT_UNARY_OPERATORS)),
3942
- expressions: new Map(Object.entries(evaluator_functions_exports))
4082
+ expressions: new Map(_to_consumable_array(Object.entries(evaluator_functions_exports)).concat([
4083
+ [
4084
+ "await",
4085
+ waitFor
4086
+ ]
4087
+ ]))
3943
4088
  };
3944
4089
  this.defaultHookOptions = _object_spread_props(_object_spread({}, defaultOptions), {
3945
4090
  evaluate: function(expr) {
@@ -3949,7 +4094,9 @@ var ReferenceAssetsPlugin = function() {
3949
4094
  return _this._execAST(node, _this.defaultHookOptions);
3950
4095
  }
3951
4096
  });
3952
- this.hooks.resolve.tap("ExpressionEvaluator", this._resolveNode.bind(this));
4097
+ this.hooks.resolve.tap("ExpressionEvaluator", function(result, node, options) {
4098
+ return _this._resolveNode(result, node, options);
4099
+ });
3953
4100
  this.evaluate = this.evaluate.bind(this);
3954
4101
  }
3955
4102
  _create_class(ExpressionEvaluator, [
@@ -3987,6 +4134,38 @@ var ReferenceAssetsPlugin = function() {
3987
4134
  return this._execString(String(expression), resolvedOpts);
3988
4135
  }
3989
4136
  },
4137
+ {
4138
+ /**
4139
+ * Evaluate functions in an async context
4140
+ * @experimental These Player APIs are in active development and may change. Use with caution
4141
+ */ key: "evaluateAsync",
4142
+ value: function evaluateAsync(expr, options) {
4143
+ if (Array.isArray(expr)) {
4144
+ var _this = this;
4145
+ return collateAwaitable(expr.map(function() {
4146
+ var _ref = _async_to_generator(function(exp) {
4147
+ return _ts_generator(this, function(_state) {
4148
+ return [
4149
+ 2,
4150
+ _this.evaluate(exp, _object_spread_props(_object_spread({}, options), {
4151
+ async: true
4152
+ }))
4153
+ ];
4154
+ });
4155
+ });
4156
+ return function(exp) {
4157
+ return _ref.apply(this, arguments);
4158
+ };
4159
+ }())).awaitableThen(function(values) {
4160
+ return values.pop();
4161
+ });
4162
+ } else {
4163
+ return this.evaluate(expr, _object_spread_props(_object_spread({}, options), {
4164
+ async: true
4165
+ }));
4166
+ }
4167
+ }
4168
+ },
3990
4169
  {
3991
4170
  key: "addExpressionFunction",
3992
4171
  value: function addExpressionFunction(name, handler) {
@@ -4032,8 +4211,10 @@ var ReferenceAssetsPlugin = function() {
4032
4211
  var matches = exp.match(/^@\[(.*)\]@$/);
4033
4212
  var matchedExp = exp;
4034
4213
  if (matches) {
4035
- var ref;
4036
- ref = _sliced_to_array(Array.from(matches), 2), matchedExp = ref[1], ref;
4214
+ var _Array_from = _sliced_to_array(Array.from(matches), 2), matched = _Array_from[1];
4215
+ if (matched) {
4216
+ matchedExp = matched;
4217
+ }
4037
4218
  }
4038
4219
  var storedAST;
4039
4220
  try {
@@ -4062,6 +4243,8 @@ var ReferenceAssetsPlugin = function() {
4062
4243
  value: function _resolveNode(_currentValue, node, options) {
4063
4244
  var _this = this;
4064
4245
  var resolveNode = options.resolveNode, model = options.model;
4246
+ var _options_async;
4247
+ var isAsync = (_options_async = options.async) !== null && _options_async !== void 0 ? _options_async : false;
4065
4248
  var expressionContext = _object_spread_props(_object_spread({}, options), {
4066
4249
  evaluate: function(expr) {
4067
4250
  return _this.evaluate(expr, options);
@@ -4081,11 +4264,33 @@ var ReferenceAssetsPlugin = function() {
4081
4264
  if (operator) {
4082
4265
  if ("resolveParams" in operator) {
4083
4266
  if (operator.resolveParams === false) {
4084
- return operator(expressionContext, node.left, node.right);
4267
+ return operator(expressionContext, node.left, node.right, isAsync);
4268
+ }
4269
+ var left2 = resolveNode(node.left);
4270
+ var right2 = resolveNode(node.right);
4271
+ if (options.async && (isAwaitable(left2) || isAwaitable(right2))) {
4272
+ return collateAwaitable([
4273
+ left2,
4274
+ right2
4275
+ ]).awaitableThen(function(param) {
4276
+ var _param = _sliced_to_array(param, 2), leftVal = _param[0], rightVal = _param[1];
4277
+ return operator(expressionContext, leftVal, rightVal, isAsync);
4278
+ });
4085
4279
  }
4086
- return operator(expressionContext, resolveNode(node.left), resolveNode(node.right));
4280
+ return operator(expressionContext, left2, right2, isAsync);
4087
4281
  }
4088
- return operator(resolveNode(node.left), resolveNode(node.right));
4282
+ var left = resolveNode(node.left);
4283
+ var right = resolveNode(node.right);
4284
+ if (options.async && (isAwaitable(left) || isAwaitable(right))) {
4285
+ return collateAwaitable([
4286
+ left,
4287
+ right
4288
+ ]).awaitableThen(function(param) {
4289
+ var _param = _sliced_to_array(param, 2), leftVal = _param[0], rightVal = _param[1];
4290
+ return operator(leftVal, rightVal, isAsync);
4291
+ });
4292
+ }
4293
+ return operator(left, right, isAsync);
4089
4294
  }
4090
4295
  return;
4091
4296
  }
@@ -4093,21 +4298,29 @@ var ReferenceAssetsPlugin = function() {
4093
4298
  var operator1 = this.operators.unary.get(node.operator);
4094
4299
  if (operator1) {
4095
4300
  if ("resolveParams" in operator1) {
4096
- return operator1(expressionContext, operator1.resolveParams === false ? node.argument : resolveNode(node.argument));
4301
+ if (operator1.resolveParams === false) {
4302
+ return operator1(expressionContext, node.argument, isAsync);
4303
+ }
4304
+ var arg2 = resolveNode(node.argument);
4305
+ if (options.async && isAwaitable(arg2)) {
4306
+ return arg2.awaitableThen(function(argVal) {
4307
+ return operator1(expressionContext, argVal, isAsync);
4308
+ });
4309
+ }
4310
+ return operator1(expressionContext, arg2, isAsync);
4311
+ }
4312
+ var arg = resolveNode(node.argument);
4313
+ if (options.async && isAwaitable(arg)) {
4314
+ return arg.awaitableThen(function(argVal) {
4315
+ return operator1(argVal, isAsync);
4316
+ });
4097
4317
  }
4098
- return operator1(resolveNode(node.argument));
4318
+ return operator1(arg, isAsync);
4099
4319
  }
4100
4320
  return;
4101
4321
  }
4102
4322
  if (node.type === "Object") {
4103
- var attributes = node.attributes;
4104
- var resolvedAttributes = {};
4105
- attributes.forEach(function(attr) {
4106
- var key = resolveNode(attr.key);
4107
- var value = resolveNode(attr.value);
4108
- resolvedAttributes[key] = value;
4109
- });
4110
- return resolvedAttributes;
4323
+ return PromiseCollectionHandler.handleObject(node.attributes, resolveNode, options.async || false);
4111
4324
  }
4112
4325
  if (node.type === "CallExpression") {
4113
4326
  var expressionName = node.callTarget.name;
@@ -4115,6 +4328,9 @@ var ReferenceAssetsPlugin = function() {
4115
4328
  if (!operator2) {
4116
4329
  throw new Error("Unknown expression function: ".concat(expressionName));
4117
4330
  }
4331
+ if (operator2.name === waitFor.name && !options.async) {
4332
+ throw new Error("Usage of await outside of async context");
4333
+ }
4118
4334
  if ("resolveParams" in operator2 && operator2.resolveParams === false) {
4119
4335
  return operator2.apply(void 0, [
4120
4336
  expressionContext
@@ -4123,6 +4339,16 @@ var ReferenceAssetsPlugin = function() {
4123
4339
  var args = node.args.map(function(n) {
4124
4340
  return resolveNode(n);
4125
4341
  });
4342
+ if (options.async) {
4343
+ var hasPromises = args.some(isAwaitable);
4344
+ if (hasPromises) {
4345
+ return collateAwaitable(args).awaitableThen(function(resolvedArgs) {
4346
+ return operator2.apply(void 0, [
4347
+ expressionContext
4348
+ ].concat(_to_consumable_array(resolvedArgs)));
4349
+ });
4350
+ }
4351
+ }
4126
4352
  return operator2.apply(void 0, [
4127
4353
  expressionContext
4128
4354
  ].concat(_to_consumable_array(args)));
@@ -4137,11 +4363,36 @@ var ReferenceAssetsPlugin = function() {
4137
4363
  if (node.type === "MemberExpression") {
4138
4364
  var obj = resolveNode(node.object);
4139
4365
  var prop = resolveNode(node.property);
4366
+ if (options.async && (isAwaitable(obj) || isAwaitable(prop))) {
4367
+ return collateAwaitable([
4368
+ obj,
4369
+ prop
4370
+ ]).awaitableThen(function(param) {
4371
+ var _param = _sliced_to_array(param, 2), objVal = _param[0], propVal = _param[1];
4372
+ return objVal[propVal];
4373
+ });
4374
+ }
4140
4375
  return obj[prop];
4141
4376
  }
4142
4377
  if (node.type === "Assignment") {
4143
4378
  if (node.left.type === "ModelRef") {
4144
4379
  var value = resolveNode(node.right);
4380
+ if (isPromiseLike(value)) {
4381
+ if (options.async && isAwaitable(value)) {
4382
+ return value.awaitableThen(function(resolvedValue) {
4383
+ model.set([
4384
+ [
4385
+ node.left.ref,
4386
+ resolvedValue
4387
+ ]
4388
+ ]);
4389
+ return resolvedValue;
4390
+ });
4391
+ } else {
4392
+ var _options_logger;
4393
+ (_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");
4394
+ }
4395
+ }
4145
4396
  model.set([
4146
4397
  [
4147
4398
  node.left.ref,
@@ -4152,19 +4403,30 @@ var ReferenceAssetsPlugin = function() {
4152
4403
  }
4153
4404
  if (node.left.type === "Identifier") {
4154
4405
  var value1 = resolveNode(node.right);
4406
+ if (options.async && isAwaitable(value1)) {
4407
+ return value1.awaitableThen(function(resolvedValue) {
4408
+ _this.vars[node.left.name] = resolvedValue;
4409
+ return resolvedValue;
4410
+ });
4411
+ }
4155
4412
  this.vars[node.left.name] = value1;
4156
4413
  return value1;
4157
4414
  }
4158
4415
  return;
4159
4416
  }
4160
4417
  if (node.type === "ConditionalExpression") {
4161
- var result = resolveNode(node.test) ? node.consequent : node.alternate;
4162
- return resolveNode(result);
4418
+ var testResult = resolveNode(node.test);
4419
+ return handleConditionalBranching(testResult, function() {
4420
+ return node.consequent;
4421
+ }, function() {
4422
+ return node.alternate;
4423
+ }, resolveNode, isAsync);
4163
4424
  }
4164
4425
  if (node.type === "ArrayExpression") {
4165
- return node.elements.map(function(ele) {
4426
+ var results = node.elements.map(function(ele) {
4166
4427
  return resolveNode(ele);
4167
4428
  });
4429
+ return PromiseCollectionHandler.handleArray(results, isAsync);
4168
4430
  }
4169
4431
  if (node.type === "Modification") {
4170
4432
  var operation = this.operators.binary.get(node.operator);
@@ -4172,14 +4434,49 @@ var ReferenceAssetsPlugin = function() {
4172
4434
  var newValue;
4173
4435
  if ("resolveParams" in operation) {
4174
4436
  if (operation.resolveParams === false) {
4175
- newValue = operation(expressionContext, node.left, node.right);
4437
+ newValue = operation(expressionContext, node.left, node.right, isAsync);
4176
4438
  } else {
4177
- newValue = operation(expressionContext, resolveNode(node.left), resolveNode(node.right));
4439
+ var left1 = resolveNode(node.left);
4440
+ var right1 = resolveNode(node.right);
4441
+ if (options.async && (isAwaitable(left1) || isAwaitable(right1))) {
4442
+ newValue = collateAwaitable([
4443
+ left1,
4444
+ right1
4445
+ ]).awaitableThen(function(param) {
4446
+ var _param = _sliced_to_array(param, 2), leftVal = _param[0], rightVal = _param[1];
4447
+ return operation(expressionContext, leftVal, rightVal, isAsync);
4448
+ });
4449
+ } else {
4450
+ newValue = operation(expressionContext, left1, right1, isAsync);
4451
+ }
4178
4452
  }
4179
4453
  } else {
4180
- newValue = operation(resolveNode(node.left), resolveNode(node.right));
4454
+ var left3 = resolveNode(node.left);
4455
+ var right3 = resolveNode(node.right);
4456
+ if (options.async && (isAwaitable(left3) || isAwaitable(right3))) {
4457
+ newValue = collateAwaitable([
4458
+ left3,
4459
+ right3
4460
+ ]).awaitableThen(function(param) {
4461
+ var _param = _sliced_to_array(param, 2), leftVal = _param[0], rightVal = _param[1];
4462
+ return operation(leftVal, rightVal, isAsync);
4463
+ });
4464
+ } else {
4465
+ newValue = operation(left3, right3, isAsync);
4466
+ }
4181
4467
  }
4182
4468
  if (node.left.type === "ModelRef") {
4469
+ if (options.async && isAwaitable(newValue)) {
4470
+ return newValue.awaitableThen(function(resolvedValue) {
4471
+ model.set([
4472
+ [
4473
+ node.left.ref,
4474
+ resolvedValue
4475
+ ]
4476
+ ]);
4477
+ return resolvedValue;
4478
+ });
4479
+ }
4183
4480
  model.set([
4184
4481
  [
4185
4482
  node.left.ref,
@@ -4187,6 +4484,12 @@ var ReferenceAssetsPlugin = function() {
4187
4484
  ]
4188
4485
  ]);
4189
4486
  } else if (node.left.type === "Identifier") {
4487
+ if (options.async && isAwaitable(newValue)) {
4488
+ return newValue.awaitableThen(function(resolvedValue) {
4489
+ _this.vars[node.left.name] = resolvedValue;
4490
+ return resolvedValue;
4491
+ });
4492
+ }
4190
4493
  this.vars[node.left.name] = newValue;
4191
4494
  }
4192
4495
  return newValue;
@@ -5052,20 +5355,15 @@ var ReferenceAssetsPlugin = function() {
5052
5355
  }();
5053
5356
  var ViewInstance = /*#__PURE__*/ function() {
5054
5357
  function ViewInstance(initialView, resolverOptions) {
5055
- var _this = this;
5056
5358
  _class_call_check(this, ViewInstance);
5057
5359
  this.hooks = {
5058
5360
  onUpdate: new SyncHook(),
5059
5361
  parser: new SyncHook(),
5060
5362
  resolver: new SyncHook(),
5061
- onTemplatePluginCreated: new SyncHook(),
5062
5363
  templatePlugin: new SyncHook()
5063
5364
  };
5064
5365
  this.initialView = initialView;
5065
5366
  this.resolverOptions = resolverOptions;
5066
- this.hooks.onTemplatePluginCreated.tap("view", function(templatePlugin) {
5067
- _this.templatePlugin = templatePlugin;
5068
- });
5069
5367
  }
5070
5368
  _create_class(ViewInstance, [
5071
5369
  {
@@ -5112,6 +5410,12 @@ var ReferenceAssetsPlugin = function() {
5112
5410
  var _this_validationProvider;
5113
5411
  return (_this_validationProvider = this.validationProvider) === null || _this_validationProvider === void 0 ? void 0 : _this_validationProvider.getValidationsForBinding(binding);
5114
5412
  }
5413
+ },
5414
+ {
5415
+ key: "setTemplatePlugin",
5416
+ value: function setTemplatePlugin(plugin) {
5417
+ this.templatePlugin = plugin;
5418
+ }
5115
5419
  }
5116
5420
  ]);
5117
5421
  return ViewInstance;
@@ -5410,6 +5714,7 @@ var ReferenceAssetsPlugin = function() {
5410
5714
  value: function apply(view) {
5411
5715
  view.hooks.parser.tap("template", this.applyParser.bind(this));
5412
5716
  view.hooks.resolver.tap("template", this.applyResolverHooks.bind(this));
5717
+ view.setTemplatePlugin(this);
5413
5718
  }
5414
5719
  }
5415
5720
  ]);
@@ -7018,8 +7323,7 @@ var ReferenceAssetsPlugin = function() {
7018
7323
  var _this1 = this;
7019
7324
  _class_call_check(this, ViewController);
7020
7325
  this.hooks = {
7021
- /** Do any processing before the `View` instance is created */ resolveView: new SyncWaterfallHook(),
7022
- // The hook right before the View starts resolving. Attach anything custom here
7326
+ resolveView: new SyncWaterfallHook(),
7023
7327
  view: new SyncHook()
7024
7328
  };
7025
7329
  this.transformRegistry = new Registry();
@@ -7067,6 +7371,7 @@ var ReferenceAssetsPlugin = function() {
7067
7371
  ]));
7068
7372
  }
7069
7373
  });
7374
+ this.viewPlugins = this.createViewPlugins();
7070
7375
  }
7071
7376
  _create_class(ViewController, [
7072
7377
  {
@@ -7122,9 +7427,50 @@ var ReferenceAssetsPlugin = function() {
7122
7427
  }
7123
7428
  var view = new ViewInstance(source, this.viewOptions);
7124
7429
  this.currentView = view;
7430
+ this.applyViewPlugins(view);
7125
7431
  this.hooks.view.call(view);
7126
7432
  view.update();
7127
7433
  }
7434
+ },
7435
+ {
7436
+ key: "applyViewPlugins",
7437
+ value: function applyViewPlugins(view) {
7438
+ var _iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = undefined;
7439
+ try {
7440
+ for(var _iterator = this.viewPlugins[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true){
7441
+ var plugin = _step.value;
7442
+ plugin.apply(view);
7443
+ }
7444
+ } catch (err) {
7445
+ _didIteratorError = true;
7446
+ _iteratorError = err;
7447
+ } finally{
7448
+ try {
7449
+ if (!_iteratorNormalCompletion && _iterator.return != null) {
7450
+ _iterator.return();
7451
+ }
7452
+ } finally{
7453
+ if (_didIteratorError) {
7454
+ throw _iteratorError;
7455
+ }
7456
+ }
7457
+ }
7458
+ }
7459
+ },
7460
+ {
7461
+ key: "createViewPlugins",
7462
+ value: function createViewPlugins() {
7463
+ var pluginOptions = toNodeResolveOptions(this.viewOptions);
7464
+ return [
7465
+ new AssetPlugin(),
7466
+ new SwitchPlugin(pluginOptions),
7467
+ new ApplicabilityPlugin(),
7468
+ new AssetTransformCorePlugin(this.transformRegistry),
7469
+ new StringResolverPlugin(),
7470
+ new TemplatePlugin(pluginOptions),
7471
+ new MultiNodePlugin()
7472
+ ];
7473
+ }
7128
7474
  }
7129
7475
  ]);
7130
7476
  return ViewController;
@@ -7497,35 +7843,6 @@ var ReferenceAssetsPlugin = function() {
7497
7843
  ref: Symbol("not-started"),
7498
7844
  status: "not-started"
7499
7845
  };
7500
- var DefaultViewPlugin = /*#__PURE__*/ function() {
7501
- function DefaultViewPlugin() {
7502
- _class_call_check(this, DefaultViewPlugin);
7503
- this.name = "default-view-plugin";
7504
- }
7505
- _create_class(DefaultViewPlugin, [
7506
- {
7507
- key: "apply",
7508
- value: function apply(player) {
7509
- var _this = this;
7510
- player.hooks.viewController.tap(this.name, function(viewController) {
7511
- viewController.hooks.view.tap(_this.name, function(view) {
7512
- var pluginOptions = toNodeResolveOptions(view.resolverOptions);
7513
- new AssetPlugin().apply(view);
7514
- new SwitchPlugin(pluginOptions).apply(view);
7515
- new ApplicabilityPlugin().apply(view);
7516
- new AssetTransformCorePlugin(viewController.transformRegistry).apply(view);
7517
- new StringResolverPlugin().apply(view);
7518
- var templatePlugin = new TemplatePlugin(pluginOptions);
7519
- templatePlugin.apply(view);
7520
- view.hooks.onTemplatePluginCreated.call(templatePlugin);
7521
- new MultiNodePlugin().apply(view);
7522
- });
7523
- });
7524
- }
7525
- }
7526
- ]);
7527
- return DefaultViewPlugin;
7528
- }();
7529
7846
  var PLAYER_VERSION = "__VERSION__";
7530
7847
  var COMMIT = "__GIT_COMMIT__";
7531
7848
  var _Player = /*#__PURE__*/ function() {
@@ -7537,26 +7854,25 @@ var ReferenceAssetsPlugin = function() {
7537
7854
  this.constantsController = new ConstantsController();
7538
7855
  this.state = NOT_STARTED_STATE;
7539
7856
  this.hooks = {
7540
- /** The hook that fires every time we create a new flowController (a new Content blob is passed in) */ flowController: new SyncHook(),
7541
- /** The hook that updates/handles views */ viewController: new SyncHook(),
7542
- /** A hook called every-time there's a new view. This is equivalent to the view hook on the view-controller */ view: new SyncHook(),
7543
- /** Called when an expression evaluator was created */ expressionEvaluator: new SyncHook(),
7544
- /** The hook that creates and manages data */ dataController: new SyncHook(),
7545
- /** Called after the schema is created for a flow */ schema: new SyncHook(),
7546
- /** Manages validations (schema and x-field ) */ validationController: new SyncHook(),
7547
- /** Manages parsing binding */ bindingParser: new SyncHook(),
7548
- /** A that's called for state changes in the flow execution */ state: new SyncHook(),
7549
- /** A hook to access the current flow */ onStart: new SyncHook(),
7550
- /** A hook for when the flow ends either in success or failure */ onEnd: new SyncHook(),
7551
- /** Mutate the Content flow before starting */ resolveFlowContent: new SyncWaterfallHook()
7857
+ flowController: new SyncHook(),
7858
+ viewController: new SyncHook(),
7859
+ view: new SyncHook(),
7860
+ expressionEvaluator: new SyncHook(),
7861
+ dataController: new SyncHook(),
7862
+ schema: new SyncHook(),
7863
+ validationController: new SyncHook(),
7864
+ bindingParser: new SyncHook(),
7865
+ state: new SyncHook(),
7866
+ onStart: new SyncHook(),
7867
+ onEnd: new SyncHook(),
7868
+ resolveFlowContent: new SyncWaterfallHook()
7552
7869
  };
7553
7870
  if (config === null || config === void 0 ? void 0 : config.logger) {
7554
7871
  this.logger.addHandler(config.logger);
7555
7872
  }
7556
7873
  this.config = config || {};
7557
7874
  this.config.plugins = [
7558
- new DefaultExpPlugin(),
7559
- new DefaultViewPlugin()
7875
+ new DefaultExpPlugin()
7560
7876
  ].concat(_to_consumable_array(this.config.plugins || []), [
7561
7877
  new FlowExpPlugin()
7562
7878
  ]);
@@ -7748,10 +8064,90 @@ var ReferenceAssetsPlugin = function() {
7748
8064
  var value = (_flowInstance_currentState = flowInstance.currentState) === null || _flowInstance_currentState === void 0 ? void 0 : _flowInstance_currentState.value;
7749
8065
  if (value && value.state_type === "ACTION") {
7750
8066
  var exp = value.exp;
7751
- flowController === null || flowController === void 0 ? void 0 : flowController.transition(String(expressionEvaluator === null || expressionEvaluator === void 0 ? void 0 : expressionEvaluator.evaluate(exp)));
8067
+ var result = expressionEvaluator.evaluate(exp);
8068
+ if (isPromiseLike(result)) {
8069
+ _this.logger.warn("Async expression used as return value in in non-async context, transitioning with '*' value");
8070
+ }
8071
+ flowController === null || flowController === void 0 ? void 0 : flowController.transition(String(result));
7752
8072
  }
7753
8073
  expressionEvaluator.reset();
7754
8074
  });
8075
+ var _this1 = _this;
8076
+ flow.hooks.afterTransition.tap("player", function() {
8077
+ var _ref = _async_to_generator(function(flowInstance) {
8078
+ var _flowInstance_currentState, value, exp, result, e;
8079
+ return _ts_generator(this, function(_state) {
8080
+ switch(_state.label){
8081
+ case 0:
8082
+ value = (_flowInstance_currentState = flowInstance.currentState) === null || _flowInstance_currentState === void 0 ? void 0 : _flowInstance_currentState.value;
8083
+ if (!(value && value.state_type === "ASYNC_ACTION")) return [
8084
+ 3,
8085
+ 8
8086
+ ];
8087
+ exp = value.exp;
8088
+ _state.label = 1;
8089
+ case 1:
8090
+ _state.trys.push([
8091
+ 1,
8092
+ 7,
8093
+ ,
8094
+ 8
8095
+ ]);
8096
+ result = expressionEvaluator.evaluateAsync(exp);
8097
+ if (!isPromiseLike(result)) return [
8098
+ 3,
8099
+ 5
8100
+ ];
8101
+ if (!value.await) return [
8102
+ 3,
8103
+ 3
8104
+ ];
8105
+ return [
8106
+ 4,
8107
+ result
8108
+ ];
8109
+ case 2:
8110
+ result = _state.sent();
8111
+ return [
8112
+ 3,
8113
+ 4
8114
+ ];
8115
+ case 3:
8116
+ _this1.logger.warn("Unawaited promise used as return value in in non-async context, transitioning with '*' value");
8117
+ _state.label = 4;
8118
+ case 4:
8119
+ return [
8120
+ 3,
8121
+ 6
8122
+ ];
8123
+ case 5:
8124
+ _this1.logger.warn("Non async expression used in async action node");
8125
+ _state.label = 6;
8126
+ case 6:
8127
+ flowController === null || flowController === void 0 ? void 0 : flowController.transition(String(result));
8128
+ return [
8129
+ 3,
8130
+ 8
8131
+ ];
8132
+ case 7:
8133
+ e = _state.sent();
8134
+ flowResultDeferred.reject(e);
8135
+ return [
8136
+ 3,
8137
+ 8
8138
+ ];
8139
+ case 8:
8140
+ expressionEvaluator.reset();
8141
+ return [
8142
+ 2
8143
+ ];
8144
+ }
8145
+ });
8146
+ });
8147
+ return function(flowInstance) {
8148
+ return _ref.apply(this, arguments);
8149
+ };
8150
+ }());
7755
8151
  });
7756
8152
  this.hooks.dataController.call(dataController);
7757
8153
  validationController.setOptions({
@@ -7789,11 +8185,9 @@ var ReferenceAssetsPlugin = function() {
7789
8185
  }),
7790
8186
  constants: this.constantsController
7791
8187
  });
7792
- this.hooks.viewController.tap("player", function(vc) {
7793
- vc.hooks.view.tap("player", function(view) {
7794
- validationController.onView(view);
7795
- _this.hooks.view.call(view);
7796
- });
8188
+ viewController.hooks.view.tap("player", function(view) {
8189
+ validationController.onView(view);
8190
+ _this.hooks.view.call(view);
7797
8191
  });
7798
8192
  this.hooks.viewController.call(viewController);
7799
8193
  return {