MCPcopy
hub / github.com/prisma/prisma / handleResponse

Method handleResponse

packages/migrate/src/SchemaEngineCLI.ts:326–364  ·  view source on GitHub ↗
(response: any)

Source from the content-addressed store, hash-verified

324 }
325
326 private handleResponse(response: any): void {
327 let result
328 try {
329 result = JSON.parse(response)
330 } catch (e) {
331 console.error(`Could not parse Schema engine response: ${response.slice(0, 200)}. Error: ${e.message}`)
332 }
333
334 // See https://www.jsonrpc.org/specification for the expected shape of messages.
335 if (result) {
336 // It's a response
337 if (result.id && (result.result !== undefined || result.error !== undefined)) {
338 if (!this.listeners[result.id]) {
339 console.error(`Got result for unknown id ${result.id}`)
340 }
341 if (this.listeners[result.id]) {
342 this.listeners[result.id](result)
343 delete this.listeners[result.id]
344 }
345 } else if (result.method) {
346 // This is a request.
347 if (result.id !== undefined) {
348 if (result.method === 'print' && result.params?.content !== undefined) {
349 // Here we print the content from the Schema Engine to stdout directly
350 // (it is not returned to the caller)
351 process.stdout.write(result.params.content + '\n')
352
353 // Send an empty response back as ACK.
354 const response: RpcSuccessResponse<{}> = {
355 id: result.id,
356 jsonrpc: '2.0',
357 result: {},
358 }
359 this.child!.stdin!.write(JSON.stringify(response) + '\n')
360 }
361 }
362 }
363 }
364 }
365
366 private init(): Promise<void> {
367 if (!this.initPromise) {

Callers 1

internalInitMethod · 0.95

Calls 4

errorMethod · 0.80
parseMethod · 0.65
writeMethod · 0.65
sliceMethod · 0.45

Tested by

no test coverage detected