(block: BlockConfig)
| 408 | * Serialize a block schema for VFS components/blocks/{type}.json |
| 409 | */ |
| 410 | export function serializeBlockSchema(block: BlockConfig): string { |
| 411 | const hiddenIds = new Set(block.subBlocks.filter(isSubBlockHidden).map((sb) => sb.id)) |
| 412 | |
| 413 | const subBlocks = block.subBlocks |
| 414 | .filter((sb) => !hiddenIds.has(sb.id)) |
| 415 | .map((sb) => { |
| 416 | const serialized = serializeSubBlock(sb) |
| 417 | |
| 418 | if (sb.id === 'model' && sb.type === 'combobox' && typeof sb.options === 'function') { |
| 419 | serialized.options = getStaticModelOptionsForVFS() |
| 420 | serialized.dynamicProviders = DYNAMIC_PROVIDERS_NOTE |
| 421 | } |
| 422 | |
| 423 | return serialized |
| 424 | }) |
| 425 | |
| 426 | const inputs = |
| 427 | block.inputs && hiddenIds.size > 0 |
| 428 | ? Object.fromEntries(Object.entries(block.inputs).filter(([key]) => !hiddenIds.has(key))) |
| 429 | : block.inputs |
| 430 | |
| 431 | return JSON.stringify( |
| 432 | { |
| 433 | type: block.type, |
| 434 | name: block.name, |
| 435 | description: block.description, |
| 436 | category: block.category, |
| 437 | longDescription: block.longDescription || undefined, |
| 438 | bestPractices: block.bestPractices || undefined, |
| 439 | triggerAllowed: block.triggerAllowed || undefined, |
| 440 | singleInstance: block.singleInstance || undefined, |
| 441 | tools: block.tools.access, |
| 442 | subBlocks, |
| 443 | inputs, |
| 444 | outputs: Object.fromEntries( |
| 445 | Object.entries(block.outputs) |
| 446 | .filter(([key, val]) => key !== 'visualization' && val != null) |
| 447 | .map(([key, val]) => [ |
| 448 | key, |
| 449 | typeof val === 'string' |
| 450 | ? { type: val } |
| 451 | : { type: val.type, description: (val as { description?: string }).description }, |
| 452 | ]) |
| 453 | ), |
| 454 | }, |
| 455 | null, |
| 456 | 2 |
| 457 | ) |
| 458 | } |
| 459 | |
| 460 | /** |
| 461 | * Serialize OAuth credentials for VFS environment/credentials.json. |
no test coverage detected