mirror of
https://github.com/invoke-ai/InvokeAI
synced 2024-08-30 20:32:17 +00:00
fix(ui): workflow migration field type
At some point, I made a mistake and imported the wrong types to some files for the old v1 and v2 workflow schema migration data. The relevant zod schemas and inferred types have been restored. This change doesn't alter runtime behaviour. Only type annotations.
This commit is contained in:
parent
8062a47d16
commit
9e55ef3d4b
@ -1,4 +1,4 @@
|
||||
import type { FieldType, StatefulFieldType } from 'features/nodes/types/field';
|
||||
import type { StatefulFieldType, StatelessFieldType } from 'features/nodes/types/v2/field';
|
||||
|
||||
import type { FieldTypeV1 } from './workflowV1';
|
||||
|
||||
@ -165,7 +165,7 @@ const FIELD_TYPE_V1_TO_STATEFUL_FIELD_TYPE_V2: {
|
||||
* Thus, this object was manually edited to ensure it is correct.
|
||||
*/
|
||||
const FIELD_TYPE_V1_TO_STATELESS_FIELD_TYPE_V2: {
|
||||
[key in FieldTypeV1]?: FieldType;
|
||||
[key in FieldTypeV1]?: StatelessFieldType;
|
||||
} = {
|
||||
Any: { name: 'AnyField', isCollection: false, isCollectionOrScalar: false },
|
||||
ClipField: {
|
||||
|
@ -316,6 +316,7 @@ const zSchedulerFieldOutputInstance = zFieldOutputInstanceBase.extend({
|
||||
const zStatelessFieldType = zFieldTypeBase.extend({
|
||||
name: z.string().min(1), // stateless --> we accept the field's name as the type
|
||||
});
|
||||
export type StatelessFieldType = z.infer<typeof zStatelessFieldType>;
|
||||
const zStatelessFieldValue = z.undefined().catch(undefined); // stateless --> no value, but making this z.never() introduces a lot of extra TS fanagling
|
||||
const zStatelessFieldInputInstance = zFieldInputInstanceBase.extend({
|
||||
type: zStatelessFieldType,
|
||||
@ -327,6 +328,27 @@ const zStatelessFieldOutputInstance = zFieldOutputInstanceBase.extend({
|
||||
|
||||
// #endregion
|
||||
|
||||
const zStatefulFieldType = z.union([
|
||||
zIntegerFieldType,
|
||||
zFloatFieldType,
|
||||
zStringFieldType,
|
||||
zBooleanFieldType,
|
||||
zEnumFieldType,
|
||||
zImageFieldType,
|
||||
zBoardFieldType,
|
||||
zMainModelFieldType,
|
||||
zSDXLMainModelFieldType,
|
||||
zSDXLRefinerModelFieldType,
|
||||
zVAEModelFieldType,
|
||||
zLoRAModelFieldType,
|
||||
zControlNetModelFieldType,
|
||||
zIPAdapterModelFieldType,
|
||||
zT2IAdapterModelFieldType,
|
||||
zColorFieldType,
|
||||
zSchedulerFieldType,
|
||||
]);
|
||||
export type StatefulFieldType = z.infer<typeof zStatefulFieldType>;
|
||||
|
||||
/**
|
||||
* Here we define the main field unions:
|
||||
* - FieldType
|
||||
|
@ -1,12 +1,12 @@
|
||||
import { deepClone } from 'common/util/deepClone';
|
||||
import { $templates } from 'features/nodes/store/nodesSlice';
|
||||
import { WorkflowMigrationError, WorkflowVersionError } from 'features/nodes/types/error';
|
||||
import type { FieldType } from 'features/nodes/types/field';
|
||||
import type { InvocationNodeData } from 'features/nodes/types/invocation';
|
||||
import { zSemVer } from 'features/nodes/types/semver';
|
||||
import { FIELD_TYPE_V1_TO_FIELD_TYPE_V2_MAPPING } from 'features/nodes/types/v1/fieldTypeMap';
|
||||
import type { WorkflowV1 } from 'features/nodes/types/v1/workflowV1';
|
||||
import { zWorkflowV1 } from 'features/nodes/types/v1/workflowV1';
|
||||
import type { StatelessFieldType } from 'features/nodes/types/v2/field';
|
||||
import type { WorkflowV2 } from 'features/nodes/types/v2/workflow';
|
||||
import { zWorkflowV2 } from 'features/nodes/types/v2/workflow';
|
||||
import type { WorkflowV3 } from 'features/nodes/types/workflow';
|
||||
@ -43,14 +43,14 @@ const migrateV1toV2 = (workflowToMigrate: WorkflowV1): WorkflowV2 => {
|
||||
if (!newFieldType) {
|
||||
throw new WorkflowMigrationError(t('nodes.unknownFieldType', { type: input.type }));
|
||||
}
|
||||
(input.type as unknown as FieldType) = newFieldType;
|
||||
(input.type as unknown as StatelessFieldType) = newFieldType;
|
||||
});
|
||||
forEach(node.data.outputs, (output) => {
|
||||
const newFieldType = FIELD_TYPE_V1_TO_FIELD_TYPE_V2_MAPPING[output.type];
|
||||
if (!newFieldType) {
|
||||
throw new WorkflowMigrationError(t('nodes.unknownFieldType', { type: output.type }));
|
||||
}
|
||||
(output.type as unknown as FieldType) = newFieldType;
|
||||
(output.type as unknown as StatelessFieldType) = newFieldType;
|
||||
});
|
||||
// Add node pack
|
||||
const invocationTemplate = templates[node.data.type];
|
||||
|
Loading…
Reference in New Issue
Block a user