@player-ui/async-node-plugin 0.11.3--canary.649.23416 → 0.11.3--canary.662.23488

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.
@@ -1190,48 +1190,6 @@ var AsyncNodePlugin = function() {
1190
1190
  }
1191
1191
  return typeof expr === "object" && expr !== null && !Array.isArray(expr) && "value" in expr;
1192
1192
  };
1193
- var isPromiselike = function isPromiselike(value) {
1194
- var // Check for standard Promise constructor name
1195
- _value_constructor;
1196
- return value != null && typeof value === "object" && typeof value.then === "function" && // Additional safeguards against false positives
1197
- (_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
1198
- typeof value.catch === "function" && typeof value.finally === "function");
1199
- };
1200
- var makePromiseAwareBinaryOp = function makePromiseAwareBinaryOp(operation) {
1201
- return function(a, b) {
1202
- if (isPromiselike(a) || isPromiselike(b)) {
1203
- return Promise.all([
1204
- Promise.resolve(a),
1205
- Promise.resolve(b)
1206
- ]).then(function(param) {
1207
- var _param = _sliced_to_array(param, 2), resolvedA = _param[0], resolvedB = _param[1];
1208
- return operation(resolvedA, resolvedB);
1209
- });
1210
- }
1211
- return operation(a, b);
1212
- };
1213
- };
1214
- var makePromiseAwareUnaryOp = function makePromiseAwareUnaryOp(operation) {
1215
- return function(a) {
1216
- if (isPromiselike(a)) {
1217
- return a.then(function(resolved) {
1218
- return operation(resolved);
1219
- });
1220
- }
1221
- return operation(a);
1222
- };
1223
- };
1224
- var handleConditionalBranching = function handleConditionalBranching(testValue, getTrueBranch, getFalseBranch, resolveNode) {
1225
- if (isPromiselike(testValue)) {
1226
- return testValue.then(function(resolved) {
1227
- var branch2 = resolved ? getTrueBranch() : getFalseBranch();
1228
- var branchResult = resolveNode(branch2);
1229
- return isPromiselike(branchResult) ? branchResult : Promise.resolve(branchResult);
1230
- });
1231
- }
1232
- var branch = testValue ? getTrueBranch() : getFalseBranch();
1233
- return resolveNode(branch);
1234
- };
1235
1193
  var parse2 = function parse2(schema) {
1236
1194
  var _loop = function() {
1237
1195
  var next = parseQueue.shift();
@@ -3621,9 +3579,6 @@ var AsyncNodePlugin = function() {
3621
3579
  },
3622
3580
  setDataVal: function() {
3623
3581
  return setDataVal;
3624
- },
3625
- waitFor: function() {
3626
- return waitFor;
3627
3582
  }
3628
3583
  });
