@valerypopoff/rivet2-core 2.1.6 → 2.1.7
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.
|
@@ -4,7 +4,34 @@ import {} from '../NodeBase.js';
|
|
|
4
4
|
import { nanoid } from 'nanoid/non-secure';
|
|
5
5
|
import {} from '../GraphProcessor.js';
|
|
6
6
|
import { dedent } from 'ts-dedent';
|
|
7
|
-
|
|
7
|
+
const INPUT_PORT_PATTERN = /^input(\d+)$/;
|
|
8
|
+
const OUTPUT_PORT_PATTERN = /^output(\d+)$/;
|
|
9
|
+
export const MAX_PASSTHROUGH_PORT_INDEX = 10_000;
|
|
10
|
+
function parsePositivePortIndex(portId, pattern) {
|
|
11
|
+
const match = pattern.exec(portId);
|
|
12
|
+
const index = match ? Number(match[1]) : Number.NaN;
|
|
13
|
+
return Number.isSafeInteger(index) && index > 0 && index <= MAX_PASSTHROUGH_PORT_INDEX ? index : undefined;
|
|
14
|
+
}
|
|
15
|
+
function getHighestConnectedSlotIndex(connections, nodeId) {
|
|
16
|
+
let highestIndex = 0;
|
|
17
|
+
for (const connection of connections) {
|
|
18
|
+
const inputIndex = connection.inputNodeId === nodeId ? parsePositivePortIndex(connection.inputId, INPUT_PORT_PATTERN) : undefined;
|
|
19
|
+
const outputIndex = connection.outputNodeId === nodeId ? parsePositivePortIndex(connection.outputId, OUTPUT_PORT_PATTERN) : undefined;
|
|
20
|
+
highestIndex = Math.max(highestIndex, inputIndex ?? 0, outputIndex ?? 0);
|
|
21
|
+
}
|
|
22
|
+
return highestIndex;
|
|
23
|
+
}
|
|
24
|
+
export function isPassthroughDataBusNode(node) {
|
|
25
|
+
return node?.type === 'passthrough' && node.data?.renderAsDataBus === true;
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* Conditional and split-run Passthrough nodes have execution semantics that a
|
|
29
|
+
* hidden canvas rail cannot communicate. Malformed or hand-edited combinations
|
|
30
|
+
* therefore fall back to the normal visible node until the conflict is removed.
|
|
31
|
+
*/
|
|
32
|
+
export function canRenderPassthroughAsDataBus(node) {
|
|
33
|
+
return isPassthroughDataBusNode(node) && !node.isConditional && !node.isSplitRun;
|
|
34
|
+
}
|
|
8
35
|
export class PassthroughNodeImpl extends NodeImpl {
|
|
9
36
|
static create = () => {
|
|
10
37
|
const chartNode = {
|
|
@@ -22,7 +49,7 @@ export class PassthroughNodeImpl extends NodeImpl {
|
|
|
22
49
|
};
|
|
23
50
|
getInputDefinitions(connections) {
|
|
24
51
|
const inputs = [];
|
|
25
|
-
const inputCount =
|
|
52
|
+
const inputCount = Math.min(getHighestConnectedSlotIndex(connections, this.chartNode.id) + 1, MAX_PASSTHROUGH_PORT_INDEX);
|
|
26
53
|
for (let i = 1; i <= inputCount; i++) {
|
|
27
54
|
inputs.push({
|
|
28
55
|
dataType: 'any',
|
|
@@ -34,8 +61,8 @@ export class PassthroughNodeImpl extends NodeImpl {
|
|
|
34
61
|
}
|
|
35
62
|
getOutputDefinitions(connections) {
|
|
36
63
|
const outputs = [];
|
|
37
|
-
const
|
|
38
|
-
for (let i = 1; i <=
|
|
64
|
+
const outputCount = getHighestConnectedSlotIndex(connections, this.chartNode.id);
|
|
65
|
+
for (let i = 1; i <= outputCount; i++) {
|
|
39
66
|
outputs.push({
|
|
40
67
|
dataType: 'any',
|
|
41
68
|
id: `output${i}`,
|
|
@@ -55,11 +82,12 @@ export class PassthroughNodeImpl extends NodeImpl {
|
|
|
55
82
|
};
|
|
56
83
|
}
|
|
57
84
|
async process(inputData) {
|
|
58
|
-
const inputCount = Object.keys(inputData).filter((key) => key.startsWith('input')).length;
|
|
59
85
|
const outputs = {};
|
|
60
|
-
for (
|
|
61
|
-
const
|
|
62
|
-
|
|
86
|
+
for (const [portId, input] of Object.entries(inputData)) {
|
|
87
|
+
const index = parsePositivePortIndex(portId, INPUT_PORT_PATTERN);
|
|
88
|
+
if (index != null) {
|
|
89
|
+
outputs[`output${index}`] = input;
|
|
90
|
+
}
|
|
63
91
|
}
|
|
64
92
|
return outputs;
|
|
65
93
|
}
|
|
@@ -2,7 +2,21 @@ import { NodeImpl, type NodeUIData } from '../NodeImpl.js';
|
|
|
2
2
|
import { type ChartNode, type NodeConnection, type NodeInputDefinition, type NodeOutputDefinition } from '../NodeBase.js';
|
|
3
3
|
import { type Inputs, type Outputs } from '../GraphProcessor.js';
|
|
4
4
|
export type PassthroughNode = ChartNode<'passthrough', PassthroughNodeData>;
|
|
5
|
-
export type PassthroughNodeData = {
|
|
5
|
+
export type PassthroughNodeData = {
|
|
6
|
+
/**
|
|
7
|
+
* Canvas-only presentation mode. Runtime execution and serialized connections
|
|
8
|
+
* remain an ordinary Passthrough node.
|
|
9
|
+
*/
|
|
10
|
+
renderAsDataBus?: boolean;
|
|
11
|
+
};
|
|
12
|
+
export declare const MAX_PASSTHROUGH_PORT_INDEX = 10000;
|
|
13
|
+
export declare function isPassthroughDataBusNode(node: ChartNode | undefined): node is PassthroughNode;
|
|
14
|
+
/**
|
|
15
|
+
* Conditional and split-run Passthrough nodes have execution semantics that a
|
|
16
|
+
* hidden canvas rail cannot communicate. Malformed or hand-edited combinations
|
|
17
|
+
* therefore fall back to the normal visible node until the conflict is removed.
|
|
18
|
+
*/
|
|
19
|
+
export declare function canRenderPassthroughAsDataBus(node: ChartNode | undefined): node is PassthroughNode;
|
|
6
20
|
export declare class PassthroughNodeImpl extends NodeImpl<PassthroughNode> {
|
|
7
21
|
static create: () => PassthroughNode;
|
|
8
22
|
getInputDefinitions(connections: NodeConnection[]): NodeInputDefinition[];
|