@player-ui/async-node-plugin 0.15.4--canary.881.37421 → 0.15.4--canary.884.37483
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 +2676 -3281
- package/dist/AsyncNodePlugin.native.js.map +1 -1
- package/dist/cjs/index.cjs +69 -214
- package/dist/cjs/index.cjs.map +1 -1
- package/dist/index.legacy-esm.js +60 -207
- package/dist/index.mjs +60 -207
- package/dist/index.mjs.map +1 -1
- package/package.json +3 -4
- package/src/__tests__/index.test.ts +4 -277
- package/src/index.ts +68 -189
- package/src/utils/index.ts +0 -2
- package/types/index.d.ts +18 -3
- package/types/utils/index.d.ts +0 -2
- package/src/AsyncNodeError.ts +0 -30
- package/src/internal-types.ts +0 -30
- package/src/utils/__tests__/getNodeFromError.test.ts +0 -219
- package/src/utils/__tests__/isAsyncPlayerError.test.ts +0 -33
- package/src/utils/getNodeFromError.ts +0 -34
- package/src/utils/isAsyncPlayerError.ts +0 -8
- package/types/AsyncNodeError.d.ts +0 -13
- package/types/internal-types.d.ts +0 -29
- package/types/utils/getNodeFromError.d.ts +0 -5
- package/types/utils/isAsyncPlayerError.d.ts +0 -4
package/dist/index.legacy-esm.js
CHANGED
|
@@ -3,23 +3,33 @@ import { NodeType as NodeType5, getNodeID } from "@player-ui/player";
|
|
|
3
3
|
import { AsyncSeriesBailHook, SyncBailHook } from "tapable-ts";
|
|
4
4
|
import queueMicrotask from "queue-microtask";
|
|
5
5
|
|
|
6
|
-
// ../../../../../../../../../../../execroot/_main/bazel-out/k8-fastbuild/bin/plugins/async-node/core/src/
|
|
7
|
-
import {
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
node
|
|
19
|
-
};
|
|
6
|
+
// ../../../../../../../../../../../execroot/_main/bazel-out/k8-fastbuild/bin/plugins/async-node/core/src/transform.ts
|
|
7
|
+
import { Builder } from "@player-ui/player";
|
|
8
|
+
var asyncTransform = (assetId, wrapperAssetType, asset, flatten, path = ["values"]) => {
|
|
9
|
+
const id = "async-" + assetId;
|
|
10
|
+
const asyncNode = Builder.asyncNode(id, flatten);
|
|
11
|
+
let multiNode;
|
|
12
|
+
let assetNode;
|
|
13
|
+
if (asset) {
|
|
14
|
+
assetNode = Builder.assetWrapper(asset);
|
|
15
|
+
multiNode = Builder.multiNode(assetNode, asyncNode);
|
|
16
|
+
} else {
|
|
17
|
+
multiNode = Builder.multiNode(asyncNode);
|
|
20
18
|
}
|
|
19
|
+
const wrapperAsset = Builder.asset({
|
|
20
|
+
id: wrapperAssetType + "-" + id,
|
|
21
|
+
type: wrapperAssetType
|
|
22
|
+
});
|
|
23
|
+
Builder.addChild(wrapperAsset, path, multiNode);
|
|
24
|
+
return wrapperAsset;
|
|
21
25
|
};
|
|
22
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
|
+
|
|
23
33
|
// ../../../../../../../../../../../execroot/_main/bazel-out/k8-fastbuild/bin/plugins/async-node/core/src/utils/extractNodeFromPath.ts
|
|
24
34
|
var getMatchValue = (pathA, pathB) => {
|
|
25
35
|
if (pathA.length > pathB.length) {
|
|
@@ -115,59 +125,7 @@ var requiresAssetWrapper = (node) => {
|
|
|
115
125
|
return node.value.type === NodeType3.Asset;
|
|
116
126
|
};
|
|
117
127
|
|
|
118
|
-
// ../../../../../../../../../../../execroot/_main/bazel-out/k8-fastbuild/bin/plugins/async-node/core/src/utils/isAsyncPlayerError.ts
|
|
119
|
-
var isAsyncPlayerError = (error) => {
|
|
120
|
-
return error.type === ASYNC_ERROR_TYPE;
|
|
121
|
-
};
|
|
122
|
-
|
|
123
|
-
// ../../../../../../../../../../../execroot/_main/bazel-out/k8-fastbuild/bin/plugins/async-node/core/src/utils/getNodeFromError.ts
|
|
124
|
-
import { ErrorTypes } from "@player-ui/player";
|
|
125
|
-
var getNodeFromError = (playerError, context) => {
|
|
126
|
-
if (playerError.type === ErrorTypes.RENDER) {
|
|
127
|
-
const { assetId } = playerError.metadata ?? {};
|
|
128
|
-
if (typeof assetId !== "string") {
|
|
129
|
-
return void 0;
|
|
130
|
-
}
|
|
131
|
-
return context.assetIdCache.get(assetId);
|
|
132
|
-
}
|
|
133
|
-
if (playerError.type === ErrorTypes.VIEW) {
|
|
134
|
-
const { node } = playerError.metadata ?? {};
|
|
135
|
-
if (typeof node === "object" && node !== null && !Array.isArray(node)) {
|
|
136
|
-
return node;
|
|
137
|
-
}
|
|
138
|
-
}
|
|
139
|
-
if (isAsyncPlayerError(playerError) && playerError.metadata !== void 0) {
|
|
140
|
-
return context.asyncNodeCache.get(playerError.metadata.node.id)?.asyncNode;
|
|
141
|
-
}
|
|
142
|
-
return void 0;
|
|
143
|
-
};
|
|
144
|
-
|
|
145
|
-
// ../../../../../../../../../../../execroot/_main/bazel-out/k8-fastbuild/bin/plugins/async-node/core/src/transform.ts
|
|
146
|
-
import { Builder } from "@player-ui/player";
|
|
147
|
-
var asyncTransform = (assetId, wrapperAssetType, asset, flatten, path = ["values"]) => {
|
|
148
|
-
const id = "async-" + assetId;
|
|
149
|
-
const asyncNode = Builder.asyncNode(id, flatten);
|
|
150
|
-
let multiNode;
|
|
151
|
-
let assetNode;
|
|
152
|
-
if (asset) {
|
|
153
|
-
assetNode = Builder.assetWrapper(asset);
|
|
154
|
-
multiNode = Builder.multiNode(assetNode, asyncNode);
|
|
155
|
-
} else {
|
|
156
|
-
multiNode = Builder.multiNode(asyncNode);
|
|
157
|
-
}
|
|
158
|
-
const wrapperAsset = Builder.asset({
|
|
159
|
-
id: wrapperAssetType + "-" + id,
|
|
160
|
-
type: wrapperAssetType
|
|
161
|
-
});
|
|
162
|
-
Builder.addChild(wrapperAsset, path, multiNode);
|
|
163
|
-
return wrapperAsset;
|
|
164
|
-
};
|
|
165
|
-
|
|
166
128
|
// ../../../../../../../../../../../execroot/_main/bazel-out/k8-fastbuild/bin/plugins/async-node/core/src/createAsyncTransform.ts
|
|
167
|
-
import {
|
|
168
|
-
Builder as Builder2,
|
|
169
|
-
NodeType as NodeType4
|
|
170
|
-
} from "@player-ui/player";
|
|
171
129
|
var defaultGetNodeId = (node) => {
|
|
172
130
|
return `async-${node.value.id}`;
|
|
173
131
|
};
|
|
@@ -277,8 +235,8 @@ var AsyncNodePluginPlugin = class {
|
|
|
277
235
|
* @param options Options provided for node resolution, including a potential parseNode function to process the result.
|
|
278
236
|
* @param view The view instance where the node resides. This can be undefined if the view is not currently active.
|
|
279
237
|
*/
|
|
280
|
-
parseNodeAndUpdate(node, context, result,
|
|
281
|
-
let parsedNode =
|
|
238
|
+
parseNodeAndUpdate(node, context, result, options) {
|
|
239
|
+
let parsedNode = options.parseNode && result ? options.parseNode(result) : void 0;
|
|
282
240
|
if (parsedNode && node.onValueReceived) {
|
|
283
241
|
parsedNode = node.onValueReceived(parsedNode);
|
|
284
242
|
}
|
|
@@ -294,30 +252,16 @@ var AsyncNodePluginPlugin = class {
|
|
|
294
252
|
* @param view The view instance where the node resides. This can be undefined if the view is not currently active.
|
|
295
253
|
*/
|
|
296
254
|
handleAsyncUpdate(node, context, newNode) {
|
|
297
|
-
const {
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
if (entry.resolvedContent !== newNode) {
|
|
303
|
-
entry.resolvedContent = newNode ? newNode : entry.asyncNode;
|
|
304
|
-
viewController.updateViewAST(entry.updateNodes);
|
|
255
|
+
const { nodeResolveCache, viewController, originalNodeCache } = context;
|
|
256
|
+
if (nodeResolveCache.get(node.id) !== newNode) {
|
|
257
|
+
nodeResolveCache.set(node.id, newNode ? newNode : node);
|
|
258
|
+
const originalNode = originalNodeCache.get(node.id) ?? /* @__PURE__ */ new Set([node]);
|
|
259
|
+
viewController.updateViewAST(originalNode);
|
|
305
260
|
}
|
|
306
261
|
}
|
|
307
|
-
hasValidMapping(
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
getOrCreateAsyncNodeCacheEntry(node, context) {
|
|
311
|
-
const { asyncNodeCache: asyncNodeInfo } = context;
|
|
312
|
-
let entry = asyncNodeInfo.get(node.id);
|
|
313
|
-
if (!entry) {
|
|
314
|
-
entry = {
|
|
315
|
-
asyncNode: node,
|
|
316
|
-
updateNodes: /* @__PURE__ */ new Set()
|
|
317
|
-
};
|
|
318
|
-
asyncNodeInfo.set(node.id, entry);
|
|
319
|
-
}
|
|
320
|
-
return entry;
|
|
262
|
+
hasValidMapping(node, context) {
|
|
263
|
+
const { nodeResolveCache } = context;
|
|
264
|
+
return nodeResolveCache.has(node.id) && nodeResolveCache.get(node.id) !== node;
|
|
321
265
|
}
|
|
322
266
|
/**
|
|
323
267
|
* Handles the asynchronous API integration for resolving nodes.
|
|
@@ -326,24 +270,16 @@ var AsyncNodePluginPlugin = class {
|
|
|
326
270
|
* @param view
|
|
327
271
|
*/
|
|
328
272
|
applyResolver(resolver, context) {
|
|
329
|
-
const { assetIdCache } = context;
|
|
330
|
-
resolver.hooks.afterNodeUpdate.tap(this.name, (original, _, update) => {
|
|
331
|
-
if (update.node.type !== NodeType5.Asset && update.node.type !== NodeType5.View) {
|
|
332
|
-
return;
|
|
333
|
-
}
|
|
334
|
-
assetIdCache.set(update.value.id, original);
|
|
335
|
-
});
|
|
336
273
|
resolver.hooks.beforeResolve.tap(this.name, (node, options) => {
|
|
337
274
|
if (!this.isAsync(node)) {
|
|
338
275
|
return node === null ? node : this.resolveAsyncChildren(node, context);
|
|
339
276
|
}
|
|
340
|
-
const entry = this.getOrCreateAsyncNodeCacheEntry(node, context);
|
|
341
277
|
if (options.node) {
|
|
342
|
-
|
|
343
|
-
context.generatedByMap.set(options.node, node.id);
|
|
278
|
+
context.originalNodeCache.set(node.id, /* @__PURE__ */ new Set([options.node]));
|
|
344
279
|
}
|
|
345
|
-
|
|
346
|
-
|
|
280
|
+
const resolvedNode = context.nodeResolveCache.get(node.id);
|
|
281
|
+
if (resolvedNode !== void 0) {
|
|
282
|
+
return this.resolveAsyncChildren(resolvedNode, context);
|
|
347
283
|
}
|
|
348
284
|
if (context.inProgressNodes.has(node.id)) {
|
|
349
285
|
return node;
|
|
@@ -367,22 +303,16 @@ var AsyncNodePluginPlugin = class {
|
|
|
367
303
|
let index = 0;
|
|
368
304
|
while (index < node.values.length) {
|
|
369
305
|
const childNode = node.values[index];
|
|
370
|
-
if (childNode?.type !== NodeType5.Async) {
|
|
306
|
+
if (childNode?.type !== NodeType5.Async || !this.hasValidMapping(childNode, context)) {
|
|
371
307
|
index++;
|
|
372
308
|
continue;
|
|
373
309
|
}
|
|
374
|
-
const
|
|
375
|
-
if (!this.hasValidMapping(entry)) {
|
|
376
|
-
index++;
|
|
377
|
-
continue;
|
|
378
|
-
}
|
|
379
|
-
const mappedNode = entry.resolvedContent;
|
|
310
|
+
const mappedNode = context.nodeResolveCache.get(childNode.id);
|
|
380
311
|
const nodeSet = /* @__PURE__ */ new Set();
|
|
381
312
|
if (mappedNode.type === NodeType5.MultiNode && childNode.flatten) {
|
|
382
313
|
mappedNode.values.forEach((v) => {
|
|
383
314
|
v.parent = node;
|
|
384
315
|
nodeSet.add(v);
|
|
385
|
-
context.originalParentMap.set(v, childNode);
|
|
386
316
|
});
|
|
387
317
|
node.values = [
|
|
388
318
|
...node.values.slice(0, index),
|
|
@@ -394,21 +324,13 @@ var AsyncNodePluginPlugin = class {
|
|
|
394
324
|
mappedNode.parent = node;
|
|
395
325
|
nodeSet.add(mappedNode);
|
|
396
326
|
}
|
|
397
|
-
|
|
398
|
-
for (const n of nodeSet) {
|
|
399
|
-
context.generatedByMap.set(n, childNode.id);
|
|
400
|
-
}
|
|
327
|
+
context.originalNodeCache.set(childNode.id, nodeSet);
|
|
401
328
|
}
|
|
402
329
|
} else if ("children" in node) {
|
|
403
330
|
node.children?.forEach((c) => {
|
|
404
|
-
while (c.value.type === NodeType5.Async) {
|
|
405
|
-
const
|
|
406
|
-
|
|
407
|
-
break;
|
|
408
|
-
}
|
|
409
|
-
const mappedNode = entry.resolvedContent;
|
|
410
|
-
entry.updateNodes = /* @__PURE__ */ new Set([mappedNode]);
|
|
411
|
-
context.generatedByMap.set(mappedNode, c.value.id);
|
|
331
|
+
while (c.value.type === NodeType5.Async && this.hasValidMapping(c.value, context)) {
|
|
332
|
+
const mappedNode = context.nodeResolveCache.get(c.value.id);
|
|
333
|
+
context.originalNodeCache.set(c.value.id, /* @__PURE__ */ new Set([mappedNode]));
|
|
412
334
|
c.value = mappedNode;
|
|
413
335
|
c.value.parent = node;
|
|
414
336
|
}
|
|
@@ -421,27 +343,27 @@ var AsyncNodePluginPlugin = class {
|
|
|
421
343
|
const result = await this.basePlugin?.hooks.onAsyncNode.call(
|
|
422
344
|
node,
|
|
423
345
|
(result2) => {
|
|
424
|
-
this.parseNodeAndUpdate(node, context, result2, options
|
|
346
|
+
this.parseNodeAndUpdate(node, context, result2, options);
|
|
425
347
|
}
|
|
426
348
|
);
|
|
427
349
|
context.inProgressNodes.delete(node.id);
|
|
428
|
-
this.parseNodeAndUpdate(node, context, result, options
|
|
350
|
+
this.parseNodeAndUpdate(node, context, result, options);
|
|
429
351
|
} catch (e) {
|
|
430
|
-
const
|
|
431
|
-
const
|
|
432
|
-
if (
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
352
|
+
const error = e instanceof Error ? e : new Error(String(e));
|
|
353
|
+
const result = this.basePlugin?.hooks.onAsyncNodeError.call(error, node);
|
|
354
|
+
if (result === void 0) {
|
|
355
|
+
const playerState = this.basePlugin?.getPlayerInstance()?.getState();
|
|
356
|
+
if (playerState?.status === "in-progress") {
|
|
357
|
+
playerState.fail(error);
|
|
358
|
+
}
|
|
437
359
|
return;
|
|
438
360
|
}
|
|
439
|
-
|
|
440
|
-
node,
|
|
441
|
-
|
|
442
|
-
cause
|
|
361
|
+
options.logger?.error(
|
|
362
|
+
"Async node handling failed and resolved with a fallback. Error:",
|
|
363
|
+
error
|
|
443
364
|
);
|
|
444
|
-
|
|
365
|
+
context.inProgressNodes.delete(node.id);
|
|
366
|
+
this.parseNodeAndUpdate(node, context, result, options);
|
|
445
367
|
}
|
|
446
368
|
}
|
|
447
369
|
isAsync(node) {
|
|
@@ -487,84 +409,15 @@ var AsyncNodePluginPlugin = class {
|
|
|
487
409
|
view.hooks.parser.tap("async", this.applyParser.bind(this));
|
|
488
410
|
}
|
|
489
411
|
applyPlayer(player) {
|
|
490
|
-
let currentContext = void 0;
|
|
491
|
-
let parser = void 0;
|
|
492
|
-
player.hooks.errorController.tap("async", (errorController) => {
|
|
493
|
-
errorController.hooks.onError.tap("async", (playerError) => {
|
|
494
|
-
if (currentContext === void 0) {
|
|
495
|
-
return void 0;
|
|
496
|
-
}
|
|
497
|
-
const tryHandleError = (asyncNode) => {
|
|
498
|
-
if (this.basePlugin === void 0) {
|
|
499
|
-
player.logger.warn(
|
|
500
|
-
`[AsyncNodePlugin]: No plugin detected. Error handling will fail`
|
|
501
|
-
);
|
|
502
|
-
}
|
|
503
|
-
let result = void 0;
|
|
504
|
-
result = this.basePlugin?.hooks.onAsyncNodeError.call(
|
|
505
|
-
playerError,
|
|
506
|
-
asyncNode
|
|
507
|
-
);
|
|
508
|
-
if (result === void 0) {
|
|
509
|
-
return false;
|
|
510
|
-
}
|
|
511
|
-
player.logger?.warn(
|
|
512
|
-
"[AsyncNodePlugin]: Async node handling failed and resolved with a fallback. Cause:",
|
|
513
|
-
playerError.message
|
|
514
|
-
);
|
|
515
|
-
currentContext.inProgressNodes.delete(asyncNode.id);
|
|
516
|
-
this.parseNodeAndUpdate(
|
|
517
|
-
asyncNode,
|
|
518
|
-
currentContext,
|
|
519
|
-
result,
|
|
520
|
-
parser?.parseObject.bind(parser)
|
|
521
|
-
);
|
|
522
|
-
return true;
|
|
523
|
-
};
|
|
524
|
-
const getNextNode = (node2) => {
|
|
525
|
-
const parent = currentContext?.originalParentMap.get(node2) ?? node2.parent;
|
|
526
|
-
if (!parent) {
|
|
527
|
-
return void 0;
|
|
528
|
-
}
|
|
529
|
-
return this.isAsync(parent) ? currentContext?.asyncNodeCache.get(parent.id)?.asyncNode : parent;
|
|
530
|
-
};
|
|
531
|
-
let node = getNodeFromError(playerError, currentContext);
|
|
532
|
-
if (node?.type === NodeType5.Async && tryHandleError(node)) {
|
|
533
|
-
return true;
|
|
534
|
-
}
|
|
535
|
-
while (node !== void 0) {
|
|
536
|
-
const generatedBy = currentContext.generatedByMap.get(node);
|
|
537
|
-
if (generatedBy) {
|
|
538
|
-
const entry = currentContext.asyncNodeCache.get(generatedBy);
|
|
539
|
-
if (!entry) {
|
|
540
|
-
node = getNextNode(node);
|
|
541
|
-
continue;
|
|
542
|
-
}
|
|
543
|
-
const { asyncNode } = entry;
|
|
544
|
-
if (tryHandleError(asyncNode)) {
|
|
545
|
-
return true;
|
|
546
|
-
}
|
|
547
|
-
}
|
|
548
|
-
node = getNextNode(node);
|
|
549
|
-
}
|
|
550
|
-
return void 0;
|
|
551
|
-
});
|
|
552
|
-
});
|
|
553
412
|
player.hooks.viewController.tap("async", (viewController) => {
|
|
554
413
|
viewController.hooks.view.tap("async", (view) => {
|
|
555
|
-
view.hooks.parser.tap(this.name, (p) => {
|
|
556
|
-
parser = p;
|
|
557
|
-
});
|
|
558
414
|
const context = {
|
|
415
|
+
nodeResolveCache: /* @__PURE__ */ new Map(),
|
|
559
416
|
inProgressNodes: /* @__PURE__ */ new Set(),
|
|
560
417
|
view,
|
|
561
418
|
viewController,
|
|
562
|
-
|
|
563
|
-
assetIdCache: /* @__PURE__ */ new Map(),
|
|
564
|
-
asyncNodeCache: /* @__PURE__ */ new Map(),
|
|
565
|
-
originalParentMap: /* @__PURE__ */ new Map()
|
|
419
|
+
originalNodeCache: /* @__PURE__ */ new Map()
|
|
566
420
|
};
|
|
567
|
-
currentContext = context;
|
|
568
421
|
view.hooks.resolver.tap("async", (resolver) => {
|
|
569
422
|
this.applyResolver(resolver, context);
|
|
570
423
|
});
|