mirror of
https://github.com/Abdulazizzn/n8n-enterprise-unlocked.git
synced 2025-12-17 01:56:46 +00:00
refactor: Fix type issues for parameter input components (#9449)
This commit is contained in:
@@ -1118,6 +1118,9 @@ export type NodeParameterValueType =
|
||||
| NodeParameterValue
|
||||
| INodeParameters
|
||||
| INodeParameterResourceLocator
|
||||
| ResourceMapperValue
|
||||
| FilterValue
|
||||
| AssignmentCollectionValue
|
||||
| NodeParameterValue[]
|
||||
| INodeParameters[]
|
||||
| INodeParameterResourceLocator[]
|
||||
@@ -2374,25 +2377,32 @@ export interface ResourceMapperField {
|
||||
readOnly?: boolean;
|
||||
}
|
||||
|
||||
export type FieldType =
|
||||
| 'string'
|
||||
| 'string-alphanumeric'
|
||||
| 'number'
|
||||
| 'dateTime'
|
||||
| 'boolean'
|
||||
| 'time'
|
||||
| 'array'
|
||||
| 'object'
|
||||
| 'options'
|
||||
| 'url'
|
||||
| 'jwt';
|
||||
|
||||
export type ValidationResult = {
|
||||
valid: boolean;
|
||||
errorMessage?: string;
|
||||
newValue?: string | number | boolean | object | null | undefined;
|
||||
export type FieldTypeMap = {
|
||||
// eslint-disable-next-line id-denylist
|
||||
boolean: boolean;
|
||||
// eslint-disable-next-line id-denylist
|
||||
number: number;
|
||||
// eslint-disable-next-line id-denylist
|
||||
string: string;
|
||||
'string-alphanumeric': string;
|
||||
dateTime: string;
|
||||
time: string;
|
||||
array: unknown[];
|
||||
object: object;
|
||||
options: any;
|
||||
url: string;
|
||||
jwt: string;
|
||||
};
|
||||
|
||||
export type FieldType = keyof FieldTypeMap;
|
||||
|
||||
export type ValidationResult<T extends FieldType = FieldType> =
|
||||
| { valid: false; errorMessage: string }
|
||||
| {
|
||||
valid: true;
|
||||
newValue?: FieldTypeMap[T];
|
||||
};
|
||||
|
||||
export type ResourceMapperValue = {
|
||||
mappingMode: string;
|
||||
value: { [key: string]: string | number | boolean | null } | null;
|
||||
@@ -2418,9 +2428,9 @@ export interface FilterOperatorValue {
|
||||
|
||||
export type FilterConditionValue = {
|
||||
id: string;
|
||||
leftValue: unknown;
|
||||
leftValue: NodeParameterValue;
|
||||
operator: FilterOperatorValue;
|
||||
rightValue: unknown;
|
||||
rightValue: NodeParameterValue;
|
||||
};
|
||||
|
||||
export type FilterOptionsValue = {
|
||||
|
||||
@@ -111,7 +111,13 @@ function parseFilterConditionValues(
|
||||
};
|
||||
}
|
||||
|
||||
return { ok: true, result: { left: parsedLeftValue.newValue, right: parsedRightValue.newValue } };
|
||||
return {
|
||||
ok: true,
|
||||
result: {
|
||||
left: parsedLeftValue.valid ? parsedLeftValue.newValue : undefined,
|
||||
right: parsedRightValue.valid ? parsedRightValue.newValue : undefined,
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
function parseRegexPattern(pattern: string): RegExp {
|
||||
|
||||
@@ -177,14 +177,21 @@ type ValidateFieldTypeOptions = Partial<{
|
||||
strict: boolean;
|
||||
parseStrings: boolean;
|
||||
}>;
|
||||
|
||||
// Validates field against the schema and tries to parse it to the correct type
|
||||
export function validateFieldType<K extends FieldType>(
|
||||
fieldName: string,
|
||||
value: unknown,
|
||||
type: K,
|
||||
options?: ValidateFieldTypeOptions,
|
||||
): ValidationResult<K>;
|
||||
// eslint-disable-next-line complexity
|
||||
export const validateFieldType = (
|
||||
export function validateFieldType(
|
||||
fieldName: string,
|
||||
value: unknown,
|
||||
type: FieldType,
|
||||
options: ValidateFieldTypeOptions = {},
|
||||
): ValidationResult => {
|
||||
): ValidationResult {
|
||||
if (value === null || value === undefined) return { valid: true };
|
||||
const strict = options.strict ?? false;
|
||||
const valueOptions = options.valueOptions ?? [];
|
||||
@@ -308,4 +315,4 @@ export const validateFieldType = (
|
||||
return { valid: true, newValue: value };
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user