@player-ui/async-node-plugin 1.1.1--canary.934.41671 → 1.1.1--canary.937.41794
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 +2649 -3270
- package/dist/AsyncNodePlugin.native.js.map +1 -1
- package/dist/cjs/index.cjs +70 -224
- package/dist/cjs/index.cjs.map +1 -1
- package/dist/index.legacy-esm.js +61 -217
- package/dist/index.mjs +61 -217
- package/dist/index.mjs.map +1 -1
- package/package.json +3 -4
- package/src/__tests__/index.test.ts +4 -414
- package/src/index.ts +69 -207
- 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
|
-
|
|
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);
|
|
301
260
|
}
|
|
302
|
-
if (entry.resolvedContent !== newNode) {
|
|
303
|
-
entry.resolvedContent = newNode ? newNode : entry.asyncNode;
|
|
304
|
-
viewController.updateViewAST(entry.updateNodes);
|
|
305
|
-
}
|
|
306
|
-
}
|
|
307
|
-
hasValidMapping(cacheEntry) {
|
|
308
|
-
return cacheEntry.resolvedContent !== void 0 && cacheEntry.resolvedContent !== cacheEntry.asyncNode;
|
|
309
261
|
}
|
|
310
|
-
|
|
311
|
-
const {
|
|
312
|
-
|
|
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) {
|
|
371
|
-
index++;
|
|
372
|
-
continue;
|
|
373
|
-
}
|
|
374
|
-
const entry = this.getOrCreateAsyncNodeCacheEntry(childNode, context);
|
|
375
|
-
if (!this.hasValidMapping(entry)) {
|
|
306
|
+
if (childNode?.type !== NodeType5.Async || !this.hasValidMapping(childNode, context)) {
|
|
376
307
|
index++;
|
|
377
308
|
continue;
|
|
378
309
|
}
|
|
379
|
-
const mappedNode =
|
|
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
|
}
|
|
@@ -418,39 +340,30 @@ var AsyncNodePluginPlugin = class {
|
|
|
418
340
|
}
|
|
419
341
|
async runAsyncNode(node, context, options) {
|
|
420
342
|
try {
|
|
421
|
-
let deliveredViaCallback = false;
|
|
422
343
|
const result = await this.basePlugin?.hooks.onAsyncNode.call(
|
|
423
344
|
node,
|
|
424
|
-
(
|
|
425
|
-
|
|
426
|
-
this.parseNodeAndUpdate(
|
|
427
|
-
node,
|
|
428
|
-
context,
|
|
429
|
-
streamedResult,
|
|
430
|
-
options.parseNode
|
|
431
|
-
);
|
|
345
|
+
(result2) => {
|
|
346
|
+
this.parseNodeAndUpdate(node, context, result2, options);
|
|
432
347
|
}
|
|
433
348
|
);
|
|
434
349
|
context.inProgressNodes.delete(node.id);
|
|
435
|
-
|
|
436
|
-
this.parseNodeAndUpdate(node, context, result, options.parseNode);
|
|
437
|
-
}
|
|
350
|
+
this.parseNodeAndUpdate(node, context, result, options);
|
|
438
351
|
} catch (e) {
|
|
439
|
-
const
|
|
440
|
-
const
|
|
441
|
-
if (
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
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
|
+
}
|
|
446
359
|
return;
|
|
447
360
|
}
|
|
448
|
-
|
|
449
|
-
node,
|
|
450
|
-
|
|
451
|
-
cause
|
|
361
|
+
options.logger?.error(
|
|
362
|
+
"Async node handling failed and resolved with a fallback. Error:",
|
|
363
|
+
error
|
|
452
364
|
);
|
|
453
|
-
|
|
365
|
+
context.inProgressNodes.delete(node.id);
|
|
366
|
+
this.parseNodeAndUpdate(node, context, result, options);
|
|
454
367
|
}
|
|
455
368
|
}
|
|
456
369
|
isAsync(node) {
|
|
@@ -496,84 +409,15 @@ var AsyncNodePluginPlugin = class {
|
|
|
496
409
|
view.hooks.parser.tap("async", this.applyParser.bind(this));
|
|
497
410
|
}
|
|
498
411
|
applyPlayer(player) {
|
|
499
|
-
let currentContext = void 0;
|
|
500
|
-
let parser = void 0;
|
|
501
|
-
player.hooks.errorController.tap("async", (errorController) => {
|
|
502
|
-
errorController.hooks.onError.tap("async", (playerError) => {
|
|
503
|
-
if (currentContext === void 0) {
|
|
504
|
-
return void 0;
|
|
505
|
-
}
|
|
506
|
-
const tryHandleError = (asyncNode) => {
|
|
507
|
-
if (this.basePlugin === void 0) {
|
|
508
|
-
player.logger.warn(
|
|
509
|
-
`[AsyncNodePlugin]: No plugin detected. Error handling will fail`
|
|
510
|
-
);
|
|
511
|
-
}
|
|
512
|
-
let result = void 0;
|
|
513
|
-
result = this.basePlugin?.hooks.onAsyncNodeError.call(
|
|
514
|
-
playerError,
|
|
515
|
-
asyncNode
|
|
516
|
-
);
|
|
517
|
-
if (result === void 0) {
|
|
518
|
-
return false;
|
|
519
|
-
}
|
|
520
|
-
player.logger?.warn(
|
|
521
|
-
"[AsyncNodePlugin]: Async node handling failed and resolved with a fallback. Cause:",
|
|
522
|
-
playerError.message
|
|
523
|
-
);
|
|
524
|
-
currentContext.inProgressNodes.delete(asyncNode.id);
|
|
525
|
-
this.parseNodeAndUpdate(
|
|
526
|
-
asyncNode,
|
|
527
|
-
currentContext,
|
|
528
|
-
result,
|
|
529
|
-
parser?.parseObject.bind(parser)
|
|
530
|
-
);
|
|
531
|
-
return true;
|
|
532
|
-
};
|
|
533
|
-
const getNextNode = (node2) => {
|
|
534
|
-
const parent = currentContext?.originalParentMap.get(node2) ?? node2.parent;
|
|
535
|
-
if (!parent) {
|
|
536
|
-
return void 0;
|
|
537
|
-
}
|
|
538
|
-
return this.isAsync(parent) ? currentContext?.asyncNodeCache.get(parent.id)?.asyncNode : parent;
|
|
539
|
-
};
|
|
540
|
-
let node = getNodeFromError(playerError, currentContext);
|
|
541
|
-
if (node?.type === NodeType5.Async && tryHandleError(node)) {
|
|
542
|
-
return true;
|
|
543
|
-
}
|
|
544
|
-
while (node !== void 0) {
|
|
545
|
-
const generatedBy = currentContext.generatedByMap.get(node);
|
|
546
|
-
if (generatedBy) {
|
|
547
|
-
const entry = currentContext.asyncNodeCache.get(generatedBy);
|
|
548
|
-
if (!entry) {
|
|
549
|
-
node = getNextNode(node);
|
|
550
|
-
continue;
|
|
551
|
-
}
|
|
552
|
-
const { asyncNode } = entry;
|
|
553
|
-
if (tryHandleError(asyncNode)) {
|
|
554
|
-
return true;
|
|
555
|
-
}
|
|
556
|
-
}
|
|
557
|
-
node = getNextNode(node);
|
|
558
|
-
}
|
|
559
|
-
return void 0;
|
|
560
|
-
});
|
|
561
|
-
});
|
|
562
412
|
player.hooks.viewController.tap("async", (viewController) => {
|
|
563
413
|
viewController.hooks.view.tap("async", (view) => {
|
|
564
|
-
view.hooks.parser.tap(this.name, (p) => {
|
|
565
|
-
parser = p;
|
|
566
|
-
});
|
|
567
414
|
const context = {
|
|
415
|
+
nodeResolveCache: /* @__PURE__ */ new Map(),
|
|
568
416
|
inProgressNodes: /* @__PURE__ */ new Set(),
|
|
569
417
|
view,
|
|
570
418
|
viewController,
|
|
571
|
-
|
|
572
|
-
assetIdCache: /* @__PURE__ */ new Map(),
|
|
573
|
-
asyncNodeCache: /* @__PURE__ */ new Map(),
|
|
574
|
-
originalParentMap: /* @__PURE__ */ new Map()
|
|
419
|
+
originalNodeCache: /* @__PURE__ */ new Map()
|
|
575
420
|
};
|
|
576
|
-
currentContext = context;
|
|
577
421
|
view.hooks.resolver.tap("async", (resolver) => {
|
|
578
422
|
this.applyResolver(resolver, context);
|
|
579
423
|
});
|