@player-ui/async-node-plugin 0.13.0 → 0.13.1--canary.716.26546

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.
Files changed (34) hide show
  1. package/dist/AsyncNodePlugin.native.js +479 -280
  2. package/dist/AsyncNodePlugin.native.js.map +1 -1
  3. package/dist/cjs/index.cjs +224 -21
  4. package/dist/cjs/index.cjs.map +1 -1
  5. package/dist/index.legacy-esm.js +224 -19
  6. package/dist/index.mjs +224 -19
  7. package/dist/index.mjs.map +1 -1
  8. package/package.json +2 -2
  9. package/src/__tests__/__snapshots__/transform.test.ts.snap +1 -0
  10. package/src/__tests__/createAsyncTransform.test.ts +515 -0
  11. package/src/__tests__/index.test.ts +94 -13
  12. package/src/__tests__/transform.bench.ts +177 -0
  13. package/src/createAsyncTransform.ts +110 -0
  14. package/src/index.ts +95 -19
  15. package/src/transform.ts +5 -2
  16. package/src/types.ts +1 -0
  17. package/src/utils/__tests__/extractNodeFromPath.test.ts +181 -0
  18. package/src/utils/__tests__/requiresAssetWrapper.test.ts +63 -0
  19. package/src/utils/__tests__/traverseAndReplace.test.ts +182 -0
  20. package/src/utils/__tests__/unwrapAsset.test.ts +65 -0
  21. package/src/utils/extractNodeFromPath.ts +56 -0
  22. package/src/utils/index.ts +4 -0
  23. package/src/utils/requiresAssetWrapper.ts +14 -0
  24. package/src/utils/traverseAndReplace.ts +34 -0
  25. package/src/utils/unwrapAsset.ts +16 -0
  26. package/types/createAsyncTransform.d.ts +26 -0
  27. package/types/index.d.ts +16 -6
  28. package/types/transform.d.ts +2 -1
  29. package/types/types.d.ts +1 -1
  30. package/types/utils/extractNodeFromPath.d.ts +4 -0
  31. package/types/utils/index.d.ts +5 -0
  32. package/types/utils/requiresAssetWrapper.d.ts +3 -0
  33. package/types/utils/traverseAndReplace.d.ts +4 -0
  34. package/types/utils/unwrapAsset.d.ts +3 -0
@@ -1,12 +1,11 @@
1
1
  // ../../../../../../../../../../../execroot/_main/bazel-out/k8-fastbuild/bin/plugins/async-node/core/src/index.ts
2
- import { NodeType, getNodeID } from "@player-ui/player";
2
+ import { NodeType as NodeType5, getNodeID } from "@player-ui/player";
3
3
  import { AsyncParallelBailHook, SyncBailHook } from "tapable-ts";
4
4
  import queueMicrotask from "queue-microtask";
5
- import { omit } from "timm";
6
5
 
7
6
  // ../../../../../../../../../../../execroot/_main/bazel-out/k8-fastbuild/bin/plugins/async-node/core/src/transform.ts
8
7
  import { Builder } from "@player-ui/player";
9
- var asyncTransform = (assetId, wrapperAssetType, asset, flatten) => {
8
+ var asyncTransform = (assetId, wrapperAssetType, asset, flatten, path = ["values"]) => {
10
9
  const id = "async-" + assetId;
11
10
  const asyncNode = Builder.asyncNode(id, flatten);
12
11
  let multiNode;
@@ -21,10 +20,166 @@ var asyncTransform = (assetId, wrapperAssetType, asset, flatten) => {
21
20
  id: wrapperAssetType + "-" + id,
22
21
  type: wrapperAssetType
23
22
  });
24
- Builder.addChild(wrapperAsset, ["values"], multiNode);
23
+ Builder.addChild(wrapperAsset, path, multiNode);
25
24
  return wrapperAsset;
26
25
  };
27
26
 
