MCPcopy Index your code
hub / github.com/simstudioai/sim / parseYAMLBuffer

Function parseYAMLBuffer

apps/sim/lib/file-parsers/yaml-parser.ts:40–62  ·  view source on GitHub ↗
(buffer: Buffer)

Source from the content-addressed store, hash-verified

38 * Parse YAML from buffer
39 */
40export async function parseYAMLBuffer(buffer: Buffer): Promise<FileParseResult> {
41 const content = buffer.toString('utf-8')
42
43 try {
44 const yamlData = yaml.load(content)
45 const jsonContent = JSON.stringify(yamlData, null, 2)
46
47 const metadata = {
48 type: 'yaml',
49 isArray: Array.isArray(yamlData),
50 keys: Array.isArray(yamlData) ? [] : Object.keys(yamlData || {}),
51 itemCount: Array.isArray(yamlData) ? yamlData.length : undefined,
52 depth: getYamlDepth(yamlData),
53 }
54
55 return {
56 content: jsonContent,
57 metadata,
58 }
59 } catch (error) {
60 throw new Error(`Invalid YAML: ${getErrorMessage(error, 'Unknown error')}`)
61 }
62}
63
64/**
65 * Calculate the depth of a YAML/JSON object

Callers

nothing calls this directly

Calls 4

getErrorMessageFunction · 0.90
getYamlDepthFunction · 0.85
loadMethod · 0.80
toStringMethod · 0.45

Tested by

no test coverage detected