@player-ui/async-node-plugin 0.13.0-next.7 → 0.14.0-next.0
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 +327 -128
- package/dist/AsyncNodePlugin.native.js.map +1 -1
- package/dist/cjs/index.cjs +199 -20
- package/dist/cjs/index.cjs.map +1 -1
- package/dist/index.legacy-esm.js +199 -18
- package/dist/index.mjs +199 -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 +215 -0
- package/src/__tests__/index.test.ts +94 -13
- package/src/__tests__/transform.bench.ts +177 -0
- package/src/createAsyncTransform.ts +91 -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__/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 +3 -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 +4 -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 NodeType4, 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,143 @@ 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 NodeType3
|
|
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/createAsyncTransform.ts
|
|
117
|
+
var defaultGetNodeId = (node) => {
|
|
118
|
+
return `async-${node.value.id}`;
|
|
119
|
+
};
|
|
120
|
+
var createAsyncTransform = (options) => {
|
|
121
|
+
const {
|
|
122
|
+
transformAssetType,
|
|
123
|
+
wrapperAssetType,
|
|
124
|
+
getNestedAsset,
|
|
125
|
+
getAsyncNodeId = defaultGetNodeId,
|
|
126
|
+
path = ["values"],
|
|
127
|
+
flatten = true
|
|
128
|
+
} = options;
|
|
129
|
+
const replaceNode = (node) => {
|
|
130
|
+
const unwrapped = unwrapAsset(node);
|
|
131
|
+
if (unwrapped.type !== NodeType3.Asset || unwrapped.value.type !== transformAssetType) {
|
|
132
|
+
return node;
|
|
133
|
+
}
|
|
134
|
+
const transformed = asyncTransform2(unwrapped);
|
|
135
|
+
return extractNodeFromPath(transformed, path) ?? node;
|
|
136
|
+
};
|
|
137
|
+
const replacer = (node) => traverseAndReplace(node, replaceNode);
|
|
138
|
+
const asyncTransform2 = (node) => {
|
|
139
|
+
const id = getAsyncNodeId(node);
|
|
140
|
+
const asset = getNestedAsset?.(node);
|
|
141
|
+
const replaceFunction = flatten ? replacer : void 0;
|
|
142
|
+
const asyncNode = Builder2.asyncNode(id, flatten, replaceFunction);
|
|
143
|
+
let multiNode;
|
|
144
|
+
if (asset) {
|
|
145
|
+
const assetNode = Builder2.assetWrapper(asset);
|
|
146
|
+
multiNode = Builder2.multiNode(assetNode, asyncNode);
|
|
147
|
+
} else {
|
|
148
|
+
multiNode = Builder2.multiNode(asyncNode);
|
|
149
|
+
}
|
|
150
|
+
const wrapperAsset = Builder2.asset({
|
|
151
|
+
id: wrapperAssetType + "-" + id,
|
|
152
|
+
type: wrapperAssetType
|
|
153
|
+
});
|
|
154
|
+
Builder2.addChild(wrapperAsset, path, multiNode);
|
|
155
|
+
return wrapperAsset;
|
|
156
|
+
};
|
|
157
|
+
return asyncTransform2;
|
|
158
|
+
};
|
|
159
|
+
|
|
28
160
|
// ../../../../../../../../../../../execroot/_main/bazel-out/k8-fastbuild/bin/plugins/async-node/core/src/index.ts
|
|
29
161
|
var AsyncNodePluginSymbol = Symbol.for("AsyncNodePlugin");
|
|
30
162
|
var _AsyncNodePlugin = class _AsyncNodePlugin {
|
|
@@ -79,7 +211,10 @@ var AsyncNodePluginPlugin = class {
|
|
|
79
211
|
* @param view The view instance where the node resides. This can be undefined if the view is not currently active.
|
|
80
212
|
*/
|
|
81
213
|
parseNodeAndUpdate(node, context, result, options) {
|
|
82
|
-
|
|
214
|
+
let parsedNode = options.parseNode && result ? options.parseNode(result) : void 0;
|
|
215
|
+
if (parsedNode && node.onValueReceived) {
|
|
216
|
+
parsedNode = node.onValueReceived(parsedNode);
|
|
217
|
+
}
|
|
83
218
|
this.handleAsyncUpdate(node, context, parsedNode);
|
|
84
219
|
}
|
|
85
220
|
/**
|
|
@@ -95,9 +230,13 @@ var AsyncNodePluginPlugin = class {
|
|
|
95
230
|
const { nodeResolveCache, view } = context;
|
|
96
231
|
if (nodeResolveCache.get(node.id) !== newNode) {
|
|
97
232
|
nodeResolveCache.set(node.id, newNode ? newNode : node);
|
|
98
|
-
view.updateAsync();
|
|
233
|
+
view.updateAsync(node.id);
|
|
99
234
|
}
|
|
100
235
|
}
|
|
236
|
+
hasValidMapping(node, context) {
|
|
237
|
+
const { nodeResolveCache } = context;
|
|
238
|
+
return nodeResolveCache.has(node.id) && nodeResolveCache.get(node.id) !== node;
|
|
239
|
+
}
|
|
101
240
|
/**
|
|
102
241
|
* Handles the asynchronous API integration for resolving nodes.
|
|
103
242
|
* This method sets up a hook on the resolver's `beforeResolve` event to process async nodes.
|
|
@@ -107,11 +246,11 @@ var AsyncNodePluginPlugin = class {
|
|
|
107
246
|
applyResolver(resolver, context) {
|
|
108
247
|
resolver.hooks.beforeResolve.tap(this.name, (node, options) => {
|
|
109
248
|
if (!this.isAsync(node)) {
|
|
110
|
-
return node;
|
|
249
|
+
return node === null ? node : this.resolveAsyncChildren(node, context);
|
|
111
250
|
}
|
|
112
251
|
const resolvedNode = context.nodeResolveCache.get(node.id);
|
|
113
252
|
if (resolvedNode !== void 0) {
|
|
114
|
-
return resolvedNode;
|
|
253
|
+
return this.resolveAsyncChildren(resolvedNode, context);
|
|
115
254
|
}
|
|
116
255
|
if (context.inProgressNodes.has(node.id)) {
|
|
117
256
|
return node;
|
|
@@ -123,6 +262,49 @@ var AsyncNodePluginPlugin = class {
|
|
|
123
262
|
return node;
|
|
124
263
|
});
|
|
125
264
|
}
|
|
265
|
+
/**
|
|
266
|
+
* 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.
|
|
267
|
+
* Handles async node chains as well to make sure all applicable nodes can get flattened.
|
|
268
|
+
* @param node - The node whose children need to be resolved.
|
|
269
|
+
* @param context - the async plugin context needed to reach into the cache
|
|
270
|
+
* @returns The same node but with async node children mapped to their resolved AST.
|
|
271
|
+
*/
|
|
272
|
+
resolveAsyncChildren(node, context) {
|
|
273
|
+
const asyncNodesResolved = node.asyncNodesResolved ?? [];
|
|
274
|
+
node.asyncNodesResolved = asyncNodesResolved;
|
|
275
|
+
if (node.type === NodeType4.MultiNode) {
|
|
276
|
+
let index = 0;
|
|
277
|
+
while (index < node.values.length) {
|
|
278
|
+
const childNode = node.values[index];
|
|
279
|
+
if (childNode?.type !== NodeType4.Async || !this.hasValidMapping(childNode, context)) {
|
|
280
|
+
index++;
|
|
281
|
+
continue;
|
|
282
|
+
}
|
|
283
|
+
const mappedNode = context.nodeResolveCache.get(childNode.id);
|
|
284
|
+
asyncNodesResolved.push(childNode.id);
|
|
285
|
+
if (mappedNode.type === NodeType4.MultiNode && childNode.flatten) {
|
|
286
|
+
mappedNode.values.forEach((v) => v.parent = node);
|
|
287
|
+
node.values = [
|
|
288
|
+
...node.values.slice(0, index),
|
|
289
|
+
...mappedNode.values,
|
|
290
|
+
...node.values.slice(index + 1)
|
|
291
|
+
];
|
|
292
|
+
} else {
|
|
293
|
+
node.values[index] = mappedNode;
|
|
294
|
+
mappedNode.parent = node;
|
|
295
|
+
}
|
|
296
|
+
}
|
|
297
|
+
} else if ("children" in node) {
|
|
298
|
+
node.children?.forEach((c) => {
|
|
299
|
+
while (c.value.type === NodeType4.Async && this.hasValidMapping(c.value, context)) {
|
|
300
|
+
asyncNodesResolved.push(c.value.id);
|
|
301
|
+
c.value = context.nodeResolveCache.get(c.value.id);
|
|
302
|
+
c.value.parent = node;
|
|
303
|
+
}
|
|
304
|
+
});
|
|
305
|
+
}
|
|
306
|
+
return node;
|
|
307
|
+
}
|
|
126
308
|
async runAsyncNode(node, context, options) {
|
|
127
309
|
try {
|
|
128
310
|
const result = await this.basePlugin?.hooks.onAsyncNode.call(
|
|
@@ -152,21 +334,18 @@ var AsyncNodePluginPlugin = class {
|
|
|
152
334
|
}
|
|
153
335
|
}
|
|
154
336
|
isAsync(node) {
|
|
155
|
-
return node?.type ===
|
|
337
|
+
return node?.type === NodeType4.Async;
|
|
156
338
|
}
|
|
157
339
|
isDeterminedAsync(obj) {
|
|
158
|
-
return obj && Object.prototype.hasOwnProperty.call(obj, "async");
|
|
340
|
+
return typeof obj === "object" && obj !== null && Object.prototype.hasOwnProperty.call(obj, "async");
|
|
159
341
|
}
|
|
160
342
|
applyParser(parser) {
|
|
161
343
|
parser.hooks.parseNode.tap(
|
|
162
344
|
this.name,
|
|
163
345
|
(obj, nodeType, options, childOptions) => {
|
|
164
346
|
if (this.isDeterminedAsync(obj)) {
|
|
165
|
-
const
|
|
166
|
-
|
|
167
|
-
nodeType,
|
|
168
|
-
options
|
|
169
|
-
);
|
|
347
|
+
const { async, flatten, ...rest } = obj;
|
|
348
|
+
const parsedAsync = parser.parseObject(rest, nodeType, options);
|
|
170
349
|
const parsedNodeId = getNodeID(parsedAsync);
|
|
171
350
|
if (parsedAsync === null || !parsedNodeId) {
|
|
172
351
|
return childOptions ? [] : null;
|
|
@@ -174,8 +353,9 @@ var AsyncNodePluginPlugin = class {
|
|
|
174
353
|
const asyncAST = parser.createASTNode(
|
|
175
354
|
{
|
|
176
355
|
id: parsedNodeId,
|
|
177
|
-
type:
|
|
178
|
-
value: parsedAsync
|
|
356
|
+
type: NodeType4.Async,
|
|
357
|
+
value: parsedAsync,
|
|
358
|
+
flatten
|
|
179
359
|
},
|
|
180
360
|
obj
|
|
181
361
|
);
|
|
@@ -211,6 +391,7 @@ export {
|
|
|
211
391
|
AsyncNodePlugin,
|
|
212
392
|
AsyncNodePluginPlugin,
|
|
213
393
|
AsyncNodePluginSymbol,
|
|
214
|
-
asyncTransform
|
|
394
|
+
asyncTransform,
|
|
395
|
+
createAsyncTransform
|
|
215
396
|
};
|
|
216
397
|
//# 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 NodeType4, 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,143 @@ 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 NodeType3
|
|
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/createAsyncTransform.ts
|
|
117
|
+
var defaultGetNodeId = (node) => {
|
|
118
|
+
return `async-${node.value.id}`;
|
|
119
|
+
};
|
|
120
|
+
var createAsyncTransform = (options) => {
|
|
121
|
+
const {
|
|
122
|
+
transformAssetType,
|
|
123
|
+
wrapperAssetType,
|
|
124
|
+
getNestedAsset,
|
|
125
|
+
getAsyncNodeId = defaultGetNodeId,
|
|
126
|
+
path = ["values"],
|
|
127
|
+
flatten = true
|
|
128
|
+
} = options;
|
|
129
|
+
const replaceNode = (node) => {
|
|
130
|
+
const unwrapped = unwrapAsset(node);
|
|
131
|
+
if (unwrapped.type !== NodeType3.Asset || unwrapped.value.type !== transformAssetType) {
|
|
132
|
+
return node;
|
|
133
|
+
}
|
|
134
|
+
const transformed = asyncTransform2(unwrapped);
|
|
135
|
+
return extractNodeFromPath(transformed, path) ?? node;
|
|
136
|
+
};
|
|
137
|
+
const replacer = (node) => traverseAndReplace(node, replaceNode);
|
|
138
|
+
const asyncTransform2 = (node) => {
|
|
139
|
+
const id = getAsyncNodeId(node);
|
|
140
|
+
const asset = getNestedAsset?.(node);
|
|
141
|
+
const replaceFunction = flatten ? replacer : void 0;
|
|
142
|
+
const asyncNode = Builder2.asyncNode(id, flatten, replaceFunction);
|
|
143
|
+
let multiNode;
|
|
144
|
+
if (asset) {
|
|
145
|
+
const assetNode = Builder2.assetWrapper(asset);
|
|
146
|
+
multiNode = Builder2.multiNode(assetNode, asyncNode);
|
|
147
|
+
} else {
|
|
148
|
+
multiNode = Builder2.multiNode(asyncNode);
|
|
149
|
+
}
|
|
150
|
+
const wrapperAsset = Builder2.asset({
|
|
151
|
+
id: wrapperAssetType + "-" + id,
|
|
152
|
+
type: wrapperAssetType
|
|
153
|
+
});
|
|
154
|
+
Builder2.addChild(wrapperAsset, path, multiNode);
|
|
155
|
+
return wrapperAsset;
|
|
156
|
+
};
|
|
157
|
+
return asyncTransform2;
|
|
158
|
+
};
|
|
159
|
+
|
|
28
160
|
// ../../../../../../../../../../../execroot/_main/bazel-out/k8-fastbuild/bin/plugins/async-node/core/src/index.ts
|
|
29
161
|
var AsyncNodePluginSymbol = Symbol.for("AsyncNodePlugin");
|
|
30
162
|
var _AsyncNodePlugin = class _AsyncNodePlugin {
|
|
@@ -79,7 +211,10 @@ var AsyncNodePluginPlugin = class {
|
|
|
79
211
|
* @param view The view instance where the node resides. This can be undefined if the view is not currently active.
|
|
80
212
|
*/
|
|
81
213
|
parseNodeAndUpdate(node, context, result, options) {
|
|
82
|
-
|
|
214
|
+
let parsedNode = options.parseNode && result ? options.parseNode(result) : void 0;
|
|
215
|
+
if (parsedNode && node.onValueReceived) {
|
|
216
|
+
parsedNode = node.onValueReceived(parsedNode);
|
|
217
|
+
}
|
|
83
218
|
this.handleAsyncUpdate(node, context, parsedNode);
|
|
84
219
|
}
|
|
85
220
|
/**
|
|
@@ -95,9 +230,13 @@ var AsyncNodePluginPlugin = class {
|
|
|
95
230
|
const { nodeResolveCache, view } = context;
|
|
96
231
|
if (nodeResolveCache.get(node.id) !== newNode) {
|
|
97
232
|
nodeResolveCache.set(node.id, newNode ? newNode : node);
|
|
98
|
-
view.updateAsync();
|
|
233
|
+
view.updateAsync(node.id);
|
|
99
234
|
}
|
|
100
235
|
}
|
|
236
|
+
hasValidMapping(node, context) {
|
|
237
|
+
const { nodeResolveCache } = context;
|
|
238
|
+
return nodeResolveCache.has(node.id) && nodeResolveCache.get(node.id) !== node;
|
|
239
|
+
}
|
|
101
240
|
/**
|
|
102
241
|
* Handles the asynchronous API integration for resolving nodes.
|
|
103
242
|
* This method sets up a hook on the resolver's `beforeResolve` event to process async nodes.
|
|
@@ -107,11 +246,11 @@ var AsyncNodePluginPlugin = class {
|
|
|
107
246
|
applyResolver(resolver, context) {
|
|
108
247
|
resolver.hooks.beforeResolve.tap(this.name, (node, options) => {
|
|
109
248
|
if (!this.isAsync(node)) {
|
|
110
|
-
return node;
|
|
249
|
+
return node === null ? node : this.resolveAsyncChildren(node, context);
|
|
111
250
|
}
|
|
112
251
|
const resolvedNode = context.nodeResolveCache.get(node.id);
|
|
113
252
|
if (resolvedNode !== void 0) {
|
|
114
|
-
return resolvedNode;
|
|
253
|
+
return this.resolveAsyncChildren(resolvedNode, context);
|
|
115
254
|
}
|
|
116
255
|
if (context.inProgressNodes.has(node.id)) {
|
|
117
256
|
return node;
|
|
@@ -123,6 +262,49 @@ var AsyncNodePluginPlugin = class {
|
|
|
123
262
|
return node;
|
|
124
263
|
});
|
|
125
264
|
}
|
|
265
|
+
/**
|
|
266
|
+
* 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.
|
|
267
|
+
* Handles async node chains as well to make sure all applicable nodes can get flattened.
|
|
268
|
+
* @param node - The node whose children need to be resolved.
|
|
269
|
+
* @param context - the async plugin context needed to reach into the cache
|
|
270
|
+
* @returns The same node but with async node children mapped to their resolved AST.
|
|
271
|
+
*/
|
|
272
|
+
resolveAsyncChildren(node, context) {
|
|
273
|
+
const asyncNodesResolved = node.asyncNodesResolved ?? [];
|
|
274
|
+
node.asyncNodesResolved = asyncNodesResolved;
|
|
275
|
+
if (node.type === NodeType4.MultiNode) {
|
|
276
|
+
let index = 0;
|
|
277
|
+
while (index < node.values.length) {
|
|
278
|
+
const childNode = node.values[index];
|
|
279
|
+
if (childNode?.type !== NodeType4.Async || !this.hasValidMapping(childNode, context)) {
|
|
280
|
+
index++;
|
|
281
|
+
continue;
|
|
282
|
+
}
|
|
283
|
+
const mappedNode = context.nodeResolveCache.get(childNode.id);
|
|
284
|
+
asyncNodesResolved.push(childNode.id);
|
|
285
|
+
if (mappedNode.type === NodeType4.MultiNode && childNode.flatten) {
|
|
286
|
+
mappedNode.values.forEach((v) => v.parent = node);
|
|
287
|
+
node.values = [
|
|
288
|
+
...node.values.slice(0, index),
|
|
289
|
+
...mappedNode.values,
|
|
290
|
+
...node.values.slice(index + 1)
|
|
291
|
+
];
|
|
292
|
+
} else {
|
|
293
|
+
node.values[index] = mappedNode;
|
|
294
|
+
mappedNode.parent = node;
|
|
295
|
+
}
|
|
296
|
+
}
|
|
297
|
+
} else if ("children" in node) {
|
|
298
|
+
node.children?.forEach((c) => {
|
|
299
|
+
while (c.value.type === NodeType4.Async && this.hasValidMapping(c.value, context)) {
|
|
300
|
+
asyncNodesResolved.push(c.value.id);
|
|
301
|
+
c.value = context.nodeResolveCache.get(c.value.id);
|
|
302
|
+
c.value.parent = node;
|
|
303
|
+
}
|
|
304
|
+
});
|
|
305
|
+
}
|
|
306
|
+
return node;
|
|
307
|
+
}
|
|
126
308
|
async runAsyncNode(node, context, options) {
|
|
127
309
|
try {
|
|
128
310
|
const result = await this.basePlugin?.hooks.onAsyncNode.call(
|
|
@@ -152,21 +334,18 @@ var AsyncNodePluginPlugin = class {
|
|
|
152
334
|
}
|
|
153
335
|
}
|
|
154
336
|
isAsync(node) {
|
|
155
|
-
return node?.type ===
|
|
337
|
+
return node?.type === NodeType4.Async;
|
|
156
338
|
}
|
|
157
339
|
isDeterminedAsync(obj) {
|
|
158
|
-
return obj && Object.prototype.hasOwnProperty.call(obj, "async");
|
|
340
|
+
return typeof obj === "object" && obj !== null && Object.prototype.hasOwnProperty.call(obj, "async");
|
|
159
341
|
}
|
|
160
342
|
applyParser(parser) {
|
|
161
343
|
parser.hooks.parseNode.tap(
|
|
162
344
|
this.name,
|
|
163
345
|
(obj, nodeType, options, childOptions) => {
|
|
164
346
|
if (this.isDeterminedAsync(obj)) {
|
|
165
|
-
const
|
|
166
|
-
|
|
167
|
-
nodeType,
|
|
168
|
-
options
|
|
169
|
-
);
|
|
347
|
+
const { async, flatten, ...rest } = obj;
|
|
348
|
+
const parsedAsync = parser.parseObject(rest, nodeType, options);
|
|
170
349
|
const parsedNodeId = getNodeID(parsedAsync);
|
|
171
350
|
if (parsedAsync === null || !parsedNodeId) {
|
|
172
351
|
return childOptions ? [] : null;
|
|
@@ -174,8 +353,9 @@ var AsyncNodePluginPlugin = class {
|
|
|
174
353
|
const asyncAST = parser.createASTNode(
|
|
175
354
|
{
|
|
176
355
|
id: parsedNodeId,
|
|
177
|
-
type:
|
|
178
|
-
value: parsedAsync
|
|
356
|
+
type: NodeType4.Async,
|
|
357
|
+
value: parsedAsync,
|
|
358
|
+
flatten
|
|
179
359
|
},
|
|
180
360
|
obj
|
|
181
361
|
);
|
|
@@ -211,6 +391,7 @@ export {
|
|
|
211
391
|
AsyncNodePlugin,
|
|
212
392
|
AsyncNodePluginPlugin,
|
|
213
393
|
AsyncNodePluginSymbol,
|
|
214
|
-
asyncTransform
|
|
394
|
+
asyncTransform,
|
|
395
|
+
createAsyncTransform
|
|
215
396
|
};
|
|
216
397
|
//# sourceMappingURL=index.mjs.map
|