27
+ // ../../../../../../../../../../../execroot/_main/bazel-out/k8-fastbuild/bin/plugins/async-node/core/src/createAsyncTransform.ts
28
+ import {
29
+ Builder as Builder2,
30
+ NodeType as NodeType4
31
+ } from "@player-ui/player";
32
+
33
+ // ../../../../../../../../../../../execroot/_main/bazel-out/k8-fastbuild/bin/plugins/async-node/core/src/utils/extractNodeFromPath.ts
34
+ var getMatchValue = (pathA, pathB) => {
35
+ if (pathA.length > pathB.length) {
36
+ return 0;
37
+ }
38
+ let matchCount = 0;
39
+ for (let i = 0; i < pathA.length; i++) {
40
+ if (pathA[i] === pathB[i]) {
41
+ matchCount++;
42
+ } else {
43
+ return 0;
44
+ }
45
+ }
46
+ return matchCount;
47
+ };
48
+ var extractNodeFromPath = (node, path) => {
49
+ if (path === void 0 || path.length === 0) {
50
+ return node;
51
+ }
52
+ if (!("children" in node && node.children)) {
53
+ return void 0;
54
+ }
55
+ let matchResult = 0;
56
+ let bestMatch;
57
+ for (const child of node.children) {
58
+ const matchValue = getMatchValue(child.path, path);
59
+ if (matchValue > matchResult) {
60
+ matchResult = matchValue;
61
+ bestMatch = child;
62
+ }
63
+ }
64
+ if (!bestMatch) {
65
+ return void 0;
66
+ }
67
+ if (matchResult >= path.length) {
68
+ return bestMatch.value;
69
+ }
70
+ return extractNodeFromPath(bestMatch.value, path.slice(matchResult));
71
+ };
72
+
73
+ // ../../../../../../../../../../../execroot/_main/bazel-out/k8-fastbuild/bin/plugins/async-node/core/src/utils/traverseAndReplace.ts
74
+ import { NodeType } from "@player-ui/player";
75
+ var traverseAndReplace = (node, replaceFn) => {
76
+ if (node.type === NodeType.MultiNode) {
77
+ let index = 0;
78
+ while (index < node.values.length) {
79
+ const child = node.values[index];
80
+ if (!child) {
81
+ index++;
82
+ continue;
83
+ }
84
+ const result = replaceFn(child);
85
+ if (result.type === NodeType.MultiNode) {
86
+ node.values = [
87
+ ...node.values.slice(0, index),
88
+ ...result.values,
89
+ ...node.values.slice(index + 1)
90
+ ];
91
+ } else {
92
+ node.values[index] = result;
93
+ index++;
94
+ }
95
+ }
96
+ return node;
97
+ }
98
+ return replaceFn(node);
99
+ };
100
+
101
+ // ../../../../../../../../../../../execroot/_main/bazel-out/k8-fastbuild/bin/plugins/async-node/core/src/utils/unwrapAsset.ts
102
+ import { NodeType as NodeType2 } from "@player-ui/player";
103
+ var unwrapAsset = (node) => {
104
+ if (node.type !== NodeType2.Value) {
105
+ return node;
106
+ }
107
+ const child = node.children?.find(
108
+ (x) => x.path.length === 1 && x.path[0] === "asset"
109
+ );
110
+ if (!child) {
111
+ return node;
112
+ }
113
+ return child.value;
114
+ };
115
+
116
+ // ../../../../../../../../../../../execroot/_main/bazel-out/k8-fastbuild/bin/plugins/async-node/core/src/utils/requiresAssetWrapper.ts
117
+ import { NodeType as NodeType3 } from "@player-ui/player";
118
+ var requiresAssetWrapper = (node) => {
119
+ if (node.type === NodeType3.Asset) {
120
+ return true;
121
+ }
122
+ if (node.type !== NodeType3.Applicability) {
123
+ return false;
124
+ }
125
+ return node.value.type === NodeType3.Asset;
126
+ };
127
+
128
+ // ../../../../../../../../../../../execroot/_main/bazel-out/k8-fastbuild/bin/plugins/async-node/core/src/createAsyncTransform.ts
129
+ var defaultGetNodeId = (node) => {
130
+ return `async-${node.value.id}`;
131
+ };
132
+ var createAsyncTransform = (options) => {
133
+ const {
134
+ transformAssetType,
135
+ wrapperAssetType,
136
+ getNestedAsset,
137
+ getAsyncNodeId = defaultGetNodeId,
138
+ path = ["values"],
139
+ flatten = true,
140
+ asyncNodePosition = "append"
141
+ } = options;
142
+ const replaceNode = (node) => {
143
+ const unwrapped = unwrapAsset(node);
144
+ if (unwrapped.type !== NodeType4.Asset || unwrapped.value.type !== transformAssetType) {
145
+ return node;
146
+ }
147
+ const transformed = asyncTransform2(unwrapped);
148
+ return extractNodeFromPath(transformed, path) ?? node;
149
+ };
150
+ const replacer = (node) => traverseAndReplace(node, replaceNode);
151
+ const asyncTransform2 = (node) => {
152
+ const id = getAsyncNodeId(node);
153
+ const asset = getNestedAsset?.(node);
154
+ const replaceFunction = flatten ? replacer : void 0;
155
+ const asyncNode = Builder2.asyncNode(id, flatten, replaceFunction);
156
+ const values = [asyncNode];
157
+ if (asset) {
158
+ const otherValues = [];
159
+ if (requiresAssetWrapper(asset)) {
160
+ otherValues.push(Builder2.assetWrapper(asset));
161
+ } else if (asset.type === NodeType4.MultiNode) {
162
+ otherValues.push(...asset.values);
163
+ } else {
164
+ otherValues.push(asset);
165
+ }
166
+ if (asyncNodePosition === "append") {
167
+ values.unshift(...otherValues);
168
+ } else {
169
+ values.push(...otherValues);
170
+ }
171
+ }
172
+ const multiNode = Builder2.multiNode(...values);
173
+ const wrapperAsset = Builder2.asset({
174
+ id: wrapperAssetType + "-" + id,
175
+ type: wrapperAssetType
176
+ });
177
+ Builder2.addChild(wrapperAsset, path, multiNode);
178
+ return wrapperAsset;
179
+ };
180
+ return asyncTransform2;
181
+ };
182
+
28
183
  // ../../../../../../../../../../../execroot/_main/bazel-out/k8-fastbuild/bin/plugins/async-node/core/src/index.ts
