mirror of
https://github.com/invoke-ai/InvokeAI
synced 2024-08-30 20:32:17 +00:00
feat(ui): make Graph class's getMetadataNode public
This commit is contained in:
parent
c5172d4c5a
commit
0c26d28278
@ -545,14 +545,14 @@ describe('Graph', () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
describe('metadata utils', () => {
|
describe('metadata utils', () => {
|
||||||
describe('_getMetadataNode', () => {
|
describe('getMetadataNode', () => {
|
||||||
it("should get the metadata node, creating it if it doesn't exist", () => {
|
it("should get the metadata node, creating it if it doesn't exist", () => {
|
||||||
const g = new Graph();
|
const g = new Graph();
|
||||||
const metadata = g._getMetadataNode();
|
const metadata = g.getMetadataNode();
|
||||||
expect(metadata.id).toBe('core_metadata');
|
expect(metadata.id).toBe('core_metadata');
|
||||||
expect(metadata.type).toBe('core_metadata');
|
expect(metadata.type).toBe('core_metadata');
|
||||||
g.upsertMetadata({ test: 'test' });
|
g.upsertMetadata({ test: 'test' });
|
||||||
const metadata2 = g._getMetadataNode();
|
const metadata2 = g.getMetadataNode();
|
||||||
expect(metadata2).toHaveProperty('test');
|
expect(metadata2).toHaveProperty('test');
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
@ -561,14 +561,14 @@ describe('Graph', () => {
|
|||||||
it('should add metadata to the metadata node', () => {
|
it('should add metadata to the metadata node', () => {
|
||||||
const g = new Graph();
|
const g = new Graph();
|
||||||
g.upsertMetadata({ test: 'test' });
|
g.upsertMetadata({ test: 'test' });
|
||||||
const metadata = g._getMetadataNode();
|
const metadata = g.getMetadataNode();
|
||||||
expect(metadata).toHaveProperty('test');
|
expect(metadata).toHaveProperty('test');
|
||||||
});
|
});
|
||||||
it('should update metadata on the metadata node', () => {
|
it('should update metadata on the metadata node', () => {
|
||||||
const g = new Graph();
|
const g = new Graph();
|
||||||
g.upsertMetadata({ test: 'test' });
|
g.upsertMetadata({ test: 'test' });
|
||||||
g.upsertMetadata({ test: 'test2' });
|
g.upsertMetadata({ test: 'test2' });
|
||||||
const metadata = g._getMetadataNode();
|
const metadata = g.getMetadataNode();
|
||||||
expect(metadata.test).toBe('test2');
|
expect(metadata.test).toBe('test2');
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
@ -578,14 +578,14 @@ describe('Graph', () => {
|
|||||||
const g = new Graph();
|
const g = new Graph();
|
||||||
g.upsertMetadata({ test: 'test', test2: 'test2' });
|
g.upsertMetadata({ test: 'test', test2: 'test2' });
|
||||||
g.removeMetadata(['test']);
|
g.removeMetadata(['test']);
|
||||||
const metadata = g._getMetadataNode();
|
const metadata = g.getMetadataNode();
|
||||||
expect(metadata).not.toHaveProperty('test');
|
expect(metadata).not.toHaveProperty('test');
|
||||||
});
|
});
|
||||||
it('should remove multiple metadata from the metadata node', () => {
|
it('should remove multiple metadata from the metadata node', () => {
|
||||||
const g = new Graph();
|
const g = new Graph();
|
||||||
g.upsertMetadata({ test: 'test', test2: 'test2' });
|
g.upsertMetadata({ test: 'test', test2: 'test2' });
|
||||||
g.removeMetadata(['test', 'test2']);
|
g.removeMetadata(['test', 'test2']);
|
||||||
const metadata = g._getMetadataNode();
|
const metadata = g.getMetadataNode();
|
||||||
expect(metadata).not.toHaveProperty('test');
|
expect(metadata).not.toHaveProperty('test');
|
||||||
expect(metadata).not.toHaveProperty('test2');
|
expect(metadata).not.toHaveProperty('test2');
|
||||||
});
|
});
|
||||||
@ -615,7 +615,7 @@ describe('Graph', () => {
|
|||||||
});
|
});
|
||||||
g.upsertMetadata({ test: 'test' });
|
g.upsertMetadata({ test: 'test' });
|
||||||
g.setMetadataReceivingNode(n1);
|
g.setMetadataReceivingNode(n1);
|
||||||
const metadata = g._getMetadataNode();
|
const metadata = g.getMetadataNode();
|
||||||
expect(g.getEdgesFrom(metadata as unknown as AnyInvocation).length).toBe(1);
|
expect(g.getEdgesFrom(metadata as unknown as AnyInvocation).length).toBe(1);
|
||||||
expect(g.getEdgesTo(n1).length).toBe(1);
|
expect(g.getEdgesTo(n1).length).toBe(1);
|
||||||
});
|
});
|
||||||
|
@ -356,10 +356,10 @@ export class Graph {
|
|||||||
//#region Metadata
|
//#region Metadata
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* INTERNAL: Get the metadata node. If it does not exist, it is created.
|
* Get the metadata node. If it does not exist, it is created.
|
||||||
* @returns The metadata node.
|
* @returns The metadata node.
|
||||||
*/
|
*/
|
||||||
_getMetadataNode(): S['CoreMetadataInvocation'] {
|
getMetadataNode(): S['CoreMetadataInvocation'] {
|
||||||
try {
|
try {
|
||||||
const node = this.getNode(METADATA) as AnyInvocationIncMetadata;
|
const node = this.getNode(METADATA) as AnyInvocationIncMetadata;
|
||||||
assert(node.type === 'core_metadata');
|
assert(node.type === 'core_metadata');
|
||||||
@ -378,7 +378,7 @@ export class Graph {
|
|||||||
* @returns The metadata node.
|
* @returns The metadata node.
|
||||||
*/
|
*/
|
||||||
upsertMetadata(metadata: Partial<S['CoreMetadataInvocation']>): S['CoreMetadataInvocation'] {
|
upsertMetadata(metadata: Partial<S['CoreMetadataInvocation']>): S['CoreMetadataInvocation'] {
|
||||||
const node = this._getMetadataNode();
|
const node = this.getMetadataNode();
|
||||||
Object.assign(node, metadata);
|
Object.assign(node, metadata);
|
||||||
return node;
|
return node;
|
||||||
}
|
}
|
||||||
@ -389,7 +389,7 @@ export class Graph {
|
|||||||
* @returns The metadata node
|
* @returns The metadata node
|
||||||
*/
|
*/
|
||||||
removeMetadata(keys: string[]): S['CoreMetadataInvocation'] {
|
removeMetadata(keys: string[]): S['CoreMetadataInvocation'] {
|
||||||
const metadataNode = this._getMetadataNode();
|
const metadataNode = this.getMetadataNode();
|
||||||
for (const k of keys) {
|
for (const k of keys) {
|
||||||
unset(metadataNode, k);
|
unset(metadataNode, k);
|
||||||
}
|
}
|
||||||
@ -417,9 +417,9 @@ export class Graph {
|
|||||||
*/
|
*/
|
||||||
setMetadataReceivingNode(node: AnyInvocation): void {
|
setMetadataReceivingNode(node: AnyInvocation): void {
|
||||||
// @ts-expect-error `Graph` excludes `core_metadata` nodes due to its excessively wide typing
|
// @ts-expect-error `Graph` excludes `core_metadata` nodes due to its excessively wide typing
|
||||||
this.deleteEdgesFrom(this._getMetadataNode());
|
this.deleteEdgesFrom(this.getMetadataNode());
|
||||||
// @ts-expect-error `Graph` excludes `core_metadata` nodes due to its excessively wide typing
|
// @ts-expect-error `Graph` excludes `core_metadata` nodes due to its excessively wide typing
|
||||||
this.addEdge(this._getMetadataNode(), 'metadata', node, 'metadata');
|
this.addEdge(this.getMetadataNode(), 'metadata', node, 'metadata');
|
||||||
}
|
}
|
||||||
//#endregion
|
//#endregion
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user