@player-ui/reference-assets-plugin 0.13.0-next.5 → 0.13.0-next.6

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.
@@ -2815,6 +2815,67 @@ var ReferenceAssetsPlugin = function() {
2815
2815
  ]);
2816
2816
  return SyncWaterfallHook;
2817
2817
  }(Hook);
2818
+ var AsyncParallelBailHook = /*#__PURE__*/ function(Hook) {
2819
+ _inherits(AsyncParallelBailHook, Hook);
2820
+ var _super = _create_super(AsyncParallelBailHook);
2821
+ function AsyncParallelBailHook() {
2822
+ _class_call_check(this, AsyncParallelBailHook);
2823
+ return _super.apply(this, arguments);
2824
+ }
2825
+ _create_class(AsyncParallelBailHook, [
2826
+ {
2827
+ key: "call",
2828
+ value: function call() {
2829
+ for(var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++){
2830
+ args[_key] = arguments[_key];
2831
+ }
2832
+ var _this = this;
2833
+ return _async_to_generator(function() {
2834
+ var _this_interceptions, ctx, rtn, e;
2835
+ return _ts_generator(this, function(_state) {
2836
+ switch(_state.label){
2837
+ case 0:
2838
+ ctx = {};
2839
+ (_this_interceptions = _this.interceptions).call.apply(_this_interceptions, [
2840
+ ctx
2841
+ ].concat(_to_consumable_array(args)));
2842
+ _state.label = 1;
2843
+ case 1:
2844
+ _state.trys.push([
2845
+ 1,
2846
+ 3,
2847
+ ,
2848
+ 4
2849
+ ]);
2850
+ return [
2851
+ 4,
2852
+ Promise.race(_this.taps.map(function(tap) {
2853
+ return callTap(tap, args, ctx);
2854
+ }))
2855
+ ];
2856
+ case 2:
2857
+ rtn = _state.sent();
2858
+ _this.interceptions.result(rtn);
2859
+ return [
2860
+ 2,
2861
+ rtn
2862
+ ];
2863
+ case 3:
2864
+ e = _state.sent();
2865
+ _this.interceptions.error(e);
2866
+ throw e;
2867
+ case 4:
2868
+ return [
2869
+ 2
2870
+ ];
2871
+ }
2872
+ });
2873
+ })();
2874
+ }
2875
+ }
2876
+ ]);
2877
+ return AsyncParallelBailHook;
2878
+ }(Hook);
2818
2879
  // ../../../../../../../../../../../execroot/_main/bazel-out/k8-fastbuild/bin/node_modules/.aspect_rules_js/@player-ui+player@0.0.0/node_modules/@player-ui/player/dist/index.mjs
2819
2880
  var import_ts_nested_error = __toESM(require_nested_error(), 1);
2820
2881
  var import_ts_nested_error2 = __toESM(require_nested_error(), 1);
@@ -4874,6 +4935,19 @@ var ReferenceAssetsPlugin = function() {
4874
4935
  ]);
4875
4936
  return ValidatorRegistry;
4876
4937
  }();
4938
+ var NodeType = /* @__PURE__ */ function(NodeType2) {
4939
+ NodeType2["Asset"] = "asset";
4940
+ NodeType2["View"] = "view";
4941
+ NodeType2["Applicability"] = "applicability";
4942
+ NodeType2["Template"] = "template";
4943
+ NodeType2["Value"] = "value";
4944
+ NodeType2["MultiNode"] = "multi-node";
4945
+ NodeType2["Switch"] = "switch";
4946
+ NodeType2["Async"] = "async";
4947
+ NodeType2["Unknown"] = "unknown";
4948
+ NodeType2["Empty"] = "empty";
4949
+ return NodeType2;
4950
+ }(NodeType || {});
4877
4951
  var EMPTY_NODE = {
4878
4952
  type: "empty"
4879
4953
  };
@@ -8280,6 +8354,266 @@ var ReferenceAssetsPlugin = function() {
8280
8354
  ], multiNode);
8281
8355
  return wrapperAsset;
8282
8356
  };
