@player-ui/async-node-plugin 0.14.0-next.2 → 0.14.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.
@@ -171,7 +171,8 @@ var createAsyncTransform = (options) => {
171
171
  getNestedAsset,
172
172
  getAsyncNodeId = defaultGetNodeId,
173
173
  path = ["values"],
174
- flatten = true
174
+ flatten = true,
175
+ asyncNodePosition = "append"
175
176
  } = options;
176
177
  const replaceNode = (node) => {
177
178
  const unwrapped = unwrapAsset(node);
@@ -187,19 +188,23 @@ var createAsyncTransform = (options) => {
187
188
  const asset = getNestedAsset?.(node);
188
189
  const replaceFunction = flatten ? replacer : void 0;
189
190
  const asyncNode = import_player5.Builder.asyncNode(id, flatten, replaceFunction);
190
- let multiNode;
191
+ const values = [asyncNode];
191
192
  if (asset) {
193
+ const otherValues = [];
192
194
  if (requiresAssetWrapper(asset)) {
193
- const assetWrappedNode = import_player5.Builder.assetWrapper(asset);
194
- multiNode = import_player5.Builder.multiNode(assetWrappedNode, asyncNode);
195
+ otherValues.push(import_player5.Builder.assetWrapper(asset));
195
196
  } else if (asset.type === import_player5.NodeType.MultiNode) {
196
- multiNode = import_player5.Builder.multiNode(...asset.values, asyncNode);
197
+ otherValues.push(...asset.values);
197
198
  } else {
198
- multiNode = import_player5.Builder.multiNode(asset, asyncNode);
199
+ otherValues.push(asset);
200
+ }
201
+ if (asyncNodePosition === "append") {
202
+ values.unshift(...otherValues);
203
+ } else {
204
+ values.push(...otherValues);
199
205
  }
200
- } else {
201
- multiNode = import_player5.Builder.multiNode(asyncNode);
202
206
  }
207
+ const multiNode = import_player5.Builder.multiNode(...values);
203
208
  const wrapperAsset = import_player5.Builder.asset({
204
209
  id: wrapperAssetType + "-" + id,
205
210
  type: wrapperAssetType
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../../../../../../../../../../execroot/_main/bazel-out/k8-fastbuild/bin/plugins/async-node/core/src/index.ts","../../../../../../../../../../../../../execroot/_main/bazel-out/k8-fastbuild/bin/plugins/async-node/core/src/transform.ts","../../../../../../../../../../../../../execroot/_main/bazel-out/k8-fastbuild/bin/plugins/async-node/core/src/createAsyncTransform.ts","../../../../../../../../../../../../../execroot/_main/bazel-out/k8-fastbuild/bin/plugins/async-node/core/src/utils/extractNodeFromPath.ts","../../../../../../../../../../../../../execroot/_main/bazel-out/k8-fastbuild/bin/plugins/async-node/core/src/utils/traverseAndReplace.ts","../../../../../../../../../../../../../execroot/_main/bazel-out/k8-fastbuild/bin/plugins/async-node/core/src/utils/unwrapAsset.ts","../../../../../../../../../../../../../execroot/_main/bazel-out/k8-fastbuild/bin/plugins/async-node/core/src/utils/requiresAssetWrapper.ts"],"sourcesContent":["import { NodeType, getNodeID } from \"@player-ui/player\";\nimport type {\n Player,\n PlayerPlugin,\n Node,\n ParseObjectOptions,\n ParseObjectChildOptions,\n ViewInstance,\n Parser,\n ViewPlugin,\n Resolver,\n Resolve,\n} from \"@player-ui/player\";\nimport { AsyncParallelBailHook, SyncBailHook } from \"tapable-ts\";\nimport queueMicrotask from \"queue-microtask\";\n\nexport * from \"./types\";\nexport * from \"./transform\";\nexport * from \"./createAsyncTransform\";\n\n/** Object type for storing data related to a single `apply` of the `AsyncNodePluginPlugin`\n * This object should be setup once per ViewInstance to keep any cached info just for that view to avoid conflicts of shared async node ids across different view states.\n */\ntype AsyncPluginContext = {\n /** Map of async node id to resolved content */\n nodeResolveCache: Map<string, any>;\n /** The view instance this context is attached to. */\n view: ViewInstance;\n /** Map of async node id to promises being used to resolve them */\n inProgressNodes: Set<string>;\n};\n\nexport interface AsyncNodePluginOptions {\n /** A set of plugins to load */\n plugins?: AsyncNodeViewPlugin[];\n}\n\nexport interface AsyncNodeViewPlugin extends ViewPlugin {\n /** Use this to tap into the async node plugin hooks */\n applyPlugin: (asyncNodePlugin: AsyncNodePlugin) => void;\n\n asyncNode: AsyncParallelBailHook<[Node.Async, (result: any) => void], any>;\n}\nexport type AsyncHandler = (\n node: Node.Async,\n callback?: (result: any) => void,\n) => Promise<any>;\n\nexport type AsyncContent = {\n async: true;\n flatten?: boolean;\n [key: string]: unknown;\n};\n\n/** Hook declaration for the AsyncNodePlugin */\nexport type AsyncNodeHooks = {\n /** Async hook to get content for an async node */\n onAsyncNode: AsyncParallelBailHook<[Node.Async, (result: any) => void], any>;\n /** Sync hook to manage errors coming from the onAsyncNode hook. Return a fallback node or null to render a fallback. The first argument of passed in the call is the error thrown. */\n onAsyncNodeError: SyncBailHook<[Error, Node.Async], any>;\n};\n\nexport const AsyncNodePluginSymbol: symbol = Symbol.for(\"AsyncNodePlugin\");\n\n/**\n * Async node plugin used to resolve async nodes in the content\n * If an async node is present, allow users to provide a replacement node to be rendered when ready\n */\nexport class AsyncNodePlugin implements PlayerPlugin {\n private plugins: AsyncNodeViewPlugin[] | undefined;\n private playerInstance: Player | undefined;\n\n static Symbol: symbol = AsyncNodePluginSymbol;\n public readonly symbol: symbol = AsyncNodePlugin.Symbol;\n\n constructor(options: AsyncNodePluginOptions, asyncHandler?: AsyncHandler) {\n if (options?.plugins) {\n this.plugins = options.plugins;\n options.plugins.forEach((plugin) => {\n plugin.applyPlugin(this);\n });\n }\n\n if (asyncHandler) {\n this.hooks.onAsyncNode.tap(\n \"async\",\n async (node: Node.Async, callback) => {\n return await asyncHandler(node, callback);\n },\n );\n }\n }\n\n public readonly hooks: AsyncNodeHooks = {\n onAsyncNode: new AsyncParallelBailHook(),\n onAsyncNodeError: new SyncBailHook(),\n };\n\n getPlayerInstance(): Player | undefined {\n return this.playerInstance;\n }\n\n name = \"AsyncNode\";\n\n apply(player: Player): void {\n this.playerInstance = player;\n\n player.hooks.viewController.tap(this.name, (viewController) => {\n viewController.hooks.view.tap(this.name, (view) => {\n this.plugins?.forEach((plugin) => {\n plugin.apply(view);\n });\n });\n });\n }\n}\n\nexport class AsyncNodePluginPlugin implements AsyncNodeViewPlugin {\n public asyncNode: AsyncParallelBailHook<\n [Node.Async, (result: any) => void],\n any\n > = new AsyncParallelBailHook();\n private basePlugin: AsyncNodePlugin | undefined;\n\n name = \"AsyncNode\";\n\n /**\n * Parses the node from the result and triggers an asynchronous view update if necessary.\n * @param node The asynchronous node that might be updated.\n * @param result The result obtained from resolving the async node. This could be any data structure or value.\n * @param options Options provided for node resolution, including a potential parseNode function to process the result.\n * @param view The view instance where the node resides. This can be undefined if the view is not currently active.\n */\n private parseNodeAndUpdate(\n node: Node.Async,\n context: AsyncPluginContext,\n result: any,\n options: Resolve.NodeResolveOptions,\n ) {\n let parsedNode =\n options.parseNode && result ? options.parseNode(result) : undefined;\n\n if (parsedNode && node.onValueReceived) {\n parsedNode = node.onValueReceived(parsedNode);\n }\n\n this.handleAsyncUpdate(node, context, parsedNode);\n }\n\n /**\n * Updates the node asynchronously based on the result provided.\n * This method is responsible for handling the update logic of asynchronous nodes.\n * It checks if the node needs to be updated based on the new result and updates the mapping accordingly.\n * If an update is necessary, it triggers an asynchronous update on the view.\n * @param node The asynchronous node that might be updated.\n * @param newNode The new node to replace the async node.\n * @param view The view instance where the node resides. This can be undefined if the view is not currently active.\n */\n private handleAsyncUpdate(\n node: Node.Async,\n context: AsyncPluginContext,\n newNode?: Node.Node | null,\n ) {\n const { nodeResolveCache, view } = context;\n if (nodeResolveCache.get(node.id) !== newNode) {\n nodeResolveCache.set(node.id, newNode ? newNode : node);\n view.updateAsync(node.id);\n }\n }\n\n private hasValidMapping(\n node: Node.Async,\n context: AsyncPluginContext,\n ): boolean {\n const { nodeResolveCache } = context;\n return (\n nodeResolveCache.has(node.id) && nodeResolveCache.get(node.id) !== node\n );\n }\n\n /**\n * Handles the asynchronous API integration for resolving nodes.\n * This method sets up a hook on the resolver's `beforeResolve` event to process async nodes.\n * @param resolver The resolver instance to attach the hook to.\n * @param view\n */\n applyResolver(resolver: Resolver, context: AsyncPluginContext): void {\n resolver.hooks.beforeResolve.tap(this.name, (node, options) => {\n if (!this.isAsync(node)) {\n return node === null ? node : this.resolveAsyncChildren(node, context);\n }\n\n const resolvedNode = context.nodeResolveCache.get(node.id);\n if (resolvedNode !== undefined) {\n return this.resolveAsyncChildren(resolvedNode, context);\n }\n\n if (context.inProgressNodes.has(node.id)) {\n return node;\n }\n\n // Track that the node is in progress.\n context.inProgressNodes.add(node.id);\n queueMicrotask(() => {\n this.runAsyncNode(node, context, options).finally();\n });\n\n return node;\n });\n }\n\n /**\n * Replaces child async nodes with their resolved content and flattens when necessary. Resolving the children directly helps manage the `parent` reference without needing as much work within the resolver itself.\n * Handles async node chains as well to make sure all applicable nodes can get flattened.\n * @param node - The node whose children need to be resolved.\n * @param context - the async plugin context needed to reach into the cache\n * @returns The same node but with async node children mapped to their resolved AST.\n */\n private resolveAsyncChildren(\n node: Node.Node,\n context: AsyncPluginContext,\n ): Node.Node {\n const asyncNodesResolved: string[] = node.asyncNodesResolved ?? [];\n node.asyncNodesResolved = asyncNodesResolved;\n if (node.type === NodeType.MultiNode) {\n // Using a while loop lets us catch when async nodes produce more async nodes that need to be flattened further\n let index = 0;\n while (index < node.values.length) {\n const childNode = node.values[index];\n if (\n childNode?.type !== NodeType.Async ||\n !this.hasValidMapping(childNode, context)\n ) {\n index++;\n continue;\n }\n\n const mappedNode = context.nodeResolveCache.get(childNode.id);\n asyncNodesResolved.push(childNode.id);\n if (mappedNode.type === NodeType.MultiNode && childNode.flatten) {\n mappedNode.values.forEach((v: Node.Node) => (v.parent = node));\n node.values = [\n ...node.values.slice(0, index),\n ...mappedNode.values,\n ...node.values.slice(index + 1),\n ];\n } else {\n node.values[index] = mappedNode;\n mappedNode.parent = node;\n }\n }\n } else if (\"children\" in node) {\n node.children?.forEach((c) => {\n // Similar to above, using a while loop lets us handle when async nodes produce more async nodes.\n while (\n c.value.type === NodeType.Async &&\n this.hasValidMapping(c.value, context)\n ) {\n asyncNodesResolved.push(c.value.id);\n c.value = context.nodeResolveCache.get(c.value.id);\n c.value.parent = node;\n }\n });\n }\n\n return node;\n }\n\n private async runAsyncNode(\n node: Node.Async,\n context: AsyncPluginContext,\n options: Resolve.NodeResolveOptions,\n ) {\n try {\n const result = await this.basePlugin?.hooks.onAsyncNode.call(\n node,\n (result) => {\n this.parseNodeAndUpdate(node, context, result, options);\n },\n );\n\n // Stop tracking before the next update is triggered\n context.inProgressNodes.delete(node.id);\n this.parseNodeAndUpdate(node, context, result, options);\n } catch (e: unknown) {\n const error = e instanceof Error ? e : new Error(String(e));\n const result = this.basePlugin?.hooks.onAsyncNodeError.call(error, node);\n\n if (result === undefined) {\n const playerState = this.basePlugin?.getPlayerInstance()?.getState();\n\n if (playerState?.status === \"in-progress\") {\n playerState.fail(error);\n }\n\n return;\n }\n\n options.logger?.error(\n \"Async node handling failed and resolved with a fallback. Error:\",\n error,\n );\n\n // Stop tracking before the next update is triggered\n context.inProgressNodes.delete(node.id);\n this.parseNodeAndUpdate(node, context, result, options);\n }\n }\n\n private isAsync(node: Node.Node | null): node is Node.Async {\n return node?.type === NodeType.Async;\n }\n\n private isDeterminedAsync(obj: unknown): obj is AsyncContent {\n return (\n typeof obj === \"object\" &&\n obj !== null &&\n Object.prototype.hasOwnProperty.call(obj, \"async\")\n );\n }\n\n applyParser(parser: Parser): void {\n parser.hooks.parseNode.tap(\n this.name,\n (\n obj: any,\n nodeType: Node.ChildrenTypes,\n options: ParseObjectOptions,\n childOptions?: ParseObjectChildOptions,\n ) => {\n if (this.isDeterminedAsync(obj)) {\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\n const { async, flatten, ...rest } = obj;\n const parsedAsync = parser.parseObject(rest, nodeType, options);\n const parsedNodeId = getNodeID(parsedAsync);\n\n if (parsedAsync === null || !parsedNodeId) {\n return childOptions ? [] : null;\n }\n\n const asyncAST = parser.createASTNode(\n {\n id: parsedNodeId,\n type: NodeType.Async,\n value: parsedAsync,\n flatten,\n },\n obj,\n );\n\n if (childOptions) {\n return asyncAST\n ? [\n {\n path: [...childOptions.path, childOptions.key],\n value: asyncAST,\n },\n ]\n : [];\n }\n\n return asyncAST;\n }\n },\n );\n }\n\n apply(view: ViewInstance): void {\n const context: AsyncPluginContext = {\n nodeResolveCache: new Map(),\n inProgressNodes: new Set(),\n view,\n };\n\n view.hooks.parser.tap(\"async\", this.applyParser.bind(this));\n view.hooks.resolver.tap(\"async\", (resolver) => {\n this.applyResolver(resolver, context);\n });\n }\n\n applyPlugin(asyncNodePlugin: AsyncNodePlugin): void {\n this.basePlugin = asyncNodePlugin;\n }\n}\n","import { Builder } from \"@player-ui/player\";\nimport type { AsyncTransformFunc } from \"./types\";\n\n/**\n * @deprecated Use {@link createAsyncTransform} to create your before transform function.\n * Util function to generate transform function for async asset\n * @param asset - async asset to apply beforeResolve transform\n * @param wrapperAssetType: container asset type\n * @param flatten: flatten the streamed in content\n * @param path: property path to add the multinode containing the next async node to\n * @returns - wrapper asset with children of transformed asset and async node\n */\n\nexport const asyncTransform: AsyncTransformFunc = (\n assetId,\n wrapperAssetType,\n asset,\n flatten,\n path = [\"values\"],\n) => {\n const id = \"async-\" + assetId;\n\n const asyncNode = Builder.asyncNode(id, flatten);\n\n let multiNode;\n let assetNode;\n\n if (asset) {\n assetNode = Builder.assetWrapper(asset);\n multiNode = Builder.multiNode(assetNode, asyncNode);\n } else {\n multiNode = Builder.multiNode(asyncNode);\n }\n\n const wrapperAsset = Builder.asset({\n id: wrapperAssetType + \"-\" + id,\n type: wrapperAssetType,\n });\n\n Builder.addChild(wrapperAsset, path, multiNode);\n\n return wrapperAsset;\n};\n","import {\n BeforeTransformFunction,\n Builder,\n Node,\n NodeType,\n} from \"@player-ui/player\";\nimport {\n extractNodeFromPath,\n requiresAssetWrapper,\n traverseAndReplace,\n unwrapAsset,\n} from \"./utils\";\n\nexport type AsyncTransformOptions = {\n /** Whether or not to flatten the results into its container. Defaults to true */\n flatten?: boolean;\n /** The path to the array within the `wrapperAssetType` that will contain the async content. Defaults to [\"values\"] */\n path?: string[];\n /** The asset type that the transform is matching against. */\n transformAssetType: string;\n /** The asset type that will contain the async content. */\n wrapperAssetType: string;\n /** Function to get any nested asset that will need to be extracted and kept when creating the wrapper asset. */\n getNestedAsset?: (node: Node.ViewOrAsset) => Node.Node | undefined;\n /** Function to get the id for the async node being generated. Defaults to creating an id with the format of async-<ASSET.ID> */\n getAsyncNodeId?: (node: Node.ViewOrAsset) => string;\n};\n\nconst defaultGetNodeId = (node: Node.ViewOrAsset): string => {\n return `async-${node.value.id}`;\n};\n\n/** Creates a BeforeTransformFunction that turns the given asset into a wrapper asset with an async node in it.\n * By setting {@link AsyncTransformOptions.flatten} to true, you can chain multiple of the same asset type to create a flow of async content that\n * exists within a single collection.\n *\n * @param options - Options for managing the transform\n * @returns The {@link BeforeTransformFunction} that can be used for your asset.\n */\nexport const createAsyncTransform = (\n options: AsyncTransformOptions,\n): BeforeTransformFunction => {\n const {\n transformAssetType,\n wrapperAssetType,\n getNestedAsset,\n getAsyncNodeId = defaultGetNodeId,\n path = [\"values\"],\n flatten = true,\n } = options;\n\n const replaceNode = (node: Node.Node): Node.Node => {\n const unwrapped = unwrapAsset(node);\n\n if (\n unwrapped.type !== NodeType.Asset ||\n unwrapped.value.type !== transformAssetType\n ) {\n return node;\n }\n\n const transformed = asyncTransform(unwrapped);\n return extractNodeFromPath(transformed, path) ?? node;\n };\n\n const replacer = (node: Node.Node) => traverseAndReplace(node, replaceNode);\n\n const asyncTransform = (node: Node.ViewOrAsset) => {\n const id = getAsyncNodeId(node);\n const asset = getNestedAsset?.(node);\n\n // If flattening is disabled, don't need to extract the multi-node when async node is resolved.\n const replaceFunction = flatten ? replacer : undefined;\n const asyncNode = Builder.asyncNode(id, flatten, replaceFunction);\n\n let multiNode: Node.MultiNode | undefined;\n if (asset) {\n if (requiresAssetWrapper(asset)) {\n const assetWrappedNode = Builder.assetWrapper(asset);\n multiNode = Builder.multiNode(assetWrappedNode, asyncNode);\n } else if (asset.type === NodeType.MultiNode) {\n multiNode = Builder.multiNode(...(asset.values as any[]), asyncNode);\n } else {\n multiNode = Builder.multiNode(asset as any, asyncNode);\n }\n } else {\n multiNode = Builder.multiNode(asyncNode);\n }\n\n const wrapperAsset: Node.ViewOrAsset = Builder.asset({\n id: wrapperAssetType + \"-\" + id,\n type: wrapperAssetType,\n });\n\n Builder.addChild(wrapperAsset, path, multiNode);\n\n return wrapperAsset;\n };\n\n return asyncTransform;\n};\n","import type { Node } from \"@player-ui/player\";\n\n/** Matches 2 segments where pathA matches or is a subset of pathB. Returns the number of matching segments */\nconst getMatchValue = (\n pathA: Node.PathSegment[],\n pathB: Node.PathSegment[],\n): number => {\n if (pathA.length > pathB.length) {\n return 0;\n }\n\n let matchCount = 0;\n for (let i = 0; i < pathA.length; i++) {\n if (pathA[i] === pathB[i]) {\n matchCount++;\n } else {\n return 0;\n }\n }\n\n return matchCount;\n};\n\n/** Follows the given path and returns the node. If there is no match, returns undefined */\nexport const extractNodeFromPath = (\n node: Node.Node,\n path?: string[],\n): Node.Node | undefined => {\n if (path === undefined || path.length === 0) {\n return node;\n }\n\n if (!(\"children\" in node && node.children)) {\n return undefined;\n }\n\n let matchResult = 0;\n let bestMatch: Node.Child | undefined;\n for (const child of node.children) {\n const matchValue = getMatchValue(child.path, path);\n if (matchValue > matchResult) {\n matchResult = matchValue;\n bestMatch = child;\n }\n }\n\n if (!bestMatch) {\n return undefined;\n }\n\n if (matchResult >= path.length) {\n return bestMatch.value;\n }\n\n return extractNodeFromPath(bestMatch.value, path.slice(matchResult));\n};\n","import { NodeType, Node } from \"@player-ui/player\";\n\n/** Replaces a node using the given replace function. If the node is a multi-node it does this transformation to all of its values. */\nexport const traverseAndReplace = (\n node: Node.Node,\n replaceFn: (node: Node.Node) => Node.Node,\n): Node.Node => {\n if (node.type === NodeType.MultiNode) {\n let index = 0;\n while (index < node.values.length) {\n const child = node.values[index];\n if (!child) {\n index++;\n continue;\n }\n\n const result = replaceFn(child);\n if (result.type === NodeType.MultiNode) {\n node.values = [\n ...node.values.slice(0, index),\n ...result.values,\n ...node.values.slice(index + 1),\n ];\n } else {\n node.values[index] = result;\n index++;\n }\n }\n\n return node;\n }\n\n return replaceFn(node);\n};\n","import { NodeType, Node } from \"@player-ui/player\";\n\nexport const unwrapAsset = (node: Node.Node): Node.Node => {\n if (node.type !== NodeType.Value) {\n return node;\n }\n const child = node.children?.find(\n (x) => x.path.length === 1 && x.path[0] === \"asset\",\n );\n\n if (!child) {\n return node;\n }\n\n return child.value;\n};\n","import { NodeType } from \"@player-ui/player\";\nimport type { Node } from \"@player-ui/player\";\n\nexport const requiresAssetWrapper = (node: Node.Node): boolean => {\n if (node.type === NodeType.Asset) {\n return true;\n }\n\n if (node.type !== NodeType.Applicability) {\n return false;\n }\n\n return node.value.type === NodeType.Asset;\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,IAAAA,iBAAoC;AAapC,wBAAoD;AACpD,6BAA2B;;;ACd3B,oBAAwB;AAajB,IAAM,iBAAqC,CAChD,SACA,kBACA,OACA,SACA,OAAO,CAAC,QAAQ,MACb;AACH,QAAM,KAAK,WAAW;AAEtB,QAAM,YAAY,sBAAQ,UAAU,IAAI,OAAO;AAE/C,MAAI;AACJ,MAAI;AAEJ,MAAI,OAAO;AACT,gBAAY,sBAAQ,aAAa,KAAK;AACtC,gBAAY,sBAAQ,UAAU,WAAW,SAAS;AAAA,EACpD,OAAO;AACL,gBAAY,sBAAQ,UAAU,SAAS;AAAA,EACzC;AAEA,QAAM,eAAe,sBAAQ,MAAM;AAAA,IACjC,IAAI,mBAAmB,MAAM;AAAA,IAC7B,MAAM;AAAA,EACR,CAAC;AAED,wBAAQ,SAAS,cAAc,MAAM,SAAS;AAE9C,SAAO;AACT;;;AC1CA,IAAAC,iBAKO;;;ACFP,IAAM,gBAAgB,CACpB,OACA,UACW;AACX,MAAI,MAAM,SAAS,MAAM,QAAQ;AAC/B,WAAO;AAAA,EACT;AAEA,MAAI,aAAa;AACjB,WAAS,IAAI,GAAG,IAAI,MAAM,QAAQ,KAAK;AACr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O,QAAQ,YACf,QAAQ,QACR,OAAO,UAAU,eAAe,KAAK,KAAK,OAAO;AAAA,EAErD;AAAA,EAEA,YAAY,QAAsB;AAChC,WAAO,MAAM,UAAU;AAAA,MACrB,KAAK;AAAA,MACL,CACE,KACA,UACA,SACA,iBACG;AACH,YAAI,KAAK,kBAAkB,GAAG,GAAG;AAE/B,gBAAM,EAAE,OAAO,SAAS,GAAG,KAAK,IAAI;AACpC,gBAAM,cAAc,OAAO,YAAY,MAAM,UAAU,OAAO;AAC9D,gBAAM,mBAAe,0BAAU,WAAW;AAE1C,cAAI,gBAAgB,QAAQ,CAAC,cAAc;AACzC,mBAAO,eAAe,CAAC,IAAI;AAAA,UAC7B;AAEA,gBAAM,WAAW,OAAO;AAAA,YACtB;AAAA,cACE,IAAI;AAAA,cACJ,MAAM,wBAAS;AAAA,cACf,OAAO;AAAA,cACP;AAAA,YACF;AAAA,YACA;AAAA,UACF;AAEA,cAAI,cAAc;AAChB,mBAAO,WACH;AAAA,cACE;AAAA,gBACE,MAAM,CAAC,GAAG,aAAa,MAAM,aAAa,GAAG;AAAA,gBAC7C,OAAO;AAAA,cACT;AAAA,YACF,IACA,CAAC;AAAA,UACP;AAEA,iBAAO;AAAA,QACT;AAAA,MACF;AAAA,IACF;AAAA,EACF;AAAA,EAEA,MAAM,MAA0B;AAC9B,UAAM,UAA8B;AAAA,MAClC,kBAAkB,oBAAI,IAAI;AAAA,MAC1B,iBAAiB,oBAAI,IAAI;AAAA,MACzB;AAAA,IACF;AAEA,SAAK,MAAM,OAAO,IAAI,SAAS,KAAK,YAAY,KAAK,IAAI,CAAC;AAC1D,SAAK,MAAM,SAAS,IAAI,SAAS,CAAC,aAAa;AAC7C,WAAK,cAAc,UAAU,OAAO;AAAA,IACtC,CAAC;AAAA,EACH;AAAA,EAEA,YAAY,iBAAwC;AAClD,SAAK,aAAa;AAAA,EACpB;AACF;","names":["import_player","import_player","import_player","import_player","import_player","asyncTransform","queueMicrotask","result"]}
1
+ {"version":3,"sources":["../../../../../../../../../../../../../execroot/_main/bazel-out/k8-fastbuild/bin/plugins/async-node/core/src/index.ts","../../../../../../../../../../../../../execroot/_main/bazel-out/k8-fastbuild/bin/plugins/async-node/core/src/transform.ts","../../../../../../../../../../../../../execroot/_main/bazel-out/k8-fastbuild/bin/plugins/async-node/core/src/createAsyncTransform.ts","../../../../../../../../../../../../../execroot/_main/bazel-out/k8-fastbuild/bin/plugins/async-node/core/src/utils/extractNodeFromPath.ts","../../../../../../../../../../../../../execroot/_main/bazel-out/k8-fastbuild/bin/plugins/async-node/core/src/utils/traverseAndReplace.ts","../../../../../../../../../../../../../execroot/_main/bazel-out/k8-fastbuild/bin/plugins/async-node/core/src/utils/unwrapAsset.ts","../../../../../../../../../../../../../execroot/_main/bazel-out/k8-fastbuild/bin/plugins/async-node/core/src/utils/requiresAssetWrapper.ts"],"sourcesContent":["import { NodeType, getNodeID } from \"@player-ui/player\";\nimport type {\n Player,\n PlayerPlugin,\n Node,\n ParseObjectOptions,\n ParseObjectChildOptions,\n ViewInstance,\n Parser,\n ViewPlugin,\n Resolver,\n Resolve,\n} from \"@player-ui/player\";\nimport { AsyncParallelBailHook, SyncBailHook } from \"tapable-ts\";\nimport queueMicrotask from \"queue-microtask\";\n\nexport * from \"./types\";\nexport * from \"./transform\";\nexport * from \"./createAsyncTransform\";\n\n/** Object type for storing data related to a single `apply` of the `AsyncNodePluginPlugin`\n * This object should be setup once per ViewInstance to keep any cached info just for that view to avoid conflicts of shared async node ids across different view states.\n */\ntype AsyncPluginContext = {\n /** Map of async node id to resolved content */\n nodeResolveCache: Map<string, any>;\n /** The view instance this context is attached to. */\n view: ViewInstance;\n /** Map of async node id to promises being used to resolve them */\n inProgressNodes: Set<string>;\n};\n\nexport interface AsyncNodePluginOptions {\n /** A set of plugins to load */\n plugins?: AsyncNodeViewPlugin[];\n}\n\nexport interface AsyncNodeViewPlugin extends ViewPlugin {\n /** Use this to tap into the async node plugin hooks */\n applyPlugin: (asyncNodePlugin: AsyncNodePlugin) => void;\n\n asyncNode: AsyncParallelBailHook<[Node.Async, (result: any) => void], any>;\n}\nexport type AsyncHandler = (\n node: Node.Async,\n callback?: (result: any) => void,\n) => Promise<any>;\n\nexport type AsyncContent = {\n async: true;\n flatten?: boolean;\n [key: string]: unknown;\n};\n\n/** Hook declaration for the AsyncNodePlugin */\nexport type AsyncNodeHooks = {\n /** Async hook to get content for an async node */\n onAsyncNode: AsyncParallelBailHook<[Node.Async, (result: any) => void], any>;\n /** Sync hook to manage errors coming from the onAsyncNode hook. Return a fallback node or null to render a fallback. The first argument of passed in the call is the error thrown. */\n onAsyncNodeError: SyncBailHook<[Error, Node.Async], any>;\n};\n\nexport const AsyncNodePluginSymbol: symbol = Symbol.for(\"AsyncNodePlugin\");\n\n/**\n * Async node plugin used to resolve async nodes in the content\n * If an async node is present, allow users to provide a replacement node to be rendered when ready\n */\nexport class AsyncNodePlugin implements PlayerPlugin {\n private plugins: AsyncNodeViewPlugin[] | undefined;\n private playerInstance: Player | undefined;\n\n static Symbol: symbol = AsyncNodePluginSymbol;\n public readonly symbol: symbol = AsyncNodePlugin.Symbol;\n\n constructor(options: AsyncNodePluginOptions, asyncHandler?: AsyncHandler) {\n if (options?.plugins) {\n this.plugins = options.plugins;\n options.plugins.forEach((plugin) => {\n plugin.applyPlugin(this);\n });\n }\n\n if (asyncHandler) {\n this.hooks.onAsyncNode.tap(\n \"async\",\n async (node: Node.Async, callback) => {\n return await asyncHandler(node, callback);\n },\n );\n }\n }\n\n public readonly hooks: AsyncNodeHooks = {\n onAsyncNode: new AsyncParallelBailHook(),\n onAsyncNodeError: new SyncBailHook(),\n };\n\n getPlayerInstance(): Player | undefined {\n return this.playerInstance;\n }\n\n name = \"AsyncNode\";\n\n apply(player: Player): void {\n this.playerInstance = player;\n\n player.hooks.viewController.tap(this.name, (viewController) => {\n viewController.hooks.view.tap(this.name, (view) => {\n this.plugins?.forEach((plugin) => {\n plugin.apply(view);\n });\n });\n });\n }\n}\n\nexport class AsyncNodePluginPlugin implements AsyncNodeViewPlugin {\n public asyncNode: AsyncParallelBailHook<\n [Node.Async, (result: any) => void],\n any\n > = new AsyncParallelBailHook();\n private basePlugin: AsyncNodePlugin | undefined;\n\n name = \"AsyncNode\";\n\n /**\n * Parses the node from the result and triggers an asynchronous view update if necessary.\n * @param node The asynchronous node that might be updated.\n * @param result The result obtained from resolving the async node. This could be any data structure or value.\n * @param options Options provided for node resolution, including a potential parseNode function to process the result.\n * @param view The view instance where the node resides. This can be undefined if the view is not currently active.\n */\n private parseNodeAndUpdate(\n node: Node.Async,\n context: AsyncPluginContext,\n result: any,\n options: Resolve.NodeResolveOptions,\n ) {\n let parsedNode =\n options.parseNode && result ? options.parseNode(result) : undefined;\n\n if (parsedNode && node.onValueReceived) {\n parsedNode = node.onValueReceived(parsedNode);\n }\n\n this.handleAsyncUpdate(node, context, parsedNode);\n }\n\n /**\n * Updates the node asynchronously based on the result provided.\n * This method is responsible for handling the update logic of asynchronous nodes.\n * It checks if the node needs to be updated based on the new result and updates the mapping accordingly.\n * If an update is necessary, it triggers an asynchronous update on the view.\n * @param node The asynchronous node that might be updated.\n * @param newNode The new node to replace the async node.\n * @param view The view instance where the node resides. This can be undefined if the view is not currently active.\n */\n private handleAsyncUpdate(\n node: Node.Async,\n context: AsyncPluginContext,\n newNode?: Node.Node | null,\n ) {\n const { nodeResolveCache, view } = context;\n if (nodeResolveCache.get(node.id) !== newNode) {\n nodeResolveCache.set(node.id, newNode ? newNode : node);\n view.updateAsync(node.id);\n }\n }\n\n private hasValidMapping(\n node: Node.Async,\n context: AsyncPluginContext,\n ): boolean {\n const { nodeResolveCache } = context;\n return (\n nodeResolveCache.has(node.id) && nodeResolveCache.get(node.id) !== node\n );\n }\n\n /**\n * Handles the asynchronous API integration for resolving nodes.\n * This method sets up a hook on the resolver's `beforeResolve` event to process async nodes.\n * @param resolver The resolver instance to attach the hook to.\n * @param view\n */\n applyResolver(resolver: Resolver, context: AsyncPluginContext): void {\n resolver.hooks.beforeResolve.tap(this.name, (node, options) => {\n if (!this.isAsync(node)) {\n return node === null ? node : this.resolveAsyncChildren(node, context);\n }\n\n const resolvedNode = context.nodeResolveCache.get(node.id);\n if (resolvedNode !== undefined) {\n return this.resolveAsyncChildren(resolvedNode, context);\n }\n\n if (context.inProgressNodes.has(node.id)) {\n return node;\n }\n\n // Track that the node is in progress.\n context.inProgressNodes.add(node.id);\n queueMicrotask(() => {\n this.runAsyncNode(node, context, options).finally();\n });\n\n return node;\n });\n }\n\n /**\n * Replaces child async nodes with their resolved content and flattens when necessary. Resolving the children directly helps manage the `parent` reference without needing as much work within the resolver itself.\n * Handles async node chains as well to make sure all applicable nodes can get flattened.\n * @param node - The node whose children need to be resolved.\n * @param context - the async plugin context needed to reach into the cache\n * @returns The same node but with async node children mapped to their resolved AST.\n */\n private resolveAsyncChildren(\n node: Node.Node,\n context: AsyncPluginContext,\n ): Node.Node {\n const asyncNodesResolved: string[] = node.asyncNodesResolved ?? [];\n node.asyncNodesResolved = asyncNodesResolved;\n if (node.type === NodeType.MultiNode) {\n // Using a while loop lets us catch when async nodes produce more async nodes that need to be flattened further\n let index = 0;\n while (index < node.values.length) {\n const childNode = node.values[index];\n if (\n childNode?.type !== NodeType.Async ||\n !this.hasValidMapping(childNode, context)\n ) {\n index++;\n continue;\n }\n\n const mappedNode = context.nodeResolveCache.get(childNode.id);\n asyncNodesResolved.push(childNode.id);\n if (mappedNode.type === NodeType.MultiNode && childNode.flatten) {\n mappedNode.values.forEach((v: Node.Node) => (v.parent = node));\n node.values = [\n ...node.values.slice(0, index),\n ...mappedNode.values,\n ...node.values.slice(index + 1),\n ];\n } else {\n node.values[index] = mappedNode;\n mappedNode.parent = node;\n }\n }\n } else if (\"children\" in node) {\n node.children?.forEach((c) => {\n // Similar to above, using a while loop lets us handle when async nodes produce more async nodes.\n while (\n c.value.type === NodeType.Async &&\n this.hasValidMapping(c.value, context)\n ) {\n asyncNodesResolved.push(c.value.id);\n c.value = context.nodeResolveCache.get(c.value.id);\n c.value.parent = node;\n }\n });\n }\n\n return node;\n }\n\n private async runAsyncNode(\n node: Node.Async,\n context: AsyncPluginContext,\n options: Resolve.NodeResolveOptions,\n ) {\n try {\n const result = await this.basePlugin?.hooks.onAsyncNode.call(\n node,\n (result) => {\n this.parseNodeAndUpdate(node, context, result, options);\n },\n );\n\n // Stop tracking before the next update is triggered\n context.inProgressNodes.delete(node.id);\n this.parseNodeAndUpdate(node, context, result, options);\n } catch (e: unknown) {\n const error = e instanceof Error ? e : new Error(String(e));\n const result = this.basePlugin?.hooks.onAsyncNodeError.call(error, node);\n\n if (result === undefined) {\n const playerState = this.basePlugin?.getPlayerInstance()?.getState();\n\n if (playerState?.status === \"in-progress\") {\n playerState.fail(error);\n }\n\n return;\n }\n\n options.logger?.error(\n \"Async node handling failed and resolved with a fallback. Error:\",\n error,\n );\n\n // Stop tracking before the next update is triggered\n context.inProgressNodes.delete(node.id);\n this.parseNodeAndUpdate(node, context, result, options);\n }\n }\n\n private isAsync(node: Node.Node | null): node is Node.Async {\n return node?.type === NodeType.Async;\n }\n\n private isDeterminedAsync(obj: unknown): obj is AsyncContent {\n return (\n typeof obj === \"object\" &&\n obj !== null &&\n Object.prototype.hasOwnProperty.call(obj, \"async\")\n );\n }\n\n applyParser(parser: Parser): void {\n parser.hooks.parseNode.tap(\n this.name,\n (\n obj: any,\n nodeType: Node.ChildrenTypes,\n options: ParseObjectOptions,\n childOptions?: ParseObjectChildOptions,\n ) => {\n if (this.isDeterminedAsync(obj)) {\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\n const { async, flatten, ...rest } = obj;\n const parsedAsync = parser.parseObject(rest, nodeType, options);\n const parsedNodeId = getNodeID(parsedAsync);\n\n if (parsedAsync === null || !parsedNodeId) {\n return childOptions ? [] : null;\n }\n\n const asyncAST = parser.createASTNode(\n {\n id: parsedNodeId,\n type: NodeType.Async,\n value: parsedAsync,\n flatten,\n },\n obj,\n );\n\n if (childOptions) {\n return asyncAST\n ? [\n {\n path: [...childOptions.path, childOptions.key],\n value: asyncAST,\n },\n ]\n : [];\n }\n\n return asyncAST;\n }\n },\n );\n }\n\n apply(view: ViewInstance): void {\n const context: AsyncPluginContext = {\n nodeResolveCache: new Map(),\n inProgressNodes: new Set(),\n view,\n };\n\n view.hooks.parser.tap(\"async\", this.applyParser.bind(this));\n view.hooks.resolver.tap(\"async\", (resolver) => {\n this.applyResolver(resolver, context);\n });\n }\n\n applyPlugin(asyncNodePlugin: AsyncNodePlugin): void {\n this.basePlugin = asyncNodePlugin;\n }\n}\n","import { Builder } from \"@player-ui/player\";\nimport type { AsyncTransformFunc } from \"./types\";\n\n/**\n * @deprecated Use {@link createAsyncTransform} to create your before transform function.\n * Util function to generate transform function for async asset\n * @param asset - async asset to apply beforeResolve transform\n * @param wrapperAssetType: container asset type\n * @param flatten: flatten the streamed in content\n * @param path: property path to add the multinode containing the next async node to\n * @returns - wrapper asset with children of transformed asset and async node\n */\n\nexport const asyncTransform: AsyncTransformFunc = (\n assetId,\n wrapperAssetType,\n asset,\n flatten,\n path = [\"values\"],\n) => {\n const id = \"async-\" + assetId;\n\n const asyncNode = Builder.asyncNode(id, flatten);\n\n let multiNode;\n let assetNode;\n\n if (asset) {\n assetNode = Builder.assetWrapper(asset);\n multiNode = Builder.multiNode(assetNode, asyncNode);\n } else {\n multiNode = Builder.multiNode(asyncNode);\n }\n\n const wrapperAsset = Builder.asset({\n id: wrapperAssetType + \"-\" + id,\n type: wrapperAssetType,\n });\n\n Builder.addChild(wrapperAsset, path, multiNode);\n\n return wrapperAsset;\n};\n","import {\n BeforeTransformFunction,\n Builder,\n Node,\n NodeType,\n} from \"@player-ui/player\";\nimport {\n extractNodeFromPath,\n requiresAssetWrapper,\n traverseAndReplace,\n unwrapAsset,\n} from \"./utils\";\n\nexport type AsyncTransformOptions = {\n /** Whether or not to flatten the results into its container. Defaults to true */\n flatten?: boolean;\n /** The path to the array within the `wrapperAssetType` that will contain the async content. Defaults to [\"values\"] */\n path?: string[];\n /** The asset type that the transform is matching against. */\n transformAssetType: string;\n /** The asset type that will contain the async content. */\n wrapperAssetType: string;\n /** Function to get any nested asset that will need to be extracted and kept when creating the wrapper asset. */\n getNestedAsset?: (node: Node.ViewOrAsset) => Node.Node | undefined;\n /** Function to get the id for the async node being generated. Defaults to creating an id with the format of async-<ASSET.ID> */\n getAsyncNodeId?: (node: Node.ViewOrAsset) => string;\n /** Where to place the async node relative to the asset from `getNestedAsset`. Defaults to \"append\" */\n asyncNodePosition?: \"append\" | \"prepend\";\n};\n\nconst defaultGetNodeId = (node: Node.ViewOrAsset): string => {\n return `async-${node.value.id}`;\n};\n\n/** Creates a BeforeTransformFunction that turns the given asset into a wrapper asset with an async node in it.\n * By setting {@link AsyncTransformOptions.flatten} to true, you can chain multiple of the same asset type to create a flow of async content that\n * exists within a single collection.\n *\n * @param options - Options for managing the transform\n * @returns The {@link BeforeTransformFunction} that can be used for your asset.\n */\nexport const createAsyncTransform = (\n options: AsyncTransformOptions,\n): BeforeTransformFunction => {\n const {\n transformAssetType,\n wrapperAssetType,\n getNestedAsset,\n getAsyncNodeId = defaultGetNodeId,\n path = [\"values\"],\n flatten = true,\n asyncNodePosition = \"append\",\n } = options;\n\n const replaceNode = (node: Node.Node): Node.Node => {\n const unwrapped = unwrapAsset(node);\n\n if (\n unwrapped.type !== NodeType.Asset ||\n unwrapped.value.type !== transformAssetType\n ) {\n return node;\n }\n\n const transformed = asyncTransform(unwrapped);\n return extractNodeFromPath(transformed, path) ?? node;\n };\n\n const replacer = (node: Node.Node) => traverseAndReplace(node, replaceNode);\n\n const asyncTransform = (node: Node.ViewOrAsset) => {\n const id = getAsyncNodeId(node);\n const asset = getNestedAsset?.(node);\n\n // If flattening is disabled, don't need to extract the multi-node when async node is resolved.\n const replaceFunction = flatten ? replacer : undefined;\n const asyncNode = Builder.asyncNode(id, flatten, replaceFunction);\n\n const values: Node.Node[] = [asyncNode];\n if (asset) {\n const otherValues = [];\n if (requiresAssetWrapper(asset)) {\n otherValues.push(Builder.assetWrapper(asset));\n } else if (asset.type === NodeType.MultiNode) {\n otherValues.push(...asset.values);\n } else {\n otherValues.push(asset);\n }\n\n if (asyncNodePosition === \"append\") {\n values.unshift(...otherValues);\n } else {\n values.push(...otherValues);\n }\n }\n\n const multiNode = Builder.multiNode(...(values as any[]));\n\n const wrapperAsset: Node.ViewOrAsset = Builder.asset({\n id: wrapperAssetType + \"-\" + id,\n type: wrapperAssetType,\n });\n\n Builder.addChild(wrapperAsset, path, multiNode);\n\n return wrapperAsset;\n };\n\n return asyncTransform;\n};\n","import type { Node } from \"@player-ui/player\";\n\n/** Matches 2 segments where pathA matches or is a subset of pathB. Returns the number of matching segments */\nconst getMatchValue = (\n pathA: Node.PathSegment[],\n pathB: Node.PathSegment[],\n): number => {\n if (pathA.length > pathB.length) {\n return 0;\n }\n\n let matchCount = 0;\n for (let i = 0; i < pathA.length; i++) {\n if (pathA[i] === pathB[i]) {\n matchCount++;\n } else {\n return 0;\n }\n }\n\n return matchCount;\n};\n\n/** Follows the given path and returns the node. If there is no match, returns undefined */\nexport const extractNodeFromPath = (\n node: Node.Node,\n path?: string[],\n): Node.Node | undefined => {\n if (path === undefined || path.length === 0) {\n return node;\n }\n\n if (!(\"children\" in node && node.children)) {\n return undefined;\n }\n\n let matchResult = 0;\n let bestMatch: Node.Child | undefined;\n for (const child of node.children) {\n const matchValue = getMatchValue(child.path, path);\n if (matchValue > matchResult) {\n matchResult = matchValue;\n bestMatch = child;\n }\n }\n\n if (!bestMatch) {\n return undefined;\n }\n\n if (matchResult >= path.length) {\n return bestMatch.value;\n }\n\n return extractNodeFromPath(bestMatch.value, path.slice(matchResult));\n};\n","import { NodeType, Node } from \"@player-ui/player\";\n\n/** Replaces a node using the given replace function. If the node is a multi-node it does this transformation to all of its values. */\nexport const traverseAndReplace = (\n node: Node.Node,\n replaceFn: (node: Node.Node) => Node.Node,\n): Node.Node => {\n if (node.type === NodeType.MultiNode) {\n let index = 0;\n while (index < node.values.length) {\n const child = node.values[index];\n if (!child) {\n index++;\n continue;\n }\n\n const result = replaceFn(child);\n if (result.type === NodeType.MultiNode) {\n node.values = [\n ...node.values.slice(0, index),\n ...result.values,\n ...node.values.slice(index + 1),\n ];\n } else {\n node.values[index] = result;\n index++;\n }\n }\n\n return node;\n }\n\n return replaceFn(node);\n};\n","import { NodeType, Node } from \"@player-ui/player\";\n\nexport const unwrapAsset = (node: Node.Node): Node.Node => {\n if (node.type !== NodeType.Value) {\n return node;\n }\n const child = node.children?.find(\n (x) => x.path.length === 1 && x.path[0] === \"asset\",\n );\n\n if (!child) {\n return node;\n }\n\n return child.value;\n};\n","import { NodeType } from \"@player-ui/player\";\nimport type { Node } from \"@player-ui/player\";\n\nexport const requiresAssetWrapper = (node: Node.Node): boolean => {\n if (node.type === NodeType.Asset) {\n return true;\n }\n\n if (node.type !== NodeType.Applicability) {\n return false;\n }\n\n return node.value.type === NodeType.Asset;\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,IAAAA,iBAAoC;AAapC,wBAAoD;AACpD,6BAA2B;;;ACd3B,oBAAwB;AAajB,IAAM,iBAAqC,CAChD,SACA,kBACA,OACA,SACA,OAAO,CAAC,QAAQ,MACb;AACH,QAAM,KAAK,WAAW;AAEtB,QAAM,YAAY,sBAAQ,UAAU,IAAI,OAAO;AAE/C,MAAI;AACJ,MAAI;AAEJ,MAAI,OAAO;AACT,gBAAY,sBAAQ,aAAa,KAAK;AACtC,gBAAY,sBAAQ,UAAU,WAAW,SAAS;AAAA,EACpD,OAAO;AACL,gBAAY,sBAAQ,UAAU,SAAS;AAAA,EACzC;AAEA,QAAM,eAAe,sBAAQ,MAAM;AAAA,IACjC,IAAI,mBAAmB,MAAM;AAAA,IAC7B,MAAM;AAAA,EACR,CAAC;AAED,wBAAQ,SAAS,cAAc,MAAM,SAAS;AAE9C,SAAO;AACT;;;AC1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AAEA,SAAK,MAAM,OAAO,IAAI,SAAS,KAAK,YAAY,KAAK,IAAI,CAAC;AAC1D,SAAK,MAAM,SAAS,IAAI,SAAS,CAAC,aAAa;AAC7C,WAAK,cAAc,UAAU,OAAO;AAAA,IACtC,CAAC;AAAA,EACH;AAAA,EAEA,YAAY,iBAAwC;AAClD,SAAK,aAAa;AAAA,EACpB;AACF;","names":["import_player","import_player","import_player","import_player","import_player","asyncTransform","queueMicrotask","result"]}
@@ -136,7 +136,8 @@ var createAsyncTransform = (options) => {
136
136
  getNestedAsset,
137
137
  getAsyncNodeId = defaultGetNodeId,
138
138
  path = ["values"],
139
- flatten = true
139
+ flatten = true,
140
+ asyncNodePosition = "append"
140
141
  } = options;
141
142
  const replaceNode = (node) => {
142
143
  const unwrapped = unwrapAsset(node);
@@ -152,19 +153,23 @@ var createAsyncTransform = (options) => {
152
153
  const asset = getNestedAsset?.(node);
153
154
  const replaceFunction = flatten ? replacer : void 0;
154
155
  const asyncNode = Builder2.asyncNode(id, flatten, replaceFunction);
155
- let multiNode;
156
+ const values = [asyncNode];
156
157
  if (asset) {
158
+ const otherValues = [];
157
159
  if (requiresAssetWrapper(asset)) {
158
- const assetWrappedNode = Builder2.assetWrapper(asset);
159
- multiNode = Builder2.multiNode(assetWrappedNode, asyncNode);
160
+ otherValues.push(Builder2.assetWrapper(asset));
160
161
  } else if (asset.type === NodeType4.MultiNode) {
161
- multiNode = Builder2.multiNode(...asset.values, asyncNode);
162
+ otherValues.push(...asset.values);
162
163
  } else {
163
- multiNode = Builder2.multiNode(asset, asyncNode);
164
+ otherValues.push(asset);
165
+ }
166
+ if (asyncNodePosition === "append") {
167
+ values.unshift(...otherValues);
168
+ } else {
169
+ values.push(...otherValues);
164
170
  }
165
- } else {
166
- multiNode = Builder2.multiNode(asyncNode);
167
171
  }
172
+ const multiNode = Builder2.multiNode(...values);
168
173
  const wrapperAsset = Builder2.asset({
169
174
  id: wrapperAssetType + "-" + id,
170
175
  type: wrapperAssetType
package/dist/index.mjs CHANGED
@@ -136,7 +136,8 @@ var createAsyncTransform = (options) => {
136
136
  getNestedAsset,
137
137
  getAsyncNodeId = defaultGetNodeId,
138
138
  path = ["values"],
139
- flatten = true
139
+ flatten = true,
140
+ asyncNodePosition = "append"
140
141
  } = options;
141
142
  const replaceNode = (node) => {
142
143
  const unwrapped = unwrapAsset(node);
@@ -152,19 +153,23 @@ var createAsyncTransform = (options) => {
152
153
  const asset = getNestedAsset?.(node);
153
154
  const replaceFunction = flatten ? replacer : void 0;
154
155
  const asyncNode = Builder2.asyncNode(id, flatten, replaceFunction);
155
- let multiNode;
156
+ const values = [asyncNode];
156
157
  if (asset) {
158
+ const otherValues = [];
157
159
  if (requiresAssetWrapper(asset)) {
158
- const assetWrappedNode = Builder2.assetWrapper(asset);
159
- multiNode = Builder2.multiNode(assetWrappedNode, asyncNode);
160
+ otherValues.push(Builder2.assetWrapper(asset));
160
161
  } else if (asset.type === NodeType4.MultiNode) {
161
- multiNode = Builder2.multiNode(...asset.values, asyncNode);
162
+ otherValues.push(...asset.values);
162
163
  } else {
163
- multiNode = Builder2.multiNode(asset, asyncNode);
164
+ otherValues.push(asset);
165
+ }
166
+ if (asyncNodePosition === "append") {
167
+ values.unshift(...otherValues);
168
+ } else {
169
+ values.push(...otherValues);
164
170
  }
165
- } else {
166
- multiNode = Builder2.multiNode(asyncNode);
167
171
  }
172
+ const multiNode = Builder2.multiNode(...values);
168
173
  const wrapperAsset = Builder2.asset({
169
174
  id: wrapperAssetType + "-" + id,
170
175
  type: wrapperAssetType
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../../../../../../../../../execroot/_main/bazel-out/k8-fastbuild/bin/plugins/async-node/core/src/index.ts","../../../../../../../../../../../../execroot/_main/bazel-out/k8-fastbuild/bin/plugins/async-node/core/src/transform.ts","../../../../../../../../../../../../execroot/_main/bazel-out/k8-fastbuild/bin/plugins/async-node/core/src/createAsyncTransform.ts","../../../../../../../../../../../../execroot/_main/bazel-out/k8-fastbuild/bin/plugins/async-node/core/src/utils/extractNodeFromPath.ts","../../../../../../../../../../../../execroot/_main/bazel-out/k8-fastbuild/bin/plugins/async-node/core/src/utils/traverseAndReplace.ts","../../../../../../../../../../../../execroot/_main/bazel-out/k8-fastbuild/bin/plugins/async-node/core/src/utils/unwrapAsset.ts","../../../../../../../../../../../../execroot/_main/bazel-out/k8-fastbuild/bin/plugins/async-node/core/src/utils/requiresAssetWrapper.ts"],"sourcesContent":["import { NodeType, getNodeID } from \"@player-ui/player\";\nimport type {\n Player,\n PlayerPlugin,\n Node,\n ParseObjectOptions,\n ParseObjectChildOptions,\n ViewInstance,\n Parser,\n ViewPlugin,\n Resolver,\n Resolve,\n} from \"@player-ui/player\";\nimport { AsyncParallelBailHook, SyncBailHook } from \"tapable-ts\";\nimport queueMicrotask from \"queue-microtask\";\n\nexport * from \"./types\";\nexport * from \"./transform\";\nexport * from \"./createAsyncTransform\";\n\n/** Object type for storing data related to a single `apply` of the `AsyncNodePluginPlugin`\n * This object should be setup once per ViewInstance to keep any cached info just for that view to avoid conflicts of shared async node ids across different view states.\n */\ntype AsyncPluginContext = {\n /** Map of async node id to resolved content */\n nodeResolveCache: Map<string, any>;\n /** The view instance this context is attached to. */\n view: ViewInstance;\n /** Map of async node id to promises being used to resolve them */\n inProgressNodes: Set<string>;\n};\n\nexport interface AsyncNodePluginOptions {\n /** A set of plugins to load */\n plugins?: AsyncNodeViewPlugin[];\n}\n\nexport interface AsyncNodeViewPlugin extends ViewPlugin {\n /** Use this to tap into the async node plugin hooks */\n applyPlugin: (asyncNodePlugin: AsyncNodePlugin) => void;\n\n asyncNode: AsyncParallelBailHook<[Node.Async, (result: any) => void], any>;\n}\nexport type AsyncHandler = (\n node: Node.Async,\n callback?: (result: any) => void,\n) => Promise<any>;\n\nexport type AsyncContent = {\n async: true;\n flatten?: boolean;\n [key: string]: unknown;\n};\n\n/** Hook declaration for the AsyncNodePlugin */\nexport type AsyncNodeHooks = {\n /** Async hook to get content for an async node */\n onAsyncNode: AsyncParallelBailHook<[Node.Async, (result: any) => void], any>;\n /** Sync hook to manage errors coming from the onAsyncNode hook. Return a fallback node or null to render a fallback. The first argument of passed in the call is the error thrown. */\n onAsyncNodeError: SyncBailHook<[Error, Node.Async], any>;\n};\n\nexport const AsyncNodePluginSymbol: symbol = Symbol.for(\"AsyncNodePlugin\");\n\n/**\n * Async node plugin used to resolve async nodes in the content\n * If an async node is present, allow users to provide a replacement node to be rendered when ready\n */\nexport class AsyncNodePlugin implements PlayerPlugin {\n private plugins: AsyncNodeViewPlugin[] | undefined;\n private playerInstance: Player | undefined;\n\n static Symbol: symbol = AsyncNodePluginSymbol;\n public readonly symbol: symbol = AsyncNodePlugin.Symbol;\n\n constructor(options: AsyncNodePluginOptions, asyncHandler?: AsyncHandler) {\n if (options?.plugins) {\n this.plugins = options.plugins;\n options.plugins.forEach((plugin) => {\n plugin.applyPlugin(this);\n });\n }\n\n if (asyncHandler) {\n this.hooks.onAsyncNode.tap(\n \"async\",\n async (node: Node.Async, callback) => {\n return await asyncHandler(node, callback);\n },\n );\n }\n }\n\n public readonly hooks: AsyncNodeHooks = {\n onAsyncNode: new AsyncParallelBailHook(),\n onAsyncNodeError: new SyncBailHook(),\n };\n\n getPlayerInstance(): Player | undefined {\n return this.playerInstance;\n }\n\n name = \"AsyncNode\";\n\n apply(player: Player): void {\n this.playerInstance = player;\n\n player.hooks.viewController.tap(this.name, (viewController) => {\n viewController.hooks.view.tap(this.name, (view) => {\n this.plugins?.forEach((plugin) => {\n plugin.apply(view);\n });\n });\n });\n }\n}\n\nexport class AsyncNodePluginPlugin implements AsyncNodeViewPlugin {\n public asyncNode: AsyncParallelBailHook<\n [Node.Async, (result: any) => void],\n any\n > = new AsyncParallelBailHook();\n private basePlugin: AsyncNodePlugin | undefined;\n\n name = \"AsyncNode\";\n\n /**\n * Parses the node from the result and triggers an asynchronous view update if necessary.\n * @param node The asynchronous node that might be updated.\n * @param result The result obtained from resolving the async node. This could be any data structure or value.\n * @param options Options provided for node resolution, including a potential parseNode function to process the result.\n * @param view The view instance where the node resides. This can be undefined if the view is not currently active.\n */\n private parseNodeAndUpdate(\n node: Node.Async,\n context: AsyncPluginContext,\n result: any,\n options: Resolve.NodeResolveOptions,\n ) {\n let parsedNode =\n options.parseNode && result ? options.parseNode(result) : undefined;\n\n if (parsedNode && node.onValueReceived) {\n parsedNode = node.onValueReceived(parsedNode);\n }\n\n this.handleAsyncUpdate(node, context, parsedNode);\n }\n\n /**\n * Updates the node asynchronously based on the result provided.\n * This method is responsible for handling the update logic of asynchronous nodes.\n * It checks if the node needs to be updated based on the new result and updates the mapping accordingly.\n * If an update is necessary, it triggers an asynchronous update on the view.\n * @param node The asynchronous node that might be updated.\n * @param newNode The new node to replace the async node.\n * @param view The view instance where the node resides. This can be undefined if the view is not currently active.\n */\n private handleAsyncUpdate(\n node: Node.Async,\n context: AsyncPluginContext,\n newNode?: Node.Node | null,\n ) {\n const { nodeResolveCache, view } = context;\n if (nodeResolveCache.get(node.id) !== newNode) {\n nodeResolveCache.set(node.id, newNode ? newNode : node);\n view.updateAsync(node.id);\n }\n }\n\n private hasValidMapping(\n node: Node.Async,\n context: AsyncPluginContext,\n ): boolean {\n const { nodeResolveCache } = context;\n return (\n nodeResolveCache.has(node.id) && nodeResolveCache.get(node.id) !== node\n );\n }\n\n /**\n * Handles the asynchronous API integration for resolving nodes.\n * This method sets up a hook on the resolver's `beforeResolve` event to process async nodes.\n * @param resolver The resolver instance to attach the hook to.\n * @param view\n */\n applyResolver(resolver: Resolver, context: AsyncPluginContext): void {\n resolver.hooks.beforeResolve.tap(this.name, (node, options) => {\n if (!this.isAsync(node)) {\n return node === null ? node : this.resolveAsyncChildren(node, context);\n }\n\n const resolvedNode = context.nodeResolveCache.get(node.id);\n if (resolvedNode !== undefined) {\n return this.resolveAsyncChildren(resolvedNode, context);\n }\n\n if (context.inProgressNodes.has(node.id)) {\n return node;\n }\n\n // Track that the node is in progress.\n context.inProgressNodes.add(node.id);\n queueMicrotask(() => {\n this.runAsyncNode(node, context, options).finally();\n });\n\n return node;\n });\n }\n\n /**\n * Replaces child async nodes with their resolved content and flattens when necessary. Resolving the children directly helps manage the `parent` reference without needing as much work within the resolver itself.\n * Handles async node chains as well to make sure all applicable nodes can get flattened.\n * @param node - The node whose children need to be resolved.\n * @param context - the async plugin context needed to reach into the cache\n * @returns The same node but with async node children mapped to their resolved AST.\n */\n private resolveAsyncChildren(\n node: Node.Node,\n context: AsyncPluginContext,\n ): Node.Node {\n const asyncNodesResolved: string[] = node.asyncNodesResolved ?? [];\n node.asyncNodesResolved = asyncNodesResolved;\n if (node.type === NodeType.MultiNode) {\n // Using a while loop lets us catch when async nodes produce more async nodes that need to be flattened further\n let index = 0;\n while (index < node.values.length) {\n const childNode = node.values[index];\n if (\n childNode?.type !== NodeType.Async ||\n !this.hasValidMapping(childNode, context)\n ) {\n index++;\n continue;\n }\n\n const mappedNode = context.nodeResolveCache.get(childNode.id);\n asyncNodesResolved.push(childNode.id);\n if (mappedNode.type === NodeType.MultiNode && childNode.flatten) {\n mappedNode.values.forEach((v: Node.Node) => (v.parent = node));\n node.values = [\n ...node.values.slice(0, index),\n ...mappedNode.values,\n ...node.values.slice(index + 1),\n ];\n } else {\n node.values[index] = mappedNode;\n mappedNode.parent = node;\n }\n }\n } else if (\"children\" in node) {\n node.children?.forEach((c) => {\n // Similar to above, using a while loop lets us handle when async nodes produce more async nodes.\n while (\n c.value.type === NodeType.Async &&\n this.hasValidMapping(c.value, context)\n ) {\n asyncNodesResolved.push(c.value.id);\n c.value = context.nodeResolveCache.get(c.value.id);\n c.value.parent = node;\n }\n });\n }\n\n return node;\n }\n\n private async runAsyncNode(\n node: Node.Async,\n context: AsyncPluginContext,\n options: Resolve.NodeResolveOptions,\n ) {\n try {\n const result = await this.basePlugin?.hooks.onAsyncNode.call(\n node,\n (result) => {\n this.parseNodeAndUpdate(node, context, result, options);\n },\n );\n\n // Stop tracking before the next update is triggered\n context.inProgressNodes.delete(node.id);\n this.parseNodeAndUpdate(node, context, result, options);\n } catch (e: unknown) {\n const error = e instanceof Error ? e : new Error(String(e));\n const result = this.basePlugin?.hooks.onAsyncNodeError.call(error, node);\n\n if (result === undefined) {\n const playerState = this.basePlugin?.getPlayerInstance()?.getState();\n\n if (playerState?.status === \"in-progress\") {\n playerState.fail(error);\n }\n\n return;\n }\n\n options.logger?.error(\n \"Async node handling failed and resolved with a fallback. Error:\",\n error,\n );\n\n // Stop tracking before the next update is triggered\n context.inProgressNodes.delete(node.id);\n this.parseNodeAndUpdate(node, context, result, options);\n }\n }\n\n private isAsync(node: Node.Node | null): node is Node.Async {\n return node?.type === NodeType.Async;\n }\n\n private isDeterminedAsync(obj: unknown): obj is AsyncContent {\n return (\n typeof obj === \"object\" &&\n obj !== null &&\n Object.prototype.hasOwnProperty.call(obj, \"async\")\n );\n }\n\n applyParser(parser: Parser): void {\n parser.hooks.parseNode.tap(\n this.name,\n (\n obj: any,\n nodeType: Node.ChildrenTypes,\n options: ParseObjectOptions,\n childOptions?: ParseObjectChildOptions,\n ) => {\n if (this.isDeterminedAsync(obj)) {\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\n const { async, flatten, ...rest } = obj;\n const parsedAsync = parser.parseObject(rest, nodeType, options);\n const parsedNodeId = getNodeID(parsedAsync);\n\n if (parsedAsync === null || !parsedNodeId) {\n return childOptions ? [] : null;\n }\n\n const asyncAST = parser.createASTNode(\n {\n id: parsedNodeId,\n type: NodeType.Async,\n value: parsedAsync,\n flatten,\n },\n obj,\n );\n\n if (childOptions) {\n return asyncAST\n ? [\n {\n path: [...childOptions.path, childOptions.key],\n value: asyncAST,\n },\n ]\n : [];\n }\n\n return asyncAST;\n }\n },\n );\n }\n\n apply(view: ViewInstance): void {\n const context: AsyncPluginContext = {\n nodeResolveCache: new Map(),\n inProgressNodes: new Set(),\n view,\n };\n\n view.hooks.parser.tap(\"async\", this.applyParser.bind(this));\n view.hooks.resolver.tap(\"async\", (resolver) => {\n this.applyResolver(resolver, context);\n });\n }\n\n applyPlugin(asyncNodePlugin: AsyncNodePlugin): void {\n this.basePlugin = asyncNodePlugin;\n }\n}\n","import { Builder } from \"@player-ui/player\";\nimport type { AsyncTransformFunc } from \"./types\";\n\n/**\n * @deprecated Use {@link createAsyncTransform} to create your before transform function.\n * Util function to generate transform function for async asset\n * @param asset - async asset to apply beforeResolve transform\n * @param wrapperAssetType: container asset type\n * @param flatten: flatten the streamed in content\n * @param path: property path to add the multinode containing the next async node to\n * @returns - wrapper asset with children of transformed asset and async node\n */\n\nexport const asyncTransform: AsyncTransformFunc = (\n assetId,\n wrapperAssetType,\n asset,\n flatten,\n path = [\"values\"],\n) => {\n const id = \"async-\" + assetId;\n\n const asyncNode = Builder.asyncNode(id, flatten);\n\n let multiNode;\n let assetNode;\n\n if (asset) {\n assetNode = Builder.assetWrapper(asset);\n multiNode = Builder.multiNode(assetNode, asyncNode);\n } else {\n multiNode = Builder.multiNode(asyncNode);\n }\n\n const wrapperAsset = Builder.asset({\n id: wrapperAssetType + \"-\" + id,\n type: wrapperAssetType,\n });\n\n Builder.addChild(wrapperAsset, path, multiNode);\n\n return wrapperAsset;\n};\n","import {\n BeforeTransformFunction,\n Builder,\n Node,\n NodeType,\n} from \"@player-ui/player\";\nimport {\n extractNodeFromPath,\n requiresAssetWrapper,\n traverseAndReplace,\n unwrapAsset,\n} from \"./utils\";\n\nexport type AsyncTransformOptions = {\n /** Whether or not to flatten the results into its container. Defaults to true */\n flatten?: boolean;\n /** The path to the array within the `wrapperAssetType` that will contain the async content. Defaults to [\"values\"] */\n path?: string[];\n /** The asset type that the transform is matching against. */\n transformAssetType: string;\n /** The asset type that will contain the async content. */\n wrapperAssetType: string;\n /** Function to get any nested asset that will need to be extracted and kept when creating the wrapper asset. */\n getNestedAsset?: (node: Node.ViewOrAsset) => Node.Node | undefined;\n /** Function to get the id for the async node being generated. Defaults to creating an id with the format of async-<ASSET.ID> */\n getAsyncNodeId?: (node: Node.ViewOrAsset) => string;\n};\n\nconst defaultGetNodeId = (node: Node.ViewOrAsset): string => {\n return `async-${node.value.id}`;\n};\n\n/** Creates a BeforeTransformFunction that turns the given asset into a wrapper asset with an async node in it.\n * By setting {@link AsyncTransformOptions.flatten} to true, you can chain multiple of the same asset type to create a flow of async content that\n * exists within a single collection.\n *\n * @param options - Options for managing the transform\n * @returns The {@link BeforeTransformFunction} that can be used for your asset.\n */\nexport const createAsyncTransform = (\n options: AsyncTransformOptions,\n): BeforeTransformFunction => {\n const {\n transformAssetType,\n wrapperAssetType,\n getNestedAsset,\n getAsyncNodeId = defaultGetNodeId,\n path = [\"values\"],\n flatten = true,\n } = options;\n\n const replaceNode = (node: Node.Node): Node.Node => {\n const unwrapped = unwrapAsset(node);\n\n if (\n unwrapped.type !== NodeType.Asset ||\n unwrapped.value.type !== transformAssetType\n ) {\n return node;\n }\n\n const transformed = asyncTransform(unwrapped);\n return extractNodeFromPath(transformed, path) ?? node;\n };\n\n const replacer = (node: Node.Node) => traverseAndReplace(node, replaceNode);\n\n const asyncTransform = (node: Node.ViewOrAsset) => {\n const id = getAsyncNodeId(node);\n const asset = getNestedAsset?.(node);\n\n // If flattening is disabled, don't need to extract the multi-node when async node is resolved.\n const replaceFunction = flatten ? replacer : undefined;\n const asyncNode = Builder.asyncNode(id, flatten, replaceFunction);\n\n let multiNode: Node.MultiNode | undefined;\n if (asset) {\n if (requiresAssetWrapper(asset)) {\n const assetWrappedNode = Builder.assetWrapper(asset);\n multiNode = Builder.multiNode(assetWrappedNode, asyncNode);\n } else if (asset.type === NodeType.MultiNode) {\n multiNode = Builder.multiNode(...(asset.values as any[]), asyncNode);\n } else {\n multiNode = Builder.multiNode(asset as any, asyncNode);\n }\n } else {\n multiNode = Builder.multiNode(asyncNode);\n }\n\n const wrapperAsset: Node.ViewOrAsset = Builder.asset({\n id: wrapperAssetType + \"-\" + id,\n type: wrapperAssetType,\n });\n\n Builder.addChild(wrapperAsset, path, multiNode);\n\n return wrapperAsset;\n };\n\n return asyncTransform;\n};\n","import type { Node } from \"@player-ui/player\";\n\n/** Matches 2 segments where pathA matches or is a subset of pathB. Returns the number of matching segments */\nconst getMatchValue = (\n pathA: Node.PathSegment[],\n pathB: Node.PathSegment[],\n): number => {\n if (pathA.length > pathB.length) {\n return 0;\n }\n\n let matchCount = 0;\n for (let i = 0; i < pathA.length; i++) {\n if (pathA[i] === pathB[i]) {\n matchCount++;\n } else {\n return 0;\n }\n }\n\n return matchCount;\n};\n\n/** Follows the given path and returns the node. If there is no match, returns undefined */\nexport const extractNodeFromPath = (\n node: Node.Node,\n path?: string[],\n): Node.Node | undefined => {\n if (path === undefined || path.length === 0) {\n return node;\n }\n\n if (!(\"children\" in node && node.children)) {\n return undefined;\n }\n\n let matchResult = 0;\n let bestMatch: Node.Child | undefined;\n for (const child of node.children) {\n const matchValue = getMatchValue(child.path, path);\n if (matchValue > matchResult) {\n matchResult = matchValue;\n bestMatch = child;\n }\n }\n\n if (!bestMatch) {\n return undefined;\n }\n\n if (matchResult >= path.length) {\n return bestMatch.value;\n }\n\n return extractNodeFromPath(bestMatch.value, path.slice(matchResult));\n};\n","import { NodeType, Node } from \"@player-ui/player\";\n\n/** Replaces a node using the given replace function. If the node is a multi-node it does this transformation to all of its values. */\nexport const traverseAndReplace = (\n node: Node.Node,\n replaceFn: (node: Node.Node) => Node.Node,\n): Node.Node => {\n if (node.type === NodeType.MultiNode) {\n let index = 0;\n while (index < node.values.length) {\n const child = node.values[index];\n if (!child) {\n index++;\n continue;\n }\n\n const result = replaceFn(child);\n if (result.type === NodeType.MultiNode) {\n node.values = [\n ...node.values.slice(0, index),\n ...result.values,\n ...node.values.slice(index + 1),\n ];\n } else {\n node.values[index] = result;\n index++;\n }\n }\n\n return node;\n }\n\n return replaceFn(node);\n};\n","import { NodeType, Node } from \"@player-ui/player\";\n\nexport const unwrapAsset = (node: Node.Node): Node.Node => {\n if (node.type !== NodeType.Value) {\n return node;\n }\n const child = node.children?.find(\n (x) => x.path.length === 1 && x.path[0] === \"asset\",\n );\n\n if (!child) {\n return node;\n }\n\n return child.value;\n};\n","import { NodeType } from \"@player-ui/player\";\nimport type { Node } from \"@player-ui/player\";\n\nexport const requiresAssetWrapper = (node: Node.Node): boolean => {\n if (node.type === NodeType.Asset) {\n return true;\n }\n\n if (node.type !== NodeType.Applicability) {\n return false;\n }\n\n return node.value.type === NodeType.Asset;\n};\n"],"mappings":";AAAA,SAAS,YAAAA,WAAU,iBAAiB;AAapC,SAAS,uBAAuB,oBAAoB;AACpD,OAAO,oBAAoB;;;ACd3B,SAAS,eAAe;AAajB,IAAM,iBAAqC,CAChD,SACA,kBACA,OACA,SACA,OAAO,CAAC,QAAQ,MACb;AACH,QAAM,KAAK,WAAW;AAEtB,QAAM,YAAY,QAAQ,UAAU,IAAI,OAAO;AAE/C,MAAI;AACJ,MAAI;AAEJ,MAAI,OAAO;AACT,gBAAY,QAAQ,aAAa,KAAK;AACtC,gBAAY,QAAQ,UAAU,WAAW,SAAS;AAAA,EACpD,OAAO;AACL,gBAAY,QAAQ,UAAU,SAAS;AAAA,EACzC;AAEA,QAAM,eAAe,QAAQ,MAAM;AAAA,IACjC,IAAI,mBAAmB,MAAM;AAAA,IAC7B,MAAM;AAAA,EACR,CAAC;AAED,UAAQ,SAAS,cAAc,MAAM,SAAS;AAE9C,SAAO;AACT;;;AC1CA;AAAA,EAEE,WAAAC;AAAA,EAEA,YAAAC;AAAA,OACK;;;ACFP,IAAM,gBAAgB,CACpB,OACA,UACW;AACX,MAAI,MAAM,SAAS,MAAM,QAAQ;AAC/B,WAAO;AAAA,EACT;AAEA,MAAI,aAAa;AACjB,WAAS,IAAI,GAAG,IAAI,MAAM,QAAQ,KAAK;AACrC,QAAI,MAAM,CAAC,MAAM,MAAM,CAAC,GAAG;AACzB;AAAA,IACF,OAAO;AACL,aAAO;AAAA,IACT;AAAA,EACF;AAEA,SAAO;AACT;AAGO,IAAM,sBAAsB,CACjC,MACA,SAC0B;AAC1B,MAAI,SAAS,UAAa,KAAK,WAA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AAkB,GAAG,GAAG;AAE/B,gBAAM,EAAE,OAAO,SAAS,GAAG,KAAK,IAAI;AACpC,gBAAM,cAAc,OAAO,YAAY,MAAM,UAAU,OAAO;AAC9D,gBAAM,eAAe,UAAU,WAAW;AAE1C,cAAI,gBAAgB,QAAQ,CAAC,cAAc;AACzC,mBAAO,eAAe,CAAC,IAAI;AAAA,UAC7B;AAEA,gBAAM,WAAW,OAAO;AAAA,YACtB;AAAA,cACE,IAAI;AAAA,cACJ,MAAMA,UAAS;AAAA,cACf,OAAO;AAAA,cACP;AAAA,YACF;AAAA,YACA;AAAA,UACF;AAEA,cAAI,cAAc;AAChB,mBAAO,WACH;AAAA,cACE;AAAA,gBACE,MAAM,CAAC,GAAG,aAAa,MAAM,aAAa,GAAG;AAAA,gBAC7C,OAAO;AAAA,cACT;AAAA,YACF,IACA,CAAC;AAAA,UACP;AAEA,iBAAO;AAAA,QACT;AAAA,MACF;AAAA,IACF;AAAA,EACF;AAAA,EAEA,MAAM,MAA0B;AAC9B,UAAM,UAA8B;AAAA,MAClC,kBAAkB,oBAAI,IAAI;AAAA,MAC1B,iBAAiB,oBAAI,IAAI;AAAA,MACzB;AAAA,IACF;AAEA,SAAK,MAAM,OAAO,IAAI,SAAS,KAAK,YAAY,KAAK,IAAI,CAAC;AAC1D,SAAK,MAAM,SAAS,IAAI,SAAS,CAAC,aAAa;AAC7C,WAAK,cAAc,UAAU,OAAO;AAAA,IACtC,CAAC;AAAA,EACH;AAAA,EAEA,YAAY,iBAAwC;AAClD,SAAK,aAAa;AAAA,EACpB;AACF;","names":["NodeType","Builder","NodeType","NodeType","NodeType","NodeType","asyncTransform","Builder","NodeType","result"]}
1
+ {"version":3,"sources":["../../../../../../../../../../../../execroot/_main/bazel-out/k8-fastbuild/bin/plugins/async-node/core/src/index.ts","../../../../../../../../../../../../execroot/_main/bazel-out/k8-fastbuild/bin/plugins/async-node/core/src/transform.ts","../../../../../../../../../../../../execroot/_main/bazel-out/k8-fastbuild/bin/plugins/async-node/core/src/createAsyncTransform.ts","../../../../../../../../../../../../execroot/_main/bazel-out/k8-fastbuild/bin/plugins/async-node/core/src/utils/extractNodeFromPath.ts","../../../../../../../../../../../../execroot/_main/bazel-out/k8-fastbuild/bin/plugins/async-node/core/src/utils/traverseAndReplace.ts","../../../../../../../../../../../../execroot/_main/bazel-out/k8-fastbuild/bin/plugins/async-node/core/src/utils/unwrapAsset.ts","../../../../../../../../../../../../execroot/_main/bazel-out/k8-fastbuild/bin/plugins/async-node/core/src/utils/requiresAssetWrapper.ts"],"sourcesContent":["import { NodeType, getNodeID } from \"@player-ui/player\";\nimport type {\n Player,\n PlayerPlugin,\n Node,\n ParseObjectOptions,\n ParseObjectChildOptions,\n ViewInstance,\n Parser,\n ViewPlugin,\n Resolver,\n Resolve,\n} from \"@player-ui/player\";\nimport { AsyncParallelBailHook, SyncBailHook } from \"tapable-ts\";\nimport queueMicrotask from \"queue-microtask\";\n\nexport * from \"./types\";\nexport * from \"./transform\";\nexport * from \"./createAsyncTransform\";\n\n/** Object type for storing data related to a single `apply` of the `AsyncNodePluginPlugin`\n * This object should be setup once per ViewInstance to keep any cached info just for that view to avoid conflicts of shared async node ids across different view states.\n */\ntype AsyncPluginContext = {\n /** Map of async node id to resolved content */\n nodeResolveCache: Map<string, any>;\n /** The view instance this context is attached to. */\n view: ViewInstance;\n /** Map of async node id to promises being used to resolve them */\n inProgressNodes: Set<string>;\n};\n\nexport interface AsyncNodePluginOptions {\n /** A set of plugins to load */\n plugins?: AsyncNodeViewPlugin[];\n}\n\nexport interface AsyncNodeViewPlugin extends ViewPlugin {\n /** Use this to tap into the async node plugin hooks */\n applyPlugin: (asyncNodePlugin: AsyncNodePlugin) => void;\n\n asyncNode: AsyncParallelBailHook<[Node.Async, (result: any) => void], any>;\n}\nexport type AsyncHandler = (\n node: Node.Async,\n callback?: (result: any) => void,\n) => Promise<any>;\n\nexport type AsyncContent = {\n async: true;\n flatten?: boolean;\n [key: string]: unknown;\n};\n\n/** Hook declaration for the AsyncNodePlugin */\nexport type AsyncNodeHooks = {\n /** Async hook to get content for an async node */\n onAsyncNode: AsyncParallelBailHook<[Node.Async, (result: any) => void], any>;\n /** Sync hook to manage errors coming from the onAsyncNode hook. Return a fallback node or null to render a fallback. The first argument of passed in the call is the error thrown. */\n onAsyncNodeError: SyncBailHook<[Error, Node.Async], any>;\n};\n\nexport const AsyncNodePluginSymbol: symbol = Symbol.for(\"AsyncNodePlugin\");\n\n/**\n * Async node plugin used to resolve async nodes in the content\n * If an async node is present, allow users to provide a replacement node to be rendered when ready\n */\nexport class AsyncNodePlugin implements PlayerPlugin {\n private plugins: AsyncNodeViewPlugin[] | undefined;\n private playerInstance: Player | undefined;\n\n static Symbol: symbol = AsyncNodePluginSymbol;\n public readonly symbol: symbol = AsyncNodePlugin.Symbol;\n\n constructor(options: AsyncNodePluginOptions, asyncHandler?: AsyncHandler) {\n if (options?.plugins) {\n this.plugins = options.plugins;\n options.plugins.forEach((plugin) => {\n plugin.applyPlugin(this);\n });\n }\n\n if (asyncHandler) {\n this.hooks.onAsyncNode.tap(\n \"async\",\n async (node: Node.Async, callback) => {\n return await asyncHandler(node, callback);\n },\n );\n }\n }\n\n public readonly hooks: AsyncNodeHooks = {\n onAsyncNode: new AsyncParallelBailHook(),\n onAsyncNodeError: new SyncBailHook(),\n };\n\n getPlayerInstance(): Player | undefined {\n return this.playerInstance;\n }\n\n name = \"AsyncNode\";\n\n apply(player: Player): void {\n this.playerInstance = player;\n\n player.hooks.viewController.tap(this.name, (viewController) => {\n viewController.hooks.view.tap(this.name, (view) => {\n this.plugins?.forEach((plugin) => {\n plugin.apply(view);\n });\n });\n });\n }\n}\n\nexport class AsyncNodePluginPlugin implements AsyncNodeViewPlugin {\n public asyncNode: AsyncParallelBailHook<\n [Node.Async, (result: any) => void],\n any\n > = new AsyncParallelBailHook();\n private basePlugin: AsyncNodePlugin | undefined;\n\n name = \"AsyncNode\";\n\n /**\n * Parses the node from the result and triggers an asynchronous view update if necessary.\n * @param node The asynchronous node that might be updated.\n * @param result The result obtained from resolving the async node. This could be any data structure or value.\n * @param options Options provided for node resolution, including a potential parseNode function to process the result.\n * @param view The view instance where the node resides. This can be undefined if the view is not currently active.\n */\n private parseNodeAndUpdate(\n node: Node.Async,\n context: AsyncPluginContext,\n result: any,\n options: Resolve.NodeResolveOptions,\n ) {\n let parsedNode =\n options.parseNode && result ? options.parseNode(result) : undefined;\n\n if (parsedNode && node.onValueReceived) {\n parsedNode = node.onValueReceived(parsedNode);\n }\n\n this.handleAsyncUpdate(node, context, parsedNode);\n }\n\n /**\n * Updates the node asynchronously based on the result provided.\n * This method is responsible for handling the update logic of asynchronous nodes.\n * It checks if the node needs to be updated based on the new result and updates the mapping accordingly.\n * If an update is necessary, it triggers an asynchronous update on the view.\n * @param node The asynchronous node that might be updated.\n * @param newNode The new node to replace the async node.\n * @param view The view instance where the node resides. This can be undefined if the view is not currently active.\n */\n private handleAsyncUpdate(\n node: Node.Async,\n context: AsyncPluginContext,\n newNode?: Node.Node | null,\n ) {\n const { nodeResolveCache, view } = context;\n if (nodeResolveCache.get(node.id) !== newNode) {\n nodeResolveCache.set(node.id, newNode ? newNode : node);\n view.updateAsync(node.id);\n }\n }\n\n private hasValidMapping(\n node: Node.Async,\n context: AsyncPluginContext,\n ): boolean {\n const { nodeResolveCache } = context;\n return (\n nodeResolveCache.has(node.id) && nodeResolveCache.get(node.id) !== node\n );\n }\n\n /**\n * Handles the asynchronous API integration for resolving nodes.\n * This method sets up a hook on the resolver's `beforeResolve` event to process async nodes.\n * @param resolver The resolver instance to attach the hook to.\n * @param view\n */\n applyResolver(resolver: Resolver, context: AsyncPluginContext): void {\n resolver.hooks.beforeResolve.tap(this.name, (node, options) => {\n if (!this.isAsync(node)) {\n return node === null ? node : this.resolveAsyncChildren(node, context);\n }\n\n const resolvedNode = context.nodeResolveCache.get(node.id);\n if (resolvedNode !== undefined) {\n return this.resolveAsyncChildren(resolvedNode, context);\n }\n\n if (context.inProgressNodes.has(node.id)) {\n return node;\n }\n\n // Track that the node is in progress.\n context.inProgressNodes.add(node.id);\n queueMicrotask(() => {\n this.runAsyncNode(node, context, options).finally();\n });\n\n return node;\n });\n }\n\n /**\n * Replaces child async nodes with their resolved content and flattens when necessary. Resolving the children directly helps manage the `parent` reference without needing as much work within the resolver itself.\n * Handles async node chains as well to make sure all applicable nodes can get flattened.\n * @param node - The node whose children need to be resolved.\n * @param context - the async plugin context needed to reach into the cache\n * @returns The same node but with async node children mapped to their resolved AST.\n */\n private resolveAsyncChildren(\n node: Node.Node,\n context: AsyncPluginContext,\n ): Node.Node {\n const asyncNodesResolved: string[] = node.asyncNodesResolved ?? [];\n node.asyncNodesResolved = asyncNodesResolved;\n if (node.type === NodeType.MultiNode) {\n // Using a while loop lets us catch when async nodes produce more async nodes that need to be flattened further\n let index = 0;\n while (index < node.values.length) {\n const childNode = node.values[index];\n if (\n childNode?.type !== NodeType.Async ||\n !this.hasValidMapping(childNode, context)\n ) {\n index++;\n continue;\n }\n\n const mappedNode = context.nodeResolveCache.get(childNode.id);\n asyncNodesResolved.push(childNode.id);\n if (mappedNode.type === NodeType.MultiNode && childNode.flatten) {\n mappedNode.values.forEach((v: Node.Node) => (v.parent = node));\n node.values = [\n ...node.values.slice(0, index),\n ...mappedNode.values,\n ...node.values.slice(index + 1),\n ];\n } else {\n node.values[index] = mappedNode;\n mappedNode.parent = node;\n }\n }\n } else if (\"children\" in node) {\n node.children?.forEach((c) => {\n // Similar to above, using a while loop lets us handle when async nodes produce more async nodes.\n while (\n c.value.type === NodeType.Async &&\n this.hasValidMapping(c.value, context)\n ) {\n asyncNodesResolved.push(c.value.id);\n c.value = context.nodeResolveCache.get(c.value.id);\n c.value.parent = node;\n }\n });\n }\n\n return node;\n }\n\n private async runAsyncNode(\n node: Node.Async,\n context: AsyncPluginContext,\n options: Resolve.NodeResolveOptions,\n ) {\n try {\n const result = await this.basePlugin?.hooks.onAsyncNode.call(\n node,\n (result) => {\n this.parseNodeAndUpdate(node, context, result, options);\n },\n );\n\n // Stop tracking before the next update is triggered\n context.inProgressNodes.delete(node.id);\n this.parseNodeAndUpdate(node, context, result, options);\n } catch (e: unknown) {\n const error = e instanceof Error ? e : new Error(String(e));\n const result = this.basePlugin?.hooks.onAsyncNodeError.call(error, node);\n\n if (result === undefined) {\n const playerState = this.basePlugin?.getPlayerInstance()?.getState();\n\n if (playerState?.status === \"in-progress\") {\n playerState.fail(error);\n }\n\n return;\n }\n\n options.logger?.error(\n \"Async node handling failed and resolved with a fallback. Error:\",\n error,\n );\n\n // Stop tracking before the next update is triggered\n context.inProgressNodes.delete(node.id);\n this.parseNodeAndUpdate(node, context, result, options);\n }\n }\n\n private isAsync(node: Node.Node | null): node is Node.Async {\n return node?.type === NodeType.Async;\n }\n\n private isDeterminedAsync(obj: unknown): obj is AsyncContent {\n return (\n typeof obj === \"object\" &&\n obj !== null &&\n Object.prototype.hasOwnProperty.call(obj, \"async\")\n );\n }\n\n applyParser(parser: Parser): void {\n parser.hooks.parseNode.tap(\n this.name,\n (\n obj: any,\n nodeType: Node.ChildrenTypes,\n options: ParseObjectOptions,\n childOptions?: ParseObjectChildOptions,\n ) => {\n if (this.isDeterminedAsync(obj)) {\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\n const { async, flatten, ...rest } = obj;\n const parsedAsync = parser.parseObject(rest, nodeType, options);\n const parsedNodeId = getNodeID(parsedAsync);\n\n if (parsedAsync === null || !parsedNodeId) {\n return childOptions ? [] : null;\n }\n\n const asyncAST = parser.createASTNode(\n {\n id: parsedNodeId,\n type: NodeType.Async,\n value: parsedAsync,\n flatten,\n },\n obj,\n );\n\n if (childOptions) {\n return asyncAST\n ? [\n {\n path: [...childOptions.path, childOptions.key],\n value: asyncAST,\n },\n ]\n : [];\n }\n\n return asyncAST;\n }\n },\n );\n }\n\n apply(view: ViewInstance): void {\n const context: AsyncPluginContext = {\n nodeResolveCache: new Map(),\n inProgressNodes: new Set(),\n view,\n };\n\n view.hooks.parser.tap(\"async\", this.applyParser.bind(this));\n view.hooks.resolver.tap(\"async\", (resolver) => {\n this.applyResolver(resolver, context);\n });\n }\n\n applyPlugin(asyncNodePlugin: AsyncNodePlugin): void {\n this.basePlugin = asyncNodePlugin;\n }\n}\n","import { Builder } from \"@player-ui/player\";\nimport type { AsyncTransformFunc } from \"./types\";\n\n/**\n * @deprecated Use {@link createAsyncTransform} to create your before transform function.\n * Util function to generate transform function for async asset\n * @param asset - async asset to apply beforeResolve transform\n * @param wrapperAssetType: container asset type\n * @param flatten: flatten the streamed in content\n * @param path: property path to add the multinode containing the next async node to\n * @returns - wrapper asset with children of transformed asset and async node\n */\n\nexport const asyncTransform: AsyncTransformFunc = (\n assetId,\n wrapperAssetType,\n asset,\n flatten,\n path = [\"values\"],\n) => {\n const id = \"async-\" + assetId;\n\n const asyncNode = Builder.asyncNode(id, flatten);\n\n let multiNode;\n let assetNode;\n\n if (asset) {\n assetNode = Builder.assetWrapper(asset);\n multiNode = Builder.multiNode(assetNode, asyncNode);\n } else {\n multiNode = Builder.multiNode(asyncNode);\n }\n\n const wrapperAsset = Builder.asset({\n id: wrapperAssetType + \"-\" + id,\n type: wrapperAssetType,\n });\n\n Builder.addChild(wrapperAsset, path, multiNode);\n\n return wrapperAsset;\n};\n","import {\n BeforeTransformFunction,\n Builder,\n Node,\n NodeType,\n} from \"@player-ui/player\";\nimport {\n extractNodeFromPath,\n requiresAssetWrapper,\n traverseAndReplace,\n unwrapAsset,\n} from \"./utils\";\n\nexport type AsyncTransformOptions = {\n /** Whether or not to flatten the results into its container. Defaults to true */\n flatten?: boolean;\n /** The path to the array within the `wrapperAssetType` that will contain the async content. Defaults to [\"values\"] */\n path?: string[];\n /** The asset type that the transform is matching against. */\n transformAssetType: string;\n /** The asset type that will contain the async content. */\n wrapperAssetType: string;\n /** Function to get any nested asset that will need to be extracted and kept when creating the wrapper asset. */\n getNestedAsset?: (node: Node.ViewOrAsset) => Node.Node | undefined;\n /** Function to get the id for the async node being generated. Defaults to creating an id with the format of async-<ASSET.ID> */\n getAsyncNodeId?: (node: Node.ViewOrAsset) => string;\n /** Where to place the async node relative to the asset from `getNestedAsset`. Defaults to \"append\" */\n asyncNodePosition?: \"append\" | \"prepend\";\n};\n\nconst defaultGetNodeId = (node: Node.ViewOrAsset): string => {\n return `async-${node.value.id}`;\n};\n\n/** Creates a BeforeTransformFunction that turns the given asset into a wrapper asset with an async node in it.\n * By setting {@link AsyncTransformOptions.flatten} to true, you can chain multiple of the same asset type to create a flow of async content that\n * exists within a single collection.\n *\n * @param options - Options for managing the transform\n * @returns The {@link BeforeTransformFunction} that can be used for your asset.\n */\nexport const createAsyncTransform = (\n options: AsyncTransformOptions,\n): BeforeTransformFunction => {\n const {\n transformAssetType,\n wrapperAssetType,\n getNestedAsset,\n getAsyncNodeId = defaultGetNodeId,\n path = [\"values\"],\n flatten = true,\n asyncNodePosition = \"append\",\n } = options;\n\n const replaceNode = (node: Node.Node): Node.Node => {\n const unwrapped = unwrapAsset(node);\n\n if (\n unwrapped.type !== NodeType.Asset ||\n unwrapped.value.type !== transformAssetType\n ) {\n return node;\n }\n\n const transformed = asyncTransform(unwrapped);\n return extractNodeFromPath(transformed, path) ?? node;\n };\n\n const replacer = (node: Node.Node) => traverseAndReplace(node, replaceNode);\n\n const asyncTransform = (node: Node.ViewOrAsset) => {\n const id = getAsyncNodeId(node);\n const asset = getNestedAsset?.(node);\n\n // If flattening is disabled, don't need to extract the multi-node when async node is resolved.\n const replaceFunction = flatten ? replacer : undefined;\n const asyncNode = Builder.asyncNode(id, flatten, replaceFunction);\n\n const values: Node.Node[] = [asyncNode];\n if (asset) {\n const otherValues = [];\n if (requiresAssetWrapper(asset)) {\n otherValues.push(Builder.assetWrapper(asset));\n } else if (asset.type === NodeType.MultiNode) {\n otherValues.push(...asset.values);\n } else {\n otherValues.push(asset);\n }\n\n if (asyncNodePosition === \"append\") {\n values.unshift(...otherValues);\n } else {\n values.push(...otherValues);\n }\n }\n\n const multiNode = Builder.multiNode(...(values as any[]));\n\n const wrapperAsset: Node.ViewOrAsset = Builder.asset({\n id: wrapperAssetType + \"-\" + id,\n type: wrapperAssetType,\n });\n\n Builder.addChild(wrapperAsset, path, multiNode);\n\n return wrapperAsset;\n };\n\n return asyncTransform;\n};\n","import type { Node } from \"@player-ui/player\";\n\n/** Matches 2 segments where pathA matches or is a subset of pathB. Returns the number of matching segments */\nconst getMatchValue = (\n pathA: Node.PathSegment[],\n pathB: Node.PathSegment[],\n): number => {\n if (pathA.length > pathB.length) {\n return 0;\n }\n\n let matchCount = 0;\n for (let i = 0; i < pathA.length; i++) {\n if (pathA[i] === pathB[i]) {\n matchCount++;\n } else {\n return 0;\n }\n }\n\n return matchCount;\n};\n\n/** Follows the given path and returns the node. If there is no match, returns undefined */\nexport const extractNodeFromPath = (\n node: Node.Node,\n path?: string[],\n): Node.Node | undefined => {\n if (path === undefined || path.length === 0) {\n return node;\n }\n\n if (!(\"children\" in node && node.children)) {\n return undefined;\n }\n\n let matchResult = 0;\n let bestMatch: Node.Child | undefined;\n for (const child of node.children) {\n const matchValue = getMatchValue(child.path, path);\n if (matchValue > matchResult) {\n matchResult = matchValue;\n bestMatch = child;\n }\n }\n\n if (!bestMatch) {\n return undefined;\n }\n\n if (matchResult >= path.length) {\n return bestMatch.value;\n }\n\n return extractNodeFromPath(bestMatch.value, path.slice(matchResult));\n};\n","import { NodeType, Node } from \"@player-ui/player\";\n\n/** Replaces a node using the given replace function. If the node is a multi-node it does this transformation to all of its values. */\nexport const traverseAndReplace = (\n node: Node.Node,\n replaceFn: (node: Node.Node) => Node.Node,\n): Node.Node => {\n if (node.type === NodeType.MultiNode) {\n let index = 0;\n while (index < node.values.length) {\n const child = node.values[index];\n if (!child) {\n index++;\n continue;\n }\n\n const result = replaceFn(child);\n if (result.type === NodeType.MultiNode) {\n node.values = [\n ...node.values.slice(0, index),\n ...result.values,\n ...node.values.slice(index + 1),\n ];\n } else {\n node.values[index] = result;\n index++;\n }\n }\n\n return node;\n }\n\n return replaceFn(node);\n};\n","import { NodeType, Node } from \"@player-ui/player\";\n\nexport const unwrapAsset = (node: Node.Node): Node.Node => {\n if (node.type !== NodeType.Value) {\n return node;\n }\n const child = node.children?.find(\n (x) => x.path.length === 1 && x.path[0] === \"asset\",\n );\n\n if (!child) {\n return node;\n }\n\n return child.value;\n};\n","import { NodeType } from \"@player-ui/player\";\nimport type { Node } from \"@player-ui/player\";\n\nexport const requiresAssetWrapper = (node: Node.Node): boolean => {\n if (node.type === NodeType.Asset) {\n return true;\n }\n\n if (node.type !== NodeType.Applicability) {\n return false;\n }\n\n return node.value.type === NodeType.Asset;\n};\n"],"mappings":";AAAA,SAAS,YAAAA,WAAU,iBAAiB;AAapC,SAAS,uBAAuB,oBAAoB;AACpD,OAAO,oBAAoB;;;ACd3B,SAAS,eAAe;AAajB,IAAM,iBAAqC,CAChD,SACA,kBACA,OACA,SACA,OAAO,CAAC,QAAQ,MACb;AACH,QAAM,KAAK,WAAW;AAEtB,QAAM,YAAY,QAAQ,UAAU,IAAI,OAAO;AAE/C,MAAI;AACJ,MAAI;AAEJ,MAAI,OAAO;AACT,gBAAY,QAAQ,aAAa,KAAK;AACtC,gBAAY,QAAQ,UAAU,WAAW,SAAS;AAAA,EACpD,OAAO;AACL,gBAAY,QAAQ,UAAU,SAAS;AAAA,EACzC;AAEA,QAAM,eAAe,QAAQ,MAAM;AAAA,IACjC,IAAI,mBAAmB,MAAM;AAAA,IAC7B,MAAM;AAAA,EACR,CAAC;AAED,UAAQ,SAAS,cAAc,MAAM,SAAS;AAE9C,SAAO;AACT;;;AC1CA;AAAA,EAEE,WAAAC;AAAA,EAEA,YAAAC;AAAA,OACK;;;ACFP,IAAM,gBAAgB,CACpB,OACA,UACW;AACX,MAAI,MAAM,SAAS,MAAM,QAAQ;AAC/B,WAAO;AAAA,EACT;AAEA,MAAI,aAAa;AACjB,WAAS,IAAI,GAAG,IAAI,MAAM,QAAQ,KAAK;AACrC,QAAI,MAAM,CAAC,MAAM,MAAM,C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;AACF;","names":["NodeType","Builder","NodeType","NodeType","NodeType","NodeType","asyncTransform","Builder","NodeType","result"]}
package/package.json CHANGED
@@ -6,10 +6,10 @@
6
6
  "types"
7
7
  ],
8
8
  "name": "@player-ui/async-node-plugin",
9
- "version": "0.14.0-next.2",
9
+ "version": "0.14.0-next.3",
10
10
  "main": "dist/cjs/index.cjs",
11
11
  "peerDependencies": {
12
- "@player-ui/player": "0.14.0-next.2"
12
+ "@player-ui/player": "0.14.0-next.3"
13
13
  },
14
14
  "devDependencies": {
15
15
  "@player-ui/check-path-plugin": "workspace:*",
@@ -318,6 +318,116 @@ describe("createAsyncTransform", () => {
318
318
  });
319
319
  });
320
320
 
321
+ describe("async node position", () => {
322
+ it("should place the async node before the inner asset node when the asyncNodePosition is 'prepend'", () => {
323
+ const transform = createAsyncTransform({
324
+ transformAssetType: "chat-message",
325
+ wrapperAssetType: "collection",
326
+ flatten: false,
327
+ path: ["array"],
328
+ getNestedAsset: () => ({
329
+ type: NodeType.Empty,
330
+ }),
331
+ getAsyncNodeId: () => "async-node",
332
+ asyncNodePosition: "prepend",
333
+ });
334
+ const result = transform(asset, {} as any, {} as any);
335
+
336
+ expect(result).toStrictEqual({
337
+ type: NodeType.Asset,
338
+ children: [
339
+ {
340
+ path: ["array"],
341
+ value: {
342
+ type: NodeType.MultiNode,
343
+ override: true,
344
+ parent: expect.anything(),
345
+ values: [
346
+ {
347
+ parent: expect.anything(),
348
+ type: NodeType.Async,
349
+ flatten: false,
350
+ onValueReceived: undefined,
351
+ id: "async-node",
352
+ value: {
353
+ type: NodeType.Value,
354
+ value: {
355
+ id: "async-node",
356
+ },
357
+ },
358
+ },
359
+ {
360
+ parent: expect.anything(),
361
+ type: NodeType.Empty,
362
+ },
363
+ ],
364
+ },
365
+ },
366
+ ],
367
+ value: {
368
+ id: "collection-async-node",
369
+ type: "collection",
370
+ },
371
+ });
372
+ });
373
+
374
+ const options = ["append", undefined] as const;
375
+ it.each(options)(
376
+ "should place the async node after the inner asset node when the asyncNodePosition is 'append' or undefined",
377
+ (position) => {
378
+ const transform = createAsyncTransform({
379
+ transformAssetType: "chat-message",
380
+ wrapperAssetType: "collection",
381
+ flatten: false,
382
+ path: ["array"],
383
+ getNestedAsset: () => ({
384
+ type: NodeType.Empty,
385
+ }),
386
+ getAsyncNodeId: () => "async-node",
387
+ asyncNodePosition: position,
388
+ });
389
+ const result = transform(asset, {} as any, {} as any);
390
+
391
+ expect(result).toStrictEqual({
392
+ type: NodeType.Asset,
393
+ children: [
394
+ {
395
+ path: ["array"],
396
+ value: {
397
+ type: NodeType.MultiNode,
398
+ override: true,
399
+ parent: expect.anything(),
400
+ values: [
401
+ {
402
+ parent: expect.anything(),
403
+ type: NodeType.Empty,
404
+ },
405
+ {
406
+ parent: expect.anything(),
407
+ type: NodeType.Async,
408
+ flatten: false,
409
+ onValueReceived: undefined,
410
+ id: "async-node",
411
+ value: {
412
+ type: NodeType.Value,
413
+ value: {
414
+ id: "async-node",
415
+ },
416
+ },
417
+ },
418
+ ],
419
+ },
420
+ },
421
+ ],
422
+ value: {
423
+ id: "collection-async-node",
424
+ type: "collection",
425
+ },
426
+ });
427
+ },
428
+ );
429
+ });
430
+
321
431
  describe("onValueReceived callback setup", () => {
322
432
  let transformedAsset: Node.Node;
323
433
  let onValueReceivedFuncion: ((node: Node.Node) => Node.Node) | undefined;
@@ -24,6 +24,8 @@ export type AsyncTransformOptions = {
24
24
  getNestedAsset?: (node: Node.ViewOrAsset) => Node.Node | undefined;
25
25
  /** Function to get the id for the async node being generated. Defaults to creating an id with the format of async-<ASSET.ID> */
26
26
  getAsyncNodeId?: (node: Node.ViewOrAsset) => string;
27
+ /** Where to place the async node relative to the asset from `getNestedAsset`. Defaults to "append" */
28
+ asyncNodePosition?: "append" | "prepend";
27
29
  };
28
30
 
29
31
  const defaultGetNodeId = (node: Node.ViewOrAsset): string => {
@@ -47,6 +49,7 @@ export const createAsyncTransform = (
47
49
  getAsyncNodeId = defaultGetNodeId,
48
50
  path = ["values"],
49
51
  flatten = true,
52
+ asyncNodePosition = "append",
50
53
  } = options;
51
54
 
52
55
  const replaceNode = (node: Node.Node): Node.Node => {
@@ -73,20 +76,26 @@ export const createAsyncTransform = (
73
76
  const replaceFunction = flatten ? replacer : undefined;
74
77
  const asyncNode = Builder.asyncNode(id, flatten, replaceFunction);
75
78
 
76
- let multiNode: Node.MultiNode | undefined;
79
+ const values: Node.Node[] = [asyncNode];
77
80
  if (asset) {
81
+ const otherValues = [];
78
82
  if (requiresAssetWrapper(asset)) {
79
- const assetWrappedNode = Builder.assetWrapper(asset);
80
- multiNode = Builder.multiNode(assetWrappedNode, asyncNode);
83
+ otherValues.push(Builder.assetWrapper(asset));
81
84
  } else if (asset.type === NodeType.MultiNode) {
82
- multiNode = Builder.multiNode(...(asset.values as any[]), asyncNode);
85
+ otherValues.push(...asset.values);
83
86
  } else {
84
- multiNode = Builder.multiNode(asset as any, asyncNode);
87
+ otherValues.push(asset);
88
+ }
89
+
90
+ if (asyncNodePosition === "append") {
91
+ values.unshift(...otherValues);
92
+ } else {
93
+ values.push(...otherValues);
85
94
  }
86
- } else {
87
- multiNode = Builder.multiNode(asyncNode);
88
95
  }
89
96
 
97
+ const multiNode = Builder.multiNode(...(values as any[]));
98
+
90
99
  const wrapperAsset: Node.ViewOrAsset = Builder.asset({
91
100
  id: wrapperAssetType + "-" + id,
92
101
  type: wrapperAssetType,
@@ -12,6 +12,8 @@ export type AsyncTransformOptions = {
12
12
  getNestedAsset?: (node: Node.ViewOrAsset) => Node.Node | undefined;
13
13
  /** Function to get the id for the async node being generated. Defaults to creating an id with the format of async-<ASSET.ID> */
14
14
  getAsyncNodeId?: (node: Node.ViewOrAsset) => string;
15
+ /** Where to place the async node relative to the asset from `getNestedAsset`. Defaults to "append" */
16
+ asyncNodePosition?: "append" | "prepend";
15
17
  };
16
18
  /** Creates a BeforeTransformFunction that turns the given asset into a wrapper asset with an async node in it.
17
19
  * By setting {@link AsyncTransformOptions.flatten} to true, you can chain multiple of the same asset type to create a flow of async content that