MCPcopy
hub / github.com/prisma/prisma / getGenerators

Function getGenerators

packages/internals/src/get-generators/getGenerators.ts:84–308  ·  view source on GitHub ↗
(options: GetGeneratorOptions)

Source from the content-addressed store, hash-verified

82 * In other words, this is basically a generator factory function.
83 */
84export async function getGenerators(options: GetGeneratorOptions): Promise<Generator[]> {
85 // A hack for backward compatibility with Prisma Studio. Remove in Prisma 7.
86 if (options.registry === undefined && options.providerAliases !== undefined) {
87 options.registry = Object.fromEntries(
88 Object.entries(options.providerAliases).map(([name, definition]) => [
89 name,
90 {
91 type: 'rpc',
92 generatorPath: definition.generatorPath,
93 isNode: definition.isNode,
94 } satisfies GeneratorRegistryEntry,
95 ]),
96 )
97 }
98
99 const {
100 schemaPath,
101 registry,
102 version,
103 printDownloadProgress,
104 overrideGenerators,
105 skipDownload,
106 binaryPathsOverride,
107 generatorNames = [],
108 allowNoModels = true,
109 typedSql,
110 } = options
111 // Fallback logic for prisma studio which still only passes a schema path
112 const schemaContext =
113 !options.schemaContext && schemaPath
114 ? await loadSchemaContext({ schemaPath: { cliProvidedPath: schemaPath } })
115 : options.schemaContext
116
117 if (!schemaContext) {
118 throw new Error(`no schema provided for getGenerators`)
119 }
120
121 if (!schemaContext.primaryDatasource) {
122 throw new Error(missingDatasource)
123 }
124
125 printConfigWarnings(schemaContext.warnings)
126
127 const dmmf = await getDMMF({ datamodel: schemaContext.schemaFiles })
128
129 if (dmmf.datamodel.models.length === 0 && !allowNoModels) {
130 // MongoDB needs extras for @id: @map("_id") @db.ObjectId
131 if (schemaContext.primaryDatasource.provider === 'mongodb') {
132 throw new Error(missingModelMessageMongoDB)
133 }
134
135 throw new Error(missingModelMessage)
136 }
137
138 const generatorConfigs = filterGenerators(overrideGenerators || schemaContext.generators, generatorNames)
139
140 await validateGenerators(generatorConfigs)
141

Callers 3

parseMethod · 0.90
getGeneratorFunction · 0.85

Calls 15

loadSchemaContextFunction · 0.90
printConfigWarningsFunction · 0.90
getDMMFFunction · 0.90
parseEnvValueFunction · 0.90
resolveOutputFunction · 0.90
mergeSchemasFunction · 0.90
getBinaryPathsByVersionFunction · 0.90
pickFunction · 0.90
filterGeneratorsFunction · 0.85
validateGeneratorsFunction · 0.85
skipIndexFunction · 0.85

Tested by

no test coverage detected