mirror of
https://github.com/invoke-ai/InvokeAI
synced 2024-08-30 20:32:17 +00:00
feat(ui): explicit field type cardinality
Replace the `isCollection` and `isCollectionOrScalar` flags with a single enum value `cardinality`. Valid values are `SINGLE`, `COLLECTION` and `SINGLE_OR_COLLECTION`. Why: - The two flags were mutually exclusive, but this wasn't enforce. You could create a field type that had both `isCollection` and `isCollectionOrScalar` set to true, whuch makes no sense. - There was no explicit declaration for scalar/single types. - Checking if a type had only a single flag was tedious. Thanks to a change a couple months back in which the workflows schema was revised, field types are internal implementation details. Changes to them are non-breaking.
This commit is contained in:
parent
8ebf2ddf15
commit
dba8c43ecb
@ -54,9 +54,10 @@ const zFieldOutputTemplateBase = zFieldTemplateBase.extend({
|
||||
fieldKind: z.literal('output'),
|
||||
});
|
||||
|
||||
const zCardinality = z.enum(['SINGLE', 'COLLECTION', 'SINGLE_OR_COLLECTION']);
|
||||
|
||||
const zFieldTypeBase = z.object({
|
||||
isCollection: z.boolean(),
|
||||
isCollectionOrScalar: z.boolean(),
|
||||
cardinality: zCardinality,
|
||||
});
|
||||
|
||||
export const zFieldIdentifier = z.object({
|
||||
@ -168,6 +169,11 @@ export const isStatefulFieldType = (fieldType: FieldType): fieldType is Stateful
|
||||
(statefulFieldTypeNames as string[]).includes(fieldType.name);
|
||||
const zFieldType = z.union([zStatefulFieldType, zStatelessFieldType]);
|
||||
export type FieldType = z.infer<typeof zFieldType>;
|
||||
|
||||
export const isSingle = (fieldType: FieldType): boolean => fieldType.cardinality === zCardinality.enum.SINGLE;
|
||||
export const isCollection = (fieldType: FieldType): boolean => fieldType.cardinality === zCardinality.enum.COLLECTION;
|
||||
export const isSingleOrCollection = (fieldType: FieldType): boolean =>
|
||||
fieldType.cardinality === zCardinality.enum.SINGLE_OR_COLLECTION;
|
||||
// #endregion
|
||||
|
||||
// #region IntegerField
|
||||
|
Loading…
Reference in New Issue
Block a user