| 23 | * This parser can handle incomplete JSON strings during streaming |
| 24 | */ |
| 25 | export class PartialJSONParser implements JSONParser { |
| 26 | /** |
| 27 | * Parse a potentially incomplete JSON string |
| 28 | * @param jsonString - The JSON string to parse (may be incomplete) |
| 29 | * @returns The parsed object, or undefined if parsing fails |
| 30 | */ |
| 31 | parse(jsonString: string): any { |
| 32 | if (!jsonString || jsonString.trim() === '') { |
| 33 | return undefined |
| 34 | } |
| 35 | |
| 36 | try { |
| 37 | return parsePartialJSONLib(jsonString) |
| 38 | } catch { |
| 39 | // If partial parsing fails, return undefined |
| 40 | // This is expected during early streaming when we have very little data |
| 41 | return undefined |
| 42 | } |
| 43 | } |
| 44 | } |
| 45 | |
| 46 | /** |
| 47 | * Default parser instance |
nothing calls this directly
no outgoing calls
no test coverage detected