MCPcopy
hub / github.com/prisma/prisma / getEnginesInfo

Function getEnginesInfo

packages/internals/src/engine-commands/getEnginesInfo.ts:31–70  ·  view source on GitHub ↗
(enginesInfo: EngineInfo)

Source from the content-addressed store, hash-verified

29export type BinaryInfoMatrix = BinaryMatrix<EngineInfo>
30
31export function getEnginesInfo(enginesInfo: EngineInfo): readonly [string, Error[]] {
32 // if the engine is not found, or the version cannot be retrieved, keep track of the resulting errors.
33 const errors = [] as Error[]
34
35 // compute message displayed when an engine is resolved via env vars
36 const resolved = match(enginesInfo)
37 .with({ fromEnvVar: P.when(O.isSome) }, (_engineInfo) => {
38 return `, resolved by ${_engineInfo.fromEnvVar.value}`
39 })
40 .otherwise(() => '')
41
42 // compute absolute path of an engine, returning an error message and populating
43 // `errors` if it fails
44 const absolutePath = match(enginesInfo)
45 .with({ path: P.when(E.isRight) }, (_engineInfo) => {
46 return _engineInfo.path.right
47 })
48 .with({ path: P.when(E.isLeft) }, (_engineInfo) => {
49 // the binary/library can't be found
50 errors.push(_engineInfo.path.left)
51 return 'E_CANNOT_RESOLVE_PATH' as const
52 })
53 .exhaustive()
54
55 // compute version (git hash) of an engine, returning an error message and populating
56 // `errors` if it fails
57 const version = match(enginesInfo)
58 .with({ version: P.when(E.isRight) }, (_engineInfo) => {
59 return _engineInfo.version.right
60 })
61 .with({ version: P.when(E.isLeft) }, (_engineInfo) => {
62 // extracting the version failed
63 errors.push(_engineInfo.version.left)
64 return 'E_CANNOT_RESOLVE_VERSION' as const
65 })
66 .exhaustive()
67
68 const versionMessage = `${version} (at ${path.relative(process.cwd(), absolutePath)}${resolved})`
69 return [versionMessage, errors] as const
70}
71
72export async function resolveEngine(binaryName: BinaryType): Promise<EngineInfo> {
73 const pathFromEnvOption = O.fromNullable(getBinaryEnvVarPath(binaryName))

Callers 1

parseMethod · 0.90

Calls 2

withMethod · 0.65
pushMethod · 0.45

Tested by

no test coverage detected