@zenstackhq/trpc 0.6.0-pre.19 → 1.0.0-alpha.100
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/README.md +3 -1
- package/generator.js +164 -54
- package/generator.js.map +1 -1
- package/helpers.d.ts +1 -2
- package/helpers.js +15 -17
- package/helpers.js.map +1 -1
- package/package.json +12 -4
- package/zod/generator.js +3 -10
- package/zod/generator.js.map +1 -1
- package/zod/transformer.d.ts +0 -5
- package/zod/transformer.js +24 -51
- package/zod/transformer.js.map +1 -1
- package/zod/helpers/aggregate-helpers.d.ts +0 -5
- package/zod/helpers/aggregate-helpers.js +0 -64
- package/zod/helpers/aggregate-helpers.js.map +0 -1
- package/zod/helpers/comments-helpers.d.ts +0 -6
- package/zod/helpers/comments-helpers.js +0 -99
- package/zod/helpers/comments-helpers.js.map +0 -1
- package/zod/helpers/helpers.d.ts +0 -8
- package/zod/helpers/helpers.js +0 -39
- package/zod/helpers/helpers.js.map +0 -1
- package/zod/helpers/include-helpers.d.ts +0 -2
- package/zod/helpers/include-helpers.js +0 -79
- package/zod/helpers/include-helpers.js.map +0 -1
- package/zod/helpers/index.d.ts +0 -4
- package/zod/helpers/index.js +0 -21
- package/zod/helpers/index.js.map +0 -1
- package/zod/helpers/model-helpers.d.ts +0 -6
- package/zod/helpers/model-helpers.js +0 -39
- package/zod/helpers/model-helpers.js.map +0 -1
- package/zod/helpers/modelArgs-helpers.d.ts +0 -2
- package/zod/helpers/modelArgs-helpers.js +0 -62
- package/zod/helpers/modelArgs-helpers.js.map +0 -1
- package/zod/helpers/mongodb-helpers.d.ts +0 -3
- package/zod/helpers/mongodb-helpers.js +0 -65
- package/zod/helpers/mongodb-helpers.js.map +0 -1
- package/zod/helpers/select-helpers.d.ts +0 -2
- package/zod/helpers/select-helpers.js +0 -137
- package/zod/helpers/select-helpers.js.map +0 -1
package/README.md
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
1
|
# ZenStack tRPC plugin
|
|
2
2
|
|
|
3
|
-
This package contains ZenStack plugin for tRPC.
|
|
3
|
+
This package contains ZenStack plugin for tRPC. The implementation is based on [prisma-trpc-generator](https://github.com/omar-dulaimi/prisma-trpc-generator).
|
|
4
|
+
|
|
5
|
+
Visit [Homepage](https://zenstack.dev) for more details.
|
package/generator.js
CHANGED
|
@@ -24,46 +24,62 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
24
24
|
};
|
|
25
25
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
26
|
exports.generate = void 0;
|
|
27
|
+
const sdk_1 = require("@zenstackhq/sdk");
|
|
28
|
+
const change_case_1 = require("change-case");
|
|
27
29
|
const fs_1 = require("fs");
|
|
28
30
|
const path_1 = __importDefault(require("path"));
|
|
29
|
-
const generator_1 = require("./zod/generator");
|
|
30
31
|
const helpers_1 = require("./helpers");
|
|
31
32
|
const project_1 = require("./project");
|
|
32
33
|
const removeDir_1 = __importDefault(require("./utils/removeDir"));
|
|
33
|
-
const
|
|
34
|
+
const generator_1 = require("./zod/generator");
|
|
34
35
|
function generate(model, options, dmmf) {
|
|
35
36
|
return __awaiter(this, void 0, void 0, function* () {
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
37
|
+
let outDir = options.output;
|
|
38
|
+
if (!outDir) {
|
|
39
|
+
throw new sdk_1.PluginError('"output" option is required');
|
|
40
|
+
}
|
|
41
|
+
if (!path_1.default.isAbsolute(outDir)) {
|
|
42
|
+
// output dir is resolved relative to the schema file path
|
|
43
|
+
outDir = path_1.default.join(path_1.default.dirname(options.schemaPath), outDir);
|
|
44
|
+
}
|
|
45
|
+
yield fs_1.promises.mkdir(outDir, { recursive: true });
|
|
46
|
+
yield (0, removeDir_1.default)(outDir, true);
|
|
39
47
|
yield (0, generator_1.generate)(model, options, dmmf);
|
|
40
48
|
const prismaClientDmmf = dmmf;
|
|
41
49
|
const modelOperations = prismaClientDmmf.mappings.modelOperations;
|
|
42
50
|
const models = prismaClientDmmf.datamodel.models;
|
|
43
51
|
const hiddenModels = [];
|
|
44
52
|
(0, helpers_1.resolveModelsComments)(models, hiddenModels);
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
53
|
+
createAppRouter(outDir, modelOperations, hiddenModels);
|
|
54
|
+
createHelper(outDir);
|
|
55
|
+
yield project_1.project.save();
|
|
56
|
+
});
|
|
57
|
+
}
|
|
58
|
+
exports.generate = generate;
|
|
59
|
+
function createAppRouter(outDir, modelOperations, hiddenModels) {
|
|
60
|
+
const appRouter = project_1.project.createSourceFile(path_1.default.resolve(outDir, 'routers', `index.ts`), undefined, {
|
|
61
|
+
overwrite: true,
|
|
62
|
+
});
|
|
63
|
+
appRouter.addStatements('/* eslint-disable */');
|
|
64
|
+
appRouter.addImportDeclarations([
|
|
65
|
+
{
|
|
66
|
+
namedImports: ['AnyRootConfig'],
|
|
67
|
+
moduleSpecifier: '@trpc/server',
|
|
68
|
+
},
|
|
69
|
+
{
|
|
70
|
+
namedImports: ['PrismaClient'],
|
|
71
|
+
moduleSpecifier: '@prisma/client',
|
|
72
|
+
},
|
|
73
|
+
{
|
|
74
|
+
namedImports: ['createRouterFactory'],
|
|
75
|
+
moduleSpecifier: '@trpc/server/dist/core/router',
|
|
76
|
+
},
|
|
77
|
+
{
|
|
78
|
+
namedImports: ['createBuilder'],
|
|
79
|
+
moduleSpecifier: '@trpc/server/dist/core/internals/procedureBuilder',
|
|
80
|
+
},
|
|
81
|
+
]);
|
|
82
|
+
appRouter.addStatements(`
|
|
67
83
|
export type BaseConfig = AnyRootConfig;
|
|
68
84
|
|
|
69
85
|
export type RouterFactory<Config extends BaseConfig> = ReturnType<
|
|
@@ -82,41 +98,39 @@ function generate(model, options, dmmf) {
|
|
|
82
98
|
}
|
|
83
99
|
|
|
84
100
|
`);
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
}
|
|
101
|
-
generateModelCreateRouter(project_1.project, model, operations, outputDir);
|
|
102
|
-
appRouter.addImportDeclaration({
|
|
103
|
-
defaultImport: `create${model}Router`,
|
|
104
|
-
moduleSpecifier: `./${model}.router`,
|
|
105
|
-
});
|
|
106
|
-
writer.writeLine(`${(0, change_case_1.camelCase)(model)}: create${model}Router<Config>(router, procedure),`);
|
|
101
|
+
const createFunction = appRouter.addFunction({
|
|
102
|
+
name: 'createRouter<Config extends BaseConfig>',
|
|
103
|
+
parameters: [
|
|
104
|
+
{ name: 'router', type: 'RouterFactory<Config>' },
|
|
105
|
+
{ name: 'procedure', type: 'ProcBuilder<Config>' },
|
|
106
|
+
],
|
|
107
|
+
isExported: true,
|
|
108
|
+
});
|
|
109
|
+
createFunction.setBodyText((writer) => {
|
|
110
|
+
writer.write('return router(');
|
|
111
|
+
writer.block(() => {
|
|
112
|
+
for (const modelOperation of modelOperations) {
|
|
113
|
+
const { model } = modelOperation, operations = __rest(modelOperation, ["model"]);
|
|
114
|
+
if (hiddenModels.includes(model)) {
|
|
115
|
+
continue;
|
|
107
116
|
}
|
|
108
|
-
|
|
109
|
-
|
|
117
|
+
generateModelCreateRouter(project_1.project, model, operations, outDir);
|
|
118
|
+
appRouter.addImportDeclaration({
|
|
119
|
+
defaultImport: `create${model}Router`,
|
|
120
|
+
moduleSpecifier: `./${model}.router`,
|
|
121
|
+
});
|
|
122
|
+
writer.writeLine(`${(0, change_case_1.camelCase)(model)}: create${model}Router<Config>(router, procedure),`);
|
|
123
|
+
}
|
|
110
124
|
});
|
|
111
|
-
|
|
112
|
-
yield project_1.project.save();
|
|
125
|
+
writer.write(');');
|
|
113
126
|
});
|
|
127
|
+
appRouter.formatText();
|
|
114
128
|
}
|
|
115
|
-
exports.generate = generate;
|
|
116
129
|
function generateModelCreateRouter(project, model, operations, outputDir) {
|
|
117
130
|
const modelRouter = project.createSourceFile(path_1.default.resolve(outputDir, 'routers', `${model}.router.ts`), undefined, {
|
|
118
131
|
overwrite: true,
|
|
119
132
|
});
|
|
133
|
+
modelRouter.addStatements('/* eslint-disable */');
|
|
120
134
|
modelRouter.addImportDeclarations([
|
|
121
135
|
{
|
|
122
136
|
namedImports: ['type RouterFactory', 'type ProcBuilder', 'type BaseConfig', 'db'],
|
|
@@ -124,6 +138,7 @@ function generateModelCreateRouter(project, model, operations, outputDir) {
|
|
|
124
138
|
},
|
|
125
139
|
]);
|
|
126
140
|
(0, helpers_1.generateRouterSchemaImports)(modelRouter, model);
|
|
141
|
+
(0, helpers_1.generateHelperImport)(modelRouter);
|
|
127
142
|
modelRouter
|
|
128
143
|
.addFunction({
|
|
129
144
|
name: 'createRouter<Config extends BaseConfig>',
|
|
@@ -149,4 +164,99 @@ function generateModelCreateRouter(project, model, operations, outputDir) {
|
|
|
149
164
|
});
|
|
150
165
|
modelRouter.formatText();
|
|
151
166
|
}
|
|
167
|
+
function createHelper(outDir) {
|
|
168
|
+
const sf = project_1.project.createSourceFile(path_1.default.resolve(outDir, 'helper.ts'), undefined, {
|
|
169
|
+
overwrite: true,
|
|
170
|
+
});
|
|
171
|
+
sf.addStatements(`import { TRPCError } from '@trpc/server';`);
|
|
172
|
+
sf.addStatements(`import { isPrismaClientKnownRequestError } from '${sdk_1.RUNTIME_PACKAGE}';`);
|
|
173
|
+
const checkMutate = sf.addFunction({
|
|
174
|
+
name: 'checkMutate',
|
|
175
|
+
typeParameters: [{ name: 'T' }],
|
|
176
|
+
parameters: [
|
|
177
|
+
{
|
|
178
|
+
name: 'promise',
|
|
179
|
+
type: 'Promise<T>',
|
|
180
|
+
},
|
|
181
|
+
],
|
|
182
|
+
isAsync: true,
|
|
183
|
+
isExported: true,
|
|
184
|
+
returnType: 'Promise<T | undefined>',
|
|
185
|
+
});
|
|
186
|
+
checkMutate.setBodyText(`try {
|
|
187
|
+
return await promise;
|
|
188
|
+
} catch (err: any) {
|
|
189
|
+
if (isPrismaClientKnownRequestError(err)) {
|
|
190
|
+
if (err.code === 'P2004') {
|
|
191
|
+
if (err.meta?.reason === '${sdk_1.CrudFailureReason.RESULT_NOT_READABLE}') {
|
|
192
|
+
// unable to readback data
|
|
193
|
+
return undefined;
|
|
194
|
+
} else {
|
|
195
|
+
// rejected by policy
|
|
196
|
+
throw new TRPCError({
|
|
197
|
+
code: 'FORBIDDEN',
|
|
198
|
+
message: err.message,
|
|
199
|
+
cause: err,
|
|
200
|
+
});
|
|
201
|
+
}
|
|
202
|
+
} else {
|
|
203
|
+
// request error
|
|
204
|
+
throw new TRPCError({
|
|
205
|
+
code: 'BAD_REQUEST',
|
|
206
|
+
message: err.message,
|
|
207
|
+
cause: err,
|
|
208
|
+
});
|
|
209
|
+
}
|
|
210
|
+
} else {
|
|
211
|
+
throw err;
|
|
212
|
+
}
|
|
213
|
+
}
|
|
214
|
+
`);
|
|
215
|
+
checkMutate.formatText();
|
|
216
|
+
const checkRead = sf.addFunction({
|
|
217
|
+
name: 'checkRead',
|
|
218
|
+
typeParameters: [{ name: 'T' }],
|
|
219
|
+
parameters: [
|
|
220
|
+
{
|
|
221
|
+
name: 'promise',
|
|
222
|
+
type: 'Promise<T>',
|
|
223
|
+
},
|
|
224
|
+
],
|
|
225
|
+
isAsync: true,
|
|
226
|
+
isExported: true,
|
|
227
|
+
returnType: 'Promise<T>',
|
|
228
|
+
});
|
|
229
|
+
checkRead.setBodyText(`try {
|
|
230
|
+
return await promise;
|
|
231
|
+
} catch (err: any) {
|
|
232
|
+
if (isPrismaClientKnownRequestError(err)) {
|
|
233
|
+
if (err.code === 'P2004') {
|
|
234
|
+
// rejected by policy
|
|
235
|
+
throw new TRPCError({
|
|
236
|
+
code: 'FORBIDDEN',
|
|
237
|
+
message: err.message,
|
|
238
|
+
cause: err,
|
|
239
|
+
});
|
|
240
|
+
} else if (err.code === 'P2025') {
|
|
241
|
+
// not found
|
|
242
|
+
throw new TRPCError({
|
|
243
|
+
code: 'NOT_FOUND',
|
|
244
|
+
message: err.message,
|
|
245
|
+
cause: err,
|
|
246
|
+
});
|
|
247
|
+
} else {
|
|
248
|
+
// request error
|
|
249
|
+
throw new TRPCError({
|
|
250
|
+
code: 'BAD_REQUEST',
|
|
251
|
+
message: err.message,
|
|
252
|
+
cause: err,
|
|
253
|
+
})
|
|
254
|
+
}
|
|
255
|
+
} else {
|
|
256
|
+
throw err;
|
|
257
|
+
}
|
|
258
|
+
}
|
|
259
|
+
`);
|
|
260
|
+
checkRead.formatText();
|
|
261
|
+
}
|
|
152
262
|
//# sourceMappingURL=generator.js.map
|
package/generator.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"generator.js","sourceRoot":"","sources":["../src/generator.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;
|
|
1
|
+
{"version":3,"file":"generator.js","sourceRoot":"","sources":["../src/generator.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;AACA,yCAAiG;AAEjG,6CAAwC;AACxC,2BAAoC;AACpC,gDAAwB;AAExB,uCAMmB;AACnB,uCAAoC;AACpC,kEAA0C;AAC1C,+CAAiE;AAEjE,SAAsB,QAAQ,CAAC,KAAY,EAAE,OAAsB,EAAE,IAAmB;;QACpF,IAAI,MAAM,GAAG,OAAO,CAAC,MAAgB,CAAC;QACtC,IAAI,CAAC,MAAM,EAAE;YACT,MAAM,IAAI,iBAAW,CAAC,6BAA6B,CAAC,CAAC;SACxD;QAED,IAAI,CAAC,cAAI,CAAC,UAAU,CAAC,MAAM,CAAC,EAAE;YAC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C,WAAW,CAAC;QAC7B,IAAI,EAAE,WAAW;QACjB,cAAc,EAAE,CAAC,EAAE,IAAI,EAAE,GAAG,EAAE,CAAC;QAC/B,UAAU,EAAE;YACR;gBACI,IAAI,EAAE,SAAS;gBACf,IAAI,EAAE,YAAY;aACrB;SACJ;QACD,OAAO,EAAE,IAAI;QACb,UAAU,EAAE,IAAI;QAChB,UAAU,EAAE,YAAY;KAC3B,CAAC,CAAC;IAEH,SAAS,CAAC,WAAW,CACjB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;KA8BH,CACA,CAAC;IACF,SAAS,CAAC,UAAU,EAAE,CAAC;AAC3B,CAAC"}
|
package/helpers.d.ts
CHANGED
|
@@ -1,9 +1,8 @@
|
|
|
1
1
|
import { DMMF } from '@prisma/generator-helper';
|
|
2
2
|
import { CodeBlockWriter, SourceFile } from 'ts-morph';
|
|
3
|
-
export declare const generatetRPCImport: (sourceFile: SourceFile) => void;
|
|
4
|
-
export declare const generateRouterImport: (sourceFile: SourceFile, modelNamePlural: string, modelNameCamelCase: string) => void;
|
|
5
3
|
export declare function generateProcedure(writer: CodeBlockWriter, opType: string, typeName: string, modelName: string, baseOpType: string): void;
|
|
6
4
|
export declare function generateRouterSchemaImports(sourceFile: SourceFile, name: string): void;
|
|
5
|
+
export declare function generateHelperImport(sourceFile: SourceFile): void;
|
|
7
6
|
export declare const getInputTypeByOpName: (opName: string, modelName: string) => string | undefined;
|
|
8
7
|
export declare const getProcedureTypeByOpName: (opName: string) => string | undefined;
|
|
9
8
|
export declare function resolveModelsComments(models: DMMF.Model[], hiddenModels: string[]): void;
|
package/helpers.js
CHANGED
|
@@ -1,32 +1,30 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.resolveModelsComments = exports.getProcedureTypeByOpName = exports.getInputTypeByOpName = exports.
|
|
3
|
+
exports.resolveModelsComments = exports.getProcedureTypeByOpName = exports.getInputTypeByOpName = exports.generateHelperImport = exports.generateRouterSchemaImports = exports.generateProcedure = void 0;
|
|
4
4
|
const uncapitalizeFirstLetter_1 = require("./utils/uncapitalizeFirstLetter");
|
|
5
|
-
const generatetRPCImport = (sourceFile) => {
|
|
6
|
-
sourceFile.addImportDeclaration({
|
|
7
|
-
moduleSpecifier: '@trpc/server',
|
|
8
|
-
namespaceImport: 'trpc',
|
|
9
|
-
});
|
|
10
|
-
};
|
|
11
|
-
exports.generatetRPCImport = generatetRPCImport;
|
|
12
|
-
const generateRouterImport = (sourceFile, modelNamePlural, modelNameCamelCase) => {
|
|
13
|
-
sourceFile.addImportDeclaration({
|
|
14
|
-
moduleSpecifier: `./${modelNameCamelCase}.router`,
|
|
15
|
-
namedImports: [`${modelNamePlural}Router`],
|
|
16
|
-
});
|
|
17
|
-
};
|
|
18
|
-
exports.generateRouterImport = generateRouterImport;
|
|
19
5
|
function generateProcedure(writer, opType, typeName, modelName, baseOpType) {
|
|
20
6
|
const procType = (0, exports.getProcedureTypeByOpName)(baseOpType);
|
|
21
|
-
|
|
22
|
-
|
|
7
|
+
const prismaMethod = opType.replace('One', '');
|
|
8
|
+
if (procType === 'query') {
|
|
9
|
+
writer.write(`
|
|
10
|
+
${opType}: procedure.input(${typeName}).query(({ctx, input}) => checkRead(db(ctx).${(0, uncapitalizeFirstLetter_1.uncapitalizeFirstLetter)(modelName)}.${prismaMethod}(input))),
|
|
11
|
+
`);
|
|
12
|
+
}
|
|
13
|
+
else if (procType === 'mutation') {
|
|
14
|
+
writer.write(`
|
|
15
|
+
${opType}: procedure.input(${typeName}).mutation(async ({ctx, input}) => checkMutate(db(ctx).${(0, uncapitalizeFirstLetter_1.uncapitalizeFirstLetter)(modelName)}.${prismaMethod}(input))),
|
|
23
16
|
`);
|
|
17
|
+
}
|
|
24
18
|
}
|
|
25
19
|
exports.generateProcedure = generateProcedure;
|
|
26
20
|
function generateRouterSchemaImports(sourceFile, name) {
|
|
27
21
|
sourceFile.addStatements(`import { ${name}Schema } from '../schemas/${name}.schema';`);
|
|
28
22
|
}
|
|
29
23
|
exports.generateRouterSchemaImports = generateRouterSchemaImports;
|
|
24
|
+
function generateHelperImport(sourceFile) {
|
|
25
|
+
sourceFile.addStatements(`import { checkRead, checkMutate } from '../helper';`);
|
|
26
|
+
}
|
|
27
|
+
exports.generateHelperImport = generateHelperImport;
|
|
30
28
|
const getInputTypeByOpName = (opName, modelName) => {
|
|
31
29
|
let inputType;
|
|
32
30
|
switch (opName) {
|
package/helpers.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"helpers.js","sourceRoot":"","sources":["../src/helpers.ts"],"names":[],"mappings":";;;AAEA,6EAA0E;
|
|
1
|
+
{"version":3,"file":"helpers.js","sourceRoot":"","sources":["../src/helpers.ts"],"names":[],"mappings":";;;AAEA,6EAA0E;AAE1E,SAAgB,iBAAiB,CAC7B,MAAuB,EACvB,MAAc,EACd,QAAgB,EAChB,SAAiB,EACjB,UAAkB;IAElB,MAAM,QAAQ,GAAG,IAAA,gCAAwB,EAAC,UAAU,CAAC,CAAC;IACtD,MAAM,YAAY,GAAG,MAAM,CAAC,OAAO,CAAC,KAAK,EAAE,EAAE,CAAC,CAAC;IAE/C,IAAI,QAAQ,KAAK,OAAO,EAAE;QACtB,MAAM,CAAC,KAAK,CAAC;UACX,MAAM,qBAAqB,QAAQ,+CAA+C,IAAA,iDAAuB,EACvG,SAAS,CACZ,IAAI,YAAY;KACpB,CAAC,CAAC;KACF;SAAM,IAAI,QAAQ,KAAK,UAAU,EAAE;QAChC,MAAM,CAAC,KAAK,CAAC;UACX,MAAM,qBAAqB,QAAQ,0DAA0D,IAAA,iDAAuB,EAClH,SAAS,CACZ,IAAI,YAAY;KACpB,CAAC,CAAC;KACF;AACL,CAAC;AAvBD,8CAuBC;AAED,SAAgB,2BAA2B,CAAC,UAAsB,EAAE,IAAY;IAC5E,UAAU,CAAC,aAAa,CAAC,YAAY,IAAI,6BAA6B,IAAI,WAAW,CAAC,CAAC;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D,IAAI,mBAAmB,CAAC,IAAI,EAAE;gBAC1B,YAAY,CAAC,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;aACjC;SACJ;KACJ;AACL,CAAC;AAhCD,sDAgCC"}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@zenstackhq/trpc",
|
|
3
3
|
"displayName": "ZenStack plugin for tRPC",
|
|
4
|
-
"version": "0.
|
|
4
|
+
"version": "1.0.0-alpha.100",
|
|
5
5
|
"description": "ZenStack plugin for tRPC",
|
|
6
6
|
"main": "index.js",
|
|
7
7
|
"repository": {
|
|
@@ -19,17 +19,25 @@
|
|
|
19
19
|
"@prisma/generator-helper": "^4.7.1",
|
|
20
20
|
"@prisma/internals": "^4.7.1",
|
|
21
21
|
"change-case": "^4.1.2",
|
|
22
|
+
"prettier": "^2.8.3",
|
|
22
23
|
"ts-morph": "^16.0.0",
|
|
24
|
+
"tslib": "^2.4.1",
|
|
23
25
|
"zod": "^3.19.1",
|
|
24
|
-
"@zenstackhq/sdk": "0.
|
|
26
|
+
"@zenstackhq/sdk": "1.0.0-alpha.100"
|
|
25
27
|
},
|
|
26
28
|
"devDependencies": {
|
|
29
|
+
"@types/jest": "^29.5.0",
|
|
30
|
+
"@types/prettier": "^2.7.2",
|
|
31
|
+
"copyfiles": "^2.4.1",
|
|
32
|
+
"jest": "^29.5.0",
|
|
27
33
|
"rimraf": "^3.0.2",
|
|
28
|
-
"
|
|
34
|
+
"ts-jest": "^29.0.5",
|
|
35
|
+
"typescript": "^4.9.4",
|
|
36
|
+
"@zenstackhq/testtools": "1.0.0-alpha.100"
|
|
29
37
|
},
|
|
30
38
|
"scripts": {
|
|
31
39
|
"clean": "rimraf dist",
|
|
32
|
-
"build": "pnpm lint && pnpm clean && tsc &&
|
|
40
|
+
"build": "pnpm lint && pnpm clean && tsc && copyfiles ./package.json ./README.md ./LICENSE dist",
|
|
33
41
|
"watch": "tsc --watch",
|
|
34
42
|
"lint": "eslint src --ext ts",
|
|
35
43
|
"publish-dev": "pnpm publish --tag dev"
|
package/zod/generator.js
CHANGED
|
@@ -15,9 +15,8 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
15
15
|
exports.generate = void 0;
|
|
16
16
|
const sdk_1 = require("@zenstackhq/sdk");
|
|
17
17
|
const ast_1 = require("@zenstackhq/sdk/ast");
|
|
18
|
+
const dmmf_helpers_1 = require("@zenstackhq/sdk/dmmf-helpers");
|
|
18
19
|
const fs_1 = require("fs");
|
|
19
|
-
const helpers_1 = require("./helpers");
|
|
20
|
-
const aggregate_helpers_1 = require("./helpers/aggregate-helpers");
|
|
21
20
|
const transformer_1 = __importDefault(require("./transformer"));
|
|
22
21
|
const removeDir_1 = __importDefault(require("./utils/removeDir"));
|
|
23
22
|
function generate(model, options, dmmf) {
|
|
@@ -28,21 +27,15 @@ function generate(model, options, dmmf) {
|
|
|
28
27
|
const modelOperations = prismaClientDmmf.mappings.modelOperations;
|
|
29
28
|
const inputObjectTypes = prismaClientDmmf.schema.inputObjectTypes.prisma;
|
|
30
29
|
const outputObjectTypes = prismaClientDmmf.schema.outputObjectTypes.prisma;
|
|
31
|
-
const enumTypes = prismaClientDmmf.schema.enumTypes;
|
|
32
30
|
const models = prismaClientDmmf.datamodel.models;
|
|
33
|
-
const hiddenModels = [];
|
|
34
|
-
const hiddenFields = [];
|
|
35
|
-
(0, helpers_1.resolveModelsComments)(models, modelOperations, enumTypes, hiddenModels, hiddenFields);
|
|
36
31
|
yield generateEnumSchemas(prismaClientDmmf.schema.enumTypes.prisma, (_b = prismaClientDmmf.schema.enumTypes.model) !== null && _b !== void 0 ? _b : []);
|
|
37
32
|
const dataSource = model.declarations.find((d) => (0, ast_1.isDataSource)(d));
|
|
38
33
|
const dataSourceProvider = (0, sdk_1.getLiteral)((_c = dataSource === null || dataSource === void 0 ? void 0 : dataSource.fields.find((f) => f.name === 'provider')) === null || _c === void 0 ? void 0 : _c.value);
|
|
39
34
|
transformer_1.default.provider = dataSourceProvider;
|
|
40
35
|
const generatorConfigOptions = {};
|
|
41
36
|
Object.entries(options).forEach(([k, v]) => (generatorConfigOptions[k] = v));
|
|
42
|
-
|
|
43
|
-
(0,
|
|
44
|
-
const aggregateOperationSupport = (0, aggregate_helpers_1.resolveAggregateOperationSupport)(inputObjectTypes);
|
|
45
|
-
(0, helpers_1.hideInputObjectTypesAndRelatedFields)(inputObjectTypes, hiddenModels, hiddenFields);
|
|
37
|
+
(0, dmmf_helpers_1.addMissingInputObjectTypes)(inputObjectTypes, outputObjectTypes, models);
|
|
38
|
+
const aggregateOperationSupport = (0, dmmf_helpers_1.resolveAggregateOperationSupport)(inputObjectTypes);
|
|
46
39
|
yield generateObjectSchemas(inputObjectTypes);
|
|
47
40
|
yield generateModelSchemas(models, modelOperations, aggregateOperationSupport);
|
|
48
41
|
});
|
package/zod/generator.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"generator.js","sourceRoot":"","sources":["../../src/zod/generator.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAEA,yCAA4D;AAC5D,6CAAsE;AACtE,2BAAoC;AACpC,
|
|
1
|
+
{"version":3,"file":"generator.js","sourceRoot":"","sources":["../../src/zod/generator.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAEA,yCAA4D;AAC5D,6CAAsE;AACtE,+DAIsC;AACtC,2BAAoC;AACpC,gEAAwC;AACxC,kEAA0C;AAE1C,SAAsB,QAAQ,CAAC,KAAY,EAAE,OAAsB,EAAE,IAAmB;;;QACpF,MAAM,0BAA0B,CAAC,MAAC,OAAO,CAAC,MAAiB,mCAAI,aAAa,CAAC,CAAC;QAE9E,MAAM,gBAAgB,GAAG,IAAI,CAAC;QAE9B,MAAM,eAAe,GAAG,gBAAgB,CAAC,QAAQ,CAAC,eAAe,CAAC;QAClE,MAAM,gBAAgB,GAAG,gBAAgB,CAAC,MAAM,CAAC,gBAAgB,CAAC,MAAM,CAAC;Q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WAAW,GAAG,IAAI,qBAAW,CAAC;YAChC,MAAM;YACN,eAAe;YACf,yBAAyB;SAC5B,CAAC,CAAC;QACH,MAAM,WAAW,CAAC,oBAAoB,EAAE,CAAC;IAC7C,CAAC;CAAA"}
|
package/zod/transformer.d.ts
CHANGED
|
@@ -17,12 +17,8 @@ export default class Transformer {
|
|
|
17
17
|
private hasJson;
|
|
18
18
|
private static prismaClientOutputPath;
|
|
19
19
|
private static isCustomPrismaClientOutputPath;
|
|
20
|
-
private static isGenerateSelect;
|
|
21
|
-
private static isGenerateInclude;
|
|
22
20
|
constructor(params: TransformerParams);
|
|
23
21
|
static setOutputPath(outPath: string): void;
|
|
24
|
-
static setIsGenerateSelect(isGenerateSelect: boolean): void;
|
|
25
|
-
static setIsGenerateInclude(isGenerateInclude: boolean): void;
|
|
26
22
|
static getOutputPath(): string;
|
|
27
23
|
static setPrismaClientOutputPath(prismaClientCustomPath: string): void;
|
|
28
24
|
generateEnumSchemas(): Promise<void>;
|
|
@@ -56,7 +52,6 @@ export default class Transformer {
|
|
|
56
52
|
resolveModelQuerySchemaName(modelName: string, queryName: string): string;
|
|
57
53
|
wrapWithZodUnion(zodStringFields: string[]): string;
|
|
58
54
|
wrapWithZodObject(zodStringFields: string | string[]): string;
|
|
59
|
-
resolveObjectSchemaName(): string;
|
|
60
55
|
generateModelSchemas(): Promise<void>;
|
|
61
56
|
generateImportStatements(imports: (string | undefined)[]): string;
|
|
62
57
|
resolveSelectIncludeImportAndZodSchemaLine(model: PrismaDMMF.Model): {
|