8357
+ var AsyncNodePluginSymbol = Symbol.for("AsyncNodePlugin");
8358
+ var _AsyncNodePlugin = /*#__PURE__*/ function() {
8359
+ function _AsyncNodePlugin2(options, asyncHandler) {
8360
+ var _this = this;
8361
+ _class_call_check(this, _AsyncNodePlugin2);
8362
+ this.symbol = _AsyncNodePlugin2.Symbol;
8363
+ this.hooks = {
8364
+ onAsyncNode: new AsyncParallelBailHook(),
8365
+ onAsyncNodeError: new SyncBailHook()
8366
+ };
8367
+ this.name = "AsyncNode";
8368
+ if (options === null || options === void 0 ? void 0 : options.plugins) {
8369
+ this.plugins = options.plugins;
8370
+ options.plugins.forEach(function(plugin) {
8371
+ plugin.applyPlugin(_this);
8372
+ });
8373
+ }
8374
+ if (asyncHandler) {
8375
+ this.hooks.onAsyncNode.tap("async", function() {
8376
+ var _ref = _async_to_generator(function(node, callback) {
8377
+ return _ts_generator(this, function(_state) {
8378
+ switch(_state.label){
8379
+ case 0:
8380
+ return [
8381
+ 4,
8382
+ asyncHandler(node, callback)
8383
+ ];
8384
+ case 1:
8385
+ return [
8386
+ 2,
8387
+ _state.sent()
8388
+ ];
8389
+ }
8390
+ });
8391
+ });
8392
+ return function(node, callback) {
8393
+ return _ref.apply(this, arguments);
8394
+ };
8395
+ }());
8396
+ }
8397
+ }
8398
+ _create_class(_AsyncNodePlugin2, [
8399
+ {
8400
+ key: "getPlayerInstance",
8401
+ value: function getPlayerInstance() {
8402
+ return this.playerInstance;
8403
+ }
8404
+ },
8405
+ {
8406
+ key: "apply",
8407
+ value: function apply(player) {
8408
+ var _this = this;
8409
+ this.playerInstance = player;
8410
+ player.hooks.viewController.tap(this.name, function(viewController) {
8411
+ viewController.hooks.view.tap(_this.name, function(view) {
8412
+ var _this_plugins;
8413
+ (_this_plugins = _this.plugins) === null || _this_plugins === void 0 ? void 0 : _this_plugins.forEach(function(plugin) {
8414
+ plugin.apply(view);
8415
+ });
8416
+ });
8417
+ });
8418
+ }
8419
+ }
8420
+ ]);
8421
+ return _AsyncNodePlugin2;
8422
+ }();
8423
+ _AsyncNodePlugin.Symbol = AsyncNodePluginSymbol;
8424
+ var AsyncNodePlugin = _AsyncNodePlugin;
8425
+ var AsyncNodePluginPlugin = /*#__PURE__*/ function() {
8426
+ function AsyncNodePluginPlugin() {
8427
+ _class_call_check(this, AsyncNodePluginPlugin);
8428
+ this.asyncNode = new AsyncParallelBailHook();
8429
+ this.name = "AsyncNode";
8430
+ }
8431
+ _create_class(AsyncNodePluginPlugin, [
8432
+ {
8433
+ /**
8434
+ * Parses the node from the result and triggers an asynchronous view update if necessary.
8435
+ * @param node The asynchronous node that might be updated.
8436
+ * @param result The result obtained from resolving the async node. This could be any data structure or value.
8437
+ * @param options Options provided for node resolution, including a potential parseNode function to process the result.
8438
+ * @param view The view instance where the node resides. This can be undefined if the view is not currently active.
8439
+ */ key: "parseNodeAndUpdate",
8440
+ value: function parseNodeAndUpdate(node, context, result, options) {
8441
+ var parsedNode = options.parseNode && result ? options.parseNode(result) : void 0;
8442
+ this.handleAsyncUpdate(node, context, parsedNode);
8443
+ }
8444
+ },
8445
+ {
8446
+ /**
8447
+ * Updates the node asynchronously based on the result provided.
8448
+ * This method is responsible for handling the update logic of asynchronous nodes.
8449
+ * It checks if the node needs to be updated based on the new result and updates the mapping accordingly.
8450
+ * If an update is necessary, it triggers an asynchronous update on the view.
8451
+ * @param node The asynchronous node that might be updated.
8452
+ * @param newNode The new node to replace the async node.
8453
+ * @param view The view instance where the node resides. This can be undefined if the view is not currently active.
8454
+ */ key: "handleAsyncUpdate",
8455
+ value: function handleAsyncUpdate(node, context, newNode) {
8456
+ var nodeResolveCache = context.nodeResolveCache, view = context.view;
8457
+ if (nodeResolveCache.get(node.id) !== newNode) {
8458
+ nodeResolveCache.set(node.id, newNode ? newNode : node);
8459
+ view.updateAsync();
8460
+ }
8461
+ }
8462
+ },
8463
+ {
8464
+ /**
8465
+ * Handles the asynchronous API integration for resolving nodes.
8466
+ * This method sets up a hook on the resolver's `beforeResolve` event to process async nodes.
8467
+ * @param resolver The resolver instance to attach the hook to.
8468
+ * @param view
8469
+ */ key: "applyResolver",
8470
+ value: function applyResolver(resolver, context) {
8471
+ var _this = this;
8472
+ resolver.hooks.beforeResolve.tap(this.name, function(node, options) {
8473
+ if (!_this.isAsync(node)) {
8474
+ return node;
8475
+ }
8476
+ var resolvedNode = context.nodeResolveCache.get(node.id);
8477
+ if (resolvedNode !== void 0) {
8478
+ return resolvedNode;
8479
+ }
8480
+ if (context.inProgressNodes.has(node.id)) {
8481
+ return node;
8482
+ }
8483
+ context.inProgressNodes.add(node.id);
8484
+ (0, import_queue_microtask3.default)(function() {
8485
+ _this.runAsyncNode(node, context, options).finally();
8486
+ });
8487
+ return node;
8488
+ });
8489
+ }
8490
+ },
8491
+ {
8492
+ key: "runAsyncNode",
8493
+ value: function runAsyncNode(node, context, options) {
8494
+ var _this = this;
8495
+ return _async_to_generator(function() {
8496
+ var _this_basePlugin, result, e, _this_basePlugin1, _options_logger, error, result1, _this_basePlugin_getPlayerInstance, _this_basePlugin2, playerState;
8497
+ return _ts_generator(this, function(_state) {
8498
+ switch(_state.label){
8499
+ case 0:
8500
+ _state.trys.push([
8501
+ 0,
8502
+ 2,
8503
+ ,
8504
+ 3
8505
+ ]);
8506
+ return [
8507
+ 4,
8508
+ (_this_basePlugin = _this.basePlugin) === null || _this_basePlugin === void 0 ? void 0 : _this_basePlugin.hooks.onAsyncNode.call(node, function(result2) {
8509
+ _this.parseNodeAndUpdate(node, context, result2, options);
8510
+ })
8511
+ ];
8512
+ case 1:
8513
+ result = _state.sent();
8514
+ context.inProgressNodes.delete(node.id);
8515
+ _this.parseNodeAndUpdate(node, context, result, options);
8516
+ return [
8517
+ 3,
8518
+ 3
8519
+ ];
8520
+ case 2:
8521
+ e = _state.sent();
8522
+ error = _instanceof(e, Error) ? e : new Error(String(e));
8523
+ result1 = (_this_basePlugin1 = _this.basePlugin) === null || _this_basePlugin1 === void 0 ? void 0 : _this_basePlugin1.hooks.onAsyncNodeError.call(error, node);
8524
+ if (result1 === void 0) {
8525
+ ;
8526
+ 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();
8527
+ if ((playerState === null || playerState === void 0 ? void 0 : playerState.status) === "in-progress") {
8528
+ playerState.fail(error);
8529
+ }
8530
+ return [
8531
+ 2
8532
+ ];
8533
+ }
8534
+ (_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);
8535
+ context.inProgressNodes.delete(node.id);
8536
+ _this.parseNodeAndUpdate(node, context, result1, options);
8537
+ return [
8538
+ 3,
8539
+ 3
8540
+ ];
8541
+ case 3:
8542
+ return [
8543
+ 2
8544
+ ];
8545
+ }
8546
+ });
8547
+ })();
8548
+ }
8549
+ },
8550
+ {
8551
+ key: "isAsync",
8552
+ value: function isAsync(node) {
8553
+ return (node === null || node === void 0 ? void 0 : node.type) === NodeType.Async;
8554
+ }
8555
+ },
8556
+ {
8557
+ key: "isDeterminedAsync",
8558
+ value: function isDeterminedAsync(obj) {
8559
+ return obj && Object.prototype.hasOwnProperty.call(obj, "async");
8560
+ }
8561
+ },
8562
+ {
8563
+ key: "applyParser",
8564
+ value: function applyParser(parser) {
8565
+ var _this = this;
8566
+ parser.hooks.parseNode.tap(this.name, function(obj, nodeType, options, childOptions) {
8567
+ if (_this.isDeterminedAsync(obj)) {
8568
+ var parsedAsync = parser.parseObject((0, import_timm10.omit)(obj, "async"), nodeType, options);
8569
+ var parsedNodeId = getNodeID(parsedAsync);
8570
+ if (parsedAsync === null || !parsedNodeId) {
8571
+ return childOptions ? [] : null;
8572
+ }
8573
+ var asyncAST = parser.createASTNode({
8574
+ id: parsedNodeId,
8575
+ type: NodeType.Async,
8576
+ value: parsedAsync
8577
+ }, obj);
8578
+ if (childOptions) {
8579
+ return asyncAST ? [
8580
+ {
8581
+ path: _to_consumable_array(childOptions.path).concat([
8582
+ childOptions.key
8583
+ ]),
8584
+ value: asyncAST
8585
+ }
8586
+ ] : [];
8587
+ }
8588
+ return asyncAST;
8589
+ }
8590
+ });
8591
+ }
8592
+ },
8593
+ {
8594
+ key: "apply",
8595
+ value: function apply(view) {
8596
+ var _this = this;
8597
+ var context = {
8598
+ nodeResolveCache: /* @__PURE__ */ new Map(),
8599
+ inProgressNodes: /* @__PURE__ */ new Set(),
8600
+ view: view
8601
+ };
8602
+ view.hooks.parser.tap("async", this.applyParser.bind(this));
8603
+ view.hooks.resolver.tap("async", function(resolver) {
8604
+ _this.applyResolver(resolver, context);
8605
+ });
8606
+ }
8607
+ },
8608
+ {
8609
+ key: "applyPlugin",
8610
+ value: function applyPlugin(asyncNodePlugin) {
8611
+ this.basePlugin = asyncNodePlugin;
8612
+ }
8613
+ }
8614
+ ]);
8615
+ return AsyncNodePluginPlugin;
8616
+ }();
8283
8617
  // ../../../../../../../../../../../execroot/_main/bazel-out/k8-fastbuild/bin/plugins/reference-assets/core/src/assets/chat-message/transform.ts
