@player-ui/common-expressions-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.
- package/dist/CommonExpressionsPlugin.native.js +444 -61
- package/dist/CommonExpressionsPlugin.native.js.map +1 -1
- package/dist/xlr/ceil.json +1 -1
- package/dist/xlr/concat.json +1 -1
- package/dist/xlr/containsAny.json +1 -1
- package/dist/xlr/findProperty.json +1 -1
- package/dist/xlr/findPropertyIndex.json +1 -1
- package/dist/xlr/floor.json +1 -1
- package/dist/xlr/isEmpty.json +1 -1
- package/dist/xlr/isNotEmpty.json +1 -1
- package/dist/xlr/length.json +1 -1
- package/dist/xlr/lowerCase.json +1 -1
- package/dist/xlr/number.json +1 -1
- package/dist/xlr/replace.json +1 -1
- package/dist/xlr/round.json +1 -1
- package/dist/xlr/sentenceCase.json +1 -1
- package/dist/xlr/size.json +1 -1
- package/dist/xlr/split.json +1 -1
- package/dist/xlr/substr.json +1 -1
- package/dist/xlr/sum.json +1 -1
- package/dist/xlr/titleCase.json +1 -1
- package/dist/xlr/trim.json +1 -1
- package/dist/xlr/upperCase.json +1 -1
- package/package.json +3 -3
|
@@ -1184,6 +1184,20 @@ var CommonExpressionsPlugin = 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 withoutContext = function withoutContext(fn) {
|
|
1188
1202
|
return function(_context) {
|
|
1189
1203
|
for(var _len = arguments.length, args = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++){
|
|
@@ -1198,6 +1212,41 @@ var CommonExpressionsPlugin = function() {
|
|
|
1198
1212
|
}
|
|
1199
1213
|
return typeof expr === "object" && expr !== null && !Array.isArray(expr) && "value" in expr;
|
|
1200
1214
|
};
|
|
1215
|
+
var makePromiseAwareBinaryOp = function makePromiseAwareBinaryOp(operation) {
|
|
1216
|
+
return function(a, b, async) {
|
|
1217
|
+
if (async && (isAwaitable(a) || isAwaitable(b))) {
|
|
1218
|
+
return collateAwaitable([
|
|
1219
|
+
Promise.resolve(a),
|
|
1220
|
+
Promise.resolve(b)
|
|
1221
|
+
]).awaitableThen(function(param) {
|
|
1222
|
+
var _param = _sliced_to_array(param, 2), resolvedA = _param[0], resolvedB = _param[1];
|
|
1223
|
+
return operation(resolvedA, resolvedB);
|
|
1224
|
+
});
|
|
1225
|
+
}
|
|
1226
|
+
return operation(a, b);
|
|
1227
|
+
};
|
|
1228
|
+
};
|
|
1229
|
+
var makePromiseAwareUnaryOp = function makePromiseAwareUnaryOp(operation) {
|
|
1230
|
+
return function(a, async) {
|
|
1231
|
+
if (async && isAwaitable(a)) {
|
|
1232
|
+
return a.awaitableThen(function(resolved) {
|
|
1233
|
+
return operation(resolved);
|
|
1234
|
+
});
|
|
1235
|
+
}
|
|
1236
|
+
return operation(a);
|
|
1237
|
+
};
|
|
1238
|
+
};
|
|
1239
|
+
var handleConditionalBranching = function handleConditionalBranching(testValue, getTrueBranch, getFalseBranch, resolveNode, async) {
|
|
1240
|
+
if (async && isAwaitable(testValue)) {
|
|
1241
|
+
return testValue.awaitableThen(function(resolved) {
|
|
1242
|
+
var branch2 = resolved ? getTrueBranch() : getFalseBranch();
|
|
1243
|
+
var branchResult = resolveNode(branch2);
|
|
1244
|
+
return isAwaitable(branchResult) ? Promise.resolve(branchResult) : branchResult;
|
|
1245
|
+
});
|
|
1246
|
+
}
|
|
1247
|
+
var branch = testValue ? getTrueBranch() : getFalseBranch();
|
|
1248
|
+
return resolveNode(branch);
|
|
1249
|
+
};
|
|
1201
1250
|
var parse2 = function parse2(schema) {
|
|
1202
1251
|
var _loop = function() {
|
|
1203
1252
|
var next = parseQueue.shift();
|
|
@@ -3635,8 +3684,19 @@ var CommonExpressionsPlugin = function() {
|
|
|
3635
3684
|
},
|
|
3636
3685
|
setDataVal: function() {
|
|
3637
3686
|
return setDataVal;
|
|
3687
|
+
},
|
|
3688
|
+
waitFor: function() {
|
|
3689
|
+
return waitFor;
|
|
3638
3690
|
}
|
|
3639
3691
|
});
|
|
3692
|
+
var AwaitableSymbol = Symbol("Awaitable");
|
|
3693
|
+
function makeAwaitable(promise) {
|
|
3694
|
+
promise[AwaitableSymbol] = AwaitableSymbol;
|
|
3695
|
+
promise.awaitableThen = function(arg) {
|
|
3696
|
+
return makeAwaitable(promise.then(arg));
|
|
3697
|
+
};
|
|
3698
|
+
return promise;
|
|
3699
|
+
}
|
|
3640
3700
|
var setDataVal = function(_context, binding, value) {
|
|
3641
3701
|
_context.model.set([
|
|
3642
3702
|
[
|
|
@@ -3652,8 +3712,19 @@ var CommonExpressionsPlugin = function() {
|
|
|
3652
3712
|
return _context.model.delete(binding);
|
|
3653
3713
|
};
|
|
3654
3714
|
var conditional = function(ctx, condition, ifTrue, ifFalse) {
|
|
3655
|
-
var
|
|
3656
|
-
if (
|
|
3715
|
+
var testResult = ctx.evaluate(condition);
|
|
3716
|
+
if (isAwaitable(testResult)) {
|
|
3717
|
+
return testResult.awaitableThen(function(resolvedTest) {
|
|
3718
|
+
if (resolvedTest) {
|
|
3719
|
+
return ctx.evaluate(ifTrue);
|
|
3720
|
+
}
|
|
3721
|
+
if (ifFalse) {
|
|
3722
|
+
return ctx.evaluate(ifFalse);
|
|
3723
|
+
}
|
|
3724
|
+
return null;
|
|
3725
|
+
});
|
|
3726
|
+
}
|
|
3727
|
+
if (testResult) {
|
|
3657
3728
|
return ctx.evaluate(ifTrue);
|
|
3658
3729
|
}
|
|
3659
3730
|
if (ifFalse) {
|
|
@@ -3662,12 +3733,15 @@ var CommonExpressionsPlugin = function() {
|
|
|
3662
3733
|
return null;
|
|
3663
3734
|
};
|
|
3664
3735
|
conditional.resolveParams = false;
|
|
3665
|
-
var
|
|
3666
|
-
return
|
|
3736
|
+
var waitFor = function(ctx, promise) {
|
|
3737
|
+
return makeAwaitable(promise);
|
|
3738
|
+
};
|
|
3739
|
+
var andandOperator = function(ctx, a, b, async) {
|
|
3740
|
+
return LogicalOperators.and(ctx, a, b, async);
|
|
3667
3741
|
};
|
|
3668
3742
|
andandOperator.resolveParams = false;
|
|
3669
|
-
var ororOperator = function(ctx, a, b) {
|
|
3670
|
-
return
|
|
3743
|
+
var ororOperator = function(ctx, a, b, async) {
|
|
3744
|
+
return LogicalOperators.or(ctx, a, b, async);
|
|
3671
3745
|
};
|
|
3672
3746
|
ororOperator.resolveParams = false;
|
|
3673
3747
|
var DEFAULT_BINARY_OPERATORS = {
|
|
@@ -3687,34 +3761,35 @@ var CommonExpressionsPlugin = function() {
|
|
|
3687
3761
|
"%": function(a, b) {
|
|
3688
3762
|
return a % b;
|
|
3689
3763
|
},
|
|
3764
|
+
// Promise-aware comparison operators
|
|
3690
3765
|
// eslint-disable-next-line
|
|
3691
|
-
"==": function(a, b) {
|
|
3766
|
+
"==": makePromiseAwareBinaryOp(function(a, b) {
|
|
3692
3767
|
return a == b;
|
|
3693
|
-
},
|
|
3768
|
+
}),
|
|
3694
3769
|
// eslint-disable-next-line
|
|
3695
|
-
"!=": function(a, b) {
|
|
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
|
-
">=": function(a, b) {
|
|
3775
|
+
}),
|
|
3776
|
+
">=": makePromiseAwareBinaryOp(function(a, b) {
|
|
3702
3777
|
return a >= b;
|
|
3703
|
-
},
|
|
3704
|
-
"<": function(a, b) {
|
|
3778
|
+
}),
|
|
3779
|
+
"<": makePromiseAwareBinaryOp(function(a, b) {
|
|
3705
3780
|
return a < b;
|
|
3706
|
-
},
|
|
3707
|
-
"<=": function(a, b) {
|
|
3781
|
+
}),
|
|
3782
|
+
"<=": makePromiseAwareBinaryOp(function(a, b) {
|
|
3708
3783
|
return a <= b;
|
|
3709
|
-
},
|
|
3710
|
-
"
|
|
3711
|
-
"||": ororOperator,
|
|
3712
|
-
"!==": function(a, b) {
|
|
3784
|
+
}),
|
|
3785
|
+
"!==": makePromiseAwareBinaryOp(function(a, b) {
|
|
3713
3786
|
return a !== b;
|
|
3714
|
-
},
|
|
3715
|
-
"===": function(a, b) {
|
|
3787
|
+
}),
|
|
3788
|
+
"===": makePromiseAwareBinaryOp(function(a, b) {
|
|
3716
3789
|
return a === b;
|
|
3717
|
-
},
|
|
3790
|
+
}),
|
|
3791
|
+
"&&": andandOperator,
|
|
3792
|
+
"||": ororOperator,
|
|
3718
3793
|
// eslint-disable-next-line
|
|
3719
3794
|
"|": function(a, b) {
|
|
3720
3795
|
return a | b;
|
|
@@ -3745,8 +3820,73 @@ var CommonExpressionsPlugin = function() {
|
|
|
3745
3820
|
"+": function(a) {
|
|
3746
3821
|
return Number(a);
|
|
3747
3822
|
},
|
|
3748
|
-
"!": function(a) {
|
|
3823
|
+
"!": makePromiseAwareUnaryOp(function(a) {
|
|
3749
3824
|
return !a;
|
|
3825
|
+
})
|
|
3826
|
+
};
|
|
3827
|
+
var PromiseCollectionHandler = {
|
|
3828
|
+
/**
|
|
3829
|
+
* Handle array with potential Promise elements
|
|
3830
|
+
*/ handleArray: function handleArray(items, async) {
|
|
3831
|
+
if (!async) {
|
|
3832
|
+
return items;
|
|
3833
|
+
}
|
|
3834
|
+
var hasPromises = items.some(function(item) {
|
|
3835
|
+
return isAwaitable(item);
|
|
3836
|
+
});
|
|
3837
|
+
return hasPromises ? collateAwaitable(items) : items;
|
|
3838
|
+
},
|
|
3839
|
+
/**
|
|
3840
|
+
* Handle object with potential Promise keys/values
|
|
3841
|
+
*/ handleObject: function handleObject(attributes, resolveNode, async) {
|
|
3842
|
+
var resolvedAttributes = {};
|
|
3843
|
+
var promises = [];
|
|
3844
|
+
var hasPromises = false;
|
|
3845
|
+
attributes.forEach(function(attr) {
|
|
3846
|
+
var key = resolveNode(attr.key);
|
|
3847
|
+
var value = resolveNode(attr.value);
|
|
3848
|
+
if (async && (isAwaitable(key) || isAwaitable(value))) {
|
|
3849
|
+
hasPromises = true;
|
|
3850
|
+
var keyPromise = Promise.resolve(key);
|
|
3851
|
+
var valuePromise = Promise.resolve(value);
|
|
3852
|
+
promises.push(collateAwaitable([
|
|
3853
|
+
keyPromise,
|
|
3854
|
+
valuePromise
|
|
3855
|
+
]).awaitableThen(function(param) {
|
|
3856
|
+
var _param = _sliced_to_array(param, 2), resolvedKey = _param[0], resolvedValue = _param[1];
|
|
3857
|
+
resolvedAttributes[resolvedKey] = resolvedValue;
|
|
3858
|
+
}));
|
|
3859
|
+
} else {
|
|
3860
|
+
resolvedAttributes[key] = value;
|
|
3861
|
+
}
|
|
3862
|
+
});
|
|
3863
|
+
return hasPromises ? collateAwaitable(promises).awaitableThen(function() {
|
|
3864
|
+
return resolvedAttributes;
|
|
3865
|
+
}) : resolvedAttributes;
|
|
3866
|
+
}
|
|
3867
|
+
};
|
|
3868
|
+
var LogicalOperators = {
|
|
3869
|
+
and: function(ctx, leftNode, rightNode, async) {
|
|
3870
|
+
var leftResult = ctx.evaluate(leftNode);
|
|
3871
|
+
if (async && isAwaitable(leftResult)) {
|
|
3872
|
+
return leftResult.awaitableThen(function(awaitedLeft) {
|
|
3873
|
+
if (!awaitedLeft) return awaitedLeft;
|
|
3874
|
+
var rightResult = ctx.evaluate(rightNode);
|
|
3875
|
+
return isAwaitable(rightResult) ? rightResult : Promise.resolve(rightResult);
|
|
3876
|
+
});
|
|
3877
|
+
}
|
|
3878
|
+
return leftResult && ctx.evaluate(rightNode);
|
|
3879
|
+
},
|
|
3880
|
+
or: function(ctx, leftNode, rightNode, async) {
|
|
3881
|
+
var leftResult = ctx.evaluate(leftNode);
|
|
3882
|
+
if (async && isAwaitable(leftResult)) {
|
|
3883
|
+
return leftResult.awaitableThen(function(awaitedLeft) {
|
|
3884
|
+
if (awaitedLeft) return awaitedLeft;
|
|
3885
|
+
var rightResult = ctx.evaluate(rightNode);
|
|
3886
|
+
return isAwaitable(rightResult) ? rightResult : Promise.resolve(rightResult);
|
|
3887
|
+
});
|
|
3888
|
+
}
|
|
3889
|
+
return leftResult || ctx.evaluate(rightNode);
|
|
3750
3890
|
}
|
|
3751
3891
|
};
|
|
3752
3892
|
var ExpressionEvaluator = /*#__PURE__*/ function() {
|
|
@@ -3767,7 +3907,12 @@ var CommonExpressionsPlugin = function() {
|
|
|
3767
3907
|
this.operators = {
|
|
3768
3908
|
binary: new Map(Object.entries(DEFAULT_BINARY_OPERATORS)),
|
|
3769
3909
|
unary: new Map(Object.entries(DEFAULT_UNARY_OPERATORS)),
|
|
3770
|
-
expressions: new Map(Object.entries(evaluator_functions_exports))
|
|
3910
|
+
expressions: new Map(_to_consumable_array(Object.entries(evaluator_functions_exports)).concat([
|
|
3911
|
+
[
|
|
3912
|
+
"await",
|
|
3913
|
+
waitFor
|
|
3914
|
+
]
|
|
3915
|
+
]))
|
|
3771
3916
|
};
|
|
3772
3917
|
this.defaultHookOptions = _object_spread_props(_object_spread({}, defaultOptions), {
|
|
3773
3918
|
evaluate: function(expr) {
|
|
@@ -3777,7 +3922,9 @@ var CommonExpressionsPlugin = function() {
|
|
|
3777
3922
|
return _this._execAST(node, _this.defaultHookOptions);
|
|
3778
3923
|
}
|
|
3779
3924
|
});
|
|
3780
|
-
this.hooks.resolve.tap("ExpressionEvaluator",
|
|
3925
|
+
this.hooks.resolve.tap("ExpressionEvaluator", function(result, node, options) {
|
|
3926
|
+
return _this._resolveNode(result, node, options);
|
|
3927
|
+
});
|
|
3781
3928
|
this.evaluate = this.evaluate.bind(this);
|
|
3782
3929
|
}
|
|
3783
3930
|
_create_class(ExpressionEvaluator, [
|
|
@@ -3815,6 +3962,38 @@ var CommonExpressionsPlugin = function() {
|
|
|
3815
3962
|
return this._execString(String(expression), resolvedOpts);
|
|
3816
3963
|
}
|
|
3817
3964
|
},
|
|
3965
|
+
{
|
|
3966
|
+
/**
|
|
3967
|
+
* Evaluate functions in an async context
|
|
3968
|
+
* @experimental These Player APIs are in active development and may change. Use with caution
|
|
3969
|
+
*/ key: "evaluateAsync",
|
|
3970
|
+
value: function evaluateAsync(expr, options) {
|
|
3971
|
+
if (Array.isArray(expr)) {
|
|
3972
|
+
var _this = this;
|
|
3973
|
+
return collateAwaitable(expr.map(function() {
|
|
3974
|
+
var _ref = _async_to_generator(function(exp) {
|
|
3975
|
+
return _ts_generator(this, function(_state) {
|
|
3976
|
+
return [
|
|
3977
|
+
2,
|
|
3978
|
+
_this.evaluate(exp, _object_spread_props(_object_spread({}, options), {
|
|
3979
|
+
async: true
|
|
3980
|
+
}))
|
|
3981
|
+
];
|
|
3982
|
+
});
|
|
3983
|
+
});
|
|
3984
|
+
return function(exp) {
|
|
3985
|
+
return _ref.apply(this, arguments);
|
|
3986
|
+
};
|
|
3987
|
+
}())).awaitableThen(function(values) {
|
|
3988
|
+
return values.pop();
|
|
3989
|
+
});
|
|
3990
|
+
} else {
|
|
3991
|
+
return this.evaluate(expr, _object_spread_props(_object_spread({}, options), {
|
|
3992
|
+
async: true
|
|
3993
|
+
}));
|
|
3994
|
+
}
|
|
3995
|
+
}
|
|
3996
|
+
},
|
|
3818
3997
|
{
|
|
3819
3998
|
key: "addExpressionFunction",
|
|
3820
3999
|
value: function addExpressionFunction(name, handler) {
|
|
@@ -3860,8 +4039,10 @@ var CommonExpressionsPlugin = function() {
|
|
|
3860
4039
|
var matches = exp.match(/^@\[(.*)\]@$/);
|
|
3861
4040
|
var matchedExp = exp;
|
|
3862
4041
|
if (matches) {
|
|
3863
|
-
var
|
|
3864
|
-
|
|
4042
|
+
var _Array_from = _sliced_to_array(Array.from(matches), 2), matched = _Array_from[1];
|
|
4043
|
+
if (matched) {
|
|
4044
|
+
matchedExp = matched;
|
|
4045
|
+
}
|
|
3865
4046
|
}
|
|
3866
4047
|
var storedAST;
|
|
3867
4048
|
try {
|
|
@@ -3890,6 +4071,8 @@ var CommonExpressionsPlugin = function() {
|
|
|
3890
4071
|
value: function _resolveNode(_currentValue, node, options) {
|
|
3891
4072
|
var _this = this;
|
|
3892
4073
|
var resolveNode = options.resolveNode, model = options.model;
|
|
4074
|
+
var _options_async;
|
|
4075
|
+
var isAsync = (_options_async = options.async) !== null && _options_async !== void 0 ? _options_async : false;
|
|
3893
4076
|
var expressionContext = _object_spread_props(_object_spread({}, options), {
|
|
3894
4077
|
evaluate: function(expr) {
|
|
3895
4078
|
return _this.evaluate(expr, options);
|
|
@@ -3909,11 +4092,33 @@ var CommonExpressionsPlugin = function() {
|
|
|
3909
4092
|
if (operator) {
|
|
3910
4093
|
if ("resolveParams" in operator) {
|
|
3911
4094
|
if (operator.resolveParams === false) {
|
|
3912
|
-
return operator(expressionContext, node.left, node.right);
|
|
4095
|
+
return operator(expressionContext, node.left, node.right, isAsync);
|
|
4096
|
+
}
|
|
4097
|
+
var left2 = resolveNode(node.left);
|
|
4098
|
+
var right2 = resolveNode(node.right);
|
|
4099
|
+
if (options.async && (isAwaitable(left2) || isAwaitable(right2))) {
|
|
4100
|
+
return collateAwaitable([
|
|
4101
|
+
left2,
|
|
4102
|
+
right2
|
|
4103
|
+
]).awaitableThen(function(param) {
|
|
4104
|
+
var _param = _sliced_to_array(param, 2), leftVal = _param[0], rightVal = _param[1];
|
|
4105
|
+
return operator(expressionContext, leftVal, rightVal, isAsync);
|
|
4106
|
+
});
|
|
3913
4107
|
}
|
|
3914
|
-
return operator(expressionContext,
|
|
4108
|
+
return operator(expressionContext, left2, right2, isAsync);
|
|
3915
4109
|
}
|
|
3916
|
-
|
|
4110
|
+
var left = resolveNode(node.left);
|
|
4111
|
+
var right = resolveNode(node.right);
|
|
4112
|
+
if (options.async && (isAwaitable(left) || isAwaitable(right))) {
|
|
4113
|
+
return collateAwaitable([
|
|
4114
|
+
left,
|
|
4115
|
+
right
|
|
4116
|
+
]).awaitableThen(function(param) {
|
|
4117
|
+
var _param = _sliced_to_array(param, 2), leftVal = _param[0], rightVal = _param[1];
|
|
4118
|
+
return operator(leftVal, rightVal, isAsync);
|
|
4119
|
+
});
|
|
4120
|
+
}
|
|
4121
|
+
return operator(left, right, isAsync);
|
|
3917
4122
|
}
|
|
3918
4123
|
return;
|
|
3919
4124
|
}
|
|
@@ -3921,21 +4126,29 @@ var CommonExpressionsPlugin = function() {
|
|
|
3921
4126
|
var operator1 = this.operators.unary.get(node.operator);
|
|
3922
4127
|
if (operator1) {
|
|
3923
4128
|
if ("resolveParams" in operator1) {
|
|
3924
|
-
|
|
4129
|
+
if (operator1.resolveParams === false) {
|
|
4130
|
+
return operator1(expressionContext, node.argument, isAsync);
|
|
4131
|
+
}
|
|
4132
|
+
var arg2 = resolveNode(node.argument);
|
|
4133
|
+
if (options.async && isAwaitable(arg2)) {
|
|
4134
|
+
return arg2.awaitableThen(function(argVal) {
|
|
4135
|
+
return operator1(expressionContext, argVal, isAsync);
|
|
4136
|
+
});
|
|
4137
|
+
}
|
|
4138
|
+
return operator1(expressionContext, arg2, isAsync);
|
|
4139
|
+
}
|
|
4140
|
+
var arg = resolveNode(node.argument);
|
|
4141
|
+
if (options.async && isAwaitable(arg)) {
|
|
4142
|
+
return arg.awaitableThen(function(argVal) {
|
|
4143
|
+
return operator1(argVal, isAsync);
|
|
4144
|
+
});
|
|
3925
4145
|
}
|
|
3926
|
-
return operator1(
|
|
4146
|
+
return operator1(arg, isAsync);
|
|
3927
4147
|
}
|
|
3928
4148
|
return;
|
|
3929
4149
|
}
|
|
3930
4150
|
if (node.type === "Object") {
|
|
3931
|
-
|
|
3932
|
-
var resolvedAttributes = {};
|
|
3933
|
-
attributes.forEach(function(attr) {
|
|
3934
|
-
var key = resolveNode(attr.key);
|
|
3935
|
-
var value = resolveNode(attr.value);
|
|
3936
|
-
resolvedAttributes[key] = value;
|
|
3937
|
-
});
|
|
3938
|
-
return resolvedAttributes;
|
|
4151
|
+
return PromiseCollectionHandler.handleObject(node.attributes, resolveNode, options.async || false);
|
|
3939
4152
|
}
|
|
3940
4153
|
if (node.type === "CallExpression") {
|
|
3941
4154
|
var expressionName = node.callTarget.name;
|
|
@@ -3943,6 +4156,9 @@ var CommonExpressionsPlugin = function() {
|
|
|
3943
4156
|
if (!operator2) {
|
|
3944
4157
|
throw new Error("Unknown expression function: ".concat(expressionName));
|
|
3945
4158
|
}
|
|
4159
|
+
if (operator2.name === waitFor.name && !options.async) {
|
|
4160
|
+
throw new Error("Usage of await outside of async context");
|
|
4161
|
+
}
|
|
3946
4162
|
if ("resolveParams" in operator2 && operator2.resolveParams === false) {
|
|
3947
4163
|
return operator2.apply(void 0, [
|
|
3948
4164
|
expressionContext
|
|
@@ -3951,6 +4167,16 @@ var CommonExpressionsPlugin = function() {
|
|
|
3951
4167
|
var args = node.args.map(function(n) {
|
|
3952
4168
|
return resolveNode(n);
|
|
3953
4169
|
});
|
|
4170
|
+
if (options.async) {
|
|
4171
|
+
var hasPromises = args.some(isAwaitable);
|
|
4172
|
+
if (hasPromises) {
|
|
4173
|
+
return collateAwaitable(args).awaitableThen(function(resolvedArgs) {
|
|
4174
|
+
return operator2.apply(void 0, [
|
|
4175
|
+
expressionContext
|
|
4176
|
+
].concat(_to_consumable_array(resolvedArgs)));
|
|
4177
|
+
});
|
|
4178
|
+
}
|
|
4179
|
+
}
|
|
3954
4180
|
return operator2.apply(void 0, [
|
|
3955
4181
|
expressionContext
|
|
3956
4182
|
].concat(_to_consumable_array(args)));
|
|
@@ -3965,11 +4191,36 @@ var CommonExpressionsPlugin = function() {
|
|
|
3965
4191
|
if (node.type === "MemberExpression") {
|
|
3966
4192
|
var obj = resolveNode(node.object);
|
|
3967
4193
|
var prop = resolveNode(node.property);
|
|
4194
|
+
if (options.async && (isAwaitable(obj) || isAwaitable(prop))) {
|
|
4195
|
+
return collateAwaitable([
|
|
4196
|
+
obj,
|
|
4197
|
+
prop
|
|
4198
|
+
]).awaitableThen(function(param) {
|
|
4199
|
+
var _param = _sliced_to_array(param, 2), objVal = _param[0], propVal = _param[1];
|
|
4200
|
+
return objVal[propVal];
|
|
4201
|
+
});
|
|
4202
|
+
}
|
|
3968
4203
|
return obj[prop];
|
|
3969
4204
|
}
|
|
3970
4205
|
if (node.type === "Assignment") {
|
|
3971
4206
|
if (node.left.type === "ModelRef") {
|
|
3972
4207
|
var value = resolveNode(node.right);
|
|
4208
|
+
if (isPromiseLike(value)) {
|
|
4209
|
+
if (options.async && isAwaitable(value)) {
|
|
4210
|
+
return value.awaitableThen(function(resolvedValue) {
|
|
4211
|
+
model.set([
|
|
4212
|
+
[
|
|
4213
|
+
node.left.ref,
|
|
4214
|
+
resolvedValue
|
|
4215
|
+
]
|
|
4216
|
+
]);
|
|
4217
|
+
return resolvedValue;
|
|
4218
|
+
});
|
|
4219
|
+
} else {
|
|
4220
|
+
var _options_logger;
|
|
4221
|
+
(_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");
|
|
4222
|
+
}
|
|
4223
|
+
}
|
|
3973
4224
|
model.set([
|
|
3974
4225
|
[
|
|
3975
4226
|
node.left.ref,
|
|
@@ -3980,19 +4231,30 @@ var CommonExpressionsPlugin = function() {
|
|
|
3980
4231
|
}
|
|
3981
4232
|
if (node.left.type === "Identifier") {
|
|
3982
4233
|
var value1 = resolveNode(node.right);
|
|
4234
|
+
if (options.async && isAwaitable(value1)) {
|
|
4235
|
+
return value1.awaitableThen(function(resolvedValue) {
|
|
4236
|
+
_this.vars[node.left.name] = resolvedValue;
|
|
4237
|
+
return resolvedValue;
|
|
4238
|
+
});
|
|
4239
|
+
}
|
|
3983
4240
|
this.vars[node.left.name] = value1;
|
|
3984
4241
|
return value1;
|
|
3985
4242
|
}
|
|
3986
4243
|
return;
|
|
3987
4244
|
}
|
|
3988
4245
|
if (node.type === "ConditionalExpression") {
|
|
3989
|
-
var
|
|
3990
|
-
return
|
|
4246
|
+
var testResult = resolveNode(node.test);
|
|
4247
|
+
return handleConditionalBranching(testResult, function() {
|
|
4248
|
+
return node.consequent;
|
|
4249
|
+
}, function() {
|
|
4250
|
+
return node.alternate;
|
|
4251
|
+
}, resolveNode, isAsync);
|
|
3991
4252
|
}
|
|
3992
4253
|
if (node.type === "ArrayExpression") {
|
|
3993
|
-
|
|
4254
|
+
var results = node.elements.map(function(ele) {
|
|
3994
4255
|
return resolveNode(ele);
|
|
3995
4256
|
});
|
|
4257
|
+
return PromiseCollectionHandler.handleArray(results, isAsync);
|
|
3996
4258
|
}
|
|
3997
4259
|
if (node.type === "Modification") {
|
|
3998
4260
|
var operation = this.operators.binary.get(node.operator);
|
|
@@ -4000,14 +4262,49 @@ var CommonExpressionsPlugin = function() {
|
|
|
4000
4262
|
var newValue;
|
|
4001
4263
|
if ("resolveParams" in operation) {
|
|
4002
4264
|
if (operation.resolveParams === false) {
|
|
4003
|
-
newValue = operation(expressionContext, node.left, node.right);
|
|
4265
|
+
newValue = operation(expressionContext, node.left, node.right, isAsync);
|
|
4004
4266
|
} else {
|
|
4005
|
-
|
|
4267
|
+
var left1 = resolveNode(node.left);
|
|
4268
|
+
var right1 = resolveNode(node.right);
|
|
4269
|
+
if (options.async && (isAwaitable(left1) || isAwaitable(right1))) {
|
|
4270
|
+
newValue = collateAwaitable([
|
|
4271
|
+
left1,
|
|
4272
|
+
right1
|
|
4273
|
+
]).awaitableThen(function(param) {
|
|
4274
|
+
var _param = _sliced_to_array(param, 2), leftVal = _param[0], rightVal = _param[1];
|
|
4275
|
+
return operation(expressionContext, leftVal, rightVal, isAsync);
|
|
4276
|
+
});
|
|
4277
|
+
} else {
|
|
4278
|
+
newValue = operation(expressionContext, left1, right1, isAsync);
|
|
4279
|
+
}
|
|
4006
4280
|
}
|
|
4007
4281
|
} else {
|
|
4008
|
-
|
|
4282
|
+
var left3 = resolveNode(node.left);
|
|
4283
|
+
var right3 = resolveNode(node.right);
|
|
4284
|
+
if (options.async && (isAwaitable(left3) || isAwaitable(right3))) {
|
|
4285
|
+
newValue = collateAwaitable([
|
|
4286
|
+
left3,
|
|
4287
|
+
right3
|
|
4288
|
+
]).awaitableThen(function(param) {
|
|
4289
|
+
var _param = _sliced_to_array(param, 2), leftVal = _param[0], rightVal = _param[1];
|
|
4290
|
+
return operation(leftVal, rightVal, isAsync);
|
|
4291
|
+
});
|
|
4292
|
+
} else {
|
|
4293
|
+
newValue = operation(left3, right3, isAsync);
|
|
4294
|
+
}
|
|
4009
4295
|
}
|
|
4010
4296
|
if (node.left.type === "ModelRef") {
|
|
4297
|
+
if (options.async && isAwaitable(newValue)) {
|
|
4298
|
+
return newValue.awaitableThen(function(resolvedValue) {
|
|
4299
|
+
model.set([
|
|
4300
|
+
[
|
|
4301
|
+
node.left.ref,
|
|
4302
|
+
resolvedValue
|
|
4303
|
+
]
|
|
4304
|
+
]);
|
|
4305
|
+
return resolvedValue;
|
|
4306
|
+
});
|
|
4307
|
+
}
|
|
4011
4308
|
model.set([
|
|
4012
4309
|
[
|
|
4013
4310
|
node.left.ref,
|
|
@@ -4015,6 +4312,12 @@ var CommonExpressionsPlugin = function() {
|
|
|
4015
4312
|
]
|
|
4016
4313
|
]);
|
|
4017
4314
|
} else if (node.left.type === "Identifier") {
|
|
4315
|
+
if (options.async && isAwaitable(newValue)) {
|
|
4316
|
+
return newValue.awaitableThen(function(resolvedValue) {
|
|
4317
|
+
_this.vars[node.left.name] = resolvedValue;
|
|
4318
|
+
return resolvedValue;
|
|
4319
|
+
});
|
|
4320
|
+
}
|
|
4018
4321
|
this.vars[node.left.name] = newValue;
|
|
4019
4322
|
}
|
|
4020
4323
|
return newValue;
|
|
@@ -7238,18 +7541,18 @@ var CommonExpressionsPlugin = function() {
|
|
|
7238
7541
|
this.constantsController = new ConstantsController();
|
|
7239
7542
|
this.state = NOT_STARTED_STATE;
|
|
7240
7543
|
this.hooks = {
|
|
7241
|
-
|
|
7242
|
-
|
|
7243
|
-
|
|
7244
|
-
|
|
7245
|
-
|
|
7246
|
-
|
|
7247
|
-
|
|
7248
|
-
|
|
7249
|
-
|
|
7250
|
-
|
|
7251
|
-
|
|
7252
|
-
|
|
7544
|
+
flowController: new SyncHook(),
|
|
7545
|
+
viewController: new SyncHook(),
|
|
7546
|
+
view: new SyncHook(),
|
|
7547
|
+
expressionEvaluator: new SyncHook(),
|
|
7548
|
+
dataController: new SyncHook(),
|
|
7549
|
+
schema: new SyncHook(),
|
|
7550
|
+
validationController: new SyncHook(),
|
|
7551
|
+
bindingParser: new SyncHook(),
|
|
7552
|
+
state: new SyncHook(),
|
|
7553
|
+
onStart: new SyncHook(),
|
|
7554
|
+
onEnd: new SyncHook(),
|
|
7555
|
+
resolveFlowContent: new SyncWaterfallHook()
|
|
7253
7556
|
};
|
|
7254
7557
|
if (config === null || config === void 0 ? void 0 : config.logger) {
|
|
7255
7558
|
this.logger.addHandler(config.logger);
|
|
@@ -7449,10 +7752,90 @@ var CommonExpressionsPlugin = function() {
|
|
|
7449
7752
|
var value = (_flowInstance_currentState = flowInstance.currentState) === null || _flowInstance_currentState === void 0 ? void 0 : _flowInstance_currentState.value;
|
|
7450
7753
|
if (value && value.state_type === "ACTION") {
|
|
7451
7754
|
var exp = value.exp;
|
|
7452
|
-
|
|
7755
|
+
var result = expressionEvaluator.evaluate(exp);
|
|
7756
|
+
if (isPromiseLike(result)) {
|
|
7757
|
+
_this.logger.warn("Async expression used as return value in in non-async context, transitioning with '*' value");
|
|
7758
|
+
}
|
|
7759
|
+
flowController === null || flowController === void 0 ? void 0 : flowController.transition(String(result));
|
|
7453
7760
|
}
|
|
7454
7761
|
expressionEvaluator.reset();
|
|
7455
7762
|
});
|
|
7763
|
+
var _this1 = _this;
|
|
7764
|
+
flow.hooks.afterTransition.tap("player", function() {
|
|
7765
|
+
var _ref = _async_to_generator(function(flowInstance) {
|
|
7766
|
+
var _flowInstance_currentState, value, exp, result, e;
|
|
7767
|
+
return _ts_generator(this, function(_state) {
|
|
7768
|
+
switch(_state.label){
|
|
7769
|
+
case 0:
|
|
7770
|
+
value = (_flowInstance_currentState = flowInstance.currentState) === null || _flowInstance_currentState === void 0 ? void 0 : _flowInstance_currentState.value;
|
|
7771
|
+
if (!(value && value.state_type === "ASYNC_ACTION")) return [
|
|
7772
|
+
3,
|
|
7773
|
+
8
|
|
7774
|
+
];
|
|
7775
|
+
exp = value.exp;
|
|
7776
|
+
_state.label = 1;
|
|
7777
|
+
case 1:
|
|
7778
|
+
_state.trys.push([
|
|
7779
|
+
1,
|
|
7780
|
+
7,
|
|
7781
|
+
,
|
|
7782
|
+
8
|
|
7783
|
+
]);
|
|
7784
|
+
result = expressionEvaluator.evaluateAsync(exp);
|
|
7785
|
+
if (!isPromiseLike(result)) return [
|
|
7786
|
+
3,
|
|
7787
|
+
5
|
|
7788
|
+
];
|
|
7789
|
+
if (!value.await) return [
|
|
7790
|
+
3,
|
|
7791
|
+
3
|
|
7792
|
+
];
|
|
7793
|
+
return [
|
|
7794
|
+
4,
|
|
7795
|
+
result
|
|
7796
|
+
];
|
|
7797
|
+
case 2:
|
|
7798
|
+
result = _state.sent();
|
|
7799
|
+
return [
|
|
7800
|
+
3,
|
|
7801
|
+
4
|
|
7802
|
+
];
|
|
7803
|
+
case 3:
|
|
7804
|
+
_this1.logger.warn("Unawaited promise used as return value in in non-async context, transitioning with '*' value");
|
|
7805
|
+
_state.label = 4;
|
|
7806
|
+
case 4:
|
|
7807
|
+
return [
|
|
7808
|
+
3,
|
|
7809
|
+
6
|
|
7810
|
+
];
|
|
7811
|
+
case 5:
|
|
7812
|
+
_this1.logger.warn("Non async expression used in async action node");
|
|
7813
|
+
_state.label = 6;
|
|
7814
|
+
case 6:
|
|
7815
|
+
flowController === null || flowController === void 0 ? void 0 : flowController.transition(String(result));
|
|
7816
|
+
return [
|
|
7817
|
+
3,
|
|
7818
|
+
8
|
|
7819
|
+
];
|
|
7820
|
+
case 7:
|
|
7821
|
+
e = _state.sent();
|
|
7822
|
+
flowResultDeferred.reject(e);
|
|
7823
|
+
return [
|
|
7824
|
+
3,
|
|
7825
|
+
8
|
|
7826
|
+
];
|
|
7827
|
+
case 8:
|
|
7828
|
+
expressionEvaluator.reset();
|
|
7829
|
+
return [
|
|
7830
|
+
2
|
|
7831
|
+
];
|
|
7832
|
+
}
|
|
7833
|
+
});
|
|
7834
|
+
});
|
|
7835
|
+
return function(flowInstance) {
|
|
7836
|
+
return _ref.apply(this, arguments);
|
|
7837
|
+
};
|
|
7838
|
+
}());
|
|
7456
7839
|
});
|
|
7457
7840
|
this.hooks.dataController.call(dataController);
|
|
7458
7841
|
validationController.setOptions({
|