mirror of
https://github.com/Abdulazizzn/n8n-enterprise-unlocked.git
synced 2025-12-18 02:21:13 +00:00
feat(core): Implement partial execution for all tool nodes (#15168)
This commit is contained in:
@@ -0,0 +1,39 @@
|
||||
import { z } from 'zod';
|
||||
|
||||
export const convertValueBySchema = (value: unknown, schema: any): unknown => {
|
||||
if (!schema || !value) return value;
|
||||
|
||||
if (typeof value === 'string') {
|
||||
if (schema instanceof z.ZodNumber) {
|
||||
return Number(value);
|
||||
} else if (schema instanceof z.ZodBoolean) {
|
||||
return value.toLowerCase() === 'true';
|
||||
} else if (schema instanceof z.ZodObject) {
|
||||
try {
|
||||
const parsed = JSON.parse(value);
|
||||
return convertValueBySchema(parsed, schema);
|
||||
} catch {
|
||||
return value;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (schema instanceof z.ZodObject && typeof value === 'object' && value !== null) {
|
||||
const result: any = {};
|
||||
for (const [key, val] of Object.entries(value)) {
|
||||
const fieldSchema = schema.shape[key];
|
||||
if (fieldSchema) {
|
||||
result[key] = convertValueBySchema(val, fieldSchema);
|
||||
} else {
|
||||
result[key] = val;
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
return value;
|
||||
};
|
||||
|
||||
export const convertObjectBySchema = (obj: any, schema: any): any => {
|
||||
return convertValueBySchema(obj, schema);
|
||||
};
|
||||
Reference in New Issue
Block a user