prismadoc 1.0.31 → 1.0.32
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/main.js +29 -2
- package/package.json +1 -1
package/dist/main.js
CHANGED
|
@@ -25,6 +25,7 @@ export class DocGen {
|
|
|
25
25
|
async init() {
|
|
26
26
|
const prismaDataModel = await PrismaUtils.readPrismaFolderDatamodel(PRISMA_DIR);
|
|
27
27
|
const { datamodel } = await getDMMF({ datamodel: prismaDataModel });
|
|
28
|
+
console.log("starting2");
|
|
28
29
|
// Busca e processa schemas externos (precisa do schema principal para resolver tipos)
|
|
29
30
|
const externalSchemas = await PrismaUtils.fetchExternalSchemas(config.externalPrismaSchemas);
|
|
30
31
|
const mainModelNames = new Set(datamodel.models.map((m) => m.name));
|
|
@@ -44,10 +45,36 @@ export class DocGen {
|
|
|
44
45
|
});
|
|
45
46
|
this.build();
|
|
46
47
|
}
|
|
48
|
+
/**
|
|
49
|
+
* Tenta getDMMF e, se falhar por tipos não encontrados, remove os campos
|
|
50
|
+
* que referenciam esses tipos e retenta.
|
|
51
|
+
*/
|
|
52
|
+
async getDMMFSafe(schema) {
|
|
53
|
+
try {
|
|
54
|
+
return await getDMMF({ datamodel: schema });
|
|
55
|
+
}
|
|
56
|
+
catch (err) {
|
|
57
|
+
const message = err?.message ?? "";
|
|
58
|
+
const missingTypes = [...message.matchAll(/Type "(\w+)" is neither a built-in type/g)].map((m) => m[1]);
|
|
59
|
+
if (missingTypes.length === 0)
|
|
60
|
+
throw err;
|
|
61
|
+
const uniqueTypes = [...new Set(missingTypes)];
|
|
62
|
+
console.log(`⚠️ Removendo campos com tipos externos: ${uniqueTypes.join(", ")}`);
|
|
63
|
+
// Remove linhas que referenciam os tipos desconhecidos
|
|
64
|
+
const typePattern = uniqueTypes.join("|");
|
|
65
|
+
const re = new RegExp(`^\\s+\\w+\\s+(${typePattern})[\\s\\[\\]\\?].*$`, "gm");
|
|
66
|
+
const cleaned = schema.replaceAll(re, "");
|
|
67
|
+
return await getDMMF({ datamodel: cleaned });
|
|
68
|
+
}
|
|
69
|
+
}
|
|
47
70
|
async processExternalSchema(name, prismaSchema, mainPrismaDataModel, mainModelNames, mainEnumNames) {
|
|
71
|
+
// Remove blocos datasource/generator do schema externo para evitar duplicatas
|
|
72
|
+
const cleanedExternal = prismaSchema
|
|
73
|
+
.replaceAll(/datasource\s+\w+\s*\{[^}]*\}/g, "")
|
|
74
|
+
.replaceAll(/generator\s+\w+\s*\{[^}]*\}/g, "");
|
|
48
75
|
// Combina com o schema principal para que o Prisma resolva todos os tipos
|
|
49
|
-
const combined = mainPrismaDataModel + "\n" +
|
|
50
|
-
const { datamodel } = await
|
|
76
|
+
const combined = mainPrismaDataModel + "\n" + cleanedExternal;
|
|
77
|
+
const { datamodel } = await this.getDMMFSafe(combined);
|
|
51
78
|
const servicePrefix = Helper.toKebab(name);
|
|
52
79
|
const serviceIndexExports = [];
|
|
53
80
|
// Filtra apenas models e enums do schema externo (ignora os do principal)
|