(options: GetGeneratorOptions)
| 82 | * In other words, this is basically a generator factory function. |
| 83 | */ |
| 84 | export 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 |
no test coverage detected