@pothos/plugin-prisma 3.37.0 → 3.38.0
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/CHANGELOG.md +6 -0
- package/esm/generator.js +84 -72
- package/esm/generator.js.map +1 -1
- package/generated.ts +67 -0
- package/lib/generator.js +82 -70
- package/lib/generator.js.map +1 -1
- package/package.json +21 -11
- package/src/generator.ts +215 -193
package/CHANGELOG.md
CHANGED
package/esm/generator.js
CHANGED
|
@@ -29,84 +29,96 @@ generatorHandler({
|
|
|
29
29
|
defaultOutput
|
|
30
30
|
}),
|
|
31
31
|
onGenerate: async (options) => {
|
|
32
|
+
var _options_generator_output;
|
|
32
33
|
checkTSVersion();
|
|
33
34
|
const config = options.generator.config;
|
|
34
35
|
var _config_clientOutput;
|
|
35
36
|
const prismaLocation = (_config_clientOutput = config.clientOutput) !== null && _config_clientOutput !== void 0 ? _config_clientOutput : options.otherGenerators.find((gen) => gen.provider.value === "prisma-client-js").output.value;
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
const possibleTypes = [
|
|
43
|
-
`${type}OrderByWithRelationInput`,
|
|
44
|
-
`${type}OrderByWithRelationAndSearchRelevanceInput`
|
|
45
|
-
];
|
|
46
|
-
const orderBy = (_options_dmmf_schema_inputObjectTypes_prisma = options.dmmf.schema.inputObjectTypes.prisma) === null || _options_dmmf_schema_inputObjectTypes_prisma === void 0 ? void 0 : _options_dmmf_schema_inputObjectTypes_prisma.find((inputType) => possibleTypes.includes(inputType.name));
|
|
47
|
-
if (!orderBy) {
|
|
48
|
-
return possibleTypes[0];
|
|
49
|
-
}
|
|
50
|
-
return orderBy.name;
|
|
37
|
+
var _options_generator_output_value;
|
|
38
|
+
const outputLocation = (_options_generator_output_value = (_options_generator_output = options.generator.output) === null || _options_generator_output === void 0 ? void 0 : _options_generator_output.value) !== null && _options_generator_output_value !== void 0 ? _options_generator_output_value : defaultOutput;
|
|
39
|
+
const prismaTypes = buildTypes(options.dmmf);
|
|
40
|
+
await generateOutput(options.dmmf, prismaTypes, prismaLocation, outputLocation);
|
|
41
|
+
if (outputLocation === defaultOutput) {
|
|
42
|
+
await generateOutput(options.dmmf, prismaTypes, prismaLocation.replace("../", "../../"), outputLocation.replace("/generated.ts", "/esm/generated.ts"));
|
|
51
43
|
}
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
});
|
|
77
|
-
const prismaTypes = ts.factory.createInterfaceDeclaration([], [
|
|
78
|
-
ts.factory.createModifier(SyntaxKind.ExportKeyword),
|
|
79
|
-
ts.factory.createModifier(SyntaxKind.DefaultKeyword)
|
|
80
|
-
], "PrismaTypes", [], [], modelTypes);
|
|
81
|
-
const printer = ts.createPrinter({});
|
|
82
|
-
const sourcefile = ts.createSourceFile(options.generator.output.value, "", ScriptTarget.ESNext, false, ScriptKind.TS);
|
|
83
|
-
const nodes = ts.factory.createNodeArray([
|
|
84
|
-
importStatement,
|
|
85
|
-
prismaTypes
|
|
86
|
-
]);
|
|
87
|
-
const result = printer.printList(ListFormat.SourceFileStatements, nodes, sourcefile);
|
|
88
|
-
await new Promise((resolve, reject) => {
|
|
89
|
-
mkdir(dirname(sourcefile.fileName), {
|
|
90
|
-
recursive: true
|
|
91
|
-
}, (err) => {
|
|
92
|
-
if (err) {
|
|
93
|
-
reject(err);
|
|
94
|
-
}
|
|
95
|
-
else {
|
|
96
|
-
resolve();
|
|
97
|
-
}
|
|
98
|
-
});
|
|
44
|
+
}
|
|
45
|
+
});
|
|
46
|
+
async function generateOutput(dmmf, prismaTypes, prismaLocation, outputLocation) {
|
|
47
|
+
const importStatement = ts.factory.createImportDeclaration([], [], ts.factory.createImportClause(true, undefined, ts.factory.createNamedImports([
|
|
48
|
+
ts.factory.createImportSpecifier(false, undefined, ts.factory.createIdentifier("Prisma")),
|
|
49
|
+
...dmmf.datamodel.models.map((model) => ts.factory.createImportSpecifier(false, undefined, ts.factory.createIdentifier(model.name)))
|
|
50
|
+
])), ts.factory.createStringLiteral(prismaLocation));
|
|
51
|
+
const printer = ts.createPrinter({});
|
|
52
|
+
const sourcefile = ts.createSourceFile(outputLocation, "", ScriptTarget.ESNext, false, ScriptKind.TS);
|
|
53
|
+
const nodes = ts.factory.createNodeArray([
|
|
54
|
+
importStatement,
|
|
55
|
+
prismaTypes
|
|
56
|
+
]);
|
|
57
|
+
const result = printer.printList(ListFormat.SourceFileStatements, nodes, sourcefile);
|
|
58
|
+
await new Promise((resolve, reject) => {
|
|
59
|
+
mkdir(dirname(sourcefile.fileName), {
|
|
60
|
+
recursive: true
|
|
61
|
+
}, (err) => {
|
|
62
|
+
if (err) {
|
|
63
|
+
reject(err);
|
|
64
|
+
}
|
|
65
|
+
else {
|
|
66
|
+
resolve();
|
|
67
|
+
}
|
|
99
68
|
});
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
}
|
|
69
|
+
});
|
|
70
|
+
return new Promise((resolve, reject) => {
|
|
71
|
+
writeFile(sourcefile.fileName, `/* eslint-disable */\n${result}`, (err) => {
|
|
72
|
+
if (err) {
|
|
73
|
+
reject(err);
|
|
74
|
+
}
|
|
75
|
+
else {
|
|
76
|
+
resolve();
|
|
77
|
+
}
|
|
109
78
|
});
|
|
79
|
+
});
|
|
80
|
+
}
|
|
81
|
+
function buildTypes(dmmf) {
|
|
82
|
+
function getOrderByTypeName(type) {
|
|
83
|
+
var _dmmf_schema_inputObjectTypes_prisma;
|
|
84
|
+
const possibleTypes = [
|
|
85
|
+
`${type}OrderByWithRelationInput`,
|
|
86
|
+
`${type}OrderByWithRelationAndSearchRelevanceInput`
|
|
87
|
+
];
|
|
88
|
+
const orderBy = (_dmmf_schema_inputObjectTypes_prisma = dmmf.schema.inputObjectTypes.prisma) === null || _dmmf_schema_inputObjectTypes_prisma === void 0 ? void 0 : _dmmf_schema_inputObjectTypes_prisma.find((inputType) => possibleTypes.includes(inputType.name));
|
|
89
|
+
if (!orderBy) {
|
|
90
|
+
return possibleTypes[0];
|
|
91
|
+
}
|
|
92
|
+
return orderBy.name;
|
|
110
93
|
}
|
|
111
|
-
|
|
94
|
+
const modelTypes = dmmf.datamodel.models.map((model) => {
|
|
95
|
+
const relations = model.fields.filter((field) => !!field.relationName);
|
|
96
|
+
const listRelations = model.fields.filter((field) => !!field.relationName && field.isList);
|
|
97
|
+
return ts.factory.createPropertySignature([], model.name, undefined, ts.factory.createTypeLiteralNode([
|
|
98
|
+
ts.factory.createPropertySignature([], "Name", undefined, ts.factory.createLiteralTypeNode(ts.factory.createStringLiteral(model.name))),
|
|
99
|
+
ts.factory.createPropertySignature([], "Shape", undefined, ts.factory.createTypeReferenceNode(model.name)),
|
|
100
|
+
ts.factory.createPropertySignature([], "Include", undefined, relations.length > 0 ? ts.factory.createTypeReferenceNode(`Prisma.${model.name}Include`) : ts.factory.createTypeReferenceNode("never")),
|
|
101
|
+
ts.factory.createPropertySignature([], "Select", undefined, ts.factory.createTypeReferenceNode(`Prisma.${model.name}Select`)),
|
|
102
|
+
ts.factory.createPropertySignature([], "OrderBy", undefined, ts.factory.createTypeReferenceNode(`Prisma.${getOrderByTypeName(model.name)}`)),
|
|
103
|
+
ts.factory.createPropertySignature([], "WhereUnique", undefined, ts.factory.createTypeReferenceNode(`Prisma.${model.name}WhereUniqueInput`)),
|
|
104
|
+
ts.factory.createPropertySignature([], "Where", undefined, ts.factory.createTypeReferenceNode(`Prisma.${model.name}WhereInput`)),
|
|
105
|
+
ts.factory.createPropertySignature([], "RelationName", undefined, relations.length > 0 ? ts.factory.createUnionTypeNode(relations.map((field) => ts.factory.createLiteralTypeNode(ts.factory.createStringLiteral(field.name)))) : ts.factory.createTypeReferenceNode("never")),
|
|
106
|
+
ts.factory.createPropertySignature([], "ListRelations", undefined, listRelations.length > 0 ? ts.factory.createUnionTypeNode(listRelations.map((field) => ts.factory.createLiteralTypeNode(ts.factory.createStringLiteral(field.name)))) : ts.factory.createTypeReferenceNode("never")),
|
|
107
|
+
ts.factory.createPropertySignature([], "Relations", undefined, ts.factory.createTypeLiteralNode(relations.map((field) => {
|
|
108
|
+
const typeName = field.type;
|
|
109
|
+
return ts.factory.createPropertySignature([], field.name, undefined, ts.factory.createTypeLiteralNode([
|
|
110
|
+
ts.factory.createPropertySignature([], "Shape", undefined, field.isList ? ts.factory.createArrayTypeNode(ts.factory.createTypeReferenceNode(typeName)) : field.isRequired ? ts.factory.createTypeReferenceNode(typeName) : ts.factory.createUnionTypeNode([
|
|
111
|
+
ts.factory.createTypeReferenceNode(typeName),
|
|
112
|
+
ts.factory.createLiteralTypeNode(ts.factory.createNull())
|
|
113
|
+
])),
|
|
114
|
+
ts.factory.createPropertySignature([], "Types", undefined, ts.factory.createIndexedAccessTypeNode(ts.factory.createTypeReferenceNode("PrismaTypes"), ts.factory.createLiteralTypeNode(ts.factory.createStringLiteral(typeName))))
|
|
115
|
+
]));
|
|
116
|
+
})))
|
|
117
|
+
]));
|
|
118
|
+
});
|
|
119
|
+
return ts.factory.createInterfaceDeclaration([], [
|
|
120
|
+
ts.factory.createModifier(SyntaxKind.ExportKeyword),
|
|
121
|
+
ts.factory.createModifier(SyntaxKind.DefaultKeyword)
|
|
122
|
+
], "PrismaTypes", [], [], modelTypes);
|
|
123
|
+
}
|
|
112
124
|
//# sourceMappingURL=generator.js.map
|
package/esm/generator.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/generator.ts"],"names":["mkdir","writeFile","dirname","resolve","resolvePath","ts","ListFormat","ScriptKind","ScriptTarget","SyntaxKind","version","generatorHandler","MIN_TS_VERSION","checkTSVersion","versionParts","split","i","part","Number","parseInt","Error","join","defaultOutput","__dirname","onManifest","prettyName","requiresGenerators","onGenerate","options","config","generator","prismaLocation","clientOutput","otherGenerators","find","gen","provider","value","output","importStatement","factory","createImportDeclaration","createImportClause","undefined","createNamedImports","createImportSpecifier","createIdentifier","
|
|
1
|
+
{"version":3,"sources":["../src/generator.ts"],"names":["mkdir","writeFile","dirname","resolve","resolvePath","ts","ListFormat","ScriptKind","ScriptTarget","SyntaxKind","version","generatorHandler","MIN_TS_VERSION","checkTSVersion","versionParts","split","i","part","Number","parseInt","Error","join","defaultOutput","__dirname","onManifest","prettyName","requiresGenerators","onGenerate","options","config","generator","prismaLocation","clientOutput","otherGenerators","find","gen","provider","value","output","outputLocation","prismaTypes","buildTypes","dmmf","generateOutput","replace","importStatement","factory","createImportDeclaration","createImportClause","undefined","createNamedImports","createImportSpecifier","createIdentifier","datamodel","models","map","model","name","createStringLiteral","printer","createPrinter","sourcefile","createSourceFile","ESNext","TS","nodes","createNodeArray","result","printList","SourceFileStatements","Promise","reject","fileName","recursive","err","getOrderByTypeName","type","possibleTypes","orderBy","schema","inputObjectTypes","prisma","inputType","includes","modelTypes","relations","fields","filter","field","relationName","listRelations","isList","createPropertySignature","createTypeLiteralNode","createLiteralTypeNode","createTypeReferenceNode","length","createUnionTypeNode","typeName","createArrayTypeNode","isRequired","createNull","createIndexedAccessTypeNode","createInterfaceDeclaration","createModifier","ExportKeyword","DefaultKeyword"],"mappings":"AAAA,wCAAwC,GACxC,0CAA0C,GAC1C,mCAAmC,GACnC,oCAAoC,GACpC,SAASA,KAAK,EAAEC,SAAS,QAAQ,KAAK;AACtC,SAASC,OAAO,EAAEC,WAAWC,WAAW,QAAQ,OAAO;AACvD,OAAOC,MAAMC,UAAU,EAAEC,UAAU,EAAEC,YAAY,EAAEC,UAAU,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AA2B,CACpCjG,GAAGyC,OAAO,CAACiD,uBAAuB,CAAC,gBACnC1F,GAAGyC,OAAO,CAACgD,qBAAqB,CAACzF,GAAGyC,OAAO,CAACY,mBAAmB,CAACwC;iBAGrE;YAEL;SAGL;IAEL;IAEA,OAAO7F,GAAGyC,OAAO,CAACyD,0BAA0B,CAC1C,EAAE,EACF;QACElG,GAAGyC,OAAO,CAAC0D,cAAc,CAAC/F,WAAWgG,aAAa;QAClDpG,GAAGyC,OAAO,CAAC0D,cAAc,CAAC/F,WAAWiG,cAAc;KACpD,EACD,eACA,EAAE,EACF,EAAE,EACFtB;AAEJ"}
|
package/generated.ts
ADDED
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
/* eslint-disable */
|
|
2
|
+
import type { Prisma, User, Post, Comment } from "/Users/michaelhayes/code/prismaday-talk/node_modules/@prisma/client";
|
|
3
|
+
export default interface PrismaTypes {
|
|
4
|
+
User: {
|
|
5
|
+
Name: "User";
|
|
6
|
+
Shape: User;
|
|
7
|
+
Include: Prisma.UserInclude;
|
|
8
|
+
Select: Prisma.UserSelect;
|
|
9
|
+
OrderBy: Prisma.UserOrderByWithRelationInput;
|
|
10
|
+
WhereUnique: Prisma.UserWhereUniqueInput;
|
|
11
|
+
Where: Prisma.UserWhereInput;
|
|
12
|
+
RelationName: "posts" | "comments";
|
|
13
|
+
ListRelations: "posts" | "comments";
|
|
14
|
+
Relations: {
|
|
15
|
+
posts: {
|
|
16
|
+
Shape: Post[];
|
|
17
|
+
Types: PrismaTypes["Post"];
|
|
18
|
+
};
|
|
19
|
+
comments: {
|
|
20
|
+
Shape: Comment[];
|
|
21
|
+
Types: PrismaTypes["Comment"];
|
|
22
|
+
};
|
|
23
|
+
};
|
|
24
|
+
};
|
|
25
|
+
Post: {
|
|
26
|
+
Name: "Post";
|
|
27
|
+
Shape: Post;
|
|
28
|
+
Include: Prisma.PostInclude;
|
|
29
|
+
Select: Prisma.PostSelect;
|
|
30
|
+
OrderBy: Prisma.PostOrderByWithRelationInput;
|
|
31
|
+
WhereUnique: Prisma.PostWhereUniqueInput;
|
|
32
|
+
Where: Prisma.PostWhereInput;
|
|
33
|
+
RelationName: "author" | "comments";
|
|
34
|
+
ListRelations: "comments";
|
|
35
|
+
Relations: {
|
|
36
|
+
author: {
|
|
37
|
+
Shape: User;
|
|
38
|
+
Types: PrismaTypes["User"];
|
|
39
|
+
};
|
|
40
|
+
comments: {
|
|
41
|
+
Shape: Comment[];
|
|
42
|
+
Types: PrismaTypes["Comment"];
|
|
43
|
+
};
|
|
44
|
+
};
|
|
45
|
+
};
|
|
46
|
+
Comment: {
|
|
47
|
+
Name: "Comment";
|
|
48
|
+
Shape: Comment;
|
|
49
|
+
Include: Prisma.CommentInclude;
|
|
50
|
+
Select: Prisma.CommentSelect;
|
|
51
|
+
OrderBy: Prisma.CommentOrderByWithRelationInput;
|
|
52
|
+
WhereUnique: Prisma.CommentWhereUniqueInput;
|
|
53
|
+
Where: Prisma.CommentWhereInput;
|
|
54
|
+
RelationName: "author" | "post";
|
|
55
|
+
ListRelations: never;
|
|
56
|
+
Relations: {
|
|
57
|
+
author: {
|
|
58
|
+
Shape: User;
|
|
59
|
+
Types: PrismaTypes["User"];
|
|
60
|
+
};
|
|
61
|
+
post: {
|
|
62
|
+
Shape: Post;
|
|
63
|
+
Types: PrismaTypes["Post"];
|
|
64
|
+
};
|
|
65
|
+
};
|
|
66
|
+
};
|
|
67
|
+
}
|
package/lib/generator.js
CHANGED
|
@@ -72,83 +72,95 @@ const defaultOutput = (0, _path.resolve)(__dirname, '../generated.ts');
|
|
|
72
72
|
defaultOutput
|
|
73
73
|
}),
|
|
74
74
|
onGenerate: async (options)=>{
|
|
75
|
+
var _options_generator_output;
|
|
75
76
|
checkTSVersion();
|
|
76
77
|
const config = options.generator.config;
|
|
77
78
|
var _config_clientOutput;
|
|
78
79
|
const prismaLocation = (_config_clientOutput = config.clientOutput) !== null && _config_clientOutput !== void 0 ? _config_clientOutput : options.otherGenerators.find((gen)=>gen.provider.value === 'prisma-client-js').output.value;
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
const possibleTypes = [
|
|
86
|
-
`${type}OrderByWithRelationInput`,
|
|
87
|
-
`${type}OrderByWithRelationAndSearchRelevanceInput`
|
|
88
|
-
];
|
|
89
|
-
const orderBy = (_options_dmmf_schema_inputObjectTypes_prisma = options.dmmf.schema.inputObjectTypes.prisma) === null || _options_dmmf_schema_inputObjectTypes_prisma === void 0 ? void 0 : _options_dmmf_schema_inputObjectTypes_prisma.find((inputType)=>possibleTypes.includes(inputType.name));
|
|
90
|
-
if (!orderBy) {
|
|
91
|
-
return possibleTypes[0];
|
|
92
|
-
}
|
|
93
|
-
return orderBy.name;
|
|
80
|
+
var _options_generator_output_value;
|
|
81
|
+
const outputLocation = (_options_generator_output_value = (_options_generator_output = options.generator.output) === null || _options_generator_output === void 0 ? void 0 : _options_generator_output.value) !== null && _options_generator_output_value !== void 0 ? _options_generator_output_value : defaultOutput;
|
|
82
|
+
const prismaTypes = buildTypes(options.dmmf);
|
|
83
|
+
await generateOutput(options.dmmf, prismaTypes, prismaLocation, outputLocation);
|
|
84
|
+
if (outputLocation === defaultOutput) {
|
|
85
|
+
await generateOutput(options.dmmf, prismaTypes, prismaLocation.replace('../', '../../'), outputLocation.replace('/generated.ts', '/esm/generated.ts'));
|
|
94
86
|
}
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
]));
|
|
119
|
-
});
|
|
120
|
-
const prismaTypes = _typescript.default.factory.createInterfaceDeclaration([], [
|
|
121
|
-
_typescript.default.factory.createModifier(_typescript.SyntaxKind.ExportKeyword),
|
|
122
|
-
_typescript.default.factory.createModifier(_typescript.SyntaxKind.DefaultKeyword)
|
|
123
|
-
], 'PrismaTypes', [], [], modelTypes);
|
|
124
|
-
const printer = _typescript.default.createPrinter({});
|
|
125
|
-
const sourcefile = _typescript.default.createSourceFile(options.generator.output.value, '', _typescript.ScriptTarget.ESNext, false, _typescript.ScriptKind.TS);
|
|
126
|
-
const nodes = _typescript.default.factory.createNodeArray([
|
|
127
|
-
importStatement,
|
|
128
|
-
prismaTypes
|
|
129
|
-
]);
|
|
130
|
-
const result = printer.printList(_typescript.ListFormat.SourceFileStatements, nodes, sourcefile);
|
|
131
|
-
await new Promise((resolve, reject)=>{
|
|
132
|
-
(0, _fs.mkdir)((0, _path.dirname)(sourcefile.fileName), {
|
|
133
|
-
recursive: true
|
|
134
|
-
}, (err)=>{
|
|
135
|
-
if (err) {
|
|
136
|
-
reject(err);
|
|
137
|
-
} else {
|
|
138
|
-
resolve();
|
|
139
|
-
}
|
|
140
|
-
});
|
|
87
|
+
}
|
|
88
|
+
});
|
|
89
|
+
async function generateOutput(dmmf, prismaTypes, prismaLocation, outputLocation) {
|
|
90
|
+
const importStatement = _typescript.default.factory.createImportDeclaration([], [], _typescript.default.factory.createImportClause(true, undefined, _typescript.default.factory.createNamedImports([
|
|
91
|
+
_typescript.default.factory.createImportSpecifier(false, undefined, _typescript.default.factory.createIdentifier('Prisma')),
|
|
92
|
+
...dmmf.datamodel.models.map((model)=>_typescript.default.factory.createImportSpecifier(false, undefined, _typescript.default.factory.createIdentifier(model.name)))
|
|
93
|
+
])), _typescript.default.factory.createStringLiteral(prismaLocation));
|
|
94
|
+
const printer = _typescript.default.createPrinter({});
|
|
95
|
+
const sourcefile = _typescript.default.createSourceFile(outputLocation, '', _typescript.ScriptTarget.ESNext, false, _typescript.ScriptKind.TS);
|
|
96
|
+
const nodes = _typescript.default.factory.createNodeArray([
|
|
97
|
+
importStatement,
|
|
98
|
+
prismaTypes
|
|
99
|
+
]);
|
|
100
|
+
const result = printer.printList(_typescript.ListFormat.SourceFileStatements, nodes, sourcefile);
|
|
101
|
+
await new Promise((resolve, reject)=>{
|
|
102
|
+
(0, _fs.mkdir)((0, _path.dirname)(sourcefile.fileName), {
|
|
103
|
+
recursive: true
|
|
104
|
+
}, (err)=>{
|
|
105
|
+
if (err) {
|
|
106
|
+
reject(err);
|
|
107
|
+
} else {
|
|
108
|
+
resolve();
|
|
109
|
+
}
|
|
141
110
|
});
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
}
|
|
111
|
+
});
|
|
112
|
+
return new Promise((resolve, reject)=>{
|
|
113
|
+
(0, _fs.writeFile)(sourcefile.fileName, `/* eslint-disable */\n${result}`, (err)=>{
|
|
114
|
+
if (err) {
|
|
115
|
+
reject(err);
|
|
116
|
+
} else {
|
|
117
|
+
resolve();
|
|
118
|
+
}
|
|
150
119
|
});
|
|
120
|
+
});
|
|
121
|
+
}
|
|
122
|
+
function buildTypes(dmmf) {
|
|
123
|
+
function getOrderByTypeName(type) {
|
|
124
|
+
var _dmmf_schema_inputObjectTypes_prisma;
|
|
125
|
+
const possibleTypes = [
|
|
126
|
+
`${type}OrderByWithRelationInput`,
|
|
127
|
+
`${type}OrderByWithRelationAndSearchRelevanceInput`
|
|
128
|
+
];
|
|
129
|
+
const orderBy = (_dmmf_schema_inputObjectTypes_prisma = dmmf.schema.inputObjectTypes.prisma) === null || _dmmf_schema_inputObjectTypes_prisma === void 0 ? void 0 : _dmmf_schema_inputObjectTypes_prisma.find((inputType)=>possibleTypes.includes(inputType.name));
|
|
130
|
+
if (!orderBy) {
|
|
131
|
+
return possibleTypes[0];
|
|
132
|
+
}
|
|
133
|
+
return orderBy.name;
|
|
151
134
|
}
|
|
152
|
-
|
|
135
|
+
const modelTypes = dmmf.datamodel.models.map((model)=>{
|
|
136
|
+
const relations = model.fields.filter((field)=>!!field.relationName);
|
|
137
|
+
const listRelations = model.fields.filter((field)=>!!field.relationName && field.isList);
|
|
138
|
+
return _typescript.default.factory.createPropertySignature([], model.name, undefined, _typescript.default.factory.createTypeLiteralNode([
|
|
139
|
+
_typescript.default.factory.createPropertySignature([], 'Name', undefined, _typescript.default.factory.createLiteralTypeNode(_typescript.default.factory.createStringLiteral(model.name))),
|
|
140
|
+
_typescript.default.factory.createPropertySignature([], 'Shape', undefined, _typescript.default.factory.createTypeReferenceNode(model.name)),
|
|
141
|
+
_typescript.default.factory.createPropertySignature([], 'Include', undefined, relations.length > 0 ? _typescript.default.factory.createTypeReferenceNode(`Prisma.${model.name}Include`) : _typescript.default.factory.createTypeReferenceNode('never')),
|
|
142
|
+
_typescript.default.factory.createPropertySignature([], 'Select', undefined, _typescript.default.factory.createTypeReferenceNode(`Prisma.${model.name}Select`)),
|
|
143
|
+
_typescript.default.factory.createPropertySignature([], 'OrderBy', undefined, _typescript.default.factory.createTypeReferenceNode(`Prisma.${getOrderByTypeName(model.name)}`)),
|
|
144
|
+
_typescript.default.factory.createPropertySignature([], 'WhereUnique', undefined, _typescript.default.factory.createTypeReferenceNode(`Prisma.${model.name}WhereUniqueInput`)),
|
|
145
|
+
_typescript.default.factory.createPropertySignature([], 'Where', undefined, _typescript.default.factory.createTypeReferenceNode(`Prisma.${model.name}WhereInput`)),
|
|
146
|
+
_typescript.default.factory.createPropertySignature([], 'RelationName', undefined, relations.length > 0 ? _typescript.default.factory.createUnionTypeNode(relations.map((field)=>_typescript.default.factory.createLiteralTypeNode(_typescript.default.factory.createStringLiteral(field.name)))) : _typescript.default.factory.createTypeReferenceNode('never')),
|
|
147
|
+
_typescript.default.factory.createPropertySignature([], 'ListRelations', undefined, listRelations.length > 0 ? _typescript.default.factory.createUnionTypeNode(listRelations.map((field)=>_typescript.default.factory.createLiteralTypeNode(_typescript.default.factory.createStringLiteral(field.name)))) : _typescript.default.factory.createTypeReferenceNode('never')),
|
|
148
|
+
_typescript.default.factory.createPropertySignature([], 'Relations', undefined, _typescript.default.factory.createTypeLiteralNode(relations.map((field)=>{
|
|
149
|
+
const typeName = field.type;
|
|
150
|
+
return _typescript.default.factory.createPropertySignature([], field.name, undefined, _typescript.default.factory.createTypeLiteralNode([
|
|
151
|
+
_typescript.default.factory.createPropertySignature([], 'Shape', undefined, field.isList ? _typescript.default.factory.createArrayTypeNode(_typescript.default.factory.createTypeReferenceNode(typeName)) : field.isRequired ? _typescript.default.factory.createTypeReferenceNode(typeName) : _typescript.default.factory.createUnionTypeNode([
|
|
152
|
+
_typescript.default.factory.createTypeReferenceNode(typeName),
|
|
153
|
+
_typescript.default.factory.createLiteralTypeNode(_typescript.default.factory.createNull())
|
|
154
|
+
])),
|
|
155
|
+
_typescript.default.factory.createPropertySignature([], 'Types', undefined, _typescript.default.factory.createIndexedAccessTypeNode(_typescript.default.factory.createTypeReferenceNode('PrismaTypes'), _typescript.default.factory.createLiteralTypeNode(_typescript.default.factory.createStringLiteral(typeName))))
|
|
156
|
+
]));
|
|
157
|
+
})))
|
|
158
|
+
]));
|
|
159
|
+
});
|
|
160
|
+
return _typescript.default.factory.createInterfaceDeclaration([], [
|
|
161
|
+
_typescript.default.factory.createModifier(_typescript.SyntaxKind.ExportKeyword),
|
|
162
|
+
_typescript.default.factory.createModifier(_typescript.SyntaxKind.DefaultKeyword)
|
|
163
|
+
], 'PrismaTypes', [], [], modelTypes);
|
|
164
|
+
}
|
|
153
165
|
|
|
154
166
|
//# sourceMappingURL=generator.js.map
|
package/lib/generator.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/generator.ts"],"names":["MIN_TS_VERSION","checkTSVersion","versionParts","version","split","i","part","Number","parseInt","Error","join","defaultOutput","resolvePath","__dirname","generatorHandler","onManifest","prettyName","requiresGenerators","onGenerate","options","config","generator","prismaLocation","clientOutput","otherGenerators","find","gen","provider","value","output","importStatement","ts","factory","createImportDeclaration","createImportClause","undefined","createNamedImports","createImportSpecifier","createIdentifier","
|
|
1
|
+
{"version":3,"sources":["../src/generator.ts"],"names":["MIN_TS_VERSION","checkTSVersion","versionParts","version","split","i","part","Number","parseInt","Error","join","defaultOutput","resolvePath","__dirname","generatorHandler","onManifest","prettyName","requiresGenerators","onGenerate","options","config","generator","prismaLocation","clientOutput","otherGenerators","find","gen","provider","value","output","outputLocation","prismaTypes","buildTypes","dmmf","generateOutput","replace","importStatement","ts","factory","createImportDeclaration","createImportClause","undefined","createNamedImports","createImportSpecifier","createIdentifier","datamodel","models","map","model","name","createStringLiteral","printer","createPrinter","sourcefile","createSourceFile","ScriptTarget","ESNext","ScriptKind","TS","nodes","createNodeArray","result","printList","ListFormat","SourceFileStatements","Promise","resolve","reject","mkdir","dirname","fileName","recursive","err","writeFile","getOrderByTypeName","type","possibleTypes","orderBy","schema","inputObjectTypes","prisma","inputType","includes","modelTypes","relations","fields","filter","field","relationName","listRelations","isList","createPropertySignature","createTypeLiteralNode","createLiteralTypeNode","createTypeReferenceNode","length","createUnionTypeNode","typeName","createArrayTypeNode","isRequired","createNull","createIndexedAccessTypeNode","createInterfaceDeclaration","createModifier","SyntaxKind","ExportKeyword","DefaultKeyword"],"mappings":"AAAA,wCAAwC,GACxC,0CAA0C,GAC1C,mCAAmC,GACnC,oCAAoC,GACpC;;;;oBAAiC;sBACe;kEAC8B;iCACvC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAEvC,MAAMA,iBAAiB;IAAC;IAAG;IAAG;CAAE;AAEhC,SAASC,iBAAiB;IACxB,MAAMC,eAAeC,mBAAO,CAACC,KAAK,CAAC;IAEnC,IAAK,IAAIC,IAAI,GAAGA,IAAI,GAAGA,KAAK,EAAG;QAC7B,MAAMC,OAAOC,OAAOC,QAAQ,CAACN,YAAY,CAACG,EAAE,EAAE;QAC9C,IAAIC,OAAON,cAAc,CAACK,EAAE,EAAE;YAC5B,MAAM,IAAII,MACR,CAAC,m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uD,qBAAqB,CAACxD,mBAAE,CAACC,OAAO,CAACY,mBAAmB,CAAC+C;iBAGrE;YAEL;SAGL;IAEL;IAEA,OAAO5D,mBAAE,CAACC,OAAO,CAACgE,0BAA0B,CAC1C,EAAE,EACF;QACEjE,mBAAE,CAACC,OAAO,CAACiE,cAAc,CAACC,sBAAU,CAACC,aAAa;QAClDpE,mBAAE,CAACC,OAAO,CAACiE,cAAc,CAACC,sBAAU,CAACE,cAAc;KACpD,EACD,eACA,EAAE,EACF,EAAE,EACFvB;AAEJ"}
|
package/package.json
CHANGED
|
@@ -1,17 +1,27 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@pothos/plugin-prisma",
|
|
3
|
-
"version": "3.
|
|
3
|
+
"version": "3.38.0",
|
|
4
4
|
"description": "A Pothos plugin for more efficient integration with prisma",
|
|
5
5
|
"main": "./lib/index.js",
|
|
6
6
|
"types": "./dts/index.d.ts",
|
|
7
7
|
"module": "./esm/index.js",
|
|
8
8
|
"exports": {
|
|
9
|
-
"
|
|
10
|
-
"
|
|
9
|
+
".": {
|
|
10
|
+
"import": {
|
|
11
|
+
"default": "./esm/index.js"
|
|
12
|
+
},
|
|
13
|
+
"require": {
|
|
14
|
+
"types": "./dts/index.d.ts",
|
|
15
|
+
"default": "./lib/index.js"
|
|
16
|
+
}
|
|
11
17
|
},
|
|
12
|
-
"
|
|
13
|
-
"
|
|
14
|
-
|
|
18
|
+
"./generated": {
|
|
19
|
+
"import": {
|
|
20
|
+
"default": "./esm/generated.ts"
|
|
21
|
+
},
|
|
22
|
+
"require": {
|
|
23
|
+
"default": "./generated.ts"
|
|
24
|
+
}
|
|
15
25
|
}
|
|
16
26
|
},
|
|
17
27
|
"repository": {
|
|
@@ -40,7 +50,7 @@
|
|
|
40
50
|
"access": "public"
|
|
41
51
|
},
|
|
42
52
|
"dependencies": {
|
|
43
|
-
"@prisma/generator-helper": "^4.
|
|
53
|
+
"@prisma/generator-helper": "^4.7.1"
|
|
44
54
|
},
|
|
45
55
|
"prisma": {
|
|
46
56
|
"seed": "node prisma/seed.mjs"
|
|
@@ -52,14 +62,14 @@
|
|
|
52
62
|
"typescript": ">=4.7.2"
|
|
53
63
|
},
|
|
54
64
|
"devDependencies": {
|
|
55
|
-
"@prisma/client": "^4.
|
|
65
|
+
"@prisma/client": "^4.7.1",
|
|
56
66
|
"graphql": "16.6.0",
|
|
57
67
|
"graphql-tag": "^2.12.6",
|
|
58
|
-
"prisma": "^4.
|
|
59
|
-
"@pothos/core": "3.23.
|
|
68
|
+
"prisma": "^4.7.1",
|
|
69
|
+
"@pothos/core": "3.23.1",
|
|
60
70
|
"@pothos/plugin-complexity": "3.11.7",
|
|
61
71
|
"@pothos/plugin-errors": "3.9.0",
|
|
62
|
-
"@pothos/plugin-relay": "3.
|
|
72
|
+
"@pothos/plugin-relay": "3.30.0",
|
|
63
73
|
"@pothos/plugin-simple-objects": "3.6.7",
|
|
64
74
|
"@pothos/test-utils": "1.4.7"
|
|
65
75
|
},
|
package/src/generator.ts
CHANGED
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
import { mkdir, writeFile } from 'fs';
|
|
6
6
|
import { dirname, resolve as resolvePath } from 'path';
|
|
7
7
|
import ts, { ListFormat, ScriptKind, ScriptTarget, SyntaxKind, version } from 'typescript';
|
|
8
|
-
import { generatorHandler } from '@prisma/generator-helper';
|
|
8
|
+
import { DMMF, generatorHandler } from '@prisma/generator-helper';
|
|
9
9
|
|
|
10
10
|
const MIN_TS_VERSION = [4, 5, 2];
|
|
11
11
|
|
|
@@ -42,210 +42,232 @@ generatorHandler({
|
|
|
42
42
|
options.otherGenerators.find((gen) => gen.provider.value === 'prisma-client-js')!.output!
|
|
43
43
|
.value;
|
|
44
44
|
|
|
45
|
-
const
|
|
46
|
-
|
|
47
|
-
[],
|
|
48
|
-
ts.factory.createImportClause(
|
|
49
|
-
true,
|
|
50
|
-
undefined,
|
|
51
|
-
ts.factory.createNamedImports([
|
|
52
|
-
ts.factory.createImportSpecifier(false, undefined, ts.factory.createIdentifier('Prisma')),
|
|
53
|
-
...options.dmmf.datamodel.models.map((model) =>
|
|
54
|
-
ts.factory.createImportSpecifier(
|
|
55
|
-
false,
|
|
56
|
-
undefined,
|
|
57
|
-
ts.factory.createIdentifier(model.name),
|
|
58
|
-
),
|
|
59
|
-
),
|
|
60
|
-
]),
|
|
61
|
-
),
|
|
62
|
-
ts.factory.createStringLiteral(prismaLocation),
|
|
63
|
-
);
|
|
45
|
+
const outputLocation = options.generator.output?.value ?? defaultOutput;
|
|
46
|
+
const prismaTypes = buildTypes(options.dmmf);
|
|
64
47
|
|
|
65
|
-
|
|
66
|
-
const possibleTypes = [
|
|
67
|
-
`${type}OrderByWithRelationInput`,
|
|
68
|
-
`${type}OrderByWithRelationAndSearchRelevanceInput`,
|
|
69
|
-
];
|
|
48
|
+
await generateOutput(options.dmmf, prismaTypes, prismaLocation, outputLocation);
|
|
70
49
|
|
|
71
|
-
|
|
72
|
-
|
|
50
|
+
if (outputLocation === defaultOutput) {
|
|
51
|
+
await generateOutput(
|
|
52
|
+
options.dmmf,
|
|
53
|
+
prismaTypes,
|
|
54
|
+
prismaLocation.replace('../', '../../'),
|
|
55
|
+
outputLocation.replace('/generated.ts', '/esm/generated.ts'),
|
|
73
56
|
);
|
|
57
|
+
}
|
|
58
|
+
},
|
|
59
|
+
});
|
|
74
60
|
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
61
|
+
async function generateOutput(
|
|
62
|
+
dmmf: DMMF.Document,
|
|
63
|
+
prismaTypes: ts.InterfaceDeclaration,
|
|
64
|
+
prismaLocation: string,
|
|
65
|
+
outputLocation: string,
|
|
66
|
+
) {
|
|
67
|
+
const importStatement = ts.factory.createImportDeclaration(
|
|
68
|
+
[],
|
|
69
|
+
[],
|
|
70
|
+
ts.factory.createImportClause(
|
|
71
|
+
true,
|
|
72
|
+
undefined,
|
|
73
|
+
ts.factory.createNamedImports([
|
|
74
|
+
ts.factory.createImportSpecifier(false, undefined, ts.factory.createIdentifier('Prisma')),
|
|
75
|
+
...dmmf.datamodel.models.map((model) =>
|
|
76
|
+
ts.factory.createImportSpecifier(
|
|
77
|
+
false,
|
|
78
|
+
undefined,
|
|
79
|
+
ts.factory.createIdentifier(model.name),
|
|
80
|
+
),
|
|
81
|
+
),
|
|
82
|
+
]),
|
|
83
|
+
),
|
|
84
|
+
ts.factory.createStringLiteral(prismaLocation),
|
|
85
|
+
);
|
|
78
86
|
|
|
79
|
-
|
|
80
|
-
}
|
|
87
|
+
const printer = ts.createPrinter({});
|
|
81
88
|
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
89
|
+
const sourcefile = ts.createSourceFile(
|
|
90
|
+
outputLocation,
|
|
91
|
+
'',
|
|
92
|
+
ScriptTarget.ESNext,
|
|
93
|
+
false,
|
|
94
|
+
ScriptKind.TS,
|
|
95
|
+
);
|
|
85
96
|
|
|
86
|
-
|
|
87
|
-
[],
|
|
88
|
-
model.name,
|
|
89
|
-
undefined,
|
|
97
|
+
const nodes = ts.factory.createNodeArray([importStatement, prismaTypes]);
|
|
90
98
|
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
'Shape',
|
|
101
|
-
undefined,
|
|
102
|
-
ts.factory.createTypeReferenceNode(model.name),
|
|
103
|
-
),
|
|
104
|
-
ts.factory.createPropertySignature(
|
|
105
|
-
[],
|
|
106
|
-
'Include',
|
|
107
|
-
undefined,
|
|
108
|
-
relations.length > 0
|
|
109
|
-
? ts.factory.createTypeReferenceNode(`Prisma.${model.name}Include`)
|
|
110
|
-
: ts.factory.createTypeReferenceNode('never'),
|
|
111
|
-
),
|
|
112
|
-
ts.factory.createPropertySignature(
|
|
113
|
-
[],
|
|
114
|
-
'Select',
|
|
115
|
-
undefined,
|
|
116
|
-
ts.factory.createTypeReferenceNode(`Prisma.${model.name}Select`),
|
|
117
|
-
),
|
|
118
|
-
ts.factory.createPropertySignature(
|
|
119
|
-
[],
|
|
120
|
-
'OrderBy',
|
|
121
|
-
undefined,
|
|
122
|
-
ts.factory.createTypeReferenceNode(`Prisma.${getOrderByTypeName(model.name)}`),
|
|
123
|
-
),
|
|
124
|
-
ts.factory.createPropertySignature(
|
|
125
|
-
[],
|
|
126
|
-
'WhereUnique',
|
|
127
|
-
undefined,
|
|
128
|
-
ts.factory.createTypeReferenceNode(`Prisma.${model.name}WhereUniqueInput`),
|
|
129
|
-
),
|
|
130
|
-
ts.factory.createPropertySignature(
|
|
131
|
-
[],
|
|
132
|
-
'Where',
|
|
133
|
-
undefined,
|
|
134
|
-
ts.factory.createTypeReferenceNode(`Prisma.${model.name}WhereInput`),
|
|
135
|
-
),
|
|
136
|
-
ts.factory.createPropertySignature(
|
|
137
|
-
[],
|
|
138
|
-
'RelationName',
|
|
139
|
-
undefined,
|
|
140
|
-
relations.length > 0
|
|
141
|
-
? ts.factory.createUnionTypeNode(
|
|
142
|
-
relations.map((field) =>
|
|
143
|
-
ts.factory.createLiteralTypeNode(ts.factory.createStringLiteral(field.name)),
|
|
144
|
-
),
|
|
145
|
-
)
|
|
146
|
-
: ts.factory.createTypeReferenceNode('never'),
|
|
147
|
-
),
|
|
148
|
-
ts.factory.createPropertySignature(
|
|
149
|
-
[],
|
|
150
|
-
'ListRelations',
|
|
151
|
-
undefined,
|
|
152
|
-
listRelations.length > 0
|
|
153
|
-
? ts.factory.createUnionTypeNode(
|
|
154
|
-
listRelations.map((field) =>
|
|
155
|
-
ts.factory.createLiteralTypeNode(ts.factory.createStringLiteral(field.name)),
|
|
156
|
-
),
|
|
157
|
-
)
|
|
158
|
-
: ts.factory.createTypeReferenceNode('never'),
|
|
159
|
-
),
|
|
160
|
-
ts.factory.createPropertySignature(
|
|
161
|
-
[],
|
|
162
|
-
'Relations',
|
|
163
|
-
undefined,
|
|
164
|
-
ts.factory.createTypeLiteralNode(
|
|
165
|
-
relations.map((field) => {
|
|
166
|
-
const typeName = field.type;
|
|
167
|
-
|
|
168
|
-
return ts.factory.createPropertySignature(
|
|
169
|
-
[],
|
|
170
|
-
field.name,
|
|
171
|
-
undefined,
|
|
172
|
-
ts.factory.createTypeLiteralNode([
|
|
173
|
-
ts.factory.createPropertySignature(
|
|
174
|
-
[],
|
|
175
|
-
'Shape',
|
|
176
|
-
undefined,
|
|
177
|
-
field.isList
|
|
178
|
-
? ts.factory.createArrayTypeNode(
|
|
179
|
-
ts.factory.createTypeReferenceNode(typeName),
|
|
180
|
-
)
|
|
181
|
-
: field.isRequired
|
|
182
|
-
? ts.factory.createTypeReferenceNode(typeName)
|
|
183
|
-
: ts.factory.createUnionTypeNode([
|
|
184
|
-
ts.factory.createTypeReferenceNode(typeName),
|
|
185
|
-
ts.factory.createLiteralTypeNode(ts.factory.createNull()),
|
|
186
|
-
]),
|
|
187
|
-
),
|
|
188
|
-
ts.factory.createPropertySignature(
|
|
189
|
-
[],
|
|
190
|
-
'Types',
|
|
191
|
-
undefined,
|
|
192
|
-
ts.factory.createIndexedAccessTypeNode(
|
|
193
|
-
ts.factory.createTypeReferenceNode('PrismaTypes'),
|
|
194
|
-
ts.factory.createLiteralTypeNode(ts.factory.createStringLiteral(typeName)),
|
|
195
|
-
),
|
|
196
|
-
),
|
|
197
|
-
]),
|
|
198
|
-
);
|
|
199
|
-
}),
|
|
200
|
-
),
|
|
201
|
-
),
|
|
202
|
-
]),
|
|
203
|
-
);
|
|
99
|
+
const result = printer.printList(ListFormat.SourceFileStatements, nodes, sourcefile);
|
|
100
|
+
|
|
101
|
+
await new Promise<void>((resolve, reject) => {
|
|
102
|
+
mkdir(dirname(sourcefile.fileName), { recursive: true }, (err) => {
|
|
103
|
+
if (err) {
|
|
104
|
+
reject(err);
|
|
105
|
+
} else {
|
|
106
|
+
resolve();
|
|
107
|
+
}
|
|
204
108
|
});
|
|
109
|
+
});
|
|
205
110
|
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
const
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
111
|
+
return new Promise<void>((resolve, reject) => {
|
|
112
|
+
writeFile(sourcefile.fileName, `/* eslint-disable */\n${result}`, (err) => {
|
|
113
|
+
if (err) {
|
|
114
|
+
reject(err);
|
|
115
|
+
} else {
|
|
116
|
+
resolve();
|
|
117
|
+
}
|
|
118
|
+
});
|
|
119
|
+
});
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
function buildTypes(dmmf: DMMF.Document) {
|
|
123
|
+
function getOrderByTypeName(type: string) {
|
|
124
|
+
const possibleTypes = [
|
|
125
|
+
`${type}OrderByWithRelationInput`,
|
|
126
|
+
`${type}OrderByWithRelationAndSearchRelevanceInput`,
|
|
127
|
+
];
|
|
128
|
+
|
|
129
|
+
const orderBy = dmmf.schema.inputObjectTypes.prisma?.find((inputType) =>
|
|
130
|
+
possibleTypes.includes(inputType.name),
|
|
225
131
|
);
|
|
226
132
|
|
|
227
|
-
|
|
133
|
+
if (!orderBy) {
|
|
134
|
+
return possibleTypes[0];
|
|
135
|
+
}
|
|
228
136
|
|
|
229
|
-
|
|
137
|
+
return orderBy.name;
|
|
138
|
+
}
|
|
230
139
|
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
reject(err);
|
|
235
|
-
} else {
|
|
236
|
-
resolve();
|
|
237
|
-
}
|
|
238
|
-
});
|
|
239
|
-
});
|
|
140
|
+
const modelTypes = dmmf.datamodel.models.map((model) => {
|
|
141
|
+
const relations = model.fields.filter((field) => !!field.relationName);
|
|
142
|
+
const listRelations = model.fields.filter((field) => !!field.relationName && field.isList);
|
|
240
143
|
|
|
241
|
-
return
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
144
|
+
return ts.factory.createPropertySignature(
|
|
145
|
+
[],
|
|
146
|
+
model.name,
|
|
147
|
+
undefined,
|
|
148
|
+
|
|
149
|
+
ts.factory.createTypeLiteralNode([
|
|
150
|
+
ts.factory.createPropertySignature(
|
|
151
|
+
[],
|
|
152
|
+
'Name',
|
|
153
|
+
undefined,
|
|
154
|
+
ts.factory.createLiteralTypeNode(ts.factory.createStringLiteral(model.name)),
|
|
155
|
+
),
|
|
156
|
+
ts.factory.createPropertySignature(
|
|
157
|
+
[],
|
|
158
|
+
'Shape',
|
|
159
|
+
undefined,
|
|
160
|
+
ts.factory.createTypeReferenceNode(model.name),
|
|
161
|
+
),
|
|
162
|
+
ts.factory.createPropertySignature(
|
|
163
|
+
[],
|
|
164
|
+
'Include',
|
|
165
|
+
undefined,
|
|
166
|
+
relations.length > 0
|
|
167
|
+
? ts.factory.createTypeReferenceNode(`Prisma.${model.name}Include`)
|
|
168
|
+
: ts.factory.createTypeReferenceNode('never'),
|
|
169
|
+
),
|
|
170
|
+
ts.factory.createPropertySignature(
|
|
171
|
+
[],
|
|
172
|
+
'Select',
|
|
173
|
+
undefined,
|
|
174
|
+
ts.factory.createTypeReferenceNode(`Prisma.${model.name}Select`),
|
|
175
|
+
),
|
|
176
|
+
ts.factory.createPropertySignature(
|
|
177
|
+
[],
|
|
178
|
+
'OrderBy',
|
|
179
|
+
undefined,
|
|
180
|
+
ts.factory.createTypeReferenceNode(`Prisma.${getOrderByTypeName(model.name)}`),
|
|
181
|
+
),
|
|
182
|
+
ts.factory.createPropertySignature(
|
|
183
|
+
[],
|
|
184
|
+
'WhereUnique',
|
|
185
|
+
undefined,
|
|
186
|
+
ts.factory.createTypeReferenceNode(`Prisma.${model.name}WhereUniqueInput`),
|
|
187
|
+
),
|
|
188
|
+
ts.factory.createPropertySignature(
|
|
189
|
+
[],
|
|
190
|
+
'Where',
|
|
191
|
+
undefined,
|
|
192
|
+
ts.factory.createTypeReferenceNode(`Prisma.${model.name}WhereInput`),
|
|
193
|
+
),
|
|
194
|
+
ts.factory.createPropertySignature(
|
|
195
|
+
[],
|
|
196
|
+
'RelationName',
|
|
197
|
+
undefined,
|
|
198
|
+
relations.length > 0
|
|
199
|
+
? ts.factory.createUnionTypeNode(
|
|
200
|
+
relations.map((field) =>
|
|
201
|
+
ts.factory.createLiteralTypeNode(ts.factory.createStringLiteral(field.name)),
|
|
202
|
+
),
|
|
203
|
+
)
|
|
204
|
+
: ts.factory.createTypeReferenceNode('never'),
|
|
205
|
+
),
|
|
206
|
+
ts.factory.createPropertySignature(
|
|
207
|
+
[],
|
|
208
|
+
'ListRelations',
|
|
209
|
+
undefined,
|
|
210
|
+
listRelations.length > 0
|
|
211
|
+
? ts.factory.createUnionTypeNode(
|
|
212
|
+
listRelations.map((field) =>
|
|
213
|
+
ts.factory.createLiteralTypeNode(ts.factory.createStringLiteral(field.name)),
|
|
214
|
+
),
|
|
215
|
+
)
|
|
216
|
+
: ts.factory.createTypeReferenceNode('never'),
|
|
217
|
+
),
|
|
218
|
+
ts.factory.createPropertySignature(
|
|
219
|
+
[],
|
|
220
|
+
'Relations',
|
|
221
|
+
undefined,
|
|
222
|
+
ts.factory.createTypeLiteralNode(
|
|
223
|
+
relations.map((field) => {
|
|
224
|
+
const typeName = field.type;
|
|
225
|
+
|
|
226
|
+
return ts.factory.createPropertySignature(
|
|
227
|
+
[],
|
|
228
|
+
field.name,
|
|
229
|
+
undefined,
|
|
230
|
+
ts.factory.createTypeLiteralNode([
|
|
231
|
+
ts.factory.createPropertySignature(
|
|
232
|
+
[],
|
|
233
|
+
'Shape',
|
|
234
|
+
undefined,
|
|
235
|
+
field.isList
|
|
236
|
+
? ts.factory.createArrayTypeNode(ts.factory.createTypeReferenceNode(typeName))
|
|
237
|
+
: field.isRequired
|
|
238
|
+
? ts.factory.createTypeReferenceNode(typeName)
|
|
239
|
+
: ts.factory.createUnionTypeNode([
|
|
240
|
+
ts.factory.createTypeReferenceNode(typeName),
|
|
241
|
+
ts.factory.createLiteralTypeNode(ts.factory.createNull()),
|
|
242
|
+
]),
|
|
243
|
+
),
|
|
244
|
+
ts.factory.createPropertySignature(
|
|
245
|
+
[],
|
|
246
|
+
'Types',
|
|
247
|
+
undefined,
|
|
248
|
+
ts.factory.createIndexedAccessTypeNode(
|
|
249
|
+
ts.factory.createTypeReferenceNode('PrismaTypes'),
|
|
250
|
+
ts.factory.createLiteralTypeNode(ts.factory.createStringLiteral(typeName)),
|
|
251
|
+
),
|
|
252
|
+
),
|
|
253
|
+
]),
|
|
254
|
+
);
|
|
255
|
+
}),
|
|
256
|
+
),
|
|
257
|
+
),
|
|
258
|
+
]),
|
|
259
|
+
);
|
|
260
|
+
});
|
|
261
|
+
|
|
262
|
+
return ts.factory.createInterfaceDeclaration(
|
|
263
|
+
[],
|
|
264
|
+
[
|
|
265
|
+
ts.factory.createModifier(SyntaxKind.ExportKeyword),
|
|
266
|
+
ts.factory.createModifier(SyntaxKind.DefaultKeyword),
|
|
267
|
+
],
|
|
268
|
+
'PrismaTypes',
|
|
269
|
+
[],
|
|
270
|
+
[],
|
|
271
|
+
modelTypes,
|
|
272
|
+
);
|
|
273
|
+
}
|