8284
8618
  var transform2 = function(asset) {
8285
8619
  var _asset_children_, _asset_children;
@@ -8290,13 +8624,155 @@ var ReferenceAssetsPlugin = function() {
8290
8624
  return asyncTransform(asset.value.id, "collection", newAsset);
8291
8625
  };
8292
8626
  var chatMessageTransform = compose(composeBefore(transform2));
8293
- // ../../../../../../../../../../../execroot/_main/bazel-out/k8-fastbuild/bin/plugins/reference-assets/core/src/plugin.ts
8294
- var ReferenceAssetsPlugin = /*#__PURE__*/ function() {
8295
- function ReferenceAssetsPlugin() {
8296
- _class_call_check(this, ReferenceAssetsPlugin);
8627
+ // ../../../../../../../../../../../execroot/_main/bazel-out/k8-fastbuild/bin/node_modules/.aspect_rules_js/@player-ui+meta-plugin@0.0.0/node_modules/@player-ui/meta-plugin/dist/index.mjs
8628
+ var MetaPlugin = /*#__PURE__*/ function() {
8629
+ function MetaPlugin() {
8630
+ var plugins = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : [];
8631
+ _class_call_check(this, MetaPlugin);
8632
+ this.name = "meta-plugin";
8633
+ this.plugins = plugins;
8634
+ }
8635
+ _create_class(MetaPlugin, [
8636
+ {
8637
+ key: "apply",
8638
+ value: function apply(player) {
8639
+ this.plugins.forEach(function(plugin) {
8640
+ return player.registerPlugin(plugin);
8641
+ });
8642
+ }
8643
+ }
8644
+ ]);
8645
+ return MetaPlugin;
8646
+ }();
8647
+ // ../../../../../../../../../../../execroot/_main/bazel-out/k8-fastbuild/bin/node_modules/.aspect_rules_js/@player-ui+expression-plugin@0.0.0/node_modules/@player-ui/expression-plugin/dist/index.mjs
8648
+ var ExpressionPlugin = /*#__PURE__*/ function() {
8649
+ function ExpressionPlugin(expressionMap) {
8650
+ _class_call_check(this, ExpressionPlugin);
8651
+ this.name = "ExpressionPlugin";
8652
+ this.expressions = expressionMap;
8653
+ }
8654
+ _create_class(ExpressionPlugin, [
8655
+ {
8656
+ key: "apply",
8657
+ value: function apply(player) {
8658
+ var _this = this;
8659
+ player.hooks.expressionEvaluator.tap(this.name, function(expEvaluator) {
8660
+ _this.expressions.forEach(function(handler, name) {
8661
+ expEvaluator.addExpressionFunction(name, handler);
8662
+ });
8663
+ });
8664
+ }
8665
+ }
8666
+ ]);
8667
+ return ExpressionPlugin;
8668
+ }();
8669
+ // ../../../../../../../../../../../execroot/_main/bazel-out/k8-fastbuild/bin/plugins/reference-assets/core/src/plugins/chat-ui-demo-plugin.ts
8670
+ var createContentFromMessage = function(message, id) {
8671
+ return {
8672
+ asset: {
8673
+ type: "chat-message",
8674
+ id: id,
8675
+ value: {
8676
+ asset: {
8677
+ type: "text",
8678
+ id: "".concat(id, "-value"),
8679
+ value: message
8680
+ }
8681
+ }
8682
+ }
8683
+ };
8684
+ };
8685
+ var ChatUiDemoPlugin = /*#__PURE__*/ function() {
8686
+ function ChatUiDemoPlugin() {
8687
+ _class_call_check(this, ChatUiDemoPlugin);
8688
+ this.name = "chat-ui-demo-plugin";
8689
+ }
8690
+ _create_class(ChatUiDemoPlugin, [
8691
+ {
8692
+ key: "apply",
8693
+ value: function apply(player) {
8694
+ var asyncNodePlugin = player.findPlugin(AsyncNodePlugin.Symbol);
8695
+ if (!asyncNodePlugin) {
8696
+ player.logger.warn("Failed to apply '".concat(this.name, "'. Reason: Could not find AsyncNodePlugin."));
8697
+ return;
8698
+ }
8699
+ var deferredPromises = {};
8700
+ var allPromiseKeys = [];
8701
+ var counter = 0;
8702
+ var sendMessage = function(context, message, nodeId) {
8703
+ if (nodeId && !(nodeId in deferredPromises)) {
8704
+ var _context_logger;
8705
+ (_context_logger = context.logger) === null || _context_logger === void 0 ? void 0 : _context_logger.warn("'send' expression called with unrecognized id '".concat(nodeId, "'"));
8706
+ return;
8707
+ }
8708
+ if (!nodeId && allPromiseKeys.length === 0) {
8709
+ var _context_logger1;
8710
+ (_context_logger1 = context.logger) === null || _context_logger1 === void 0 ? void 0 : _context_logger1.warn("'send' called with no waiting async nodes");
8711
+ return;
8712
+ }
8713
+ var keys = nodeId ? [
8714
+ nodeId
8715
+ ] : allPromiseKeys;
8716
+ var _iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = undefined;
8717
+ try {
8718
+ for(var _iterator = keys[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true){
8719
+ var id = _step.value;
8720
+ var content = createContentFromMessage(message, "message-".concat(counter++));
8721
+ var resolveFunction = deferredPromises[id];
8722
+ resolveFunction === null || resolveFunction === void 0 ? void 0 : resolveFunction(content);
8723
+ delete deferredPromises[id];
8724
+ }
8725
+ } catch (err) {
8726
+ _didIteratorError = true;
8727
+ _iteratorError = err;
8728
+ } finally{
8729
+ try {
8730
+ if (!_iteratorNormalCompletion && _iterator.return != null) {
8731
+ _iterator.return();
8732
+ }
8733
+ } finally{
8734
+ if (_didIteratorError) {
8735
+ throw _iteratorError;
8736
+ }
8737
+ }
8738
+ }
8739
+ if (nodeId) {
8740
+ var index = allPromiseKeys.indexOf(nodeId);
8741
+ allPromiseKeys.splice(index, 1);
8742
+ } else {
8743
+ allPromiseKeys = [];
8744
+ }
8745
+ };
8746
+ asyncNodePlugin.hooks.onAsyncNode.tap(this.name, function(node) {
8747
+ return new Promise(function(res) {
8748
+ deferredPromises[node.id] = res;
8749
+ allPromiseKeys.push(node.id);
8750
+ });
8751
+ });
8752
+ player.hooks.view.tap(this.name, function(_) {
8753
+ deferredPromises = {};
8754
+ allPromiseKeys = [];
8755
+ counter = 0;
8756
+ });
8757
+ var expressionPlugin = new ExpressionPlugin(/* @__PURE__ */ new Map([
8758
+ [
8759
+ "send",
8760
+ sendMessage
8761
+ ]
8762
+ ]));
8763
+ player.registerPlugin(expressionPlugin);
8764
+ }
8765
+ }
8766
+ ]);
8767
+ return ChatUiDemoPlugin;
8768
+ }();
8769
+ // ../../../../../../../../../../../execroot/_main/bazel-out/k8-fastbuild/bin/plugins/reference-assets/core/src/plugins/reference-assets-transform-plugin.ts
8770
+ var ReferenceAssetsTransformPlugin = /*#__PURE__*/ function() {
8771
+ function ReferenceAssetsTransformPlugin() {
8772
+ _class_call_check(this, ReferenceAssetsTransformPlugin);
8297
8773
  this.name = "reference-assets-transforms";
8298
8774
  }
8299
- _create_class(ReferenceAssetsPlugin, [
8775
+ _create_class(ReferenceAssetsTransformPlugin, [
8300
8776
  {
8301
8777
  key: "apply",
8302
8778
  value: function apply(player) {
@@ -8341,6 +8817,31 @@ var ReferenceAssetsPlugin = function() {
8341
8817
  }
8342
8818
  }
8343
8819
  ]);
8820
+ return ReferenceAssetsTransformPlugin;
8821
+ }();
8822
+ // ../../../../../../../../../../../execroot/_main/bazel-out/k8-fastbuild/bin/plugins/reference-assets/core/src/plugin.ts
8823
+ var ReferenceAssetsPlugin = /*#__PURE__*/ function() {
8824
+ function ReferenceAssetsPlugin() {
8825
+ _class_call_check(this, ReferenceAssetsPlugin);
8826
+ this.name = "reference-assets-plugin";
8827
+ this.metaPlugin = new MetaPlugin([
8828
+ new AsyncNodePlugin({
8829
+ plugins: [
8830
+ new AsyncNodePluginPlugin()
8831
+ ]
8832
+ }),
8833
+ new ReferenceAssetsTransformPlugin(),
8834
+ new ChatUiDemoPlugin()
8835
+ ]);
8836
+ }
8837
+ _create_class(ReferenceAssetsPlugin, [
8838
+ {
8839
+ key: "apply",
8840
+ value: function apply(player) {
8841
+ player.registerPlugin(this.metaPlugin);
8842
+ }
8843
+ }
8844
+ ]);
8344
8845
  return ReferenceAssetsPlugin;
8345
8846
  }();
8346
8847
  return __toCommonJS(src_exports);