@player-ui/async-node-plugin 0.13.0-next.1 → 0.13.0-next.3

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.
@@ -2576,9 +2576,10 @@ var AsyncNodePlugin = function() {
2576
2576
  var import_timm7 = __toESM(require_timm(), 1);
2577
2577
  var import_timm8 = __toESM(require_timm(), 1);
2578
2578
  var import_p_defer = __toESM(require_p_defer(), 1);
2579
+ var import_queue_microtask = __toESM(require_queue_microtask(), 1);
2579
2580
  var import_p_defer2 = __toESM(require_p_defer(), 1);
2580
2581
  var import_timm9 = __toESM(require_timm(), 1);
2581
- var import_queue_microtask = __toESM(require_queue_microtask(), 1);
2582
+ var import_queue_microtask2 = __toESM(require_queue_microtask(), 1);
2582
2583
  // ../../../../../../../../../../../execroot/_main/bazel-out/k8-fastbuild/bin/node_modules/.aspect_rules_js/@player-ui+partial-match-registry@0.0.0/node_modules/@player-ui/partial-match-registry/dist/index.mjs
2583
2584
  var import_sorted_array = __toESM(require_sorted_array(), 1);
2584
2585
  function traverseObj(object) {
@@ -6079,13 +6080,13 @@ var AsyncNodePlugin = function() {
6079
6080
  this.isTransitioning = false;
6080
6081
  this.hooks = {
6081
6082
  beforeStart: new SyncBailHook(),
6082
- /** A callback when the onStart node was present */ onStart: new SyncHook(),
6083
- /** A callback when the onEnd node was present */ onEnd: new SyncHook(),
6084
- /** A hook to intercept and block a transition */ skipTransition: new SyncBailHook(),
6085
- /** A chance to manipulate the flow-node used to calculate the given transition used */ beforeTransition: new SyncWaterfallHook(),
6086
- /** A chance to manipulate the flow-node calculated after a transition */ resolveTransitionNode: new SyncWaterfallHook(),
6087
- /** A callback when a transition from 1 state to another was made */ transition: new SyncHook(),
6088
- /** A callback to run actions after a transition occurs */ afterTransition: new SyncHook()
6083
+ onStart: new SyncHook(),
6084
+ onEnd: new SyncHook(),
6085
+ skipTransition: new SyncBailHook(),
6086
+ beforeTransition: new SyncWaterfallHook(),
6087
+ resolveTransitionNode: new SyncWaterfallHook(),
6088
+ transition: new SyncHook(),
6089
+ afterTransition: new SyncHook()
6089
6090
  };
6090
6091
  this.id = id;
6091
6092
  this.flow = flow;
@@ -7175,7 +7176,7 @@ var AsyncNodePlugin = function() {
7175
7176
  }
7176
7177
  if (!this.pendingUpdate.scheduled && !silent) {
7177
7178
  this.pendingUpdate.scheduled = true;
7178
- (0, import_queue_microtask.default)(function() {
7179
+ (0, import_queue_microtask2.default)(function() {
7179
7180
  var _this_pendingUpdate, _this_currentView;
7180
7181
  var updates = (_this_pendingUpdate = _this.pendingUpdate) === null || _this_pendingUpdate === void 0 ? void 0 : _this_pendingUpdate.changedBindings;
7181
7182
  _this.pendingUpdate = void 0;
@@ -7844,95 +7845,41 @@ var AsyncNodePlugin = function() {
7844
7845
  validationController.reset();
7845
7846
  }
7846
7847
  });
7847
- flow.hooks.afterTransition.tap("player", function(flowInstance) {
7848
+ flow.hooks.afterTransition.tap("player-action-states", function(flowInstance) {
7848
7849
  var _flowInstance_currentState;
7849
7850
  var value = (_flowInstance_currentState = flowInstance.currentState) === null || _flowInstance_currentState === void 0 ? void 0 : _flowInstance_currentState.value;
7850
- if (value && value.state_type === "ACTION") {
7851
+ if (value && value.state_type === "ASYNC_ACTION") {
7851
7852
  var exp = value.exp;
7852
- var result = expressionEvaluator.evaluate(exp);
7853
- if (isPromiseLike(result)) {
7853
+ try {
7854
+ var result = expressionEvaluator.evaluateAsync(exp);
7855
+ if (isPromiseLike(result)) {
7856
+ if (value.await) {
7857
+ (0, import_queue_microtask.default)(function() {
7858
+ result.then(function(r) {
7859
+ return flowController === null || flowController === void 0 ? void 0 : flowController.transition(String(r));
7860
+ }).catch(flowResultDeferred.reject);
7861
+ });
7862
+ } else {
7863
+ _this.logger.warn("Unawaited promise used as return value in in non-async context, transitioning with '*' value");
7864
+ flowController === null || flowController === void 0 ? void 0 : flowController.transition(String(result));
7865
+ }
7866
+ } else {
7867
+ _this.logger.warn("Non async expression used in async action node");
7868
+ flowController === null || flowController === void 0 ? void 0 : flowController.transition(String(result));
7869
+ }
7870
+ } catch (e) {
7871
+ flowResultDeferred.reject(e);
7872
+ }
7873
+ } else if (value && value.state_type === "ACTION") {
7874
+ var exp1 = value.exp;
7875
+ var result1 = expressionEvaluator.evaluate(exp1);
7876
+ if (isPromiseLike(result1)) {
7854
7877
  _this.logger.warn("Async expression used as return value in in non-async context, transitioning with '*' value");
7855
7878
  }
7856
- flowController === null || flowController === void 0 ? void 0 : flowController.transition(String(result));
7879
+ flowController === null || flowController === void 0 ? void 0 : flowController.transition(String(result1));
7857
7880
  }
7858
7881
  expressionEvaluator.reset();
7859
7882
  });
7860
- var _this1 = _this;
7861
- flow.hooks.afterTransition.tap("player", function() {
7862
- var _ref = _async_to_generator(function(flowInstance) {
7863
- var _flowInstance_currentState, value, exp, result, e;
7864
- return _ts_generator(this, function(_state) {
7865
- switch(_state.label){
7866
- case 0:
7867
- value = (_flowInstance_currentState = flowInstance.currentState) === null || _flowInstance_currentState === void 0 ? void 0 : _flowInstance_currentState.value;
7868
- if (!(value && value.state_type === "ASYNC_ACTION")) return [
7869
- 3,
7870
- 8
7871
- ];
7872
- exp = value.exp;
7873
- _state.label = 1;
7874
- case 1:
7875
- _state.trys.push([
7876
- 1,
7877
- 7,
7878
- ,
7879
- 8
7880
- ]);
7881
- result = expressionEvaluator.evaluateAsync(exp);
7882
- if (!isPromiseLike(result)) return [
7883
- 3,
7884
- 5
7885
- ];
7886
- if (!value.await) return [
7887
- 3,
7888
- 3
7889
- ];
7890
- return [
7891
- 4,
7892
- result
7893
- ];
7894
- case 2:
7895
- result = _state.sent();
7896
- return [
7897
- 3,
7898
- 4
7899
- ];
7900
- case 3:
7901
- _this1.logger.warn("Unawaited promise used as return value in in non-async context, transitioning with '*' value");
7902
- _state.label = 4;
7903
- case 4:
7904
- return [
7905
- 3,
7906
- 6
7907
- ];
7908
- case 5:
7909
- _this1.logger.warn("Non async expression used in async action node");
7910
- _state.label = 6;
7911
- case 6:
7912
- flowController === null || flowController === void 0 ? void 0 : flowController.transition(String(result));
7913
- return [
7914
- 3,
7915
- 8
7916
- ];
7917
- case 7:
7918
- e = _state.sent();
7919
- flowResultDeferred.reject(e);
7920
- return [
7921
- 3,
7922
- 8
7923
- ];
7924
- case 8:
7925
- expressionEvaluator.reset();
7926
- return [
7927
- 2
7928
- ];
7929
- }
7930
- });
7931
- });
7932
- return function(flowInstance) {
7933
- return _ref.apply(this, arguments);
7934
- };
7935
- }());
7936
7883
  });
7937
7884
  this.hooks.dataController.call(dataController);
7938
7885
  validationController.setOptions({
@@ -8096,7 +8043,7 @@ var AsyncNodePlugin = function() {
8096
8043
  commit: COMMIT
8097
8044
  };
8098
8045
  // ../../../../../../../../../../../execroot/_main/bazel-out/k8-fastbuild/bin/plugins/async-node/core/src/index.ts
8099
- var import_queue_microtask2 = __toESM(require_queue_microtask());
8046
+ var import_queue_microtask3 = __toESM(require_queue_microtask());
8100
8047
  var import_timm10 = __toESM(require_timm());
8101
8048
  // ../../../../../../../../../../../execroot/_main/bazel-out/k8-fastbuild/bin/plugins/async-node/core/src/transform.ts
8102
8049
  var asyncTransform = function(assetId, wrapperAssetType, asset, flatten2) {
@@ -8125,7 +8072,8 @@ var AsyncNodePlugin = function() {
8125
8072
  var _this = this;
8126
8073
  _class_call_check(this, AsyncNodePlugin);
8127
8074
  this.hooks = {
8128
- onAsyncNode: new AsyncParallelBailHook()
8075
+ onAsyncNode: new AsyncParallelBailHook(),
8076
+ onAsyncNodeError: new SyncBailHook()
8129
8077
  };
8130
8078
  this.name = "AsyncNode";
8131
8079
  if (options === null || options === void 0 ? void 0 : options.plugins) {
@@ -8159,10 +8107,17 @@ var AsyncNodePlugin = function() {
8159
8107
  }
8160
8108
  }
8161
8109
  _create_class(AsyncNodePlugin, [
8110
+ {
8111
+ key: "getPlayerInstance",
8112
+ value: function getPlayerInstance() {
8113
+ return this.playerInstance;
8114
+ }
8115
+ },
8162
8116
  {
8163
8117
  key: "apply",
8164
8118
  value: function apply(player) {
8165
8119
  var _this = this;
8120
+ this.playerInstance = player;
8166
8121
  player.hooks.viewController.tap(this.name, function(viewController) {
8167
8122
  viewController.hooks.view.tap(_this.name, function(view) {
8168
8123
  var _this_plugins;
@@ -8181,25 +8136,36 @@ var AsyncNodePlugin = function() {
8181
8136
  _class_call_check(this, AsyncNodePluginPlugin);
8182
8137
  this.asyncNode = new AsyncParallelBailHook();
8183
8138
  this.name = "AsyncNode";
8184
- this.resolvedMapping = /* @__PURE__ */ new Map();
8185
8139
  }
8186
8140
  _create_class(AsyncNodePluginPlugin, [
8187
8141
  {
8188
8142
  /**
8143
+ * Parses the node from the result and triggers an asynchronous view update if necessary.
8144
+ * @param node The asynchronous node that might be updated.
8145
+ * @param result The result obtained from resolving the async node. This could be any data structure or value.
8146
+ * @param options Options provided for node resolution, including a potential parseNode function to process the result.
8147
+ * @param view The view instance where the node resides. This can be undefined if the view is not currently active.
8148
+ */ key: "parseNodeAndUpdate",
8149
+ value: function parseNodeAndUpdate(node, context, result, options) {
8150
+ var parsedNode = options.parseNode && result ? options.parseNode(result) : void 0;
8151
+ this.handleAsyncUpdate(node, context, parsedNode);
8152
+ }
8153
+ },
8154
+ {
8155
+ /**
8189
8156
  * Updates the node asynchronously based on the result provided.
8190
8157
  * This method is responsible for handling the update logic of asynchronous nodes.
8191
8158
  * It checks if the node needs to be updated based on the new result and updates the mapping accordingly.
8192
8159
  * If an update is necessary, it triggers an asynchronous update on the view.
8193
8160
  * @param node The asynchronous node that might be updated.
8194
- * @param result The result obtained from resolving the async node. This could be any data structure or value.
8195
- * @param options Options provided for node resolution, including a potential parseNode function to process the result.
8161
+ * @param newNode The new node to replace the async node.
8196
8162
  * @param view The view instance where the node resides. This can be undefined if the view is not currently active.
8197
8163
  */ key: "handleAsyncUpdate",
8198
- value: function handleAsyncUpdate(node, result, options, view) {
8199
- var parsedNode = options.parseNode && result ? options.parseNode(result) : void 0;
8200
- if (this.resolvedMapping.get(node.id) !== parsedNode) {
8201
- this.resolvedMapping.set(node.id, parsedNode ? parsedNode : node);
8202
- view === null || view === void 0 ? void 0 : view.updateAsync();
8164
+ value: function handleAsyncUpdate(node, context, newNode) {
8165
+ var nodeResolveCache = context.nodeResolveCache, view = context.view;
8166
+ if (nodeResolveCache.get(node.id) !== newNode) {
8167
+ nodeResolveCache.set(node.id, newNode ? newNode : node);
8168
+ view.updateAsync();
8203
8169
  }
8204
8170
  }
8205
8171
  },
@@ -8210,47 +8176,80 @@ var AsyncNodePlugin = function() {
8210
8176
  * @param resolver The resolver instance to attach the hook to.
8211
8177
  * @param view
8212
8178
  */ key: "applyResolver",
8213
- value: function applyResolver(resolver) {
8179
+ value: function applyResolver(resolver, context) {
8214
8180
  var _this = this;
8215
8181
  resolver.hooks.beforeResolve.tap(this.name, function(node, options) {
8216
- var resolvedNode;
8217
- if (_this.isAsync(node)) {
8218
- var mappedValue = _this.resolvedMapping.get(node.id);
8219
- if (mappedValue) {
8220
- resolvedNode = mappedValue;
8221
- }
8222
- } else {
8223
- resolvedNode = null;
8224
- }
8225
- var newNode = resolvedNode || node;
8226
- if (!resolvedNode && (node === null || node === void 0 ? void 0 : node.type) === NodeType.Async) {
8227
- var _this1 = _this;
8228
- (0, import_queue_microtask2.default)(/*#__PURE__*/ _async_to_generator(function() {
8229
- var _this_basePlugin, result;
8230
- return _ts_generator(this, function(_state) {
8231
- switch(_state.label){
8232
- case 0:
8233
- return [
8234
- 4,
8235
- (_this_basePlugin = _this1.basePlugin) === null || _this_basePlugin === void 0 ? void 0 : _this_basePlugin.hooks.onAsyncNode.call(node, function(result2) {
8236
- _this1.handleAsyncUpdate(node, result2, options, _this1.currentView);
8237
- })
8238
- ];
8239
- case 1:
8240
- result = _state.sent();
8241
- _this1.handleAsyncUpdate(node, result, options, _this1.currentView);
8242
- return [
8243
- 2
8244
- ];
8245
- }
8246
- });
8247
- }));
8182
+ if (!_this.isAsync(node)) {
8248
8183
  return node;
8249
8184
  }
8250
- return newNode;
8185
+ var resolvedNode = context.nodeResolveCache.get(node.id);
8186
+ if (resolvedNode !== void 0) {
8187
+ return resolvedNode;
8188
+ }
8189
+ (0, import_queue_microtask3.default)(function() {
8190
+ return _this.runAsyncNode(node, context, options);
8191
+ });
8192
+ return node;
8251
8193
  });
8252
8194
  }
8253
8195
  },
8196
+ {
8197
+ key: "runAsyncNode",
8198
+ value: function runAsyncNode(node, context, options) {
8199
+ var _this = this;
8200
+ return _async_to_generator(function() {
8201
+ var _this_basePlugin, result, e, _this_basePlugin1, _options_logger, error, result1, _this_basePlugin_getPlayerInstance, _this_basePlugin2, playerState;
8202
+ return _ts_generator(this, function(_state) {
8203
+ switch(_state.label){
8204
+ case 0:
8205
+ _state.trys.push([
8206
+ 0,
8207
+ 2,
8208
+ ,
8209
+ 3
8210
+ ]);
8211
+ return [
8212
+ 4,
8213
+ (_this_basePlugin = _this.basePlugin) === null || _this_basePlugin === void 0 ? void 0 : _this_basePlugin.hooks.onAsyncNode.call(node, function(result2) {
8214
+ _this.parseNodeAndUpdate(node, context, result2, options);
8215
+ })
8216
+ ];
8217
+ case 1:
8218
+ result = _state.sent();
8219
+ _this.parseNodeAndUpdate(node, context, result, options);
8220
+ return [
8221
+ 3,
8222
+ 3
8223
+ ];
8224
+ case 2:
8225
+ e = _state.sent();
8226
+ error = _instanceof(e, Error) ? e : new Error(String(e));
8227
+ result1 = (_this_basePlugin1 = _this.basePlugin) === null || _this_basePlugin1 === void 0 ? void 0 : _this_basePlugin1.hooks.onAsyncNodeError.call(error, node);
8228
+ if (result1 === void 0) {
8229
+ ;
8230
+ playerState = (_this_basePlugin2 = _this.basePlugin) === null || _this_basePlugin2 === void 0 ? void 0 : (_this_basePlugin_getPlayerInstance = _this_basePlugin2.getPlayerInstance()) === null || _this_basePlugin_getPlayerInstance === void 0 ? void 0 : _this_basePlugin_getPlayerInstance.getState();
8231
+ if ((playerState === null || playerState === void 0 ? void 0 : playerState.status) === "in-progress") {
8232
+ playerState.fail(error);
8233
+ }
8234
+ return [
8235
+ 2
8236
+ ];
8237
+ }
8238
+ (_options_logger = options.logger) === null || _options_logger === void 0 ? void 0 : _options_logger.error("Async node handling failed and resolved with a fallback. Error:", error);
8239
+ _this.parseNodeAndUpdate(node, context, result1, options);
8240
+ return [
8241
+ 3,
8242
+ 3
8243
+ ];
8244
+ case 3:
8245
+ return [
8246
+ 2
8247
+ ];
8248
+ }
8249
+ });
8250
+ })();
8251
+ }
8252
+ },
8254
8253
  {
8255
8254
  key: "isAsync",
8256
8255
  value: function isAsync(node) {
@@ -8297,9 +8296,15 @@ var AsyncNodePlugin = function() {
8297
8296
  {
8298
8297
  key: "apply",
8299
8298
  value: function apply(view) {
8300
- this.currentView = view;
8299
+ var _this = this;
8300
+ var context = {
8301
+ nodeResolveCache: /* @__PURE__ */ new Map(),
8302
+ view: view
8303
+ };
8301
8304
  view.hooks.parser.tap("async", this.applyParser.bind(this));
8302
- view.hooks.resolver.tap("async", this.applyResolver.bind(this));
8305
+ view.hooks.resolver.tap("async", function(resolver) {
8306
+ _this.applyResolver(resolver, context);
8307
+ });
8303
8308
  }
8304
8309
  },
8305
8310
  {