import { parseCurlCommand, extractJsonCandidates } from '../src/utils/parseCurl.ts'; import { parseJsonTextToParameterFlatList, defaultResolveParameterType } from '../src/utils/jsonParameterTree.ts'; import { readFileSync } from 'fs'; const curl = readFileSync(new URL('./booking.curl', import.meta.url), 'utf8'); const parsed = parseCurlCommand(curl); console.log('body len', parsed.body?.length, 'json ok', (() => { try { JSON.parse(parsed.body); return true;} catch(e) { return e.message; }})()); console.log('candidates', extractJsonCandidates(parsed).length); try { const flat = parseJsonTextToParameterFlatList(parsed.body, { resolveParameterType: defaultResolveParameterType, }); console.log('flat nodes', flat.length, 'roots', flat.filter((n) => n.pId === 0).map((n) => n.name)); const root = flat.find((n) => n.name === 'bookingOrderDTO'); const children = flat.filter((n) => n.pId === root?.id); console.log('bookingOrderDTO id', root?.id, 'children', children.map((n) => n.name)); console.log('all', flat.map((n) => ({ name: n.name, id: n.id, pId: n.pId }))); } catch (e) { console.log('parse flat FAIL', e.message); }