3629
3584
  var setDataVal = function(_context, binding, value) {
@@ -3641,19 +3596,8 @@ var AsyncNodePlugin = function() {
3641
3596
  return _context.model.delete(binding);
3642
3597
  };
3643
3598
  var conditional = function(ctx, condition, ifTrue, ifFalse) {
3644
- var testResult = ctx.evaluate(condition);
3645
- if (_instanceof(testResult, Promise)) {
3646
- return testResult.then(function(resolvedTest) {
3647
- if (resolvedTest) {
3648
- return ctx.evaluate(ifTrue);
3649
- }
3650
- if (ifFalse) {
3651
- return ctx.evaluate(ifFalse);
3652
- }
3653
- return null;
3654
- });
3655
- }
3656
- if (testResult) {
3599
+ var resolution = ctx.evaluate(condition);
3600
+ if (resolution) {
3657
3601
  return ctx.evaluate(ifTrue);
3658
3602
  }
3659
3603
  if (ifFalse) {
@@ -3662,33 +3606,12 @@ var AsyncNodePlugin = function() {
3662
3606
  return null;
3663
3607
  };
3664
3608
  conditional.resolveParams = false;
3665
- var waitFor = function() {
3666
- var _ref = _async_to_generator(function(ctx, promise) {
3667
- return _ts_generator(this, function(_state) {
3668
- switch(_state.label){
3669
- case 0:
3670
- return [
3671
- 4,
3672
- promise
3673
- ];
3674
- case 1:
3675
- return [
3676
- 2,
3677
- _state.sent()
3678
- ];
3679
- }
3680
- });
3681
- });
3682
- return function waitFor(ctx, promise) {
3683
- return _ref.apply(this, arguments);
3684
- };
3685
- }();
3686
3609
  var andandOperator = function(ctx, a, b) {
3687
- return LogicalOperators.and(ctx, a, b);
3610
+ return ctx.evaluate(a) && ctx.evaluate(b);
3688
3611
  };
3689
3612
  andandOperator.resolveParams = false;
3690
3613
  var ororOperator = function(ctx, a, b) {
3691
- return LogicalOperators.or(ctx, a, b);
3614
+ return ctx.evaluate(a) || ctx.evaluate(b);
3692
3615
  };
3693
3616
  ororOperator.resolveParams = false;
3694
3617
  var DEFAULT_BINARY_OPERATORS = {
@@ -3708,35 +3631,34 @@ var AsyncNodePlugin = function() {
3708
3631
  "%": function(a, b) {
3709
3632
  return a % b;
3710
3633
  },
3711
- // Promise-aware comparison operators
3712
3634
  // eslint-disable-next-line
3713
- "==": makePromiseAwareBinaryOp(function(a, b) {
3635
+ "==": function(a, b) {
3714
3636
  return a == b;
3715
- }),
3637
+ },
3716
3638
  // eslint-disable-next-line
3717
- "!=": makePromiseAwareBinaryOp(function(a, b) {
3639
+ "!=": function(a, b) {
3718
3640
  return a != b;
3719
- }),
3720
- ">": makePromiseAwareBinaryOp(function(a, b) {
3641
+ },
3642
+ ">": function(a, b) {
3721
3643
  return a > b;
3722
- }),
3723
- ">=": makePromiseAwareBinaryOp(function(a, b) {
3644
+ },
3645
+ ">=": function(a, b) {
3724
3646
  return a >= b;
3725
- }),
3726
- "<": makePromiseAwareBinaryOp(function(a, b) {
3647
+ },
3648
+ "<": function(a, b) {
3727
3649
  return a < b;
3728
- }),
3729
- "<=": makePromiseAwareBinaryOp(function(a, b) {
3650
+ },
3651
+ "<=": function(a, b) {
3730
3652
  return a <= b;
3731
- }),
3732
- "!==": makePromiseAwareBinaryOp(function(a, b) {
3733
- return a !== b;
3734
- }),
3735
- "===": makePromiseAwareBinaryOp(function(a, b) {
3736
- return a === b;
3737
- }),
3653
+ },
3738
3654
  "&&": andandOperator,
3739
3655
  "||": ororOperator,
3656
+ "!==": function(a, b) {
3657
+ return a !== b;
3658
+ },
3659
+ "===": function(a, b) {
3660
+ return a === b;
3661
+ },
3740
3662
  // eslint-disable-next-line
3741
3663
  "|": function(a, b) {
3742
3664
  return a | b;
@@ -3767,70 +3689,8 @@ var AsyncNodePlugin = function() {
3767
3689
  "+": function(a) {
3768
3690
  return Number(a);
3769
3691
  },
3770
- "!": makePromiseAwareUnaryOp(function(a) {
3692
+ "!": function(a) {
3771
3693
  return !a;
3772
- })
3773
- };
3774
- var PromiseCollectionHandler = {
3775
- /**
3776
- * Handle array with potential Promise elements
3777
- */ handleArray: function handleArray(items) {
3778
- var hasPromises = items.some(function(item) {
3779
- return isPromiselike(item);
3780
- });
3781
- return hasPromises ? Promise.all(items) : items;
3782
- },
3783
- /**
3784
- * Handle object with potential Promise keys/values
3785
- */ handleObject: function handleObject(attributes, resolveNode) {
3786
- var resolvedAttributes = {};
3787
- var promises = [];
3788
- var hasPromises = false;
3789
- attributes.forEach(function(attr) {
3790
- var key = resolveNode(attr.key);
3791
- var value = resolveNode(attr.value);
3792
- if (isPromiselike(key) || isPromiselike(value)) {
3793
- hasPromises = true;
3794
- var keyPromise = Promise.resolve(key);
3795
- var valuePromise = Promise.resolve(value);
3796
- promises.push(Promise.all([
3797
- keyPromise,
3798
- valuePromise
3799
- ]).then(function(param) {
3800
- var _param = _sliced_to_array(param, 2), resolvedKey = _param[0], resolvedValue = _param[1];
3801
- resolvedAttributes[resolvedKey] = resolvedValue;
3802
- }));
3803
- } else {
3804
- resolvedAttributes[key] = value;
3805
- }
3806
- });
3807
- return hasPromises ? Promise.all(promises).then(function() {
3808
- return resolvedAttributes;
3809
- }) : resolvedAttributes;
3810
- }
3811
- };
3812
- var LogicalOperators = {
3813
- and: function(ctx, leftNode, rightNode) {
3814
- var leftResult = ctx.evaluate(leftNode);
3815
- if (isPromiselike(leftResult)) {
3816
- return leftResult.then(function(awaitedLeft) {
3817
- if (!awaitedLeft) return awaitedLeft;
3818
- var rightResult = ctx.evaluate(rightNode);
3819
- return isPromiselike(rightResult) ? rightResult : Promise.resolve(rightResult);
3820
- });
3821
- }
3822
- return leftResult && ctx.evaluate(rightNode);
3823
- },
3824
- or: function(ctx, leftNode, rightNode) {
3825
- var leftResult = ctx.evaluate(leftNode);
3826
- if (isPromiselike(leftResult)) {
3827
- return leftResult.then(function(awaitedLeft) {
3828
- if (awaitedLeft) return awaitedLeft;
3829
- var rightResult = ctx.evaluate(rightNode);
3830
- return isPromiselike(rightResult) ? rightResult : Promise.resolve(rightResult);
3831
- });
3832
- }
3833
- return leftResult || ctx.evaluate(rightNode);
3834
3694
  }
3835
3695
  };
3836
3696
  var ExpressionEvaluator = /*#__PURE__*/ function() {
@@ -3851,12 +3711,7 @@ var AsyncNodePlugin = function() {
3851
3711
  this.operators = {
3852
3712
  binary: new Map(Object.entries(DEFAULT_BINARY_OPERATORS)),
3853
3713
  unary: new Map(Object.entries(DEFAULT_UNARY_OPERATORS)),
3854
- expressions: new Map(_to_consumable_array(Object.entries(evaluator_functions_exports)).concat([
3855
- [
3856
- "await",
3857
- waitFor
3858
- ]
3859
- ]))
3714
+ expressions: new Map(Object.entries(evaluator_functions_exports))
3860
3715
  };
3861
3716
  this.defaultHookOptions = _object_spread_props(_object_spread({}, defaultOptions), {
3862
3717
  evaluate: function(expr) {
@@ -3866,9 +3721,7 @@ var AsyncNodePlugin = function() {
3866
3721
  return _this._execAST(node, _this.defaultHookOptions);
3867
3722
  }
3868
3723
  });
3869
- this.hooks.resolve.tap("ExpressionEvaluator", function(result, node, options) {
3870
- return _this._resolveNode(result, node, options);
3871
- });
3724
+ this.hooks.resolve.tap("ExpressionEvaluator", this._resolveNode.bind(this));
3872
3725
  this.evaluate = this.evaluate.bind(this);
3873
3726
  }
3874
3727
  _create_class(ExpressionEvaluator, [
@@ -3906,14 +3759,6 @@ var AsyncNodePlugin = function() {
3906
3759
  return this._execString(String(expression), resolvedOpts);
3907
3760
  }
3908
3761
  },
3909
- {
3910
- key: "evaluateAsync",
3911
- value: function evaluateAsync(expr, options) {
3912
- return this.evaluate(expr, _object_spread_props(_object_spread({}, options), {
3913
- async: true
3914
- }));
3915
- }
3916
- },
3917
3762
  {
3918
3763
  key: "addExpressionFunction",
3919
3764
  value: function addExpressionFunction(name, handler) {
@@ -3959,10 +3804,8 @@ var AsyncNodePlugin = function() {
3959
3804
  var matches = exp.match(/^@\[(.*)\]@$/);
3960
3805
  var matchedExp = exp;
3961
3806
  if (matches) {
3962
- var _Array_from = _sliced_to_array(Array.from(matches), 2), matched = _Array_from[1];
3963
- if (matched) {
3964
- matchedExp = matched;
3965
- }
3807
+ var ref;
3808
+ ref = _sliced_to_array(Array.from(matches), 2), matchedExp = ref[1], ref;
3966
3809
  }
3967
3810
  var storedAST;
3968
3811
  try {
@@ -4012,31 +3855,9 @@ var AsyncNodePlugin = function() {
4012
3855
  if (operator.resolveParams === false) {
4013
3856
  return operator(expressionContext, node.left, node.right);
4014
3857
  }
4015
- var left2 = resolveNode(node.left);
4016
- var right2 = resolveNode(node.right);
4017
- if (isPromiselike(left2) || isPromiselike(right2)) {
4018
- return Promise.all([
4019
- left2,
4020
- right2
4021
- ]).then(function(param) {
4022
- var _param = _sliced_to_array(param, 2), leftVal = _param[0], rightVal = _param[1];
4023
- return operator(expressionContext, leftVal, rightVal);
4024
- });
4025
- }
4026
- return operator(expressionContext, left2, right2);
4027
- }
4028
- var left = resolveNode(node.left);
4029
- var right = resolveNode(node.right);
4030
- if (isPromiselike(left) || isPromiselike(right)) {
4031
- return Promise.all([
4032
- left,
4033
- right
4034
- ]).then(function(param) {
4035
- var _param = _sliced_to_array(param, 2), leftVal = _param[0], rightVal = _param[1];
4036
- return operator(leftVal, rightVal);
4037
- });
3858
+ return operator(expressionContext, resolveNode(node.left), resolveNode(node.right));
4038
3859
  }
4039
- return operator(left, right);
3860
+ return operator(resolveNode(node.left), resolveNode(node.right));
4040
3861
  }
4041
3862
  return;
4042
3863
  }
@@ -4044,29 +3865,21 @@ var AsyncNodePlugin = function() {
4044
3865
  var operator1 = this.operators.unary.get(node.operator);
4045
3866
  if (operator1) {
4046
3867
  if ("resolveParams" in operator1) {
4047
- if (operator1.resolveParams === false) {
4048
- return operator1(expressionContext, node.argument);
4049
- }
4050
- var arg2 = resolveNode(node.argument);
4051
- if (isPromiselike(arg2)) {
4052
- return arg2.then(function(argVal) {
4053
- return operator1(expressionContext, argVal);
4054
- });
4055
- }
4056
- return operator1(expressionContext, arg2);
3868
+ return operator1(expressionContext, operator1.resolveParams === false ? node.argument : resolveNode(node.argument));
4057
3869
  }
4058
- var arg = resolveNode(node.argument);
4059
- if (isPromiselike(arg)) {
4060
- return arg.then(function(argVal) {
4061
- return operator1(argVal);
4062
- });
4063
- }
4064
- return operator1(arg);
3870
+ return operator1(resolveNode(node.argument));
4065
3871
  }
4066
3872
  return;
4067
3873
  }
4068
3874
  if (node.type === "Object") {
4069
- return PromiseCollectionHandler.handleObject(node.attributes, resolveNode);
3875
+ var attributes = node.attributes;
3876
+ var resolvedAttributes = {};
3877
+ attributes.forEach(function(attr) {
3878
+ var key = resolveNode(attr.key);
3879
+ var value = resolveNode(attr.value);
3880
+ resolvedAttributes[key] = value;
3881
+ });
3882
+ return resolvedAttributes;
4070
3883
  }
4071
3884
  if (node.type === "CallExpression") {
4072
3885
  var expressionName = node.callTarget.name;
@@ -4082,14 +3895,6 @@ var AsyncNodePlugin = function() {
4082
3895
  var args = node.args.map(function(n) {
4083
3896
  return resolveNode(n);
4084
3897
  });
4085
- var hasPromises = args.some(isPromiselike);
4086
- if (hasPromises) {
4087
- return Promise.all(args).then(function(resolvedArgs) {
4088
- return operator2.apply(void 0, [
4089
- expressionContext
4090
- ].concat(_to_consumable_array(resolvedArgs)));
4091
- });
4092
- }
4093
3898
  return operator2.apply(void 0, [
4094
3899
  expressionContext
4095
3900
  ].concat(_to_consumable_array(args)));
@@ -4104,31 +3909,11 @@ var AsyncNodePlugin = function() {
4104
3909
  if (node.type === "MemberExpression") {
4105
3910
  var obj = resolveNode(node.object);
4106
3911
  var prop = resolveNode(node.property);
4107
- if (isPromiselike(obj) || isPromiselike(prop)) {
4108
- return Promise.all([
4109
- obj,
4110
- prop
4111
- ]).then(function(param) {
4112
- var _param = _sliced_to_array(param, 2), objVal = _param[0], propVal = _param[1];
4113
- return objVal[propVal];
4114
- });
4115
- }
4116
3912
  return obj[prop];
4117
3913
  }
4118
3914
  if (node.type === "Assignment") {
4119
3915
  if (node.left.type === "ModelRef") {
4120
3916
  var value = resolveNode(node.right);
4121
- if (isPromiselike(value)) {
4122
- return value.then(function(resolvedValue) {
4123
- model.set([
4124
- [
4125
- node.left.ref,
4126
- resolvedValue
4127
- ]
4128
- ]);
4129
- return resolvedValue;
4130
- });
4131
- }
4132
3917
  model.set([
4133
3918
  [
4134
3919
  node.left.ref,
@@ -4139,30 +3924,19 @@ var AsyncNodePlugin = function() {
4139
3924
  }
4140
3925
  if (node.left.type === "Identifier") {
4141
3926
  var value1 = resolveNode(node.right);
4142
- if (isPromiselike(value1)) {
4143
- return value1.then(function(resolvedValue) {
4144
- _this.vars[node.left.name] = resolvedValue;
4145
- return resolvedValue;
4146
- });
4147
- }
4148
3927
  this.vars[node.left.name] = value1;
4149
3928
  return value1;
4150
3929
  }
4151
3930
  return;
4152
3931
  }
4153
3932
  if (node.type === "ConditionalExpression") {
4154
- var testResult = resolveNode(node.test);
4155
- return handleConditionalBranching(testResult, function() {
4156
- return node.consequent;
4157
- }, function() {
4158
- return node.alternate;
4159
- }, resolveNode);
3933
+ var result = resolveNode(node.test) ? node.consequent : node.alternate;
3934
+ return resolveNode(result);
4160
3935
  }
4161
3936
  if (node.type === "ArrayExpression") {
4162
- var results = node.elements.map(function(ele) {
3937
+ return node.elements.map(function(ele) {
4163
3938
  return resolveNode(ele);
4164
3939
  });
4165
- return PromiseCollectionHandler.handleArray(results);
4166
3940
  }
4167
3941
  if (node.type === "Modification") {
4168
3942
  var operation = this.operators.binary.get(node.operator);
@@ -4172,47 +3946,12 @@ var AsyncNodePlugin = function() {
4172
3946
  if (operation.resolveParams === false) {
4173
3947
  newValue = operation(expressionContext, node.left, node.right);
4174
3948
  } else {
4175
- var left1 = resolveNode(node.left);
4176
- var right1 = resolveNode(node.right);
4177
- if (isPromiselike(left1) || isPromiselike(right1)) {
4178
- newValue = Promise.all([
4179
- left1,
4180
- right1
4181
- ]).then(function(param) {
4182
- var _param = _sliced_to_array(param, 2), leftVal = _param[0], rightVal = _param[1];
4183
- return operation(expressionContext, leftVal, rightVal);
4184
- });
4185
- } else {
4186
- newValue = operation(expressionContext, left1, right1);
4187
- }
3949
+ newValue = operation(expressionContext, resolveNode(node.left), resolveNode(node.right));
4188
3950
  }
4189
3951
  } else {
4190
- var left3 = resolveNode(node.left);
4191
- var right3 = resolveNode(node.right);
4192
- if (isPromiselike(left3) || isPromiselike(right3)) {
4193
- newValue = Promise.all([
4194
- left3,
4195
- right3
4196
- ]).then(function(param) {
4197
- var _param = _sliced_to_array(param, 2), leftVal = _param[0], rightVal = _param[1];
4198
- return operation(leftVal, rightVal);
4199
- });
4200
- } else {
4201
- newValue = operation(left3, right3);
4202
- }
3952
+ newValue = operation(resolveNode(node.left), resolveNode(node.right));
4203
3953
  }
4204
3954
  if (node.left.type === "ModelRef") {
4205
- if (isPromiselike(newValue)) {
4206
- return newValue.then(function(resolvedValue) {
4207
- model.set([
4208
- [
4209
- node.left.ref,
4210
- resolvedValue
4211
- ]
4212
- ]);
4213
- return resolvedValue;
4214
- });
4215
- }
4216
3955
  model.set([
4217
3956
  [
4218
3957
  node.left.ref,
@@ -4220,12 +3959,6 @@ var AsyncNodePlugin = function() {
4220
3959
  ]
4221
3960
  ]);
4222
3961
  } else if (node.left.type === "Identifier") {
4223
- if (isPromiselike(newValue)) {
4224
- return newValue.then(function(resolvedValue) {
4225
- _this.vars[node.left.name] = resolvedValue;
4226
- return resolvedValue;
4227
- });
4228
- }
4229
3962
  this.vars[node.left.name] = newValue;
4230
3963
  }
4231
3964
  return newValue;
@@ -7797,56 +7530,15 @@ var AsyncNodePlugin = function() {
7797
7530
  validationController.reset();
7798
7531
  }
7799
7532
  });
7800
- flow.hooks.afterTransition.tap("player", function() {
7801
- var _ref = _async_to_generator(function(flowInstance) {
7802
- var _flowInstance_currentState, value, exp, result, e;
7803
- return _ts_generator(this, function(_state) {
7804
- switch(_state.label){
7805
- case 0:
7806
- value = (_flowInstance_currentState = flowInstance.currentState) === null || _flowInstance_currentState === void 0 ? void 0 : _flowInstance_currentState.value;
7807
- if (!(value && value.state_type === "ACTION")) return [
7808
- 3,
7809
- 4
7810
- ];
7811
- exp = value.exp;
7812
- _state.label = 1;
7813
- case 1:
7814
- _state.trys.push([
7815
- 1,
7816
- 3,
7817
- ,
7818
- 4
7819
- ]);
7820
- return [
7821
- 4,
7822
- expressionEvaluator.evaluateAsync(exp)
7823
- ];
7824
- case 2:
7825
- result = _state.sent();
7826
- flowController === null || flowController === void 0 ? void 0 : flowController.transition(String(result));
7827
- return [
7828
- 3,
7829
- 4
7830
- ];
7831
- case 3:
7832
- e = _state.sent();
7833
- flowResultDeferred.reject(e);
7834
- return [
7835
- 3,
7836
- 4
7837
- ];
7838
- case 4:
7839
- expressionEvaluator.reset();
7840
- return [
7841
- 2
7842
- ];
7843
- }
7844
- });
7845
- });
7846
- return function(flowInstance) {
7847
- return _ref.apply(this, arguments);
7848
- };
7849
- }());
7533
+ flow.hooks.afterTransition.tap("player", function(flowInstance) {
7534
+ var _flowInstance_currentState;
7535
+ var value = (_flowInstance_currentState = flowInstance.currentState) === null || _flowInstance_currentState === void 0 ? void 0 : _flowInstance_currentState.value;
7536
+ if (value && value.state_type === "ACTION") {
7537
+ var exp = value.exp;
7538
+ flowController === null || flowController === void 0 ? void 0 : flowController.transition(String(expressionEvaluator === null || expressionEvaluator === void 0 ? void 0 : expressionEvaluator.evaluate(exp)));
7539
+ }
7540
+ expressionEvaluator.reset();
7541
+ });
7850
7542
  });
7851
7543
  this.hooks.dataController.call(dataController);
7852
7544
  validationController.setOptions({