( args: Record<string, any>, schema?: Record<string, any>, )
| 32 | * any values that should be strings. |
| 33 | */ |
| 34 | export function coerceArgsToSchema( |
| 35 | args: Record<string, any>, |
| 36 | schema?: Record<string, any>, |
| 37 | ): Record<string, any> { |
| 38 | if (!schema?.properties) { |
| 39 | return args; |
| 40 | } |
| 41 | |
| 42 | const coerced = { ...args }; |
| 43 | for (const [key, value] of Object.entries(coerced)) { |
| 44 | const propSchema = schema.properties[key]; |
| 45 | if (!propSchema) { |
| 46 | continue; |
| 47 | } |
| 48 | |
| 49 | if ( |
| 50 | propSchema.type === "string" && |
| 51 | typeof value === "object" && |
| 52 | value !== null |
| 53 | ) { |
| 54 | try { |
| 55 | coerced[key] = JSON.stringify(value); |
| 56 | } catch { |
| 57 | // leave as-is if stringify fails |
| 58 | } |
| 59 | } |
| 60 | } |
| 61 | |
| 62 | return coerced; |
| 63 | } |
| 64 | |
| 65 | export function getStringArg( |
| 66 | args: any, |
no outgoing calls
no test coverage detected