mirror of
https://github.com/invoke-ai/InvokeAI
synced 2024-08-30 20:32:17 +00:00
feat(ui): add addEdgeToMetadata graph helper
This commit is contained in:
parent
071c7c7c7e
commit
7cee4e42a7
@ -522,6 +522,21 @@ describe('Graph', () => {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
describe('addEdgeToMetadata', () => {
|
||||||
|
it('should add an edge to the metadata node', () => {
|
||||||
|
const g = new Graph();
|
||||||
|
const n1 = g.addNode({
|
||||||
|
id: 'n1',
|
||||||
|
type: 'img_resize',
|
||||||
|
});
|
||||||
|
g.upsertMetadata({ test: 'test' });
|
||||||
|
g.addEdgeToMetadata(n1, 'width', 'width');
|
||||||
|
const metadata = g._getMetadataNode();
|
||||||
|
expect(g.getEdgesFrom(n1).length).toBe(1);
|
||||||
|
expect(g.getEdgesTo(metadata as unknown as AnyInvocation).length).toBe(1);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
describe('setMetadataReceivingNode', () => {
|
describe('setMetadataReceivingNode', () => {
|
||||||
it('should set the metadata receiving node', () => {
|
it('should set the metadata receiving node', () => {
|
||||||
const g = new Graph();
|
const g = new Graph();
|
||||||
|
@ -372,6 +372,21 @@ export class Graph {
|
|||||||
return metadataNode;
|
return metadataNode;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Adds an edge from a node to a metadata field. Use this when the metadata value is dynamic depending on a node.
|
||||||
|
* @param fromNode The node to add an edge from
|
||||||
|
* @param fromField The field of the node to add an edge from
|
||||||
|
* @param metadataField The metadata field to add an edge to (will overwrite hard-coded metadata)
|
||||||
|
* @returns
|
||||||
|
*/
|
||||||
|
addEdgeToMetadata<TFrom extends AnyInvocation>(
|
||||||
|
fromNode: TFrom,
|
||||||
|
fromField: OutputFields<TFrom>,
|
||||||
|
metadataField: string
|
||||||
|
): Edge {
|
||||||
|
// @ts-expect-error `Graph` excludes `core_metadata` nodes due to its excessively wide typing
|
||||||
|
return this.addEdge(fromNode, fromField, this._getMetadataNode(), metadataField);
|
||||||
|
}
|
||||||
/**
|
/**
|
||||||
* Set the node that should receive metadata. All other edges from the metadata node are deleted.
|
* Set the node that should receive metadata. All other edges from the metadata node are deleted.
|
||||||
* @param node The node to set as the receiving node
|
* @param node The node to set as the receiving node
|
||||||
|
Loading…
x
Reference in New Issue
Block a user