MCPcopy
hub / github.com/prisma/prisma / getConfig

Function getConfig

packages/internals/src/engine-commands/getConfig.ts:71–167  ·  view source on GitHub ↗
(options: GetConfigOptions)

Source from the content-addressed store, hash-verified

69 * Wasm'd version of `getConfig`.
70 */
71export async function getConfig(options: GetConfigOptions): Promise<ConfigMetaFormat> {
72 const debugErrorType = createDebugErrorType(debug, 'getConfigWasm')
73 debug(`Using getConfig Wasm`)
74
75 const configEither = pipe(
76 E.tryCatch(
77 () => {
78 if (process.env.FORCE_PANIC_GET_CONFIG) {
79 debug('Triggering a Rust panic...')
80 prismaSchemaWasm.debug_panic()
81 }
82
83 const params = JSON.stringify({ prismaSchema: options.datamodel })
84
85 return prismaSchemaWasm.get_config(params)
86 },
87 (e) => ({
88 type: 'wasm-error' as const,
89 reason: '(get-config wasm)',
90 error: e as Error | WasmPanic,
91 }),
92 ),
93 E.map((result) => ({ result })),
94 E.chainW(({ result }) =>
95 // NOTE: this should never fail, as we expect returned values to be valid JSON-serializable strings
96 E.tryCatch(
97 () => JSON.parse(result) as GetConfigResponse,
98 (e) => ({
99 type: 'parse-json' as const,
100 reason: 'Unable to parse JSON',
101 error: e as Error,
102 }),
103 ),
104 ),
105 E.chainW((response) => {
106 if (response.errors.length > 0) {
107 return E.left({
108 type: 'validation-error' as const,
109 reason: '(get-config wasm)',
110 error: response.errors,
111 })
112 }
113 return E.right(response.config)
114 }),
115 )
116
117 if (E.isRight(configEither)) {
118 debug('config data retrieved without errors in getConfig Wasm')
119 const { right: data } = configEither
120
121 for (const generator of data.generators) {
122 await resolveBinaryTargets(generator)
123 }
124
125 return Promise.resolve(data)
126 }
127
128 /**

Callers 6

getTestClientFunction · 0.90
generateInFolderFunction · 0.90
processSchemaResultFunction · 0.90
parseMethod · 0.90
parseMethod · 0.90
getConfig.test.tsFile · 0.85

Calls 11

createDebugErrorTypeFunction · 0.90
isWasmPanicFunction · 0.90
getWasmErrorFunction · 0.90
parseQueryEngineErrorFunction · 0.90
debugFunction · 0.85
resolveBinaryTargetsFunction · 0.85
formatErrorsFunction · 0.85
parseMethod · 0.65
withMethod · 0.65
pipeFunction · 0.50

Tested by

no test coverage detected