MCPcopy
hub / github.com/prisma/prisma / resolveEngine

Function resolveEngine

packages/internals/src/engine-commands/getEnginesInfo.ts:72–112  ·  view source on GitHub ↗
(binaryName: BinaryType)

Source from the content-addressed store, hash-verified

70}
71
72export async function resolveEngine(binaryName: BinaryType): Promise<EngineInfo> {
73 const pathFromEnvOption = O.fromNullable(getBinaryEnvVarPath(binaryName))
74
75 /**
76 * Read the binary path, preferably from the environment, or resolving the canonical path
77 * from the given `binaryName`.
78 */
79
80 const fromEnvVarOption: O.Option<string> = pipe(
81 pathFromEnvOption,
82 O.map((p) => p.fromEnvVar),
83 )
84
85 const enginePathEither: E.Either<Error, string> = await pipe(
86 pathFromEnvOption,
87 O.fold(
88 () => safeResolveBinary(binaryName),
89 (pathFromEnv) => TE.right(pathFromEnv.path),
90 ),
91 )()
92
93 /**
94 * Read the version from the engine, but only if the enginePath is valid.
95 */
96
97 const versionEither: E.Either<Error, string> = await pipe(
98 enginePathEither,
99 TE.fromEither,
100 TE.chain((enginePath) => {
101 return safeGetEngineVersion(enginePath, binaryName)
102 }),
103 )()
104
105 const engineInfo: EngineInfo = {
106 path: enginePathEither,
107 version: versionEither,
108 fromEnvVar: fromEnvVarOption,
109 }
110
111 return engineInfo
112}

Callers 1

parseMethod · 0.90

Calls 4

getBinaryEnvVarPathFunction · 0.90
safeResolveBinaryFunction · 0.90
safeGetEngineVersionFunction · 0.90
pipeFunction · 0.50

Tested by

no test coverage detected