Skip to content

Commit

Permalink
Rename node.type -> node.name
Browse files Browse the repository at this point in the history
  • Loading branch information
ajthinking committed Jan 8, 2025
1 parent 24eda6c commit bc16abb
Show file tree
Hide file tree
Showing 18 changed files with 56 additions and 56 deletions.
6 changes: 3 additions & 3 deletions packages/core/src/Diagram.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ describe('add', () => {
const diagram = new Diagram()
const node: Node = {
id: 'node-id',
type: 'MyNode',
name: 'MyNode',
inputs: [],
outputs: [],
params: []
Expand All @@ -30,7 +30,7 @@ describe('nodeWithOutputPortId', () => {

const node: Node = {
id: 'node-id',
type: 'MyNode',
name: 'MyNode',
inputs: [],
outputs: [output],
params: []
Expand Down Expand Up @@ -70,7 +70,7 @@ describe('clone', () => {
it('creates a deep clone of the diagram', () => {
const node: Node = {
id: 'node-id',
type: 'MyNode',
name: 'MyNode',
inputs: [],
outputs: [],
params: []
Expand Down
4 changes: 2 additions & 2 deletions packages/core/src/Diagram.ts
Original file line number Diff line number Diff line change
Expand Up @@ -128,10 +128,10 @@ export class Diagram {
}

inputNodes(): Node[] {
return this.nodes.filter(node => node.type === 'Input')
return this.nodes.filter(node => node.name === 'Input')
}

outputNodes(): Node[] {
return this.nodes.filter(node => node.type === 'Output')
return this.nodes.filter(node => node.name === 'Output')
}
}
4 changes: 2 additions & 2 deletions packages/core/src/DiagramBuilder.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@ describe('add', () => {
.get()

expect(diagram.nodes).toMatchObject([
{ id: 'Create.1', type: 'Create' },
{ id: 'Ignore.1', type: 'Ignore' },
{ id: 'Create.1', name: 'Create' },
{ id: 'Ignore.1', name: 'Ignore' },
])
})

Expand Down
6 changes: 3 additions & 3 deletions packages/core/src/DiagramBuilder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ export class DiagramBuilder {
const node: Node = {
id: nodeId,
label: name,
type: name,
name: name,
// The inputs have not yet been assigned ids, to it here
inputs: diagram.inputNodes().map(inputNode => {
const param = inputNode.params.find(param => param.name === 'port_name');
Expand Down Expand Up @@ -227,7 +227,7 @@ export class DiagramBuilder {

return structuredClone({
id,
type: nodeDescription.name,
name: nodeDescription.name,
label: nodeDescription.label,
inputs: nodeDescription.inputs.map(input => {
return {
Expand Down Expand Up @@ -296,7 +296,7 @@ export class DiagramBuilder {

protected getScopedId(nodeName: string) {
const max = this.diagram.nodes
.filter(node => node.type === nodeName)
.filter(node => node.name === nodeName)
.map(node => node.id)
.map(id => id.split('.')[1])
.map(id => parseInt(id))
Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/DiagramQuery.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ export class DiagramQuery {
protected getPortId(portDescriptor: PortDescriptor): PortId {
const [nodeType, portName] = portDescriptor.split('.')

const node = this.diagram.nodes.find(node => node.type === nodeType)
const node = this.diagram.nodes.find(node => node.name === nodeType)
if(!node) throw new Error(`Node with type ${nodeType} not found in diagram`);

const port = [
Expand Down
4 changes: 2 additions & 2 deletions packages/core/src/ExecutionMemoryFactory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,8 @@ export class ExecutionMemoryFactory {
memory.outputDevices.set(node.id, outputDevice)

// Initialize runner generators
const computer = this.registry.computers[node.type]
if (!computer) throw new Error(`Computer "${node.type}" not found`)
const computer = this.registry.computers[node.name]
if (!computer) throw new Error(`Computer "${node.name}" not found`)

memory.setNodeRunner(
node.id,
Expand Down
10 changes: 5 additions & 5 deletions packages/core/src/Executor.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ describe('execute', () => {
it('can execute a diagram with a single no-input no-output node', async () => {
const node: Node = {
id: 'node-id',
type: 'Dummy',
name: 'Dummy',
inputs: [],
outputs: [],
params: []
Expand Down Expand Up @@ -73,7 +73,7 @@ describe('execute', () => {
it('can execute a diagram with non connected input node', async () => {
const node: Node = {
id: 'node-id',
type: 'Accepter',
name: 'Accepter',
inputs: [{
id: 'input-id',
name: 'input',
Expand Down Expand Up @@ -110,7 +110,7 @@ describe('execute', () => {
it('can execute a diagram with a node outputting items', async () => {
const node: Node = {
id: 'zergling-spawner-id',
type: 'Spawner',
name: 'Spawner',
inputs: [],
outputs: [
{
Expand Down Expand Up @@ -153,7 +153,7 @@ describe('execute', () => {
it('can execute a diagram with item flowing between two nodes', async () => {
const create: Node = {
id: 'create-id',
type: 'Create',
name: 'Create',
inputs: [],
outputs: [{
id: 'Create.1.output',
Expand All @@ -165,7 +165,7 @@ describe('execute', () => {

const log: Node = {
id: 'log-id',
type: 'Log',
name: 'Log',
inputs: [{
id: 'Log.1.input',
name: 'input',
Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/Executor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ export class Executor {
protected getRunnableNodes(): Node[] {
return this.diagram.nodes.filter(node => {
// If the computer implements a custom hook
const computer = this.registry.computers[node.type]
const computer = this.registry.computers[node.name]
const hook = computer.canRun
if(hook) return hook({
isAvailable: () => this.memory.getNodeStatus(node.id) === 'AVAILABLE',
Expand Down
14 changes: 7 additions & 7 deletions packages/core/src/InputDevice.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ describe('pull', () => {
it('returns items at port named "input" wrapped as ItemWithParams', () => {
const node: Node = {
id: 'target',
type: 'node-type',
name: 'node-type',
inputs: [{id: 'target-input-id', name: 'input', schema: {}}],
outputs: [],
params: []
Expand Down Expand Up @@ -49,7 +49,7 @@ describe('pull', () => {
expect(() => {
const node: Node = {
id: 'target',
type: 'node-type',
name: 'node-type',
inputs: [{id: 'target-input-id', name: 'some-other-name', schema: {}}],
outputs: [],
params: []
Expand All @@ -70,7 +70,7 @@ describe('pull', () => {
it('removes the items pulled from the links', () => {
const node: Node = {
id: 'target',
type: 'node-type',
name: 'node-type',
inputs: [{id: 'target-input-id', name: 'input', schema: {}}],
outputs: [],
params: []
Expand Down Expand Up @@ -107,7 +107,7 @@ describe('pull', () => {
it('may pull a specified number of items', () => {
const node: Node = {
id: 'target',
type: 'node-type',
name: 'node-type',
inputs: [{id: 'target-input-id', name: 'input', schema: {}}],
outputs: [],
params: []
Expand Down Expand Up @@ -143,7 +143,7 @@ describe('pullFrom', () => {
it('returns items at named port', () => {
const node: Node = {
id: 'target',
type: 'node-type',
name: 'node-type',
inputs: [{id: 'target-input-id', name: 'numbers', schema: {}}],
outputs: [],
params: []
Expand Down Expand Up @@ -180,7 +180,7 @@ describe('pullFrom', () => {
it('removes the items pulled from the links', () => {
const node: Node = {
id: 'target',
type: 'node-type',
name: 'node-type',
inputs: [{id: 'target-input-id', name: 'numbers', schema: {}}],
outputs: [],
params: []
Expand Down Expand Up @@ -219,7 +219,7 @@ describe('params', () => {
it('has getters for params returning interpolated values', () => {
const node: Node = {
id: 'target',
type: 'node-type',
name: 'node-type',
inputs: [{id: 'target-input-id', name: 'input', schema: {}}],
outputs: [],
params: [createDefaultStringable({
Expand Down
4 changes: 2 additions & 2 deletions packages/core/src/NodeDescriptionFactory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ export const NodeDescriptionFactory = {
label: name,
category: undefined,
inputs: diagram.nodes
.filter(node => node.type === 'Input')
.filter(node => node.name === 'Input')
.map(node => {
const portParam = node.params
.find(param => param.name === 'port_name')! as StringableInputValue
Expand All @@ -34,7 +34,7 @@ export const NodeDescriptionFactory = {
}
}),
outputs: diagram.nodes
.filter(node => node.type === 'Output')
.filter(node => node.name === 'Output')
.map(node => {
const portParam = node.params
.find(param => param.name === 'port_name')! as StringableInputValue
Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/PositionGuesser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ export class PositionGuesser {
const maxY = this.diagram.nodes.map((node) => node.position!.y).reduce((max, y) => Math.max(max, y), 0)

const isStarterNode = node.inputs.length === 0;
const type = (node as Node).type ?? (node as NodeDescription).name;
const type = (node as Node).name ?? (node as NodeDescription).name;
const isInputNode = type === 'Input';

if(isStarterNode || isInputNode) {
Expand Down
22 changes: 11 additions & 11 deletions packages/core/src/UnfoldedDiagramFactory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,11 @@ export class UnfoldedDiagramFactory {
}

unfold(): UnfoldedDiagram {
const replacables = this.diagram.nodes.filter(node => node.type in this.nestedNodes)
const replacables = this.diagram.nodes.filter(node => node.name in this.nestedNodes)

for(const node of replacables) {
const nestedDiagram = this.nestedNodes[node.type]
if(!nestedDiagram) throw new Error(`No nesteddiagram found for node type "${node.type}"`)
const nestedDiagram = this.nestedNodes[node.name]
if(!nestedDiagram) throw new Error(`No nesteddiagram found for node type "${node.name}"`)

this.diagram.nodes.push(...nestedDiagram.nodes)
this.diagram.links.push(...nestedDiagram.links)
Expand All @@ -54,8 +54,8 @@ export class UnfoldedDiagramFactory {
if(index === -1) throw new Error('Node not found in diagram')
this.diagram.nodes.splice(index, 1)

const nestedDiagram = this.nestedNodes[node.type]
if(!nestedDiagram) throw new Error(`No nesteddiagram found for node type "${node.type}"`)
const nestedDiagram = this.nestedNodes[node.name]
if(!nestedDiagram) throw new Error(`No nesteddiagram found for node type "${node.name}"`)

// Rewire incoming links
for(const inputPort of node.inputs) {
Expand All @@ -64,7 +64,7 @@ export class UnfoldedDiagramFactory {
for(const link of links) {
const newTargetNode = nestedDiagram.nodes
.find(node => {
const isInputNode = node.type === 'Input'
const isInputNode = node.name === 'Input'
if(!isInputNode) return false;

const param = node.params[0];
Expand All @@ -76,10 +76,10 @@ export class UnfoldedDiagramFactory {
return matchesPortName
})

if(!newTargetNode) throw new Error(`No input node found for input port "${inputPort.name}" on the nesteddiagram of "${node.type}"`)
if(!newTargetNode) throw new Error(`No input node found for input port "${inputPort.name}" on the nesteddiagram of "${node.name}"`)

const newInputPort = newTargetNode.inputs[0]
if(!newInputPort) throw new Error(`No input port found for input port "${inputPort.name}" on the nesteddiagram of "${node.type}". The node was ${JSON.stringify(node)}`)
if(!newInputPort) throw new Error(`No input port found for input port "${inputPort.name}" on the nesteddiagram of "${node.name}". The node was ${JSON.stringify(node)}`)

link.targetPortId = newInputPort.id
}
Expand All @@ -91,7 +91,7 @@ export class UnfoldedDiagramFactory {
for(const link of links) {
const newSourceNode = nestedDiagram.nodes
.find(node => {
const isOutputNode = node.type === 'Output'
const isOutputNode = node.name === 'Output'
if(!isOutputNode) return false;

const param = node.params[0];
Expand All @@ -103,10 +103,10 @@ export class UnfoldedDiagramFactory {
return matchesPortName
})

if(!newSourceNode) throw new Error(`No output node found for output port "${outputPort.name}" on the nesteddiagram of "${node.type}"`)
if(!newSourceNode) throw new Error(`No output node found for output port "${outputPort.name}" on the nesteddiagram of "${node.name}"`)

const newOutputPort = newSourceNode.outputs[0]
if(!newOutputPort) throw new Error(`No output port found for output port "${outputPort.name}" on the nesteddiagram of "${node.type}"`)
if(!newOutputPort) throw new Error(`No output port found for output port "${outputPort.name}" on the nesteddiagram of "${node.name}"`)

link.sourcePortId = newOutputPort.id
}
Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/support/computerTester/ComputerTester.ts
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ export class ComputerTester {
// Create a new Node from the computer + params (TODO: this is a general need)
const node: Node = {
id: nodeId,
type: this.computer.name,
name: this.computer.name,
inputs: (this.computer.inputs || []).map(input => ({
id: `${nodeId}.${input.name}`,
name: input.name,
Expand Down
4 changes: 2 additions & 2 deletions packages/core/src/syncPortSchemas.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ it('forwards schema to linked ports', () => {

const node1: Node = {
id: 'node1',
type: 'MyNode',
name: 'MyNode',
inputs: [],
outputs: [outputPort],
params: []
Expand All @@ -27,7 +27,7 @@ it('forwards schema to linked ports', () => {

const node2: Node = {
id: 'node2',
type: 'MyNode',
name: 'MyNode',
inputs: [inputPort],
outputs: [],
params: []
Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/types/Node.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ export type NodeId = string

export type Node = {
id: NodeId
type: string
name: string
label?: string
inputs: Port[]
outputs: Port[]
Expand Down
4 changes: 2 additions & 2 deletions packages/ui/src/factories/NodeFactory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ export const NodeFactory = {
fromReactFlowNode: (flowNode: ReactFlowNode): Node => {
return {
id: flowNode.id,
type: flowNode.data.computer,
name: flowNode.data.computer,
label: flowNode.data.label,
inputs: flowNode.data.inputs.map(input => {
return {
Expand Down Expand Up @@ -34,7 +34,7 @@ export const NodeFactory = {

return structuredClone({
id,
type: nodeDescription.name,
name: nodeDescription.name,
label: nodeDescription.label,
inputs: nodeDescription.inputs.map(input => {
return {
Expand Down
14 changes: 7 additions & 7 deletions packages/ui/src/factories/ReactFlowFactory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,17 +15,17 @@ export const ReactFlowFactory = {
},
data: {
params: node.params,
computer: node.type,
label: (node?.label || node.type) as string,
computer: node.name,
label: (node?.label || node.name) as string,
inputs: node.inputs,
outputs: node.outputs,
},
type: (() => {
if (node.type === 'Comment') return 'commentNodeComponent';
if (node.type === 'Input') return 'inputNodeComponent';
if (node.type === 'Output') return 'outputNodeComponent';
if (node.type === 'Table') return 'tableNodeComponent';
if (node.type === 'ConsoleLog') return 'consoleNodeComponent';
if (node.name === 'Comment') return 'commentNodeComponent';
if (node.name === 'Input') return 'inputNodeComponent';
if (node.name === 'Output') return 'outputNodeComponent';
if (node.name === 'Table') return 'tableNodeComponent';
if (node.name === 'ConsoleLog') return 'consoleNodeComponent';

return 'nodeComponent';
})(),
Expand Down
Loading

0 comments on commit bc16abb

Please sign in to comment.