29
184
  var AsyncNodePluginSymbol = Symbol.for("AsyncNodePlugin");
30
185
  var _AsyncNodePlugin = class _AsyncNodePlugin {
@@ -68,7 +223,6 @@ _AsyncNodePlugin.Symbol = AsyncNodePluginSymbol;
68
223
  var AsyncNodePlugin = _AsyncNodePlugin;
69
224
  var AsyncNodePluginPlugin = class {
70
225
  constructor() {
71
- this.asyncNode = new AsyncParallelBailHook();
72
226
  this.name = "AsyncNode";
73
227
  }
74
228
  /**
@@ -79,7 +233,10 @@ var AsyncNodePluginPlugin = class {
79
233
  * @param view The view instance where the node resides. This can be undefined if the view is not currently active.
80
234
  */
81
235
  parseNodeAndUpdate(node, context, result, options) {
82
- const parsedNode = options.parseNode && result ? options.parseNode(result) : void 0;
236
+ let parsedNode = options.parseNode && result ? options.parseNode(result) : void 0;
237
+ if (parsedNode && node.onValueReceived) {
238
+ parsedNode = node.onValueReceived(parsedNode);
239
+ }
83
240
  this.handleAsyncUpdate(node, context, parsedNode);
84
241
  }
85
242
  /**
@@ -95,9 +252,13 @@ var AsyncNodePluginPlugin = class {
95
252
  const { nodeResolveCache, view } = context;
96
253
  if (nodeResolveCache.get(node.id) !== newNode) {
97
254
  nodeResolveCache.set(node.id, newNode ? newNode : node);
98
- view.updateAsync();
255
+ view.updateAsync(node.id);
99
256
  }
100
257
  }
258
+ hasValidMapping(node, context) {
259
+ const { nodeResolveCache } = context;
260
+ return nodeResolveCache.has(node.id) && nodeResolveCache.get(node.id) !== node;
261
+ }
101
262
  /**
102
263
  * Handles the asynchronous API integration for resolving nodes.
103
264
  * This method sets up a hook on the resolver's `beforeResolve` event to process async nodes.
@@ -107,11 +268,13 @@ var AsyncNodePluginPlugin = class {
107
268
  applyResolver(resolver, context) {
108
269
  resolver.hooks.beforeResolve.tap(this.name, (node, options) => {
109
270
  if (!this.isAsync(node)) {
110
- return node;
271
+ return node === null ? node : this.resolveAsyncChildren(node, context);
111
272
  }
112
273
  const resolvedNode = context.nodeResolveCache.get(node.id);
113
274
  if (resolvedNode !== void 0) {
114
- return resolvedNode;
275
+ const existingResolvedNodes = node.asyncNodesResolved ?? [];
276
+ resolvedNode.asyncNodesResolved = [...existingResolvedNodes, node.id];
277
+ return this.resolveAsyncChildren(resolvedNode, context);
115
278
  }
116
279
  if (context.inProgressNodes.has(node.id)) {
117
280
  return node;
@@ -123,6 +286,49 @@ var AsyncNodePluginPlugin = class {
123
286
  return node;
124
287
  });
125
288
  }
289
+ /**
290
+ * 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.
291
+ * Handles async node chains as well to make sure all applicable nodes can get flattened.
292
+ * @param node - The node whose children need to be resolved.
293
+ * @param context - the async plugin context needed to reach into the cache
294
+ * @returns The same node but with async node children mapped to their resolved AST.
295
+ */
296
+ resolveAsyncChildren(node, context) {
297
+ const asyncNodesResolved = node.asyncNodesResolved ?? [];
298
+ node.asyncNodesResolved = asyncNodesResolved;
299
+ if (node.type === NodeType5.MultiNode) {
300
+ let index = 0;
301
+ while (index < node.values.length) {
302
+ const childNode = node.values[index];
303
+ if (childNode?.type !== NodeType5.Async || !this.hasValidMapping(childNode, context)) {
304
+ index++;
305
+ continue;
306
+ }
307
+ const mappedNode = context.nodeResolveCache.get(childNode.id);
308
+ asyncNodesResolved.push(childNode.id);
309
+ if (mappedNode.type === NodeType5.MultiNode && childNode.flatten) {
310
+ mappedNode.values.forEach((v) => v.parent = node);
311
+ node.values = [
312
+ ...node.values.slice(0, index),
313
+ ...mappedNode.values,
314
+ ...node.values.slice(index + 1)
315
+ ];
316
+ } else {
317
+ node.values[index] = mappedNode;
318
+ mappedNode.parent = node;
319
+ }
320
+ }
321
+ } else if ("children" in node) {
322
+ node.children?.forEach((c) => {
323
+ while (c.value.type === NodeType5.Async && this.hasValidMapping(c.value, context)) {
324
+ asyncNodesResolved.push(c.value.id);
325
+ c.value = context.nodeResolveCache.get(c.value.id);
326
+ c.value.parent = node;
327
+ }
328
+ });
329
+ }
330
+ return node;
331
+ }
126
332
  async runAsyncNode(node, context, options) {
127
333
  try {
128
334
  const result = await this.basePlugin?.hooks.onAsyncNode.call(
@@ -152,21 +358,18 @@ var AsyncNodePluginPlugin = class {
152
358
  }
153
359
  }
154
360
  isAsync(node) {
155
- return node?.type === NodeType.Async;
361
+ return node?.type === NodeType5.Async;
156
362
  }
157
363
  isDeterminedAsync(obj) {
158
- return obj && Object.prototype.hasOwnProperty.call(obj, "async");
364
+ return typeof obj === "object" && obj !== null && Object.prototype.hasOwnProperty.call(obj, "async");
159
365
  }
160
366
  applyParser(parser) {
161
367
  parser.hooks.parseNode.tap(
162
368
  this.name,
163
369
  (obj, nodeType, options, childOptions) => {
164
370
  if (this.isDeterminedAsync(obj)) {
165
- const parsedAsync = parser.parseObject(
166
- omit(obj, "async"),
167
- nodeType,
168
- options
169
- );
371
+ const { async, flatten, ...rest } = obj;
372
+ const parsedAsync = parser.parseObject(rest, nodeType, options);
170
373
  const parsedNodeId = getNodeID(parsedAsync);
171
374
  if (parsedAsync === null || !parsedNodeId) {
172
375
  return childOptions ? [] : null;
@@ -174,8 +377,9 @@ var AsyncNodePluginPlugin = class {
174
377
  const asyncAST = parser.createASTNode(
175
378
  {
176
379
  id: parsedNodeId,
177
- type: NodeType.Async,
178
- value: parsedAsync
380
+ type: NodeType5.Async,
381
+ value: parsedAsync,
382
+ flatten
179
383
  },
180
384
  obj
181
385
  );
@@ -211,6 +415,7 @@ export {
211
415
  AsyncNodePlugin,
212
416
  AsyncNodePluginPlugin,
213
417
  AsyncNodePluginSymbol,
214
- asyncTransform
418
+ asyncTransform,
419
+ createAsyncTransform
215
420
  };
216
421
  //# sourceMappingURL=index.mjs.map
package/dist/index.mjs CHANGED
@@ -1,12 +1,11 @@
1
1
  // ../../../../../../../../../../../execroot/_main/bazel-out/k8-fastbuild/bin/plugins/async-node/core/src/index.ts
2
- import { NodeType, getNodeID } from "@player-ui/player";
2
+ import { NodeType as NodeType5, getNodeID } from "@player-ui/player";
3
3
  import { AsyncParallelBailHook, SyncBailHook } from "tapable-ts";
4
4
  import queueMicrotask from "queue-microtask";
5
- import { omit } from "timm";
6
5
 
7
6
  // ../../../../../../../../../../../execroot/_main/bazel-out/k8-fastbuild/bin/plugins/async-node/core/src/transform.ts
8
7
  import { Builder } from "@player-ui/player";
9
- var asyncTransform = (assetId, wrapperAssetType, asset, flatten) => {
8
+ var asyncTransform = (assetId, wrapperAssetType, asset, flatten, path = ["values"]) => {
10
9
  const id = "async-" + assetId;
11
10
  const asyncNode = Builder.asyncNode(id, flatten);
12
11
  let multiNode;
@@ -21,10 +20,166 @@ var asyncTransform = (assetId, wrapperAssetType, asset, flatten) => {
21
20
  id: wrapperAssetType + "-" + id,
22
21
  type: wrapperAssetType
23
22
  });
24
- Builder.addChild(wrapperAsset, ["values"], multiNode);
23
+ Builder.addChild(wrapperAsset, path, multiNode);
25
24
  return wrapperAsset;
26
25
  };
27
26
 
27
+ // ../../../../../../../../../../../execroot/_main/bazel-out/k8-fastbuild/bin/plugins/async-node/core/src/createAsyncTransform.ts
28
+ import {
29
+ Builder as Builder2,
30
+ NodeType as NodeType4
31
+ } from "@player-ui/player";
32
+
33
+ // ../../../../../../../../../../../execroot/_main/bazel-out/k8-fastbuild/bin/plugins/async-node/core/src/utils/extractNodeFromPath.ts
34
+ var getMatchValue = (pathA, pathB) => {
35
+ if (pathA.length > pathB.length) {
36
+ return 0;
37
+ }
38
+ let matchCount = 0;
39
+ for (let i = 0; i < pathA.length; i++) {
40
+ if (pathA[i] === pathB[i]) {
41
+ matchCount++;
42
+ } else {
43
+ return 0;
44
+ }
45
+ }
46
+ return matchCount;
47
+ };
48
+ var extractNodeFromPath = (node, path) => {
49
+ if (path === void 0 || path.length === 0) {
50
+ return node;
51
+ }
52
+ if (!("children" in node && node.children)) {
53
+ return void 0;
54
+ }
55
+ let matchResult = 0;
56
+ let bestMatch;
57
+ for (const child of node.children) {
58
+ const matchValue = getMatchValue(child.path, path);
59
+ if (matchValue > matchResult) {
60
+ matchResult = matchValue;
61
+ bestMatch = child;
62
+ }
63
+ }
64
+ if (!bestMatch) {
65
+ return void 0;
66
+ }
67
+ if (matchResult >= path.length) {
68
+ return bestMatch.value;
69
+ }
70
+ return extractNodeFromPath(bestMatch.value, path.slice(matchResult));
71
+ };
72
+
73
+ // ../../../../../../../../../../../execroot/_main/bazel-out/k8-fastbuild/bin/plugins/async-node/core/src/utils/traverseAndReplace.ts
74
+ import { NodeType } from "@player-ui/player";
75
+ var traverseAndReplace = (node, replaceFn) => {
76
+ if (node.type === NodeType.MultiNode) {
77
+ let index = 0;
78
+ while (index < node.values.length) {
79
+ const child = node.values[index];
80
+ if (!child) {
81
+ index++;
82
+ continue;
83
+ }
84
+ const result = replaceFn(child);
85
+ if (result.type === NodeType.MultiNode) {
86
+ node.values = [
87
+ ...node.values.slice(0, index),
88
+ ...result.values,
89
+ ...node.values.slice(index + 1)
90
+ ];
91
+ } else {
92
+ node.values[index] = result;
93
+ index++;
94
+ }
95
+ }
96
+ return node;
97
+ }
98
+ return replaceFn(node);
99
+ };
100
+
101
+ // ../../../../../../../../../../../execroot/_main/bazel-out/k8-fastbuild/bin/plugins/async-node/core/src/utils/unwrapAsset.ts
102
+ import { NodeType as NodeType2 } from "@player-ui/player";
103
+ var unwrapAsset = (node) => {
104
+ if (node.type !== NodeType2.Value) {
105
+ return node;
106
+ }
107
+ const child = node.children?.find(
108
+ (x) => x.path.length === 1 && x.path[0] === "asset"
109
+ );
110
+ if (!child) {
111
+ return node;
112
+ }
113
+ return child.value;
114
+ };
115
+
116
+ // ../../../../../../../../../../../execroot/_main/bazel-out/k8-fastbuild/bin/plugins/async-node/core/src/utils/requiresAssetWrapper.ts
117
+ import { NodeType as NodeType3 } from "@player-ui/player";
118
+ var requiresAssetWrapper = (node) => {
119
+ if (node.type === NodeType3.Asset) {
120
+ return true;
121
+ }
122
+ if (node.type !== NodeType3.Applicability) {
123
+ return false;
124
+ }
125
+ return node.value.type === NodeType3.Asset;
126
+ };
127
+
128
+ // ../../../../../../../../../../../execroot/_main/bazel-out/k8-fastbuild/bin/plugins/async-node/core/src/createAsyncTransform.ts
129
+ var defaultGetNodeId = (node) => {
130
+ return `async-${node.value.id}`;
131
+ };
132
+ var createAsyncTransform = (options) => {
133
+ const {
134
+ transformAssetType,
135
+ wrapperAssetType,
136
+ getNestedAsset,
137
+ getAsyncNodeId = defaultGetNodeId,
138
+ path = ["values"],
139
+ flatten = true,
140
+ asyncNodePosition = "append"
141
+ } = options;
142
+ const replaceNode = (node) => {
143
+ const unwrapped = unwrapAsset(node);
144
+ if (unwrapped.type !== NodeType4.Asset || unwrapped.value.type !== transformAssetType) {
145
+ return node;
146
+ }
147
+ const transformed = asyncTransform2(unwrapped);
148
+ return extractNodeFromPath(transformed, path) ?? node;
149
+ };
150
+ const replacer = (node) => traverseAndReplace(node, replaceNode);
151
+ const asyncTransform2 = (node) => {
152
+ const id = getAsyncNodeId(node);
153
+ const asset = getNestedAsset?.(node);
154
+ const replaceFunction = flatten ? replacer : void 0;
155
+ const asyncNode = Builder2.asyncNode(id, flatten, replaceFunction);
156
+ const values = [asyncNode];
157
+ if (asset) {
158
+ const otherValues = [];
159
+ if (requiresAssetWrapper(asset)) {
160
+ otherValues.push(Builder2.assetWrapper(asset));
161
+ } else if (asset.type === NodeType4.MultiNode) {
162
+ otherValues.push(...asset.values);
163
+ } else {
164
+ otherValues.push(asset);
165
+ }
166
+ if (asyncNodePosition === "append") {
167
+ values.unshift(...otherValues);
168
+ } else {
169
+ values.push(...otherValues);
170
+ }
171
+ }
172
+ const multiNode = Builder2.multiNode(...values);
173
+ const wrapperAsset = Builder2.asset({
174
+ id: wrapperAssetType + "-" + id,
175
+ type: wrapperAssetType
176
+ });
177
+ Builder2.addChild(wrapperAsset, path, multiNode);
178
+ return wrapperAsset;
179
+ };
180
+ return asyncTransform2;
181
+ };
182
+
28
183
  // ../../../../../../../../../../../execroot/_main/bazel-out/k8-fastbuild/bin/plugins/async-node/core/src/index.ts
29
184
  var AsyncNodePluginSymbol = Symbol.for("AsyncNodePlugin");
30
185
  var _AsyncNodePlugin = class _AsyncNodePlugin {
@@ -68,7 +223,6 @@ _AsyncNodePlugin.Symbol = AsyncNodePluginSymbol;
68
223
  var AsyncNodePlugin = _AsyncNodePlugin;
69
224
  var AsyncNodePluginPlugin = class {
70
225
  constructor() {
71
- this.asyncNode = new AsyncParallelBailHook();
72
226
  this.name = "AsyncNode";
73
227
  }
74
228
  /**
@@ -79,7 +233,10 @@ var AsyncNodePluginPlugin = class {
79
233
  * @param view The view instance where the node resides. This can be undefined if the view is not currently active.
80
234
  */
81
235
  parseNodeAndUpdate(node, context, result, options) {
82
- const parsedNode = options.parseNode && result ? options.parseNode(result) : void 0;
236
+ let parsedNode = options.parseNode && result ? options.parseNode(result) : void 0;
237
+ if (parsedNode && node.onValueReceived) {
238
+ parsedNode = node.onValueReceived(parsedNode);
239
+ }
83
240
  this.handleAsyncUpdate(node, context, parsedNode);
84
241
  }
85
242
  /**
@@ -95,9 +252,13 @@ var AsyncNodePluginPlugin = class {
95
252
  const { nodeResolveCache, view } = context;
96
253
  if (nodeResolveCache.get(node.id) !== newNode) {
97
254
  nodeResolveCache.set(node.id, newNode ? newNode : node);
98
- view.updateAsync();
255
+ view.updateAsync(node.id);
99
256
  }
100
257
  }
258
+ hasValidMapping(node, context) {
259
+ const { nodeResolveCache } = context;
260
+ return nodeResolveCache.has(node.id) && nodeResolveCache.get(node.id) !== node;
261
+ }
101
262
  /**
102
263
  * Handles the asynchronous API integration for resolving nodes.
103
264
  * This method sets up a hook on the resolver's `beforeResolve` event to process async nodes.
@@ -107,11 +268,13 @@ var AsyncNodePluginPlugin = class {
107
268
  applyResolver(resolver, context) {
108
269
  resolver.hooks.beforeResolve.tap(this.name, (node, options) => {
109
270
  if (!this.isAsync(node)) {
110
- return node;
271
+ return node === null ? node : this.resolveAsyncChildren(node, context);
111
272
  }
112
273
  const resolvedNode = context.nodeResolveCache.get(node.id);
113
274
  if (resolvedNode !== void 0) {
114
- return resolvedNode;
275
+ const existingResolvedNodes = node.asyncNodesResolved ?? [];
276
+ resolvedNode.asyncNodesResolved = [...existingResolvedNodes, node.id];
277
+ return this.resolveAsyncChildren(resolvedNode, context);
115
278
  }
116
279
  if (context.inProgressNodes.has(node.id)) {
117
280
  return node;
@@ -123,6 +286,49 @@ var AsyncNodePluginPlugin = class {
123
286
  return node;
124
287
  });
125
288
  }
289
+ /**
290
+ * 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.
291
+ * Handles async node chains as well to make sure all applicable nodes can get flattened.
292
+ * @param node - The node whose children need to be resolved.
293
+ * @param context - the async plugin context needed to reach into the cache
294
+ * @returns The same node but with async node children mapped to their resolved AST.
295
+ */
296
+ resolveAsyncChildren(node, context) {
297
+ const asyncNodesResolved = node.asyncNodesResolved ?? [];
298
+ node.asyncNodesResolved = asyncNodesResolved;
299
+ if (node.type === NodeType5.MultiNode) {
300
+ let index = 0;
301
+ while (index < node.values.length) {
302
+ const childNode = node.values[index];
303
+ if (childNode?.type !== NodeType5.Async || !this.hasValidMapping(childNode, context)) {
304
+ index++;
305
+ continue;
306
+ }
307
+ const mappedNode = context.nodeResolveCache.get(childNode.id);
308
+ asyncNodesResolved.push(childNode.id);
309
+ if (mappedNode.type === NodeType5.MultiNode && childNode.flatten) {
310
+ mappedNode.values.forEach((v) => v.parent = node);
311
+ node.values = [
312
+ ...node.values.slice(0, index),
313
+ ...mappedNode.values,
314
+ ...node.values.slice(index + 1)
315
+ ];
316
+ } else {
317
+ node.values[index] = mappedNode;
318
+ mappedNode.parent = node;
319
+ }
320
+ }
321
+ } else if ("children" in node) {
322
+ node.children?.forEach((c) => {
323
+ while (c.value.type === NodeType5.Async && this.hasValidMapping(c.value, context)) {
324
+ asyncNodesResolved.push(c.value.id);
325
+ c.value = context.nodeResolveCache.get(c.value.id);
326
+ c.value.parent = node;
327
+ }
328
+ });
329
+ }
330
+ return node;
331
+ }
126
332
  async runAsyncNode(node, context, options) {
127
333
  try {
128
334
  const result = await this.basePlugin?.hooks.onAsyncNode.call(
@@ -152,21 +358,18 @@ var AsyncNodePluginPlugin = class {
152
358
  }
153
359
  }
154
360
  isAsync(node) {
155
- return node?.type === NodeType.Async;
361
+ return node?.type === NodeType5.Async;
156
362
  }
157
363
  isDeterminedAsync(obj) {
158
- return obj && Object.prototype.hasOwnProperty.call(obj, "async");
364
+ return typeof obj === "object" && obj !== null && Object.prototype.hasOwnProperty.call(obj, "async");
159
365
  }
160
366
  applyParser(parser) {
161
367
  parser.hooks.parseNode.tap(
162
368
  this.name,
163
369
  (obj, nodeType, options, childOptions) => {
164
370
  if (this.isDeterminedAsync(obj)) {
165
- const parsedAsync = parser.parseObject(
166
- omit(obj, "async"),
167
- nodeType,
168
- options
169
- );
371
+ const { async, flatten, ...rest } = obj;
372
+ const parsedAsync = parser.parseObject(rest, nodeType, options);
170
373
  const parsedNodeId = getNodeID(parsedAsync);
171
374
  if (parsedAsync === null || !parsedNodeId) {
172
375
  return childOptions ? [] : null;
@@ -174,8 +377,9 @@ var AsyncNodePluginPlugin = class {
174
377
  const asyncAST = parser.createASTNode(
175
378
  {
176
379
  id: parsedNodeId,
177
- type: NodeType.Async,
178
- value: parsedAsync
380
+ type: NodeType5.Async,
381
+ value: parsedAsync,
382
+ flatten
179
383
  },
180
384
  obj
181
385
  );
@@ -211,6 +415,7 @@ export {
211
415
  AsyncNodePlugin,
212
416
  AsyncNodePluginPlugin,
213
417
  AsyncNodePluginSymbol,
214
- asyncTransform
418
+ asyncTransform,
419
+ createAsyncTransform
215
420
  };
216
421
  //# sourceMappingURL=index.mjs.map