@player-ui/async-node-plugin 0.13.0 → 0.14.0-next.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/AsyncNodePlugin.native.js +467 -279
- package/dist/AsyncNodePlugin.native.js.map +1 -1
- package/dist/cjs/index.cjs +217 -20
- package/dist/cjs/index.cjs.map +1 -1
- package/dist/index.legacy-esm.js +217 -18
- package/dist/index.mjs +217 -18
- package/dist/index.mjs.map +1 -1
- package/package.json +2 -2
- package/src/__tests__/__snapshots__/transform.test.ts.snap +1 -0
- package/src/__tests__/createAsyncTransform.test.ts +405 -0
- package/src/__tests__/index.test.ts +94 -13
- package/src/__tests__/transform.bench.ts +177 -0
- package/src/createAsyncTransform.ts +101 -0
- package/src/index.ts +93 -13
- package/src/transform.ts +5 -2
- package/src/types.ts +1 -0
- package/src/utils/__tests__/extractNodeFromPath.test.ts +181 -0
- package/src/utils/__tests__/requiresAssetWrapper.test.ts +63 -0
- package/src/utils/__tests__/traverseAndReplace.test.ts +182 -0
- package/src/utils/__tests__/unwrapAsset.test.ts +65 -0
- package/src/utils/extractNodeFromPath.ts +56 -0
- package/src/utils/index.ts +4 -0
- package/src/utils/requiresAssetWrapper.ts +14 -0
- package/src/utils/traverseAndReplace.ts +34 -0
- package/src/utils/unwrapAsset.ts +16 -0
- package/types/createAsyncTransform.d.ts +24 -0
- package/types/index.d.ts +16 -1
- package/types/transform.d.ts +2 -1
- package/types/types.d.ts +1 -1
- package/types/utils/extractNodeFromPath.d.ts +4 -0
- package/types/utils/index.d.ts +5 -0
- package/types/utils/requiresAssetWrapper.d.ts +3 -0
- package/types/utils/traverseAndReplace.d.ts +4 -0
- package/types/utils/unwrapAsset.d.ts +3 -0
package/dist/index.legacy-esm.js
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,161 @@ var asyncTransform = (assetId, wrapperAssetType, asset, flatten) => {
|
|
|
21
20
|
id: wrapperAssetType + "-" + id,
|
|
22
21
|
type: wrapperAssetType
|
|
23
22
|
});
|
|
24
|
-
Builder.addChild(wrapperAsset,
|
|
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
|
+
} = options;
|
|
141
|
+
const replaceNode = (node) => {
|
|
142
|
+
const unwrapped = unwrapAsset(node);
|
|
143
|
+
if (unwrapped.type !== NodeType4.Asset || unwrapped.value.type !== transformAssetType) {
|
|
144
|
+
return node;
|
|
145
|
+
}
|
|
146
|
+
const transformed = asyncTransform2(unwrapped);
|
|
147
|
+
return extractNodeFromPath(transformed, path) ?? node;
|
|
148
|
+
};
|
|
149
|
+
const replacer = (node) => traverseAndReplace(node, replaceNode);
|
|
150
|
+
const asyncTransform2 = (node) => {
|
|
151
|
+
const id = getAsyncNodeId(node);
|
|
152
|
+
const asset = getNestedAsset?.(node);
|
|
153
|
+
const replaceFunction = flatten ? replacer : void 0;
|
|
154
|
+
const asyncNode = Builder2.asyncNode(id, flatten, replaceFunction);
|
|
155
|
+
let multiNode;
|
|
156
|
+
if (asset) {
|
|
157
|
+
if (requiresAssetWrapper(asset)) {
|
|
158
|
+
const assetWrappedNode = Builder2.assetWrapper(asset);
|
|
159
|
+
multiNode = Builder2.multiNode(assetWrappedNode, asyncNode);
|
|
160
|
+
} else if (asset.type === NodeType4.MultiNode) {
|
|
161
|
+
multiNode = Builder2.multiNode(...asset.values, asyncNode);
|
|
162
|
+
} else {
|
|
163
|
+
multiNode = Builder2.multiNode(asset, asyncNode);
|
|
164
|
+
}
|
|
165
|
+
} else {
|
|
166
|
+
multiNode = Builder2.multiNode(asyncNode);
|
|
167
|
+
}
|
|
168
|
+
const wrapperAsset = Builder2.asset({
|
|
169
|
+
id: wrapperAssetType + "-" + id,
|
|
170
|
+
type: wrapperAssetType
|
|
171
|
+
});
|
|
172
|
+
Builder2.addChild(wrapperAsset, path, multiNode);
|
|
173
|
+
return wrapperAsset;
|
|
174
|
+
};
|
|
175
|
+
return asyncTransform2;
|
|
176
|
+
};
|
|
177
|
+
|
|
28
178
|
// ../../../../../../../../../../../execroot/_main/bazel-out/k8-fastbuild/bin/plugins/async-node/core/src/index.ts
|
|
29
179
|
var AsyncNodePluginSymbol = Symbol.for("AsyncNodePlugin");
|
|
30
180
|
var _AsyncNodePlugin = class _AsyncNodePlugin {
|
|
@@ -79,7 +229,10 @@ var AsyncNodePluginPlugin = class {
|
|
|
79
229
|
* @param view The view instance where the node resides. This can be undefined if the view is not currently active.
|
|
80
230
|
*/
|
|
81
231
|
parseNodeAndUpdate(node, context, result, options) {
|
|
82
|
-
|
|
232
|
+
let parsedNode = options.parseNode && result ? options.parseNode(result) : void 0;
|
|
233
|
+
if (parsedNode && node.onValueReceived) {
|
|
234
|
+
parsedNode = node.onValueReceived(parsedNode);
|
|
235
|
+
}
|
|
83
236
|
this.handleAsyncUpdate(node, context, parsedNode);
|
|
84
237
|
}
|
|
85
238
|
/**
|
|
@@ -95,9 +248,13 @@ var AsyncNodePluginPlugin = class {
|
|
|
95
248
|
const { nodeResolveCache, view } = context;
|
|
96
249
|
if (nodeResolveCache.get(node.id) !== newNode) {
|
|
97
250
|
nodeResolveCache.set(node.id, newNode ? newNode : node);
|
|
98
|
-
view.updateAsync();
|
|
251
|
+
view.updateAsync(node.id);
|
|
99
252
|
}
|
|
100
253
|
}
|
|
254
|
+
hasValidMapping(node, context) {
|
|
255
|
+
const { nodeResolveCache } = context;
|
|
256
|
+
return nodeResolveCache.has(node.id) && nodeResolveCache.get(node.id) !== node;
|
|
257
|
+
}
|
|
101
258
|
/**
|
|
102
259
|
* Handles the asynchronous API integration for resolving nodes.
|
|
103
260
|
* This method sets up a hook on the resolver's `beforeResolve` event to process async nodes.
|
|
@@ -107,11 +264,11 @@ var AsyncNodePluginPlugin = class {
|
|
|
107
264
|
applyResolver(resolver, context) {
|
|
108
265
|
resolver.hooks.beforeResolve.tap(this.name, (node, options) => {
|
|
109
266
|
if (!this.isAsync(node)) {
|
|
110
|
-
return node;
|
|
267
|
+
return node === null ? node : this.resolveAsyncChildren(node, context);
|
|
111
268
|
}
|
|
112
269
|
const resolvedNode = context.nodeResolveCache.get(node.id);
|
|
113
270
|
if (resolvedNode !== void 0) {
|
|
114
|
-
return resolvedNode;
|
|
271
|
+
return this.resolveAsyncChildren(resolvedNode, context);
|
|
115
272
|
}
|
|
116
273
|
if (context.inProgressNodes.has(node.id)) {
|
|
117
274
|
return node;
|
|
@@ -123,6 +280,49 @@ var AsyncNodePluginPlugin = class {
|
|
|
123
280
|
return node;
|
|
124
281
|
});
|
|
125
282
|
}
|
|
283
|
+
/**
|
|
284
|
+
* 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.
|
|
285
|
+
* Handles async node chains as well to make sure all applicable nodes can get flattened.
|
|
286
|
+
* @param node - The node whose children need to be resolved.
|
|
287
|
+
* @param context - the async plugin context needed to reach into the cache
|
|
288
|
+
* @returns The same node but with async node children mapped to their resolved AST.
|
|
289
|
+
*/
|
|
290
|
+
resolveAsyncChildren(node, context) {
|
|
291
|
+
const asyncNodesResolved = node.asyncNodesResolved ?? [];
|
|
292
|
+
node.asyncNodesResolved = asyncNodesResolved;
|
|
293
|
+
if (node.type === NodeType5.MultiNode) {
|
|
294
|
+
let index = 0;
|
|
295
|
+
while (index < node.values.length) {
|
|
296
|
+
const childNode = node.values[index];
|
|
297
|
+
if (childNode?.type !== NodeType5.Async || !this.hasValidMapping(childNode, context)) {
|
|
298
|
+
index++;
|
|
299
|
+
continue;
|
|
300
|
+
}
|
|
301
|
+
const mappedNode = context.nodeResolveCache.get(childNode.id);
|
|
302
|
+
asyncNodesResolved.push(childNode.id);
|
|
303
|
+
if (mappedNode.type === NodeType5.MultiNode && childNode.flatten) {
|
|
304
|
+
mappedNode.values.forEach((v) => v.parent = node);
|
|
305
|
+
node.values = [
|
|
306
|
+
...node.values.slice(0, index),
|
|
307
|
+
...mappedNode.values,
|
|
308
|
+
...node.values.slice(index + 1)
|
|
309
|
+
];
|
|
310
|
+
} else {
|
|
311
|
+
node.values[index] = mappedNode;
|
|
312
|
+
mappedNode.parent = node;
|
|
313
|
+
}
|
|
314
|
+
}
|
|
315
|
+
} else if ("children" in node) {
|
|
316
|
+
node.children?.forEach((c) => {
|
|
317
|
+
while (c.value.type === NodeType5.Async && this.hasValidMapping(c.value, context)) {
|
|
318
|
+
asyncNodesResolved.push(c.value.id);
|
|
319
|
+
c.value = context.nodeResolveCache.get(c.value.id);
|
|
320
|
+
c.value.parent = node;
|
|
321
|
+
}
|
|
322
|
+
});
|
|
323
|
+
}
|
|
324
|
+
return node;
|
|
325
|
+
}
|
|
126
326
|
async runAsyncNode(node, context, options) {
|
|
127
327
|
try {
|
|
128
328
|
const result = await this.basePlugin?.hooks.onAsyncNode.call(
|
|
@@ -152,21 +352,18 @@ var AsyncNodePluginPlugin = class {
|
|
|
152
352
|
}
|
|
153
353
|
}
|
|
154
354
|
isAsync(node) {
|
|
155
|
-
return node?.type ===
|
|
355
|
+
return node?.type === NodeType5.Async;
|
|
156
356
|
}
|
|
157
357
|
isDeterminedAsync(obj) {
|
|
158
|
-
return obj && Object.prototype.hasOwnProperty.call(obj, "async");
|
|
358
|
+
return typeof obj === "object" && obj !== null && Object.prototype.hasOwnProperty.call(obj, "async");
|
|
159
359
|
}
|
|
160
360
|
applyParser(parser) {
|
|
161
361
|
parser.hooks.parseNode.tap(
|
|
162
362
|
this.name,
|
|
163
363
|
(obj, nodeType, options, childOptions) => {
|
|
164
364
|
if (this.isDeterminedAsync(obj)) {
|
|
165
|
-
const
|
|
166
|
-
|
|
167
|
-
nodeType,
|
|
168
|
-
options
|
|
169
|
-
);
|
|
365
|
+
const { async, flatten, ...rest } = obj;
|
|
366
|
+
const parsedAsync = parser.parseObject(rest, nodeType, options);
|
|
170
367
|
const parsedNodeId = getNodeID(parsedAsync);
|
|
171
368
|
if (parsedAsync === null || !parsedNodeId) {
|
|
172
369
|
return childOptions ? [] : null;
|
|
@@ -174,8 +371,9 @@ var AsyncNodePluginPlugin = class {
|
|
|
174
371
|
const asyncAST = parser.createASTNode(
|
|
175
372
|
{
|
|
176
373
|
id: parsedNodeId,
|
|
177
|
-
type:
|
|
178
|
-
value: parsedAsync
|
|
374
|
+
type: NodeType5.Async,
|
|
375
|
+
value: parsedAsync,
|
|
376
|
+
flatten
|
|
179
377
|
},
|
|
180
378
|
obj
|
|
181
379
|
);
|
|
@@ -211,6 +409,7 @@ export {
|
|
|
211
409
|
AsyncNodePlugin,
|
|
212
410
|
AsyncNodePluginPlugin,
|
|
213
411
|
AsyncNodePluginSymbol,
|
|
214
|
-
asyncTransform
|
|
412
|
+
asyncTransform,
|
|
413
|
+
createAsyncTransform
|
|
215
414
|
};
|
|
216
415
|
//# 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,161 @@ var asyncTransform = (assetId, wrapperAssetType, asset, flatten) => {
|
|
|
21
20
|
id: wrapperAssetType + "-" + id,
|
|
22
21
|
type: wrapperAssetType
|
|
23
22
|
});
|
|
24
|
-
Builder.addChild(wrapperAsset,
|
|
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
|
+
} = options;
|
|
141
|
+
const replaceNode = (node) => {
|
|
142
|
+
const unwrapped = unwrapAsset(node);
|
|
143
|
+
if (unwrapped.type !== NodeType4.Asset || unwrapped.value.type !== transformAssetType) {
|
|
144
|
+
return node;
|
|
145
|
+
}
|
|
146
|
+
const transformed = asyncTransform2(unwrapped);
|
|
147
|
+
return extractNodeFromPath(transformed, path) ?? node;
|
|
148
|
+
};
|
|
149
|
+
const replacer = (node) => traverseAndReplace(node, replaceNode);
|
|
150
|
+
const asyncTransform2 = (node) => {
|
|
151
|
+
const id = getAsyncNodeId(node);
|
|
152
|
+
const asset = getNestedAsset?.(node);
|
|
153
|
+
const replaceFunction = flatten ? replacer : void 0;
|
|
154
|
+
const asyncNode = Builder2.asyncNode(id, flatten, replaceFunction);
|
|
155
|
+
let multiNode;
|
|
156
|
+
if (asset) {
|
|
157
|
+
if (requiresAssetWrapper(asset)) {
|
|
158
|
+
const assetWrappedNode = Builder2.assetWrapper(asset);
|
|
159
|
+
multiNode = Builder2.multiNode(assetWrappedNode, asyncNode);
|
|
160
|
+
} else if (asset.type === NodeType4.MultiNode) {
|
|
161
|
+
multiNode = Builder2.multiNode(...asset.values, asyncNode);
|
|
162
|
+
} else {
|
|
163
|
+
multiNode = Builder2.multiNode(asset, asyncNode);
|
|
164
|
+
}
|
|
165
|
+
} else {
|
|
166
|
+
multiNode = Builder2.multiNode(asyncNode);
|
|
167
|
+
}
|
|
168
|
+
const wrapperAsset = Builder2.asset({
|
|
169
|
+
id: wrapperAssetType + "-" + id,
|
|
170
|
+
type: wrapperAssetType
|
|
171
|
+
});
|
|
172
|
+
Builder2.addChild(wrapperAsset, path, multiNode);
|
|
173
|
+
return wrapperAsset;
|
|
174
|
+
};
|
|
175
|
+
return asyncTransform2;
|
|
176
|
+
};
|
|
177
|
+
|
|
28
178
|
// ../../../../../../../../../../../execroot/_main/bazel-out/k8-fastbuild/bin/plugins/async-node/core/src/index.ts
|
|
29
179
|
var AsyncNodePluginSymbol = Symbol.for("AsyncNodePlugin");
|
|
30
180
|
var _AsyncNodePlugin = class _AsyncNodePlugin {
|
|
@@ -79,7 +229,10 @@ var AsyncNodePluginPlugin = class {
|
|
|
79
229
|
* @param view The view instance where the node resides. This can be undefined if the view is not currently active.
|
|
80
230
|
*/
|
|
81
231
|
parseNodeAndUpdate(node, context, result, options) {
|
|
82
|
-
|
|
232
|
+
let parsedNode = options.parseNode && result ? options.parseNode(result) : void 0;
|
|
233
|
+
if (parsedNode && node.onValueReceived) {
|
|
234
|
+
parsedNode = node.onValueReceived(parsedNode);
|
|
235
|
+
}
|
|
83
236
|
this.handleAsyncUpdate(node, context, parsedNode);
|
|
84
237
|
}
|
|
85
238
|
/**
|
|
@@ -95,9 +248,13 @@ var AsyncNodePluginPlugin = class {
|
|
|
95
248
|
const { nodeResolveCache, view } = context;
|
|
96
249
|
if (nodeResolveCache.get(node.id) !== newNode) {
|
|
97
250
|
nodeResolveCache.set(node.id, newNode ? newNode : node);
|
|
98
|
-
view.updateAsync();
|
|
251
|
+
view.updateAsync(node.id);
|
|
99
252
|
}
|
|
100
253
|
}
|
|
254
|
+
hasValidMapping(node, context) {
|
|
255
|
+
const { nodeResolveCache } = context;
|
|
256
|
+
return nodeResolveCache.has(node.id) && nodeResolveCache.get(node.id) !== node;
|
|
257
|
+
}
|
|
101
258
|
/**
|
|
102
259
|
* Handles the asynchronous API integration for resolving nodes.
|
|
103
260
|
* This method sets up a hook on the resolver's `beforeResolve` event to process async nodes.
|
|
@@ -107,11 +264,11 @@ var AsyncNodePluginPlugin = class {
|
|
|
107
264
|
applyResolver(resolver, context) {
|
|
108
265
|
resolver.hooks.beforeResolve.tap(this.name, (node, options) => {
|
|
109
266
|
if (!this.isAsync(node)) {
|
|
110
|
-
return node;
|
|
267
|
+
return node === null ? node : this.resolveAsyncChildren(node, context);
|
|
111
268
|
}
|
|
112
269
|
const resolvedNode = context.nodeResolveCache.get(node.id);
|
|
113
270
|
if (resolvedNode !== void 0) {
|
|
114
|
-
return resolvedNode;
|
|
271
|
+
return this.resolveAsyncChildren(resolvedNode, context);
|
|
115
272
|
}
|
|
116
273
|
if (context.inProgressNodes.has(node.id)) {
|
|
117
274
|
return node;
|
|
@@ -123,6 +280,49 @@ var AsyncNodePluginPlugin = class {
|
|
|
123
280
|
return node;
|
|
124
281
|
});
|
|
125
282
|
}
|
|
283
|
+
/**
|
|
284
|
+
* 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.
|
|
285
|
+
* Handles async node chains as well to make sure all applicable nodes can get flattened.
|
|
286
|
+
* @param node - The node whose children need to be resolved.
|
|
287
|
+
* @param context - the async plugin context needed to reach into the cache
|
|
288
|
+
* @returns The same node but with async node children mapped to their resolved AST.
|
|
289
|
+
*/
|
|
290
|
+
resolveAsyncChildren(node, context) {
|
|
291
|
+
const asyncNodesResolved = node.asyncNodesResolved ?? [];
|
|
292
|
+
node.asyncNodesResolved = asyncNodesResolved;
|
|
293
|
+
if (node.type === NodeType5.MultiNode) {
|
|
294
|
+
let index = 0;
|
|
295
|
+
while (index < node.values.length) {
|
|
296
|
+
const childNode = node.values[index];
|
|
297
|
+
if (childNode?.type !== NodeType5.Async || !this.hasValidMapping(childNode, context)) {
|
|
298
|
+
index++;
|
|
299
|
+
continue;
|
|
300
|
+
}
|
|
301
|
+
const mappedNode = context.nodeResolveCache.get(childNode.id);
|
|
302
|
+
asyncNodesResolved.push(childNode.id);
|
|
303
|
+
if (mappedNode.type === NodeType5.MultiNode && childNode.flatten) {
|
|
304
|
+
mappedNode.values.forEach((v) => v.parent = node);
|
|
305
|
+
node.values = [
|
|
306
|
+
...node.values.slice(0, index),
|
|
307
|
+
...mappedNode.values,
|
|
308
|
+
...node.values.slice(index + 1)
|
|
309
|
+
];
|
|
310
|
+
} else {
|
|
311
|
+
node.values[index] = mappedNode;
|
|
312
|
+
mappedNode.parent = node;
|
|
313
|
+
}
|
|
314
|
+
}
|
|
315
|
+
} else if ("children" in node) {
|
|
316
|
+
node.children?.forEach((c) => {
|
|
317
|
+
while (c.value.type === NodeType5.Async && this.hasValidMapping(c.value, context)) {
|
|
318
|
+
asyncNodesResolved.push(c.value.id);
|
|
319
|
+
c.value = context.nodeResolveCache.get(c.value.id);
|
|
320
|
+
c.value.parent = node;
|
|
321
|
+
}
|
|
322
|
+
});
|
|
323
|
+
}
|
|
324
|
+
return node;
|
|
325
|
+
}
|
|
126
326
|
async runAsyncNode(node, context, options) {
|
|
127
327
|
try {
|
|
128
328
|
const result = await this.basePlugin?.hooks.onAsyncNode.call(
|
|
@@ -152,21 +352,18 @@ var AsyncNodePluginPlugin = class {
|
|
|
152
352
|
}
|
|
153
353
|
}
|
|
154
354
|
isAsync(node) {
|
|
155
|
-
return node?.type ===
|
|
355
|
+
return node?.type === NodeType5.Async;
|
|
156
356
|
}
|
|
157
357
|
isDeterminedAsync(obj) {
|
|
158
|
-
return obj && Object.prototype.hasOwnProperty.call(obj, "async");
|
|
358
|
+
return typeof obj === "object" && obj !== null && Object.prototype.hasOwnProperty.call(obj, "async");
|
|
159
359
|
}
|
|
160
360
|
applyParser(parser) {
|
|
161
361
|
parser.hooks.parseNode.tap(
|
|
162
362
|
this.name,
|
|
163
363
|
(obj, nodeType, options, childOptions) => {
|
|
164
364
|
if (this.isDeterminedAsync(obj)) {
|
|
165
|
-
const
|
|
166
|
-
|
|
167
|
-
nodeType,
|
|
168
|
-
options
|
|
169
|
-
);
|
|
365
|
+
const { async, flatten, ...rest } = obj;
|
|
366
|
+
const parsedAsync = parser.parseObject(rest, nodeType, options);
|
|
170
367
|
const parsedNodeId = getNodeID(parsedAsync);
|
|
171
368
|
if (parsedAsync === null || !parsedNodeId) {
|
|
172
369
|
return childOptions ? [] : null;
|
|
@@ -174,8 +371,9 @@ var AsyncNodePluginPlugin = class {
|
|
|
174
371
|
const asyncAST = parser.createASTNode(
|
|
175
372
|
{
|
|
176
373
|
id: parsedNodeId,
|
|
177
|
-
type:
|
|
178
|
-
value: parsedAsync
|
|
374
|
+
type: NodeType5.Async,
|
|
375
|
+
value: parsedAsync,
|
|
376
|
+
flatten
|
|
179
377
|
},
|
|
180
378
|
obj
|
|
181
379
|
);
|
|
@@ -211,6 +409,7 @@ export {
|
|
|
211
409
|
AsyncNodePlugin,
|
|
212
410
|
AsyncNodePluginPlugin,
|
|
213
411
|
AsyncNodePluginSymbol,
|
|
214
|
-
asyncTransform
|
|
412
|
+
asyncTransform,
|
|
413
|
+
createAsyncTransform
|
|
215
414
|
};
|
|
216
415
|
//# sourceMappingURL=index.mjs.map
|