@player-ui/check-path-plugin 0.12.1-next.0 → 0.13.0-next.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -1184,12 +1184,61 @@ var 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
|
|
3555
|
-
if (
|
|
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
|
|
3565
|
-
return
|
|
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
|
|
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
|
-
"
|
|
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",
|
|
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
|
|
3763
|
-
|
|
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,
|
|
4007
|
+
return operator(expressionContext, left2, right2, isAsync);
|
|
3814
4008
|
}
|
|
3815
|
-
|
|
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
|
+
});
|
|
4019
|
+
}
|
|
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
|
-
|
|
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(
|
|
4045
|
+
return operator1(arg, isAsync);
|
|
3826
4046
|
}
|
|
3827
4047
|
return;
|
|
3828
4048
|
}
|
|
3829
4049
|
if (node.type === "Object") {
|
|
3830
|
-
|
|
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
|
|
3889
|
-
return
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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;
|
|
@@ -7150,18 +7453,18 @@ var CheckPathPlugin = function() {
|
|
|
7150
7453
|
this.constantsController = new ConstantsController();
|
|
7151
7454
|
this.state = NOT_STARTED_STATE;
|
|
7152
7455
|
this.hooks = {
|
|
7153
|
-
|
|
7154
|
-
|
|
7155
|
-
|
|
7156
|
-
|
|
7157
|
-
|
|
7158
|
-
|
|
7159
|
-
|
|
7160
|
-
|
|
7161
|
-
|
|
7162
|
-
|
|
7163
|
-
|
|
7164
|
-
|
|
7456
|
+
flowController: new SyncHook(),
|
|
7457
|
+
viewController: new SyncHook(),
|
|
7458
|
+
view: new SyncHook(),
|
|
7459
|
+
expressionEvaluator: new SyncHook(),
|
|
7460
|
+
dataController: new SyncHook(),
|
|
7461
|
+
schema: new SyncHook(),
|
|
7462
|
+
validationController: new SyncHook(),
|
|
7463
|
+
bindingParser: new SyncHook(),
|
|
7464
|
+
state: new SyncHook(),
|
|
7465
|
+
onStart: new SyncHook(),
|
|
7466
|
+
onEnd: new SyncHook(),
|
|
7467
|
+
resolveFlowContent: new SyncWaterfallHook()
|
|
7165
7468
|
};
|
|
7166
7469
|
if (config === null || config === void 0 ? void 0 : config.logger) {
|
|
7167
7470
|
this.logger.addHandler(config.logger);
|
|
@@ -7361,10 +7664,90 @@ var CheckPathPlugin = function() {
|
|
|
7361
7664
|
var value = (_flowInstance_currentState = flowInstance.currentState) === null || _flowInstance_currentState === void 0 ? void 0 : _flowInstance_currentState.value;
|
|
7362
7665
|
if (value && value.state_type === "ACTION") {
|
|
7363
7666
|
var exp = value.exp;
|
|
7364
|
-
|
|
7667
|
+
var result = expressionEvaluator.evaluate(exp);
|
|
7668
|
+
if (isPromiseLike(result)) {
|
|
7669
|
+
_this.logger.warn("Async expression used as return value in in non-async context, transitioning with '*' value");
|
|
7670
|
+
}
|
|
7671
|
+
flowController === null || flowController === void 0 ? void 0 : flowController.transition(String(result));
|
|
7365
7672
|
}
|
|
7366
7673
|
expressionEvaluator.reset();
|
|
7367
7674
|
});
|
|
7675
|
+
var _this1 = _this;
|
|
7676
|
+
flow.hooks.afterTransition.tap("player", function() {
|
|
7677
|
+
var _ref = _async_to_generator(function(flowInstance) {
|
|
7678
|
+
var _flowInstance_currentState, value, exp, result, e;
|
|
7679
|
+
return _ts_generator(this, function(_state) {
|
|
7680
|
+
switch(_state.label){
|
|
7681
|
+
case 0:
|
|
7682
|
+
value = (_flowInstance_currentState = flowInstance.currentState) === null || _flowInstance_currentState === void 0 ? void 0 : _flowInstance_currentState.value;
|
|
7683
|
+
if (!(value && value.state_type === "ASYNC_ACTION")) return [
|
|
7684
|
+
3,
|
|
7685
|
+
8
|
|
7686
|
+
];
|
|
7687
|
+
exp = value.exp;
|
|
7688
|
+
_state.label = 1;
|
|
7689
|
+
case 1:
|
|
7690
|
+
_state.trys.push([
|
|
7691
|
+
1,
|
|
7692
|
+
7,
|
|
7693
|
+
,
|
|
7694
|
+
8
|
|
7695
|
+
]);
|
|
7696
|
+
result = expressionEvaluator.evaluateAsync(exp);
|
|
7697
|
+
if (!isPromiseLike(result)) return [
|
|
7698
|
+
3,
|
|
7699
|
+
5
|
|
7700
|
+
];
|
|
7701
|
+
if (!value.await) return [
|
|
7702
|
+
3,
|
|
7703
|
+
3
|
|
7704
|
+
];
|
|
7705
|
+
return [
|
|
7706
|
+
4,
|
|
7707
|
+
result
|
|
7708
|
+
];
|
|
7709
|
+
case 2:
|
|
7710
|
+
result = _state.sent();
|
|
7711
|
+
return [
|
|
7712
|
+
3,
|
|
7713
|
+
4
|
|
7714
|
+
];
|
|
7715
|
+
case 3:
|
|
7716
|
+
_this1.logger.warn("Unawaited promise used as return value in in non-async context, transitioning with '*' value");
|
|
7717
|
+
_state.label = 4;
|
|
7718
|
+
case 4:
|
|
7719
|
+
return [
|
|
7720
|
+
3,
|
|
7721
|
+
6
|
|
7722
|
+
];
|
|
7723
|
+
case 5:
|
|
7724
|
+
_this1.logger.warn("Non async expression used in async action node");
|
|
7725
|
+
_state.label = 6;
|
|
7726
|
+
case 6:
|
|
7727
|
+
flowController === null || flowController === void 0 ? void 0 : flowController.transition(String(result));
|
|
7728
|
+
return [
|
|
7729
|
+
3,
|
|
7730
|
+
8
|
|
7731
|
+
];
|
|
7732
|
+
case 7:
|
|
7733
|
+
e = _state.sent();
|
|
7734
|
+
flowResultDeferred.reject(e);
|
|
7735
|
+
return [
|
|
7736
|
+
3,
|
|
7737
|
+
8
|
|
7738
|
+
];
|
|
7739
|
+
case 8:
|
|
7740
|
+
expressionEvaluator.reset();
|
|
7741
|
+
return [
|
|
7742
|
+
2
|
|
7743
|
+
];
|
|
7744
|
+
}
|
|
7745
|
+
});
|
|
7746
|
+
});
|
|
7747
|
+
return function(flowInstance) {
|
|
7748
|
+
return _ref.apply(this, arguments);
|
|
7749
|
+
};
|
|
7750
|
+
}());
|
|
7368
7751
|
});
|
|
7369
7752
|
this.hooks.dataController.call(dataController);
|
|
7370
7753
|
validationController.setOptions({
|