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

Function parseNdjsonObjects

apps/sim/lib/data-drains/destinations/utils.ts:100–124  ·  view source on GitHub ↗
(
  body: Buffer,
  options: ParseNdjsonObjectsOptions = {}
)

Source from the content-addressed store, hash-verified

98 * headers reference NDJSON payloads.
99 */
100export function parseNdjsonObjects(
101 body: Buffer,
102 options: ParseNdjsonObjectsOptions = {}
103): unknown[] {
104 const text = body.toString('utf8')
105 const rows: unknown[] = []
106 const lines = text.split(/\r?\n/)
107 for (let i = 0; i < lines.length; i++) {
108 const line = lines[i]
109 if (line.length === 0) continue
110 let parsed: unknown
111 try {
112 parsed = JSON.parse(line)
113 } catch (error) {
114 throw new Error(`NDJSON parse failed at line ${i + 1}: ${toError(error).message}`)
115 }
116 if (options.requireObject) {
117 if (typeof parsed !== 'object' || parsed === null || Array.isArray(parsed)) {
118 throw new Error(`NDJSON row at line ${i + 1} is not an object`)
119 }
120 }
121 rows.push(parsed)
122 }
123 return rows
124}
125
126export function refineServiceAccountJson(
127 value: { serviceAccountJson: string },

Callers 2

deliverFunction · 0.90
deliverFunction · 0.90

Calls 4

toErrorFunction · 0.90
parseMethod · 0.80
toStringMethod · 0.45
pushMethod · 0.45

Tested by

no test coverage detected