@player-ui/common-types-plugin 0.12.1-next.0 → 0.13.0-next.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -1184,12 +1184,61 @@ var CommonTypesPlugin = 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();
|
|
@@ -3626,8 +3675,19 @@ var CommonTypesPlugin = function() {
|
|
|
3626
3675
|
},
|
|
3627
3676
|
setDataVal: function() {
|
|
3628
3677
|
return setDataVal;
|
|
3678
|
+
},
|
|
3679
|
+
waitFor: function() {
|
|
3680
|
+
return waitFor;
|
|
3629
3681
|
}
|
|
3630
3682
|
});
|
|
3683
|
+
var AwaitableSymbol = Symbol("Awaitable");
|
|
3684
|
+
function makeAwaitable(promise) {
|
|
3685
|
+
promise[AwaitableSymbol] = AwaitableSymbol;
|
|
3686
|
+
promise.awaitableThen = function(arg) {
|
|
3687
|
+
return makeAwaitable(promise.then(arg));
|
|
3688
|
+
};
|
|
3689
|
+
return promise;
|
|
3690
|
+
}
|
|
3631
3691
|
var setDataVal = function(_context, binding, value) {
|
|
3632
3692
|
_context.model.set([
|
|
3633
3693
|
[
|
|
@@ -3643,8 +3703,19 @@ var CommonTypesPlugin = function() {
|
|
|
3643
3703
|
return _context.model.delete(binding);
|
|
3644
3704
|
};
|
|
3645
3705
|
var conditional = function(ctx, condition, ifTrue, ifFalse) {
|
|
3646
|
-
var
|
|
3647
|
-
if (
|
|
3706
|
+
var testResult = ctx.evaluate(condition);
|
|
3707
|
+
if (isAwaitable(testResult)) {
|
|
3708
|
+
return testResult.awaitableThen(function(resolvedTest) {
|
|
3709
|
+
if (resolvedTest) {
|
|
3710
|
+
return ctx.evaluate(ifTrue);
|
|
3711
|
+
}
|
|
3712
|
+
if (ifFalse) {
|
|
3713
|
+
return ctx.evaluate(ifFalse);
|
|
3714
|
+
}
|
|
3715
|
+
return null;
|
|
3716
|
+
});
|
|
3717
|
+
}
|
|
3718
|
+
if (testResult) {
|
|
3648
3719
|
return ctx.evaluate(ifTrue);
|
|
3649
3720
|
}
|
|
3650
3721
|
if (ifFalse) {
|
|
@@ -3653,12 +3724,15 @@ var CommonTypesPlugin = function() {
|
|
|
3653
3724
|
return null;
|
|
3654
3725
|
};
|
|
3655
3726
|
conditional.resolveParams = false;
|
|
3656
|
-
var
|
|
3657
|
-
return
|
|
3727
|
+
var waitFor = function(ctx, promise) {
|
|
3728
|
+
return makeAwaitable(promise);
|
|
3729
|
+
};
|
|
3730
|
+
var andandOperator = function(ctx, a, b, async) {
|
|
3731
|
+
return LogicalOperators.and(ctx, a, b, async);
|
|
3658
3732
|
};
|
|
3659
3733
|
andandOperator.resolveParams = false;
|
|
3660
|
-
var ororOperator = function(ctx, a, b) {
|
|
3661
|
-
return
|
|
3734
|
+
var ororOperator = function(ctx, a, b, async) {
|
|
3735
|
+
return LogicalOperators.or(ctx, a, b, async);
|
|
3662
3736
|
};
|
|
3663
3737
|
ororOperator.resolveParams = false;
|
|
3664
3738
|
var DEFAULT_BINARY_OPERATORS = {
|
|
@@ -3678,34 +3752,35 @@ var CommonTypesPlugin = function() {
|
|
|
3678
3752
|
"%": function(a, b) {
|
|
3679
3753
|
return a % b;
|
|
3680
3754
|
},
|
|
3755
|
+
// Promise-aware comparison operators
|
|
3681
3756
|
// eslint-disable-next-line
|
|
3682
|
-
"==": function(a, b) {
|
|
3757
|
+
"==": makePromiseAwareBinaryOp(function(a, b) {
|
|
3683
3758
|
return a == b;
|
|
3684
|
-
},
|
|
3759
|
+
}),
|
|
3685
3760
|
// eslint-disable-next-line
|
|
3686
|
-
"!=": function(a, b) {
|
|
3761
|
+
"!=": makePromiseAwareBinaryOp(function(a, b) {
|
|
3687
3762
|
return a != b;
|
|
3688
|
-
},
|
|
3689
|
-
">": function(a, b) {
|
|
3763
|
+
}),
|
|
3764
|
+
">": makePromiseAwareBinaryOp(function(a, b) {
|
|
3690
3765
|
return a > b;
|
|
3691
|
-
},
|
|
3692
|
-
">=": function(a, b) {
|
|
3766
|
+
}),
|
|
3767
|
+
">=": makePromiseAwareBinaryOp(function(a, b) {
|
|
3693
3768
|
return a >= b;
|
|
3694
|
-
},
|
|
3695
|
-
"<": function(a, b) {
|
|
3769
|
+
}),
|
|
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
|
-
"
|
|
3702
|
-
"||": ororOperator,
|
|
3703
|
-
"!==": function(a, b) {
|
|
3775
|
+
}),
|
|
3776
|
+
"!==": makePromiseAwareBinaryOp(function(a, b) {
|
|
3704
3777
|
return a !== b;
|
|
3705
|
-
},
|
|
3706
|
-
"===": function(a, b) {
|
|
3778
|
+
}),
|
|
3779
|
+
"===": makePromiseAwareBinaryOp(function(a, b) {
|
|
3707
3780
|
return a === b;
|
|
3708
|
-
},
|
|
3781
|
+
}),
|
|
3782
|
+
"&&": andandOperator,
|
|
3783
|
+
"||": ororOperator,
|
|
3709
3784
|
// eslint-disable-next-line
|
|
3710
3785
|
"|": function(a, b) {
|
|
3711
3786
|
return a | b;
|
|
@@ -3736,8 +3811,73 @@ var CommonTypesPlugin = function() {
|
|
|
3736
3811
|
"+": function(a) {
|
|
3737
3812
|
return Number(a);
|
|
3738
3813
|
},
|
|
3739
|
-
"!": function(a) {
|
|
3814
|
+
"!": makePromiseAwareUnaryOp(function(a) {
|
|
3740
3815
|
return !a;
|
|
3816
|
+
})
|
|
3817
|
+
};
|
|
3818
|
+
var PromiseCollectionHandler = {
|
|
3819
|
+
/**
|
|
3820
|
+
* Handle array with potential Promise elements
|
|
3821
|
+
*/ handleArray: function handleArray(items, async) {
|
|
3822
|
+
if (!async) {
|
|
3823
|
+
return items;
|
|
3824
|
+
}
|
|
3825
|
+
var hasPromises = items.some(function(item) {
|
|
3826
|
+
return isAwaitable(item);
|
|
3827
|
+
});
|
|
3828
|
+
return hasPromises ? collateAwaitable(items) : items;
|
|
3829
|
+
},
|
|
3830
|
+
/**
|
|
3831
|
+
* Handle object with potential Promise keys/values
|
|
3832
|
+
*/ handleObject: function handleObject(attributes, resolveNode, async) {
|
|
3833
|
+
var resolvedAttributes = {};
|
|
3834
|
+
var promises = [];
|
|
3835
|
+
var hasPromises = false;
|
|
3836
|
+
attributes.forEach(function(attr) {
|
|
3837
|
+
var key = resolveNode(attr.key);
|
|
3838
|
+
var value = resolveNode(attr.value);
|
|
3839
|
+
if (async && (isAwaitable(key) || isAwaitable(value))) {
|
|
3840
|
+
hasPromises = true;
|
|
3841
|
+
var keyPromise = Promise.resolve(key);
|
|
3842
|
+
var valuePromise = Promise.resolve(value);
|
|
3843
|
+
promises.push(collateAwaitable([
|
|
3844
|
+
keyPromise,
|
|
3845
|
+
valuePromise
|
|
3846
|
+
]).awaitableThen(function(param) {
|
|
3847
|
+
var _param = _sliced_to_array(param, 2), resolvedKey = _param[0], resolvedValue = _param[1];
|
|
3848
|
+
resolvedAttributes[resolvedKey] = resolvedValue;
|
|
3849
|
+
}));
|
|
3850
|
+
} else {
|
|
3851
|
+
resolvedAttributes[key] = value;
|
|
3852
|
+
}
|
|
3853
|
+
});
|
|
3854
|
+
return hasPromises ? collateAwaitable(promises).awaitableThen(function() {
|
|
3855
|
+
return resolvedAttributes;
|
|
3856
|
+
}) : resolvedAttributes;
|
|
3857
|
+
}
|
|
3858
|
+
};
|
|
3859
|
+
var LogicalOperators = {
|
|
3860
|
+
and: function(ctx, leftNode, rightNode, async) {
|
|
3861
|
+
var leftResult = ctx.evaluate(leftNode);
|
|
3862
|
+
if (async && isAwaitable(leftResult)) {
|
|
3863
|
+
return leftResult.awaitableThen(function(awaitedLeft) {
|
|
3864
|
+
if (!awaitedLeft) return awaitedLeft;
|
|
3865
|
+
var rightResult = ctx.evaluate(rightNode);
|
|
3866
|
+
return isAwaitable(rightResult) ? rightResult : Promise.resolve(rightResult);
|
|
3867
|
+
});
|
|
3868
|
+
}
|
|
3869
|
+
return leftResult && ctx.evaluate(rightNode);
|
|
3870
|
+
},
|
|
3871
|
+
or: function(ctx, leftNode, rightNode, async) {
|
|
3872
|
+
var leftResult = ctx.evaluate(leftNode);
|
|
3873
|
+
if (async && isAwaitable(leftResult)) {
|
|
3874
|
+
return leftResult.awaitableThen(function(awaitedLeft) {
|
|
3875
|
+
if (awaitedLeft) return awaitedLeft;
|
|
3876
|
+
var rightResult = ctx.evaluate(rightNode);
|
|
3877
|
+
return isAwaitable(rightResult) ? rightResult : Promise.resolve(rightResult);
|
|
3878
|
+
});
|
|
3879
|
+
}
|
|
3880
|
+
return leftResult || ctx.evaluate(rightNode);
|
|
3741
3881
|
}
|
|
3742
3882
|
};
|
|
3743
3883
|
var ExpressionEvaluator = /*#__PURE__*/ function() {
|
|
@@ -3758,7 +3898,12 @@ var CommonTypesPlugin = function() {
|
|
|
3758
3898
|
this.operators = {
|
|
3759
3899
|
binary: new Map(Object.entries(DEFAULT_BINARY_OPERATORS)),
|
|
3760
3900
|
unary: new Map(Object.entries(DEFAULT_UNARY_OPERATORS)),
|
|
3761
|
-
expressions: new Map(Object.entries(evaluator_functions_exports))
|
|
3901
|
+
expressions: new Map(_to_consumable_array(Object.entries(evaluator_functions_exports)).concat([
|
|
3902
|
+
[
|
|
3903
|
+
"await",
|
|
3904
|
+
waitFor
|
|
3905
|
+
]
|
|
3906
|
+
]))
|
|
3762
3907
|
};
|
|
3763
3908
|
this.defaultHookOptions = _object_spread_props(_object_spread({}, defaultOptions), {
|
|
3764
3909
|
evaluate: function(expr) {
|
|
@@ -3768,7 +3913,9 @@ var CommonTypesPlugin = function() {
|
|
|
3768
3913
|
return _this._execAST(node, _this.defaultHookOptions);
|
|
3769
3914
|
}
|
|
3770
3915
|
});
|
|
3771
|
-
this.hooks.resolve.tap("ExpressionEvaluator",
|
|
3916
|
+
this.hooks.resolve.tap("ExpressionEvaluator", function(result, node, options) {
|
|
3917
|
+
return _this._resolveNode(result, node, options);
|
|
3918
|
+
});
|
|
3772
3919
|
this.evaluate = this.evaluate.bind(this);
|
|
3773
3920
|
}
|
|
3774
3921
|
_create_class(ExpressionEvaluator, [
|
|
@@ -3806,6 +3953,38 @@ var CommonTypesPlugin = function() {
|
|
|
3806
3953
|
return this._execString(String(expression2), resolvedOpts);
|
|
3807
3954
|
}
|
|
3808
3955
|
},
|
|
3956
|
+
{
|
|
3957
|
+
/**
|
|
3958
|
+
* Evaluate functions in an async context
|
|
3959
|
+
* @experimental These Player APIs are in active development and may change. Use with caution
|
|
3960
|
+
*/ key: "evaluateAsync",
|
|
3961
|
+
value: function evaluateAsync(expr, options) {
|
|
3962
|
+
if (Array.isArray(expr)) {
|
|
3963
|
+
var _this = this;
|
|
3964
|
+
return collateAwaitable(expr.map(function() {
|
|
3965
|
+
var _ref = _async_to_generator(function(exp) {
|
|
3966
|
+
return _ts_generator(this, function(_state) {
|
|
3967
|
+
return [
|
|
3968
|
+
2,
|
|
3969
|
+
_this.evaluate(exp, _object_spread_props(_object_spread({}, options), {
|
|
3970
|
+
async: true
|
|
3971
|
+
}))
|
|
3972
|
+
];
|
|
3973
|
+
});
|
|
3974
|
+
});
|
|
3975
|
+
return function(exp) {
|
|
3976
|
+
return _ref.apply(this, arguments);
|
|
3977
|
+
};
|
|
3978
|
+
}())).awaitableThen(function(values) {
|
|
3979
|
+
return values.pop();
|
|
3980
|
+
});
|
|
3981
|
+
} else {
|
|
3982
|
+
return this.evaluate(expr, _object_spread_props(_object_spread({}, options), {
|
|
3983
|
+
async: true
|
|
3984
|
+
}));
|
|
3985
|
+
}
|
|
3986
|
+
}
|
|
3987
|
+
},
|
|
3809
3988
|
{
|
|
3810
3989
|
key: "addExpressionFunction",
|
|
3811
3990
|
value: function addExpressionFunction(name, handler) {
|
|
@@ -3851,8 +4030,10 @@ var CommonTypesPlugin = function() {
|
|
|
3851
4030
|
var matches = exp.match(/^@\[(.*)\]@$/);
|
|
3852
4031
|
var matchedExp = exp;
|
|
3853
4032
|
if (matches) {
|
|
3854
|
-
var
|
|
3855
|
-
|
|
4033
|
+
var _Array_from = _sliced_to_array(Array.from(matches), 2), matched = _Array_from[1];
|
|
4034
|
+
if (matched) {
|
|
4035
|
+
matchedExp = matched;
|
|
4036
|
+
}
|
|
3856
4037
|
}
|
|
3857
4038
|
var storedAST;
|
|
3858
4039
|
try {
|
|
@@ -3881,6 +4062,8 @@ var CommonTypesPlugin = function() {
|
|
|
3881
4062
|
value: function _resolveNode(_currentValue, node, options) {
|
|
3882
4063
|
var _this = this;
|
|
3883
4064
|
var resolveNode = options.resolveNode, model = options.model;
|
|
4065
|
+
var _options_async;
|
|
4066
|
+
var isAsync = (_options_async = options.async) !== null && _options_async !== void 0 ? _options_async : false;
|
|
3884
4067
|
var expressionContext = _object_spread_props(_object_spread({}, options), {
|
|
3885
4068
|
evaluate: function(expr) {
|
|
3886
4069
|
return _this.evaluate(expr, options);
|
|
@@ -3900,11 +4083,33 @@ var CommonTypesPlugin = function() {
|
|
|
3900
4083
|
if (operator) {
|
|
3901
4084
|
if ("resolveParams" in operator) {
|
|
3902
4085
|
if (operator.resolveParams === false) {
|
|
3903
|
-
return operator(expressionContext, node.left, node.right);
|
|
4086
|
+
return operator(expressionContext, node.left, node.right, isAsync);
|
|
4087
|
+
}
|
|
4088
|
+
var left2 = resolveNode(node.left);
|
|
4089
|
+
var right2 = resolveNode(node.right);
|
|
4090
|
+
if (options.async && (isAwaitable(left2) || isAwaitable(right2))) {
|
|
4091
|
+
return collateAwaitable([
|
|
4092
|
+
left2,
|
|
4093
|
+
right2
|
|
4094
|
+
]).awaitableThen(function(param) {
|
|
4095
|
+
var _param = _sliced_to_array(param, 2), leftVal = _param[0], rightVal = _param[1];
|
|
4096
|
+
return operator(expressionContext, leftVal, rightVal, isAsync);
|
|
4097
|
+
});
|
|
3904
4098
|
}
|
|
3905
|
-
return operator(expressionContext,
|
|
4099
|
+
return operator(expressionContext, left2, right2, isAsync);
|
|
4100
|
+
}
|
|
4101
|
+
var left = resolveNode(node.left);
|
|
4102
|
+
var right = resolveNode(node.right);
|
|
4103
|
+
if (options.async && (isAwaitable(left) || isAwaitable(right))) {
|
|
4104
|
+
return collateAwaitable([
|
|
4105
|
+
left,
|
|
4106
|
+
right
|
|
4107
|
+
]).awaitableThen(function(param) {
|
|
4108
|
+
var _param = _sliced_to_array(param, 2), leftVal = _param[0], rightVal = _param[1];
|
|
4109
|
+
return operator(leftVal, rightVal, isAsync);
|
|
4110
|
+
});
|
|
3906
4111
|
}
|
|
3907
|
-
return operator(
|
|
4112
|
+
return operator(left, right, isAsync);
|
|
3908
4113
|
}
|
|
3909
4114
|
return;
|
|
3910
4115
|
}
|
|
@@ -3912,21 +4117,29 @@ var CommonTypesPlugin = function() {
|
|
|
3912
4117
|
var operator1 = this.operators.unary.get(node.operator);
|
|
3913
4118
|
if (operator1) {
|
|
3914
4119
|
if ("resolveParams" in operator1) {
|
|
3915
|
-
|
|
4120
|
+
if (operator1.resolveParams === false) {
|
|
4121
|
+
return operator1(expressionContext, node.argument, isAsync);
|
|
4122
|
+
}
|
|
4123
|
+
var arg2 = resolveNode(node.argument);
|
|
4124
|
+
if (options.async && isAwaitable(arg2)) {
|
|
4125
|
+
return arg2.awaitableThen(function(argVal) {
|
|
4126
|
+
return operator1(expressionContext, argVal, isAsync);
|
|
4127
|
+
});
|
|
4128
|
+
}
|
|
4129
|
+
return operator1(expressionContext, arg2, isAsync);
|
|
3916
4130
|
}
|
|
3917
|
-
|
|
4131
|
+
var arg = resolveNode(node.argument);
|
|
4132
|
+
if (options.async && isAwaitable(arg)) {
|
|
4133
|
+
return arg.awaitableThen(function(argVal) {
|
|
4134
|
+
return operator1(argVal, isAsync);
|
|
4135
|
+
});
|
|
4136
|
+
}
|
|
4137
|
+
return operator1(arg, isAsync);
|
|
3918
4138
|
}
|
|
3919
4139
|
return;
|
|
3920
4140
|
}
|
|
3921
4141
|
if (node.type === "Object") {
|
|
3922
|
-
|
|
3923
|
-
var resolvedAttributes = {};
|
|
3924
|
-
attributes.forEach(function(attr) {
|
|
3925
|
-
var key = resolveNode(attr.key);
|
|
3926
|
-
var value = resolveNode(attr.value);
|
|
3927
|
-
resolvedAttributes[key] = value;
|
|
3928
|
-
});
|
|
3929
|
-
return resolvedAttributes;
|
|
4142
|
+
return PromiseCollectionHandler.handleObject(node.attributes, resolveNode, options.async || false);
|
|
3930
4143
|
}
|
|
3931
4144
|
if (node.type === "CallExpression") {
|
|
3932
4145
|
var expressionName = node.callTarget.name;
|
|
@@ -3934,6 +4147,9 @@ var CommonTypesPlugin = function() {
|
|
|
3934
4147
|
if (!operator2) {
|
|
3935
4148
|
throw new Error("Unknown expression function: ".concat(expressionName));
|
|
3936
4149
|
}
|
|
4150
|
+
if (operator2.name === waitFor.name && !options.async) {
|
|
4151
|
+
throw new Error("Usage of await outside of async context");
|
|
4152
|
+
}
|
|
3937
4153
|
if ("resolveParams" in operator2 && operator2.resolveParams === false) {
|
|
3938
4154
|
return operator2.apply(void 0, [
|
|
3939
4155
|
expressionContext
|
|
@@ -3942,6 +4158,16 @@ var CommonTypesPlugin = function() {
|
|
|
3942
4158
|
var args = node.args.map(function(n) {
|
|
3943
4159
|
return resolveNode(n);
|
|
3944
4160
|
});
|
|
4161
|
+
if (options.async) {
|
|
4162
|
+
var hasPromises = args.some(isAwaitable);
|
|
4163
|
+
if (hasPromises) {
|
|
4164
|
+
return collateAwaitable(args).awaitableThen(function(resolvedArgs) {
|
|
4165
|
+
return operator2.apply(void 0, [
|
|
4166
|
+
expressionContext
|
|
4167
|
+
].concat(_to_consumable_array(resolvedArgs)));
|
|
4168
|
+
});
|
|
4169
|
+
}
|
|
4170
|
+
}
|
|
3945
4171
|
return operator2.apply(void 0, [
|
|
3946
4172
|
expressionContext
|
|
3947
4173
|
].concat(_to_consumable_array(args)));
|
|
@@ -3956,11 +4182,36 @@ var CommonTypesPlugin = function() {
|
|
|
3956
4182
|
if (node.type === "MemberExpression") {
|
|
3957
4183
|
var obj = resolveNode(node.object);
|
|
3958
4184
|
var prop = resolveNode(node.property);
|
|
4185
|
+
if (options.async && (isAwaitable(obj) || isAwaitable(prop))) {
|
|
4186
|
+
return collateAwaitable([
|
|
4187
|
+
obj,
|
|
4188
|
+
prop
|
|
4189
|
+
]).awaitableThen(function(param) {
|
|
4190
|
+
var _param = _sliced_to_array(param, 2), objVal = _param[0], propVal = _param[1];
|
|
4191
|
+
return objVal[propVal];
|
|
4192
|
+
});
|
|
4193
|
+
}
|
|
3959
4194
|
return obj[prop];
|
|
3960
4195
|
}
|
|
3961
4196
|
if (node.type === "Assignment") {
|
|
3962
4197
|
if (node.left.type === "ModelRef") {
|
|
3963
4198
|
var value = resolveNode(node.right);
|
|
4199
|
+
if (isPromiseLike(value)) {
|
|
4200
|
+
if (options.async && isAwaitable(value)) {
|
|
4201
|
+
return value.awaitableThen(function(resolvedValue) {
|
|
4202
|
+
model.set([
|
|
4203
|
+
[
|
|
4204
|
+
node.left.ref,
|
|
4205
|
+
resolvedValue
|
|
4206
|
+
]
|
|
4207
|
+
]);
|
|
4208
|
+
return resolvedValue;
|
|
4209
|
+
});
|
|
4210
|
+
} else {
|
|
4211
|
+
var _options_logger;
|
|
4212
|
+
(_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");
|
|
4213
|
+
}
|
|
4214
|
+
}
|
|
3964
4215
|
model.set([
|
|
3965
4216
|
[
|
|
3966
4217
|
node.left.ref,
|
|
@@ -3971,19 +4222,30 @@ var CommonTypesPlugin = function() {
|
|
|
3971
4222
|
}
|
|
3972
4223
|
if (node.left.type === "Identifier") {
|
|
3973
4224
|
var value1 = resolveNode(node.right);
|
|
4225
|
+
if (options.async && isAwaitable(value1)) {
|
|
4226
|
+
return value1.awaitableThen(function(resolvedValue) {
|
|
4227
|
+
_this.vars[node.left.name] = resolvedValue;
|
|
4228
|
+
return resolvedValue;
|
|
4229
|
+
});
|
|
4230
|
+
}
|
|
3974
4231
|
this.vars[node.left.name] = value1;
|
|
3975
4232
|
return value1;
|
|
3976
4233
|
}
|
|
3977
4234
|
return;
|
|
3978
4235
|
}
|
|
3979
4236
|
if (node.type === "ConditionalExpression") {
|
|
3980
|
-
var
|
|
3981
|
-
return
|
|
4237
|
+
var testResult = resolveNode(node.test);
|
|
4238
|
+
return handleConditionalBranching(testResult, function() {
|
|
4239
|
+
return node.consequent;
|
|
4240
|
+
}, function() {
|
|
4241
|
+
return node.alternate;
|
|
4242
|
+
}, resolveNode, isAsync);
|
|
3982
4243
|
}
|
|
3983
4244
|
if (node.type === "ArrayExpression") {
|
|
3984
|
-
|
|
4245
|
+
var results = node.elements.map(function(ele) {
|
|
3985
4246
|
return resolveNode(ele);
|
|
3986
4247
|
});
|
|
4248
|
+
return PromiseCollectionHandler.handleArray(results, isAsync);
|
|
3987
4249
|
}
|
|
3988
4250
|
if (node.type === "Modification") {
|
|
3989
4251
|
var operation = this.operators.binary.get(node.operator);
|
|
@@ -3991,14 +4253,49 @@ var CommonTypesPlugin = function() {
|
|
|
3991
4253
|
var newValue;
|
|
3992
4254
|
if ("resolveParams" in operation) {
|
|
3993
4255
|
if (operation.resolveParams === false) {
|
|
3994
|
-
newValue = operation(expressionContext, node.left, node.right);
|
|
4256
|
+
newValue = operation(expressionContext, node.left, node.right, isAsync);
|
|
3995
4257
|
} else {
|
|
3996
|
-
|
|
4258
|
+
var left1 = resolveNode(node.left);
|
|
4259
|
+
var right1 = resolveNode(node.right);
|
|
4260
|
+
if (options.async && (isAwaitable(left1) || isAwaitable(right1))) {
|
|
4261
|
+
newValue = collateAwaitable([
|
|
4262
|
+
left1,
|
|
4263
|
+
right1
|
|
4264
|
+
]).awaitableThen(function(param) {
|
|
4265
|
+
var _param = _sliced_to_array(param, 2), leftVal = _param[0], rightVal = _param[1];
|
|
4266
|
+
return operation(expressionContext, leftVal, rightVal, isAsync);
|
|
4267
|
+
});
|
|
4268
|
+
} else {
|
|
4269
|
+
newValue = operation(expressionContext, left1, right1, isAsync);
|
|
4270
|
+
}
|
|
3997
4271
|
}
|
|
3998
4272
|
} else {
|
|
3999
|
-
|
|
4273
|
+
var left3 = resolveNode(node.left);
|
|
4274
|
+
var right3 = resolveNode(node.right);
|
|
4275
|
+
if (options.async && (isAwaitable(left3) || isAwaitable(right3))) {
|
|
4276
|
+
newValue = collateAwaitable([
|
|
4277
|
+
left3,
|
|
4278
|
+
right3
|
|
4279
|
+
]).awaitableThen(function(param) {
|
|
4280
|
+
var _param = _sliced_to_array(param, 2), leftVal = _param[0], rightVal = _param[1];
|
|
4281
|
+
return operation(leftVal, rightVal, isAsync);
|
|
4282
|
+
});
|
|
4283
|
+
} else {
|
|
4284
|
+
newValue = operation(left3, right3, isAsync);
|
|
4285
|
+
}
|
|
4000
4286
|
}
|
|
4001
4287
|
if (node.left.type === "ModelRef") {
|
|
4288
|
+
if (options.async && isAwaitable(newValue)) {
|
|
4289
|
+
return newValue.awaitableThen(function(resolvedValue) {
|
|
4290
|
+
model.set([
|
|
4291
|
+
[
|
|
4292
|
+
node.left.ref,
|
|
4293
|
+
resolvedValue
|
|
4294
|
+
]
|
|
4295
|
+
]);
|
|
4296
|
+
return resolvedValue;
|
|
4297
|
+
});
|
|
4298
|
+
}
|
|
4002
4299
|
model.set([
|
|
4003
4300
|
[
|
|
4004
4301
|
node.left.ref,
|
|
@@ -4006,6 +4303,12 @@ var CommonTypesPlugin = function() {
|
|
|
4006
4303
|
]
|
|
4007
4304
|
]);
|
|
4008
4305
|
} else if (node.left.type === "Identifier") {
|
|
4306
|
+
if (options.async && isAwaitable(newValue)) {
|
|
4307
|
+
return newValue.awaitableThen(function(resolvedValue) {
|
|
4308
|
+
_this.vars[node.left.name] = resolvedValue;
|
|
4309
|
+
return resolvedValue;
|
|
4310
|
+
});
|
|
4311
|
+
}
|
|
4009
4312
|
this.vars[node.left.name] = newValue;
|
|
4010
4313
|
}
|
|
4011
4314
|
return newValue;
|
|
@@ -4871,20 +5174,15 @@ var CommonTypesPlugin = function() {
|
|
|
4871
5174
|
}();
|
|
4872
5175
|
var ViewInstance = /*#__PURE__*/ function() {
|
|
4873
5176
|
function ViewInstance(initialView, resolverOptions) {
|
|
4874
|
-
var _this = this;
|
|
4875
5177
|
_class_call_check(this, ViewInstance);
|
|
4876
5178
|
this.hooks = {
|
|
4877
5179
|
onUpdate: new SyncHook(),
|
|
4878
5180
|
parser: new SyncHook(),
|
|
4879
5181
|
resolver: new SyncHook(),
|
|
4880
|
-
onTemplatePluginCreated: new SyncHook(),
|
|
4881
5182
|
templatePlugin: new SyncHook()
|
|
4882
5183
|
};
|
|
4883
5184
|
this.initialView = initialView;
|
|
4884
5185
|
this.resolverOptions = resolverOptions;
|
|
4885
|
-
this.hooks.onTemplatePluginCreated.tap("view", function(templatePlugin) {
|
|
4886
|
-
_this.templatePlugin = templatePlugin;
|
|
4887
|
-
});
|
|
4888
5186
|
}
|
|
4889
5187
|
_create_class(ViewInstance, [
|
|
4890
5188
|
{
|
|
@@ -4931,6 +5229,12 @@ var CommonTypesPlugin = function() {
|
|
|
4931
5229
|
var _this_validationProvider;
|
|
4932
5230
|
return (_this_validationProvider = this.validationProvider) === null || _this_validationProvider === void 0 ? void 0 : _this_validationProvider.getValidationsForBinding(binding);
|
|
4933
5231
|
}
|
|
5232
|
+
},
|
|
5233
|
+
{
|
|
5234
|
+
key: "setTemplatePlugin",
|
|
5235
|
+
value: function setTemplatePlugin(plugin) {
|
|
5236
|
+
this.templatePlugin = plugin;
|
|
5237
|
+
}
|
|
4934
5238
|
}
|
|
4935
5239
|
]);
|
|
4936
5240
|
return ViewInstance;
|
|
@@ -5102,6 +5406,7 @@ var CommonTypesPlugin = function() {
|
|
|
5102
5406
|
value: function apply(view) {
|
|
5103
5407
|
view.hooks.parser.tap("template", this.applyParser.bind(this));
|
|
5104
5408
|
view.hooks.resolver.tap("template", this.applyResolverHooks.bind(this));
|
|
5409
|
+
view.setTemplatePlugin(this);
|
|
5105
5410
|
}
|
|
5106
5411
|
}
|
|
5107
5412
|
]);
|
|
@@ -6710,8 +7015,7 @@ var CommonTypesPlugin = function() {
|
|
|
6710
7015
|
var _this1 = this;
|
|
6711
7016
|
_class_call_check(this, ViewController);
|
|
6712
7017
|
this.hooks = {
|
|
6713
|
-
|
|
6714
|
-
// The hook right before the View starts resolving. Attach anything custom here
|
|
7018
|
+
resolveView: new SyncWaterfallHook(),
|
|
6715
7019
|
view: new SyncHook()
|
|
6716
7020
|
};
|
|
6717
7021
|
this.transformRegistry = new Registry();
|
|
@@ -6759,6 +7063,7 @@ var CommonTypesPlugin = function() {
|
|
|
6759
7063
|
]));
|
|
6760
7064
|
}
|
|
6761
7065
|
});
|
|
7066
|
+
this.viewPlugins = this.createViewPlugins();
|
|
6762
7067
|
}
|
|
6763
7068
|
_create_class(ViewController, [
|
|
6764
7069
|
{
|
|
@@ -6814,9 +7119,50 @@ var CommonTypesPlugin = function() {
|
|
|
6814
7119
|
}
|
|
6815
7120
|
var view = new ViewInstance(source, this.viewOptions);
|
|
6816
7121
|
this.currentView = view;
|
|
7122
|
+
this.applyViewPlugins(view);
|
|
6817
7123
|
this.hooks.view.call(view);
|
|
6818
7124
|
view.update();
|
|
6819
7125
|
}
|
|
7126
|
+
},
|
|
7127
|
+
{
|
|
7128
|
+
key: "applyViewPlugins",
|
|
7129
|
+
value: function applyViewPlugins(view) {
|
|
7130
|
+
var _iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = undefined;
|
|
7131
|
+
try {
|
|
7132
|
+
for(var _iterator = this.viewPlugins[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true){
|
|
7133
|
+
var plugin = _step.value;
|
|
7134
|
+
plugin.apply(view);
|
|
7135
|
+
}
|
|
7136
|
+
} catch (err) {
|
|
7137
|
+
_didIteratorError = true;
|
|
7138
|
+
_iteratorError = err;
|
|
7139
|
+
} finally{
|
|
7140
|
+
try {
|
|
7141
|
+
if (!_iteratorNormalCompletion && _iterator.return != null) {
|
|
7142
|
+
_iterator.return();
|
|
7143
|
+
}
|
|
7144
|
+
} finally{
|
|
7145
|
+
if (_didIteratorError) {
|
|
7146
|
+
throw _iteratorError;
|
|
7147
|
+
}
|
|
7148
|
+
}
|
|
7149
|
+
}
|
|
7150
|
+
}
|
|
7151
|
+
},
|
|
7152
|
+
{
|
|
7153
|
+
key: "createViewPlugins",
|
|
7154
|
+
value: function createViewPlugins() {
|
|
7155
|
+
var pluginOptions = toNodeResolveOptions(this.viewOptions);
|
|
7156
|
+
return [
|
|
7157
|
+
new AssetPlugin(),
|
|
7158
|
+
new SwitchPlugin(pluginOptions),
|
|
7159
|
+
new ApplicabilityPlugin(),
|
|
7160
|
+
new AssetTransformCorePlugin(this.transformRegistry),
|
|
7161
|
+
new StringResolverPlugin(),
|
|
7162
|
+
new TemplatePlugin(pluginOptions),
|
|
7163
|
+
new MultiNodePlugin()
|
|
7164
|
+
];
|
|
7165
|
+
}
|
|
6820
7166
|
}
|
|
6821
7167
|
]);
|
|
6822
7168
|
return ViewController;
|
|
@@ -7189,35 +7535,6 @@ var CommonTypesPlugin = function() {
|
|
|
7189
7535
|
ref: Symbol("not-started"),
|
|
7190
7536
|
status: "not-started"
|
|
7191
7537
|
};
|
|
7192
|
-
var DefaultViewPlugin = /*#__PURE__*/ function() {
|
|
7193
|
-
function DefaultViewPlugin() {
|
|
7194
|
-
_class_call_check(this, DefaultViewPlugin);
|
|
7195
|
-
this.name = "default-view-plugin";
|
|
7196
|
-
}
|
|
7197
|
-
_create_class(DefaultViewPlugin, [
|
|
7198
|
-
{
|
|
7199
|
-
key: "apply",
|
|
7200
|
-
value: function apply(player) {
|
|
7201
|
-
var _this = this;
|
|
7202
|
-
player.hooks.viewController.tap(this.name, function(viewController) {
|
|
7203
|
-
viewController.hooks.view.tap(_this.name, function(view) {
|
|
7204
|
-
var pluginOptions = toNodeResolveOptions(view.resolverOptions);
|
|
7205
|
-
new AssetPlugin().apply(view);
|
|
7206
|
-
new SwitchPlugin(pluginOptions).apply(view);
|
|
7207
|
-
new ApplicabilityPlugin().apply(view);
|
|
7208
|
-
new AssetTransformCorePlugin(viewController.transformRegistry).apply(view);
|
|
7209
|
-
new StringResolverPlugin().apply(view);
|
|
7210
|
-
var templatePlugin = new TemplatePlugin(pluginOptions);
|
|
7211
|
-
templatePlugin.apply(view);
|
|
7212
|
-
view.hooks.onTemplatePluginCreated.call(templatePlugin);
|
|
7213
|
-
new MultiNodePlugin().apply(view);
|
|
7214
|
-
});
|
|
7215
|
-
});
|
|
7216
|
-
}
|
|
7217
|
-
}
|
|
7218
|
-
]);
|
|
7219
|
-
return DefaultViewPlugin;
|
|
7220
|
-
}();
|
|
7221
7538
|
var PLAYER_VERSION = "__VERSION__";
|
|
7222
7539
|
var COMMIT = "__GIT_COMMIT__";
|
|
7223
7540
|
var _Player = /*#__PURE__*/ function() {
|
|
@@ -7229,26 +7546,25 @@ var CommonTypesPlugin = function() {
|
|
|
7229
7546
|
this.constantsController = new ConstantsController();
|
|
7230
7547
|
this.state = NOT_STARTED_STATE;
|
|
7231
7548
|
this.hooks = {
|
|
7232
|
-
|
|
7233
|
-
|
|
7234
|
-
|
|
7235
|
-
|
|
7236
|
-
|
|
7237
|
-
|
|
7238
|
-
|
|
7239
|
-
|
|
7240
|
-
|
|
7241
|
-
|
|
7242
|
-
|
|
7243
|
-
|
|
7549
|
+
flowController: new SyncHook(),
|
|
7550
|
+
viewController: new SyncHook(),
|
|
7551
|
+
view: new SyncHook(),
|
|
7552
|
+
expressionEvaluator: new SyncHook(),
|
|
7553
|
+
dataController: new SyncHook(),
|
|
7554
|
+
schema: new SyncHook(),
|
|
7555
|
+
validationController: new SyncHook(),
|
|
7556
|
+
bindingParser: new SyncHook(),
|
|
7557
|
+
state: new SyncHook(),
|
|
7558
|
+
onStart: new SyncHook(),
|
|
7559
|
+
onEnd: new SyncHook(),
|
|
7560
|
+
resolveFlowContent: new SyncWaterfallHook()
|
|
7244
7561
|
};
|
|
7245
7562
|
if (config === null || config === void 0 ? void 0 : config.logger) {
|
|
7246
7563
|
this.logger.addHandler(config.logger);
|
|
7247
7564
|
}
|
|
7248
7565
|
this.config = config || {};
|
|
7249
7566
|
this.config.plugins = [
|
|
7250
|
-
new DefaultExpPlugin()
|
|
7251
|
-
new DefaultViewPlugin()
|
|
7567
|
+
new DefaultExpPlugin()
|
|
7252
7568
|
].concat(_to_consumable_array(this.config.plugins || []), [
|
|
7253
7569
|
new FlowExpPlugin()
|
|
7254
7570
|
]);
|
|
@@ -7440,10 +7756,90 @@ var CommonTypesPlugin = function() {
|
|
|
7440
7756
|
var value = (_flowInstance_currentState = flowInstance.currentState) === null || _flowInstance_currentState === void 0 ? void 0 : _flowInstance_currentState.value;
|
|
7441
7757
|
if (value && value.state_type === "ACTION") {
|
|
7442
7758
|
var exp = value.exp;
|
|
7443
|
-
|
|
7759
|
+
var result = expressionEvaluator.evaluate(exp);
|
|
7760
|
+
if (isPromiseLike(result)) {
|
|
7761
|
+
_this.logger.warn("Async expression used as return value in in non-async context, transitioning with '*' value");
|
|
7762
|
+
}
|
|
7763
|
+
flowController === null || flowController === void 0 ? void 0 : flowController.transition(String(result));
|
|
7444
7764
|
}
|
|
7445
7765
|
expressionEvaluator.reset();
|
|
7446
7766
|
});
|
|
7767
|
+
var _this1 = _this;
|
|
7768
|
+
flow.hooks.afterTransition.tap("player", function() {
|
|
7769
|
+
var _ref = _async_to_generator(function(flowInstance) {
|
|
7770
|
+
var _flowInstance_currentState, value, exp, result, e;
|
|
7771
|
+
return _ts_generator(this, function(_state) {
|
|
7772
|
+
switch(_state.label){
|
|
7773
|
+
case 0:
|
|
7774
|
+
value = (_flowInstance_currentState = flowInstance.currentState) === null || _flowInstance_currentState === void 0 ? void 0 : _flowInstance_currentState.value;
|
|
7775
|
+
if (!(value && value.state_type === "ASYNC_ACTION")) return [
|
|
7776
|
+
3,
|
|
7777
|
+
8
|
|
7778
|
+
];
|
|
7779
|
+
exp = value.exp;
|
|
7780
|
+
_state.label = 1;
|
|
7781
|
+
case 1:
|
|
7782
|
+
_state.trys.push([
|
|
7783
|
+
1,
|
|
7784
|
+
7,
|
|
7785
|
+
,
|
|
7786
|
+
8
|
|
7787
|
+
]);
|
|
7788
|
+
result = expressionEvaluator.evaluateAsync(exp);
|
|
7789
|
+
if (!isPromiseLike(result)) return [
|
|
7790
|
+
3,
|
|
7791
|
+
5
|
|
7792
|
+
];
|
|
7793
|
+
if (!value.await) return [
|
|
7794
|
+
3,
|
|
7795
|
+
3
|
|
7796
|
+
];
|
|
7797
|
+
return [
|
|
7798
|
+
4,
|
|
7799
|
+
result
|
|
7800
|
+
];
|
|
7801
|
+
case 2:
|
|
7802
|
+
result = _state.sent();
|
|
7803
|
+
return [
|
|
7804
|
+
3,
|
|
7805
|
+
4
|
|
7806
|
+
];
|
|
7807
|
+
case 3:
|
|
7808
|
+
_this1.logger.warn("Unawaited promise used as return value in in non-async context, transitioning with '*' value");
|
|
7809
|
+
_state.label = 4;
|
|
7810
|
+
case 4:
|
|
7811
|
+
return [
|
|
7812
|
+
3,
|
|
7813
|
+
6
|
|
7814
|
+
];
|
|
7815
|
+
case 5:
|
|
7816
|
+
_this1.logger.warn("Non async expression used in async action node");
|
|
7817
|
+
_state.label = 6;
|
|
7818
|
+
case 6:
|
|
7819
|
+
flowController === null || flowController === void 0 ? void 0 : flowController.transition(String(result));
|
|
7820
|
+
return [
|
|
7821
|
+
3,
|
|
7822
|
+
8
|
|
7823
|
+
];
|
|
7824
|
+
case 7:
|
|
7825
|
+
e = _state.sent();
|
|
7826
|
+
flowResultDeferred.reject(e);
|
|
7827
|
+
return [
|
|
7828
|
+
3,
|
|
7829
|
+
8
|
|
7830
|
+
];
|
|
7831
|
+
case 8:
|
|
7832
|
+
expressionEvaluator.reset();
|
|
7833
|
+
return [
|
|
7834
|
+
2
|
|
7835
|
+
];
|
|
7836
|
+
}
|
|
7837
|
+
});
|
|
7838
|
+
});
|
|
7839
|
+
return function(flowInstance) {
|
|
7840
|
+
return _ref.apply(this, arguments);
|
|
7841
|
+
};
|
|
7842
|
+
}());
|
|
7447
7843
|
});
|
|
7448
7844
|
this.hooks.dataController.call(dataController);
|
|
7449
7845
|
validationController.setOptions({
|
|
@@ -7481,11 +7877,9 @@ var CommonTypesPlugin = function() {
|
|
|
7481
7877
|
}),
|
|
7482
7878
|
constants: this.constantsController
|
|
7483
7879
|
});
|
|
7484
|
-
|
|
7485
|
-
|
|
7486
|
-
|
|
7487
|
-
_this.hooks.view.call(view);
|
|
7488
|
-
});
|
|
7880
|
+
viewController.hooks.view.tap("player", function(view) {
|
|
7881
|
+
validationController.onView(view);
|
|
7882
|
+
_this.hooks.view.call(view);
|
|
7489
7883
|
});
|
|
7490
7884
|
this.hooks.viewController.call(viewController);
|
|
7491
7885
|
return {
|