MCPcopy
hub / github.com/prisma/prisma / tryToReadDataFromSchema

Function tryToReadDataFromSchema

packages/cli/src/utils/checkpoint.ts:120–161  ·  view source on GitHub ↗
(schemaPath: SchemaPathInput)

Source from the content-addressed store, hash-verified

118 * if an error occurs it will silently fail and return undefined values
119 */
120export async function tryToReadDataFromSchema(schemaPath: SchemaPathInput) {
121 let schemaProvider: string | undefined
122 let schemaPreviewFeatures: string[] | undefined
123 let schemaGeneratorsProviders: string[] | undefined
124
125 try {
126 const schemaContext = await loadSchemaContext({ schemaPath, printLoadMessage: false })
127
128 if (schemaContext.datasources.length > 0) {
129 schemaProvider = schemaContext.datasources[0].provider
130 }
131
132 // Example 'prisma-client-js'
133 schemaGeneratorsProviders = schemaContext.generators
134 // Check that value is defined
135 .filter((generator) => generator && generator.provider)
136 .map((generator) => parseEnvValue(generator.provider))
137
138 const clientGeneratorProviders: string[] = [BuiltInProvider.PrismaClientTs, BuiltInProvider.PrismaClientJs]
139 const previewFeatures = schemaContext.generators
140 .filter((generator) => {
141 const provider = generator?.provider ? parseEnvValue(generator.provider) : undefined
142 return provider !== undefined && clientGeneratorProviders.includes(provider)
143 })
144 .flatMap((generator) => generator.previewFeatures ?? [])
145
146 if (previewFeatures.length > 0) {
147 schemaPreviewFeatures = Array.from(new Set(previewFeatures))
148 }
149 } catch (e) {
150 debug(
151 'Error from tryToReadDataFromSchema() while processing the schema. This is not a fatal error. It will continue without the processed data.',
152 )
153 debug(e)
154 }
155
156 return {
157 schemaProvider,
158 schemaPreviewFeatures,
159 schemaGeneratorsProviders,
160 }
161}
162
163/*
164 * String options of the CLI

Callers 2

checkpoint.test.tsFile · 0.90
runCheckpointClientCheckFunction · 0.85

Calls 5

loadSchemaContextFunction · 0.90
parseEnvValueFunction · 0.90
debugFunction · 0.85
includesMethod · 0.80
fromMethod · 0.80

Tested by

no test coverage detected