@tsed/prisma 8.0.1 → 8.0.3
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/package.json +12 -11
- package/readme.md +5 -5
- package/src/cli/prismaGenerator.ts +50 -0
- package/src/dev.ts +10 -0
- package/src/generator/domain/DmmfEnum.ts +42 -0
- package/src/generator/domain/DmmfField.spec.ts +40 -0
- package/src/generator/domain/DmmfField.ts +52 -0
- package/src/generator/domain/DmmfModel.ts +94 -0
- package/src/generator/domain/ScalarTsTypes.ts +54 -0
- package/src/generator/domain/TransformContext.ts +7 -0
- package/src/generator/generateCode.spec.ts +16 -0
- package/src/generator/generateCode.ts +51 -0
- package/src/generator/transform/transformEnumsToEnums.spec.ts +44 -0
- package/src/generator/transform/transformEnumsToEnums.ts +21 -0
- package/src/generator/transform/transformFieldToDecorators.spec.ts +222 -0
- package/src/generator/transform/transformFieldToDecorators.ts +72 -0
- package/src/generator/transform/transformFieldToProperty.ts +16 -0
- package/src/generator/transform/transformModelToClass.spec.ts +495 -0
- package/src/generator/transform/transformModelToClass.ts +19 -0
- package/src/generator/transform/transformScalarToType.spec.ts +125 -0
- package/src/generator/transform/transformScalarToType.ts +50 -0
- package/src/generator/utils/__snapshots__/generateEnums.spec.ts.snap +10 -0
- package/src/generator/utils/__snapshots__/generateModels.spec.ts.snap +113 -0
- package/src/generator/utils/__snapshots__/generatePrismaService.spec.ts.snap +28 -0
- package/src/generator/utils/__snapshots__/generateRespositories.spec.ts.snap +151 -0
- package/src/generator/utils/generateClientIndex.ts +20 -0
- package/src/generator/utils/generateDocuments.ts +20 -0
- package/src/generator/utils/generateEnums.spec.ts +15 -0
- package/src/generator/utils/generateEnums.ts +25 -0
- package/src/generator/utils/generateIndex.ts +28 -0
- package/src/generator/utils/generateInterfaces.ts +33 -0
- package/src/generator/utils/generateModels.spec.ts +30 -0
- package/src/generator/utils/generateModels.ts +28 -0
- package/src/generator/utils/generateOutputsBarrelFile.ts +14 -0
- package/src/generator/utils/generatePrismaService.spec.ts +12 -0
- package/src/generator/utils/generatePrismaService.ts +90 -0
- package/src/generator/utils/generateRepositories.ts +207 -0
- package/src/generator/utils/generateRespositories.spec.ts +29 -0
- package/src/generator/utils/isCircularRef.spec.ts +22 -0
- package/src/generator/utils/isCircularRef.ts +33 -0
- package/src/generator/utils/parseDocumentationAttributes.spec.ts +73 -0
- package/src/generator/utils/parseDocumentationAttributes.ts +64 -0
- package/src/generator/utils/removeDir.ts +15 -0
- package/src/generator/utils/resolveExtension.ts +7 -0
- package/src/generator/utils/saveProject.ts +8 -0
- package/src/generator.ts +18 -0
- package/src/index.ts +1 -0
|
@@ -0,0 +1,207 @@
|
|
|
1
|
+
import {DMMF} from "@prisma/generator-helper";
|
|
2
|
+
import {toMap} from "@tsed/core";
|
|
3
|
+
import {camelCase, pascalCase} from "change-case";
|
|
4
|
+
import path from "path";
|
|
5
|
+
import pluralize from "pluralize";
|
|
6
|
+
import {ClassDeclaration, Project, Scope} from "ts-morph";
|
|
7
|
+
|
|
8
|
+
import {DmmfModel} from "../domain/DmmfModel.js";
|
|
9
|
+
import {generateOutputsBarrelFile} from "./generateOutputsBarrelFile.js";
|
|
10
|
+
import {resolveExtension} from "./resolveExtension.js";
|
|
11
|
+
|
|
12
|
+
interface MethodOptions {
|
|
13
|
+
repository: ClassDeclaration;
|
|
14
|
+
name: string;
|
|
15
|
+
model: string;
|
|
16
|
+
returnType?: string | undefined;
|
|
17
|
+
hasQuestionToken?: boolean;
|
|
18
|
+
isAsync?: boolean;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
function addDelegatedMethod({name, hasQuestionToken, repository, model, returnType, isAsync = true}: MethodOptions) {
|
|
22
|
+
const method = repository.addMethod({
|
|
23
|
+
name: name,
|
|
24
|
+
isAsync,
|
|
25
|
+
returnType: returnType ? `Promise<${returnType}>` : undefined,
|
|
26
|
+
parameters: [
|
|
27
|
+
{
|
|
28
|
+
name: "args",
|
|
29
|
+
type: `Prisma.${model}${pascalCase(name)}Args`,
|
|
30
|
+
hasQuestionToken
|
|
31
|
+
}
|
|
32
|
+
]
|
|
33
|
+
});
|
|
34
|
+
|
|
35
|
+
if (returnType) {
|
|
36
|
+
method.setBodyText(`const obj = await this.collection.${name}(args);
|
|
37
|
+
return this.deserialize<${returnType}>(obj);`);
|
|
38
|
+
} else {
|
|
39
|
+
method.setBodyText(`return this.collection.${name}(args)`);
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
export function generateRepositories(dmmf: DMMF.Document, project: Project, baseDirPath: string) {
|
|
44
|
+
const modelsMap = toMap<string, DMMF.Model>(dmmf.datamodel.models as any, "name");
|
|
45
|
+
const models = DmmfModel.getModels(dmmf, modelsMap);
|
|
46
|
+
const repoDirPath = path.resolve(baseDirPath, "repositories");
|
|
47
|
+
const repoDirectory = project.createDirectory(repoDirPath);
|
|
48
|
+
const repositoriesIndex = repoDirectory.createSourceFile(`index.ts`, undefined, {overwrite: true});
|
|
49
|
+
|
|
50
|
+
const exportedModels = models.map((model) => {
|
|
51
|
+
const name = pascalCase(`${pluralize(model.name)}Repository`);
|
|
52
|
+
const modelName = model.toString();
|
|
53
|
+
const sourceFile = repoDirectory.createSourceFile(`${name}.ts`, undefined, {overwrite: true});
|
|
54
|
+
|
|
55
|
+
sourceFile.addImportDeclarations([
|
|
56
|
+
{
|
|
57
|
+
moduleSpecifier: "@tsed/core",
|
|
58
|
+
namedImports: ["isArray"]
|
|
59
|
+
},
|
|
60
|
+
{
|
|
61
|
+
moduleSpecifier: "@tsed/json-mapper",
|
|
62
|
+
namedImports: ["deserialize"]
|
|
63
|
+
},
|
|
64
|
+
{
|
|
65
|
+
moduleSpecifier: "@tsed/di",
|
|
66
|
+
namedImports: ["Injectable", "Inject"]
|
|
67
|
+
},
|
|
68
|
+
{
|
|
69
|
+
moduleSpecifier: resolveExtension("../services/PrismaService"),
|
|
70
|
+
namedImports: ["PrismaService"]
|
|
71
|
+
},
|
|
72
|
+
{
|
|
73
|
+
moduleSpecifier: resolveExtension("../client/index"),
|
|
74
|
+
namedImports: ["Prisma", model.name]
|
|
75
|
+
},
|
|
76
|
+
{
|
|
77
|
+
moduleSpecifier: resolveExtension("../models/index"),
|
|
78
|
+
namedImports: [model.toString()]
|
|
79
|
+
}
|
|
80
|
+
]);
|
|
81
|
+
|
|
82
|
+
const repository = sourceFile.addClass({
|
|
83
|
+
name,
|
|
84
|
+
isExported: true,
|
|
85
|
+
decorators: [
|
|
86
|
+
{
|
|
87
|
+
name: "Injectable",
|
|
88
|
+
arguments: []
|
|
89
|
+
}
|
|
90
|
+
]
|
|
91
|
+
});
|
|
92
|
+
|
|
93
|
+
repository.addProperty({
|
|
94
|
+
name: "prisma",
|
|
95
|
+
type: "PrismaService",
|
|
96
|
+
scope: Scope.Protected,
|
|
97
|
+
decorators: [
|
|
98
|
+
{
|
|
99
|
+
name: "Inject",
|
|
100
|
+
arguments: []
|
|
101
|
+
}
|
|
102
|
+
]
|
|
103
|
+
});
|
|
104
|
+
|
|
105
|
+
repository
|
|
106
|
+
.addGetAccessor({
|
|
107
|
+
name: "collection"
|
|
108
|
+
})
|
|
109
|
+
.setBodyText(`return this.prisma.${camelCase(model.name)}`);
|
|
110
|
+
|
|
111
|
+
repository
|
|
112
|
+
.addGetAccessor({
|
|
113
|
+
name: "groupBy"
|
|
114
|
+
})
|
|
115
|
+
.setBodyText(`return this.collection.groupBy.bind(this.collection)`);
|
|
116
|
+
|
|
117
|
+
repository
|
|
118
|
+
.addMethod({
|
|
119
|
+
name: "deserialize",
|
|
120
|
+
scope: Scope.Protected,
|
|
121
|
+
returnType: "T",
|
|
122
|
+
parameters: [
|
|
123
|
+
{
|
|
124
|
+
name: "obj",
|
|
125
|
+
type: `null | ${model.name} | ${model.name}[]`
|
|
126
|
+
}
|
|
127
|
+
],
|
|
128
|
+
typeParameters: ["T"]
|
|
129
|
+
})
|
|
130
|
+
.setBodyText(`return deserialize<T>(obj, {type: ${modelName}, collectionType: isArray(obj) ? Array : undefined})`);
|
|
131
|
+
|
|
132
|
+
addDelegatedMethod({
|
|
133
|
+
repository,
|
|
134
|
+
name: "findUnique",
|
|
135
|
+
model: model.name,
|
|
136
|
+
returnType: `${modelName} | null`
|
|
137
|
+
});
|
|
138
|
+
|
|
139
|
+
addDelegatedMethod({
|
|
140
|
+
repository,
|
|
141
|
+
name: "findFirst",
|
|
142
|
+
model: model.name,
|
|
143
|
+
returnType: `${modelName} | null`
|
|
144
|
+
});
|
|
145
|
+
|
|
146
|
+
addDelegatedMethod({
|
|
147
|
+
repository,
|
|
148
|
+
name: "findMany",
|
|
149
|
+
model: model.name,
|
|
150
|
+
returnType: `${modelName}[]`,
|
|
151
|
+
hasQuestionToken: true
|
|
152
|
+
});
|
|
153
|
+
|
|
154
|
+
addDelegatedMethod({
|
|
155
|
+
repository,
|
|
156
|
+
name: "create",
|
|
157
|
+
model: model.name,
|
|
158
|
+
returnType: `${modelName}`
|
|
159
|
+
});
|
|
160
|
+
|
|
161
|
+
addDelegatedMethod({
|
|
162
|
+
repository,
|
|
163
|
+
name: "update",
|
|
164
|
+
model: model.name,
|
|
165
|
+
returnType: `${modelName}`
|
|
166
|
+
});
|
|
167
|
+
|
|
168
|
+
addDelegatedMethod({
|
|
169
|
+
repository,
|
|
170
|
+
name: "upsert",
|
|
171
|
+
model: model.name,
|
|
172
|
+
returnType: `${modelName}`
|
|
173
|
+
});
|
|
174
|
+
|
|
175
|
+
addDelegatedMethod({
|
|
176
|
+
repository,
|
|
177
|
+
name: "delete",
|
|
178
|
+
model: model.name,
|
|
179
|
+
returnType: `${modelName}`
|
|
180
|
+
});
|
|
181
|
+
|
|
182
|
+
addDelegatedMethod({
|
|
183
|
+
repository,
|
|
184
|
+
name: "deleteMany",
|
|
185
|
+
model: model.name,
|
|
186
|
+
isAsync: false
|
|
187
|
+
});
|
|
188
|
+
|
|
189
|
+
addDelegatedMethod({
|
|
190
|
+
repository,
|
|
191
|
+
name: "updateMany",
|
|
192
|
+
model: model.name,
|
|
193
|
+
isAsync: false
|
|
194
|
+
});
|
|
195
|
+
|
|
196
|
+
addDelegatedMethod({
|
|
197
|
+
repository,
|
|
198
|
+
name: "aggregate",
|
|
199
|
+
model: pascalCase(model.name),
|
|
200
|
+
isAsync: false
|
|
201
|
+
});
|
|
202
|
+
|
|
203
|
+
return name;
|
|
204
|
+
});
|
|
205
|
+
|
|
206
|
+
generateOutputsBarrelFile(repositoriesIndex, exportedModels);
|
|
207
|
+
}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import {createDmmfFixture} from "../../__mock__/createDmmfFixture.js";
|
|
2
|
+
import {createProjectFixture} from "../../__mock__/createProjectFixture.js";
|
|
3
|
+
import {generateRepositories} from "./generateRepositories.js";
|
|
4
|
+
|
|
5
|
+
describe("generateRepositories", () => {
|
|
6
|
+
it("should generate repositories (user)", () => {
|
|
7
|
+
const {project, render, baseDir} = createProjectFixture("generate_repositories");
|
|
8
|
+
const dmmf = createDmmfFixture();
|
|
9
|
+
|
|
10
|
+
generateRepositories(dmmf, project, baseDir);
|
|
11
|
+
|
|
12
|
+
const userRepo = render("/repositories/UsersRepository.ts");
|
|
13
|
+
|
|
14
|
+
userRepo.not.toContain("Post");
|
|
15
|
+
userRepo.toMatchSnapshot();
|
|
16
|
+
});
|
|
17
|
+
|
|
18
|
+
it("should generate repositories (posts)", () => {
|
|
19
|
+
const {project, render, baseDir} = createProjectFixture("generate_repositories");
|
|
20
|
+
const dmmf = createDmmfFixture();
|
|
21
|
+
|
|
22
|
+
generateRepositories(dmmf, project, baseDir);
|
|
23
|
+
|
|
24
|
+
const postsRepository = render("/repositories/PostsRepository.ts");
|
|
25
|
+
|
|
26
|
+
postsRepository.not.toContain("User");
|
|
27
|
+
postsRepository.toMatchSnapshot();
|
|
28
|
+
});
|
|
29
|
+
});
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import {createContextFixture} from "../../__mock__/createContextFixture.js";
|
|
2
|
+
import {isCircularRef} from "./isCircularRef.js";
|
|
3
|
+
|
|
4
|
+
const ctx = createContextFixture();
|
|
5
|
+
|
|
6
|
+
describe("isCircularRef()", () => {
|
|
7
|
+
it("should return true (self-ref)", () => {
|
|
8
|
+
expect(isCircularRef("User", "User", ctx)).toEqual(true);
|
|
9
|
+
});
|
|
10
|
+
it("should return true (circular-ref)", () => {
|
|
11
|
+
expect(isCircularRef("User", "Role", ctx)).toEqual(true);
|
|
12
|
+
});
|
|
13
|
+
it("should return true (transitive ref)", () => {
|
|
14
|
+
expect(isCircularRef("User", "Transitive", ctx)).toEqual(true);
|
|
15
|
+
});
|
|
16
|
+
it("should return false", () => {
|
|
17
|
+
expect(isCircularRef("User", "Other", ctx)).toEqual(false);
|
|
18
|
+
});
|
|
19
|
+
it("should return false (transitive)", () => {
|
|
20
|
+
expect(isCircularRef("User", "Hello", ctx)).toEqual(false);
|
|
21
|
+
});
|
|
22
|
+
});
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import {DMMF} from "@prisma/generator-helper";
|
|
2
|
+
|
|
3
|
+
import {TransformContext} from "../domain/TransformContext.js";
|
|
4
|
+
|
|
5
|
+
export function isCircularRef(modelName: string, fieldType: string, ctx: TransformContext): boolean {
|
|
6
|
+
if (modelName === fieldType) {
|
|
7
|
+
return true;
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
const relation1 = ctx.modelsMap.get(modelName);
|
|
11
|
+
const relation2 = ctx.modelsMap.get(fieldType);
|
|
12
|
+
|
|
13
|
+
return Boolean(relation1 && relation2 && hasModelInFields(relation1, fieldType, ctx) && hasModelInFields(relation2, modelName, ctx));
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
function hasModelInFields(model: DMMF.Model, relation: string, ctx: TransformContext, inspected: string[] = []): boolean {
|
|
17
|
+
return !!model.fields.find((field) => {
|
|
18
|
+
if (field.type === relation) {
|
|
19
|
+
return true;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
if (!inspected.includes(field.type)) {
|
|
23
|
+
const nextModel = ctx.modelsMap.get(field.type);
|
|
24
|
+
|
|
25
|
+
if (nextModel) {
|
|
26
|
+
inspected = [...inspected, field.type];
|
|
27
|
+
return hasModelInFields(nextModel, relation, ctx, inspected);
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
return false;
|
|
32
|
+
});
|
|
33
|
+
}
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
import {parseDocumentationAttributes} from "./parseDocumentationAttributes.js";
|
|
2
|
+
|
|
3
|
+
describe("parseDocumentationAttributes", () => {
|
|
4
|
+
it('should parse @TsED.Groups(type: "test", fix: "other")', () => {
|
|
5
|
+
expect(parseDocumentationAttributes('/// @TsED.Groups(type: "test", fix: "other")')).toEqual([
|
|
6
|
+
{
|
|
7
|
+
arguments: [
|
|
8
|
+
{
|
|
9
|
+
type: "test",
|
|
10
|
+
fix: "other"
|
|
11
|
+
}
|
|
12
|
+
],
|
|
13
|
+
content: '@TsED.Groups(type: "test", fix: "other")',
|
|
14
|
+
name: "Groups"
|
|
15
|
+
}
|
|
16
|
+
]);
|
|
17
|
+
});
|
|
18
|
+
it("should ignore undefined comment", () => {
|
|
19
|
+
expect(parseDocumentationAttributes(undefined)).toEqual([]);
|
|
20
|
+
});
|
|
21
|
+
it("should parse @TsED.Email()", () => {
|
|
22
|
+
expect(parseDocumentationAttributes("/// @TsED.Email()")).toEqual([
|
|
23
|
+
{
|
|
24
|
+
arguments: [],
|
|
25
|
+
content: "@TsED.Email()",
|
|
26
|
+
name: "Email"
|
|
27
|
+
}
|
|
28
|
+
]);
|
|
29
|
+
});
|
|
30
|
+
it("should parse @TsED.Ignore(endpoint = true)", () => {
|
|
31
|
+
expect(parseDocumentationAttributes("/// @TsED.Ignore(ctx.endpoint === true)")).toEqual([
|
|
32
|
+
{
|
|
33
|
+
arguments: ["(value: any, ctx: any) => ctx.endpoint === true"],
|
|
34
|
+
content: "@TsED.Ignore(ctx.endpoint === true)",
|
|
35
|
+
name: "Ignore"
|
|
36
|
+
}
|
|
37
|
+
]);
|
|
38
|
+
});
|
|
39
|
+
it("should parse @TsED.Ignore()", () => {
|
|
40
|
+
expect(parseDocumentationAttributes("/// @TsED.Ignore()")).toEqual([
|
|
41
|
+
{
|
|
42
|
+
arguments: [],
|
|
43
|
+
content: "@TsED.Ignore()",
|
|
44
|
+
name: "Ignore"
|
|
45
|
+
}
|
|
46
|
+
]);
|
|
47
|
+
});
|
|
48
|
+
it('should parse @TsED.Groups("!creation")', () => {
|
|
49
|
+
expect(parseDocumentationAttributes('/// @TsED.Groups("!creation")')).toEqual([
|
|
50
|
+
{
|
|
51
|
+
arguments: ['"!creation"'],
|
|
52
|
+
content: '@TsED.Groups("!creation")',
|
|
53
|
+
name: "Groups"
|
|
54
|
+
}
|
|
55
|
+
]);
|
|
56
|
+
});
|
|
57
|
+
it('should parse @TsED.Groups(type: "test")', () => {
|
|
58
|
+
expect(parseDocumentationAttributes('/// @TsED.Groups(type: "test")')).toEqual([
|
|
59
|
+
{
|
|
60
|
+
arguments: [
|
|
61
|
+
{
|
|
62
|
+
type: "test"
|
|
63
|
+
}
|
|
64
|
+
],
|
|
65
|
+
content: '@TsED.Groups(type: "test")',
|
|
66
|
+
name: "Groups"
|
|
67
|
+
}
|
|
68
|
+
]);
|
|
69
|
+
});
|
|
70
|
+
it("should ignore other comments", () => {
|
|
71
|
+
expect(parseDocumentationAttributes("/// comments")).toEqual([]);
|
|
72
|
+
});
|
|
73
|
+
});
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
export const attributeRegex = /(@TsED\.)+([A-z])+(\()(.*)(\))+/;
|
|
2
|
+
export const attributeNameRegex = /(?:\.)+([A-Za-z])+(?:\()+/;
|
|
3
|
+
export const attributeArgsRegex = /(?:\()+([A-Za-z])+\:+(.+)+(?:\))+/;
|
|
4
|
+
export const argsRegex = /(?:\()+((.+))+(?:\))+/;
|
|
5
|
+
|
|
6
|
+
export function parseDocumentationAttributes(documentation: string | undefined): {name: string; content: string; arguments: string[]}[] {
|
|
7
|
+
if (!documentation) {
|
|
8
|
+
return [];
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
return documentation
|
|
12
|
+
.split("\n")
|
|
13
|
+
.map((current) => {
|
|
14
|
+
const attribute = current.match(attributeRegex)?.[0];
|
|
15
|
+
|
|
16
|
+
if (!attribute) {
|
|
17
|
+
return;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
const attributeName = current.match(attributeNameRegex)?.[0]?.slice(1, -1);
|
|
21
|
+
const rawAttributeArgs = attribute.match(attributeArgsRegex)?.[0]?.slice(1, -1);
|
|
22
|
+
const args: any[] = [];
|
|
23
|
+
|
|
24
|
+
if (rawAttributeArgs) {
|
|
25
|
+
const splitRawArgsArray = rawAttributeArgs.split(",").map((it) => it.trim());
|
|
26
|
+
const parsedAttributeArgs =
|
|
27
|
+
splitRawArgsArray &&
|
|
28
|
+
(Object.fromEntries(
|
|
29
|
+
splitRawArgsArray.map((it) => {
|
|
30
|
+
const [key, value] = it.split(": ");
|
|
31
|
+
return [key, JSON.parse(value)];
|
|
32
|
+
})
|
|
33
|
+
) as Partial<object>);
|
|
34
|
+
|
|
35
|
+
args.push(parsedAttributeArgs);
|
|
36
|
+
} else {
|
|
37
|
+
const inputs = attribute
|
|
38
|
+
.match(argsRegex)?.[0]
|
|
39
|
+
?.slice(1, -1)
|
|
40
|
+
?.split(",")
|
|
41
|
+
.map((it) => it.trim());
|
|
42
|
+
|
|
43
|
+
args.push(...(inputs || []));
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
return {
|
|
47
|
+
name: attributeName,
|
|
48
|
+
content: attribute,
|
|
49
|
+
arguments: args
|
|
50
|
+
};
|
|
51
|
+
})
|
|
52
|
+
.map((options) => {
|
|
53
|
+
if (options?.name === "Ignore") {
|
|
54
|
+
const args = options.arguments.join(" && ");
|
|
55
|
+
|
|
56
|
+
return {
|
|
57
|
+
...options,
|
|
58
|
+
arguments: args.length > 0 ? [`(value: any, ctx: any) => ${args}`] : []
|
|
59
|
+
};
|
|
60
|
+
}
|
|
61
|
+
return options;
|
|
62
|
+
})
|
|
63
|
+
.filter(Boolean) as any[];
|
|
64
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import {promises as fs} from "fs";
|
|
2
|
+
import path from "path";
|
|
3
|
+
|
|
4
|
+
export default async function removeDir(dirPath: string, onlyContent: boolean) {
|
|
5
|
+
const dirEntries = await fs.readdir(dirPath, {withFileTypes: true});
|
|
6
|
+
await Promise.all(
|
|
7
|
+
dirEntries.map((dirEntry) => {
|
|
8
|
+
const fullPath = path.join(dirPath, dirEntry.name);
|
|
9
|
+
return dirEntry.isDirectory() ? removeDir(fullPath, false) : fs.unlink(fullPath);
|
|
10
|
+
})
|
|
11
|
+
);
|
|
12
|
+
if (!onlyContent) {
|
|
13
|
+
await fs.rmdir(dirPath);
|
|
14
|
+
}
|
|
15
|
+
}
|
package/src/generator.ts
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
#!/usr/bin/env ts-node
|
|
2
|
+
import * as helpers from "@prisma/generator-helper";
|
|
3
|
+
import {join} from "path";
|
|
4
|
+
|
|
5
|
+
import {generate} from "./cli/prismaGenerator.js";
|
|
6
|
+
|
|
7
|
+
const rootDir = import.meta.dirname; // automatically replaced by tsed tools on build
|
|
8
|
+
export const defaultOutput = join(rootDir, "..", ".schema");
|
|
9
|
+
export const packageDir = join(rootDir, "..", "..");
|
|
10
|
+
|
|
11
|
+
helpers.generatorHandler({
|
|
12
|
+
onManifest: () => ({
|
|
13
|
+
defaultOutput,
|
|
14
|
+
prettyName: "Ts.ED integration",
|
|
15
|
+
requiresGenerators: ["prisma-client-js"]
|
|
16
|
+
}),
|
|
17
|
+
onGenerate: generate({defaultOutput, packageDir})
|
|
18
|
+
});
|
package/src/index.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "./generator.js";
|