@stryke/prisma-trpc-generator 0.2.0 → 0.2.1
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/chunk-6UJ53OQ6.js +19 -0
- package/dist/chunk-GQ7ABBSV.js +160 -0
- package/dist/chunk-LVOPI6NH.js +18 -0
- package/dist/chunk-RYVIOFDO.js +333 -0
- package/dist/chunk-SHUYVCID.js +6 -0
- package/dist/chunk-V6DNCMCB.js +31 -0
- package/dist/config.cjs +52 -18
- package/dist/config.js +7 -0
- package/dist/generator.cjs +1 -3
- package/dist/generator.js +7 -0
- package/dist/helpers.cjs +360 -206
- package/dist/helpers.js +29 -0
- package/dist/index.cjs +520 -8
- package/dist/index.js +6 -0
- package/dist/prisma-generator.cjs +502 -77
- package/dist/prisma-generator.js +10 -0
- package/dist/project.cjs +36 -13
- package/dist/project.js +7 -0
- package/package.json +59 -151
- package/dist/config.d.ts +0 -28
- package/dist/config.mjs +0 -1
- package/dist/generator.d.ts +0 -2
- package/dist/generator.mjs +0 -2
- package/dist/helpers.d.ts +0 -18
- package/dist/helpers.mjs +0 -26
- package/dist/index.d.ts +0 -1
- package/dist/index.mjs +0 -1
- package/dist/prisma-generator.d.ts +0 -2
- package/dist/prisma-generator.mjs +0 -6
- package/dist/project.d.ts +0 -2
- package/dist/project.mjs +0 -1
- package/dist/utils/getRelativePath.cjs +0 -18
- package/dist/utils/getRelativePath.d.ts +0 -1
- package/dist/utils/getRelativePath.mjs +0 -1
- package/dist/utils/removeDir.cjs +0 -18
- package/dist/utils/removeDir.d.ts +0 -1
- package/dist/utils/removeDir.mjs +0 -1
- package/dist/utils/uncapitalizeFirstLetter.cjs +0 -8
- package/dist/utils/uncapitalizeFirstLetter.d.ts +0 -1
- package/dist/utils/uncapitalizeFirstLetter.mjs +0 -1
package/dist/helpers.cjs
CHANGED
|
@@ -1,221 +1,375 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __create = Object.create;
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
+
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
9
|
+
var __export = (target, all) => {
|
|
10
|
+
for (var name in all)
|
|
11
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
12
|
+
};
|
|
13
|
+
var __copyProps = (to, from, except, desc) => {
|
|
14
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
15
|
+
for (let key of __getOwnPropNames(from))
|
|
16
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
17
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
18
|
+
}
|
|
19
|
+
return to;
|
|
20
|
+
};
|
|
21
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
22
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
23
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
24
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
25
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
26
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
27
|
+
mod
|
|
28
|
+
));
|
|
29
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
2
30
|
|
|
3
|
-
|
|
4
|
-
|
|
31
|
+
// src/helpers.ts
|
|
32
|
+
var helpers_exports = {};
|
|
33
|
+
__export(helpers_exports, {
|
|
34
|
+
generateBaseRouter: () => generateBaseRouter,
|
|
35
|
+
generateCreateRouterImport: () => generateCreateRouterImport,
|
|
36
|
+
generateMiddlewareImport: () => generateMiddlewareImport,
|
|
37
|
+
generateProcedure: () => generateProcedure,
|
|
38
|
+
generateRPCImport: () => generateRPCImport,
|
|
39
|
+
generateRouterImport: () => generateRouterImport,
|
|
40
|
+
generateRouterSchemaImports: () => generateRouterSchemaImports,
|
|
41
|
+
generateShieldImport: () => generateShieldImport,
|
|
42
|
+
getInputTypeByOpName: () => getInputTypeByOpName,
|
|
43
|
+
getProcedureTypeByOpName: () => getProcedureTypeByOpName,
|
|
44
|
+
getRouterSchemaImportByOpName: () => getRouterSchemaImportByOpName,
|
|
45
|
+
resolveModelsComments: () => resolveModelsComments
|
|
5
46
|
});
|
|
6
|
-
exports
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
47
|
+
module.exports = __toCommonJS(helpers_exports);
|
|
48
|
+
var import_internals = require("@prisma/internals");
|
|
49
|
+
|
|
50
|
+
// src/utils/getRelativePath.ts
|
|
51
|
+
var import_node_path = __toESM(require("path"), 1);
|
|
52
|
+
function getRelativePath(outputPath, filePath, isOutsideOutputPath, schemaPath) {
|
|
53
|
+
const fromPath = import_node_path.default.join(outputPath, "routers", "helpers");
|
|
54
|
+
let toPath = import_node_path.default.join(outputPath, filePath);
|
|
55
|
+
if (isOutsideOutputPath) {
|
|
56
|
+
const schemaPathSplit = schemaPath?.split(import_node_path.default.sep);
|
|
57
|
+
const schemaPathWithoutFileAndExtension = schemaPathSplit.slice(0, schemaPathSplit.length - 1).join(import_node_path.default.posix.sep);
|
|
58
|
+
toPath = import_node_path.default.join(schemaPathWithoutFileAndExtension, filePath);
|
|
59
|
+
}
|
|
60
|
+
const newPath = import_node_path.default.relative(fromPath, toPath).split(import_node_path.default.sep).join(import_node_path.default.posix.sep);
|
|
61
|
+
return newPath;
|
|
62
|
+
}
|
|
63
|
+
__name(getRelativePath, "getRelativePath");
|
|
64
|
+
|
|
65
|
+
// src/utils/uncapitalizeFirstLetter.ts
|
|
66
|
+
var uncapitalizeFirstLetter = /* @__PURE__ */ __name((str) => {
|
|
67
|
+
return str.charAt(0).toLowerCase() + str.slice(1);
|
|
68
|
+
}, "uncapitalizeFirstLetter");
|
|
69
|
+
|
|
70
|
+
// src/helpers.ts
|
|
71
|
+
var getProcedureName = /* @__PURE__ */ __name((config) => {
|
|
72
|
+
return config.withShield ? "shieldedProcedure" : config.withMiddleware ? "protectedProcedure" : "publicProcedure";
|
|
73
|
+
}, "getProcedureName");
|
|
74
|
+
var generateCreateRouterImport = /* @__PURE__ */ __name(({ sourceFile, config }) => {
|
|
75
|
+
const imports = [
|
|
76
|
+
"t"
|
|
77
|
+
];
|
|
78
|
+
if (config) {
|
|
79
|
+
imports.push(getProcedureName(config));
|
|
80
|
+
}
|
|
81
|
+
sourceFile.addImportDeclaration({
|
|
82
|
+
moduleSpecifier: "./helpers/createRouter",
|
|
83
|
+
namedImports: imports
|
|
84
|
+
});
|
|
85
|
+
}, "generateCreateRouterImport");
|
|
86
|
+
var generateRPCImport = /* @__PURE__ */ __name((sourceFile) => {
|
|
87
|
+
sourceFile.addImportDeclaration({
|
|
88
|
+
moduleSpecifier: "@trpc/server",
|
|
89
|
+
namespaceImport: "trpc"
|
|
90
|
+
});
|
|
91
|
+
}, "generateRPCImport");
|
|
92
|
+
var generateShieldImport = /* @__PURE__ */ __name((sourceFile, options, value) => {
|
|
93
|
+
const outputDir = (0, import_internals.parseEnvValue)(options.generator.output);
|
|
94
|
+
let shieldPath = getRelativePath(outputDir, "shield/shield");
|
|
95
|
+
if (typeof value === "string") {
|
|
96
|
+
shieldPath = getRelativePath(outputDir, value, true, options.schemaPath);
|
|
97
|
+
}
|
|
98
|
+
sourceFile.addImportDeclaration({
|
|
99
|
+
moduleSpecifier: shieldPath,
|
|
100
|
+
namedImports: [
|
|
101
|
+
"permissions"
|
|
102
|
+
]
|
|
103
|
+
});
|
|
104
|
+
}, "generateShieldImport");
|
|
105
|
+
var generateMiddlewareImport = /* @__PURE__ */ __name((sourceFile, options) => {
|
|
106
|
+
const outputDir = (0, import_internals.parseEnvValue)(options.generator.output);
|
|
107
|
+
sourceFile.addImportDeclaration({
|
|
108
|
+
moduleSpecifier: getRelativePath(outputDir, "middleware"),
|
|
109
|
+
namedImports: [
|
|
110
|
+
"permissions"
|
|
111
|
+
]
|
|
112
|
+
});
|
|
113
|
+
}, "generateMiddlewareImport");
|
|
114
|
+
var generateRouterImport = /* @__PURE__ */ __name((sourceFile, modelNamePlural, modelNameCamelCase) => {
|
|
115
|
+
sourceFile.addImportDeclaration({
|
|
116
|
+
moduleSpecifier: `./${modelNameCamelCase}.router`,
|
|
117
|
+
namedImports: [
|
|
118
|
+
`${modelNamePlural}Router`
|
|
119
|
+
]
|
|
120
|
+
});
|
|
121
|
+
}, "generateRouterImport");
|
|
122
|
+
function generateBaseRouter(sourceFile, config, options) {
|
|
123
|
+
const outputDir = (0, import_internals.parseEnvValue)(options.generator.output);
|
|
124
|
+
sourceFile.addStatements(
|
|
125
|
+
/* ts */
|
|
126
|
+
`
|
|
127
|
+
import type { Context } from '${getRelativePath(outputDir, config.contextPath, true, options.schemaPath)}';
|
|
128
|
+
`
|
|
129
|
+
);
|
|
130
|
+
if (config.trpcOptionsPath) {
|
|
131
|
+
sourceFile.addStatements(
|
|
132
|
+
/* ts */
|
|
133
|
+
`
|
|
134
|
+
import trpcOptions from '${getRelativePath(outputDir, config.trpcOptionsPath, true, options.schemaPath)}';
|
|
135
|
+
`
|
|
136
|
+
);
|
|
137
|
+
}
|
|
138
|
+
sourceFile.addStatements(
|
|
139
|
+
/* ts */
|
|
140
|
+
`
|
|
141
|
+
export const t = trpc.initTRPC.context<Context>().create(${config.trpcOptionsPath ? "trpcOptions" : ""});
|
|
142
|
+
`
|
|
143
|
+
);
|
|
144
|
+
const middlewares = [];
|
|
145
|
+
if (config.withMiddleware && typeof config.withMiddleware === "boolean") {
|
|
146
|
+
sourceFile.addStatements(
|
|
147
|
+
/* ts */
|
|
148
|
+
`
|
|
71
149
|
export const globalMiddleware = t.middleware(async ({ ctx, next }) => {
|
|
72
150
|
console.log('inside middleware!')
|
|
73
151
|
return next()
|
|
74
|
-
});`
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
}
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
152
|
+
});`
|
|
153
|
+
);
|
|
154
|
+
middlewares.push({
|
|
155
|
+
type: "global",
|
|
156
|
+
value: (
|
|
157
|
+
/* ts */
|
|
158
|
+
`.use(globalMiddleware)`
|
|
159
|
+
)
|
|
160
|
+
});
|
|
161
|
+
}
|
|
162
|
+
if (config.withMiddleware && typeof config.withMiddleware === "string") {
|
|
163
|
+
sourceFile.addStatements(
|
|
164
|
+
/* ts */
|
|
165
|
+
`
|
|
166
|
+
import defaultMiddleware from '${getRelativePath(outputDir, config.withMiddleware, true, options.schemaPath)}';
|
|
167
|
+
`
|
|
168
|
+
);
|
|
169
|
+
sourceFile.addStatements(
|
|
170
|
+
/* ts */
|
|
171
|
+
`
|
|
172
|
+
export const globalMiddleware = t.middleware(defaultMiddleware);`
|
|
173
|
+
);
|
|
174
|
+
middlewares.push({
|
|
175
|
+
type: "global",
|
|
176
|
+
value: (
|
|
177
|
+
/* ts */
|
|
178
|
+
`.use(globalMiddleware)`
|
|
179
|
+
)
|
|
180
|
+
});
|
|
181
|
+
}
|
|
182
|
+
if (config.withShield) {
|
|
183
|
+
sourceFile.addStatements(
|
|
184
|
+
/* ts */
|
|
185
|
+
`
|
|
186
|
+
export const permissionsMiddleware = t.middleware(permissions); `
|
|
187
|
+
);
|
|
188
|
+
middlewares.push({
|
|
189
|
+
type: "shield",
|
|
190
|
+
value: (
|
|
191
|
+
/* ts */
|
|
192
|
+
`
|
|
87
193
|
.use(permissions)`
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
194
|
+
)
|
|
195
|
+
});
|
|
196
|
+
}
|
|
197
|
+
sourceFile.addStatements(
|
|
198
|
+
/* ts */
|
|
199
|
+
`
|
|
200
|
+
export const publicProcedure = t.procedure; `
|
|
201
|
+
);
|
|
202
|
+
if (middlewares.length > 0) {
|
|
203
|
+
const procName = getProcedureName(config);
|
|
204
|
+
middlewares.forEach((middleware, i) => {
|
|
205
|
+
if (i === 0) {
|
|
206
|
+
sourceFile.addStatements(
|
|
207
|
+
/* ts */
|
|
208
|
+
`
|
|
209
|
+
export const ${procName} = t.procedure
|
|
210
|
+
`
|
|
211
|
+
);
|
|
212
|
+
}
|
|
213
|
+
sourceFile.addStatements(
|
|
214
|
+
/* ts */
|
|
215
|
+
`
|
|
216
|
+
.use(${middleware.type === "shield" ? "permissionsMiddleware" : "globalMiddleware"})
|
|
217
|
+
`
|
|
218
|
+
);
|
|
97
219
|
});
|
|
98
220
|
}
|
|
99
221
|
}
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
222
|
+
__name(generateBaseRouter, "generateBaseRouter");
|
|
223
|
+
function generateProcedure(sourceFile, name, typeName, modelName, opType, baseOpType, config) {
|
|
224
|
+
let input = `input${!config.withZod ? " as any" : ""}`;
|
|
225
|
+
const nameWithoutModel = name.replace(modelName, "");
|
|
226
|
+
if (nameWithoutModel === "groupBy" && config.withZod) {
|
|
227
|
+
input = "{ where: input.where, orderBy: input.orderBy, by: input.by, having: input.having, take: input.take, skip: input.skip }";
|
|
228
|
+
}
|
|
229
|
+
sourceFile.addStatements(
|
|
230
|
+
/* ts */
|
|
231
|
+
`${config.showModelNameInProcedure ? name : nameWithoutModel}: ${getProcedureName(config)}
|
|
232
|
+
${config.withZod ? `.input(${typeName})` : ""}.${getProcedureTypeByOpName(baseOpType)}(async ({ ctx, input }) => {
|
|
233
|
+
const ${name} = await ctx.prisma.${uncapitalizeFirstLetter(modelName)}.${opType.replace("One", "")}(${input});
|
|
234
|
+
return ${name};
|
|
235
|
+
}),`
|
|
236
|
+
);
|
|
108
237
|
}
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
238
|
+
__name(generateProcedure, "generateProcedure");
|
|
239
|
+
function generateRouterSchemaImports(sourceFile, modelName, modelActions) {
|
|
240
|
+
sourceFile.addStatements(
|
|
241
|
+
/* ts */
|
|
242
|
+
[
|
|
243
|
+
// remove any duplicate import statements
|
|
244
|
+
...new Set(modelActions.map((opName) => getRouterSchemaImportByOpName(opName, modelName)))
|
|
245
|
+
].join("\n")
|
|
246
|
+
);
|
|
112
247
|
}
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
}
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
const
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
248
|
+
__name(generateRouterSchemaImports, "generateRouterSchemaImports");
|
|
249
|
+
var getRouterSchemaImportByOpName = /* @__PURE__ */ __name((opName, modelName) => {
|
|
250
|
+
const opType = opName.replace("OrThrow", "");
|
|
251
|
+
const inputType = getInputTypeByOpName(opType, modelName);
|
|
252
|
+
return inputType ? `import { ${inputType} } from "../schemas/${opType}${modelName}.schema"; ` : "";
|
|
253
|
+
}, "getRouterSchemaImportByOpName");
|
|
254
|
+
var getInputTypeByOpName = /* @__PURE__ */ __name((opName, modelName) => {
|
|
255
|
+
let inputType;
|
|
256
|
+
switch (opName) {
|
|
257
|
+
case "findUnique":
|
|
258
|
+
inputType = `${modelName}FindUniqueSchema`;
|
|
259
|
+
break;
|
|
260
|
+
case "findFirst":
|
|
261
|
+
inputType = `${modelName}FindFirstSchema`;
|
|
262
|
+
break;
|
|
263
|
+
case "findMany":
|
|
264
|
+
inputType = `${modelName}FindManySchema`;
|
|
265
|
+
break;
|
|
266
|
+
case "findRaw":
|
|
267
|
+
inputType = `${modelName}FindRawObjectSchema`;
|
|
268
|
+
break;
|
|
269
|
+
case "createOne":
|
|
270
|
+
inputType = `${modelName}CreateOneSchema`;
|
|
271
|
+
break;
|
|
272
|
+
case "createMany":
|
|
273
|
+
inputType = `${modelName}CreateManySchema`;
|
|
274
|
+
break;
|
|
275
|
+
case "deleteOne":
|
|
276
|
+
inputType = `${modelName}DeleteOneSchema`;
|
|
277
|
+
break;
|
|
278
|
+
case "updateOne":
|
|
279
|
+
inputType = `${modelName}UpdateOneSchema`;
|
|
280
|
+
break;
|
|
281
|
+
case "deleteMany":
|
|
282
|
+
inputType = `${modelName}DeleteManySchema`;
|
|
283
|
+
break;
|
|
284
|
+
case "updateMany":
|
|
285
|
+
inputType = `${modelName}UpdateManySchema`;
|
|
286
|
+
break;
|
|
287
|
+
case "upsertOne":
|
|
288
|
+
inputType = `${modelName}UpsertSchema`;
|
|
289
|
+
break;
|
|
290
|
+
case "aggregate":
|
|
291
|
+
inputType = `${modelName}AggregateSchema`;
|
|
292
|
+
break;
|
|
293
|
+
case "aggregateRaw":
|
|
294
|
+
inputType = `${modelName}AggregateRawObjectSchema`;
|
|
295
|
+
break;
|
|
296
|
+
case "groupBy":
|
|
297
|
+
inputType = `${modelName}GroupBySchema`;
|
|
298
|
+
break;
|
|
299
|
+
default:
|
|
300
|
+
console.log("getInputTypeByOpName: ", {
|
|
301
|
+
opName,
|
|
302
|
+
modelName
|
|
303
|
+
});
|
|
304
|
+
}
|
|
305
|
+
return inputType;
|
|
306
|
+
}, "getInputTypeByOpName");
|
|
307
|
+
var getProcedureTypeByOpName = /* @__PURE__ */ __name((opName) => {
|
|
308
|
+
let procType;
|
|
309
|
+
switch (opName) {
|
|
310
|
+
case "findUnique":
|
|
311
|
+
case "findFirst":
|
|
312
|
+
case "findMany":
|
|
313
|
+
case "findRaw":
|
|
314
|
+
case "aggregate":
|
|
315
|
+
case "aggregateRaw":
|
|
316
|
+
case "groupBy":
|
|
317
|
+
procType = "query";
|
|
318
|
+
break;
|
|
319
|
+
case "createOne":
|
|
320
|
+
case "createMany":
|
|
321
|
+
case "deleteOne":
|
|
322
|
+
case "updateOne":
|
|
323
|
+
case "deleteMany":
|
|
324
|
+
case "updateMany":
|
|
325
|
+
case "upsertOne":
|
|
326
|
+
procType = "mutation";
|
|
327
|
+
break;
|
|
328
|
+
default:
|
|
329
|
+
console.log("getProcedureTypeByOpName: ", {
|
|
330
|
+
opName
|
|
331
|
+
});
|
|
332
|
+
}
|
|
333
|
+
return procType;
|
|
334
|
+
}, "getProcedureTypeByOpName");
|
|
335
|
+
function resolveModelsComments(models, hiddenModels) {
|
|
336
|
+
const modelAttributeRegex = /(?:@@Gen\.)+[A-z]+\(.+\)/;
|
|
337
|
+
const attributeNameRegex = /\.+[A-Z]+\(+/i;
|
|
338
|
+
const attributeArgsRegex = /\(+[A-Z]+:.+\)/i;
|
|
339
|
+
for (const model of models) {
|
|
340
|
+
if (model.documentation) {
|
|
341
|
+
const attribute = model.documentation?.match(modelAttributeRegex)?.[0];
|
|
342
|
+
const attributeName = attribute?.match(attributeNameRegex)?.[0]?.slice(1, -1);
|
|
343
|
+
if (attributeName !== "model") continue;
|
|
344
|
+
const rawAttributeArgs = attribute?.match(attributeArgsRegex)?.[0]?.slice(1, -1);
|
|
345
|
+
const parsedAttributeArgs = {};
|
|
346
|
+
if (rawAttributeArgs) {
|
|
347
|
+
const rawAttributeArgsParts = rawAttributeArgs.split(":").map((it) => it.trim()).map((part) => part.startsWith("[") ? part : part.split(",")).flat().map((it) => it.trim());
|
|
348
|
+
for (let i = 0; i < rawAttributeArgsParts.length; i += 2) {
|
|
349
|
+
const key = rawAttributeArgsParts[i];
|
|
350
|
+
const value = rawAttributeArgsParts[i + 1];
|
|
351
|
+
parsedAttributeArgs[key] = JSON.parse(value);
|
|
352
|
+
}
|
|
353
|
+
}
|
|
354
|
+
if (parsedAttributeArgs.hide) {
|
|
355
|
+
hiddenModels.push(model.name);
|
|
217
356
|
}
|
|
218
357
|
}
|
|
219
|
-
h.hide && e.push(s.name);
|
|
220
358
|
}
|
|
221
|
-
}
|
|
359
|
+
}
|
|
360
|
+
__name(resolveModelsComments, "resolveModelsComments");
|
|
361
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
362
|
+
0 && (module.exports = {
|
|
363
|
+
generateBaseRouter,
|
|
364
|
+
generateCreateRouterImport,
|
|
365
|
+
generateMiddlewareImport,
|
|
366
|
+
generateProcedure,
|
|
367
|
+
generateRPCImport,
|
|
368
|
+
generateRouterImport,
|
|
369
|
+
generateRouterSchemaImports,
|
|
370
|
+
generateShieldImport,
|
|
371
|
+
getInputTypeByOpName,
|
|
372
|
+
getProcedureTypeByOpName,
|
|
373
|
+
getRouterSchemaImportByOpName,
|
|
374
|
+
resolveModelsComments
|
|
375
|
+
});
|
package/dist/helpers.js
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import {
|
|
2
|
+
generateBaseRouter,
|
|
3
|
+
generateCreateRouterImport,
|
|
4
|
+
generateMiddlewareImport,
|
|
5
|
+
generateProcedure,
|
|
6
|
+
generateRPCImport,
|
|
7
|
+
generateRouterImport,
|
|
8
|
+
generateRouterSchemaImports,
|
|
9
|
+
generateShieldImport,
|
|
10
|
+
getInputTypeByOpName,
|
|
11
|
+
getProcedureTypeByOpName,
|
|
12
|
+
getRouterSchemaImportByOpName,
|
|
13
|
+
resolveModelsComments
|
|
14
|
+
} from "./chunk-RYVIOFDO.js";
|
|
15
|
+
import "./chunk-SHUYVCID.js";
|
|
16
|
+
export {
|
|
17
|
+
generateBaseRouter,
|
|
18
|
+
generateCreateRouterImport,
|
|
19
|
+
generateMiddlewareImport,
|
|
20
|
+
generateProcedure,
|
|
21
|
+
generateRPCImport,
|
|
22
|
+
generateRouterImport,
|
|
23
|
+
generateRouterSchemaImports,
|
|
24
|
+
generateShieldImport,
|
|
25
|
+
getInputTypeByOpName,
|
|
26
|
+
getProcedureTypeByOpName,
|
|
27
|
+
getRouterSchemaImportByOpName,
|
|
28
|
+
resolveModelsComments
|
|
29
|
+
};
|