@stryke/prisma-trpc-generator 0.2.17 → 0.3.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/generator.cjs +45 -9
- package/dist/generator.js +45 -9
- package/dist/index.cjs +45 -9
- package/dist/index.js +45 -9
- package/package.json +1 -1
package/dist/generator.cjs
CHANGED
|
@@ -4926,6 +4926,7 @@ var configShield = z.union([
|
|
|
4926
4926
|
]);
|
|
4927
4927
|
var modelActionEnum = z.nativeEnum(ModelAction);
|
|
4928
4928
|
var configSchema = z.object({
|
|
4929
|
+
debug: configBoolean.default("false"),
|
|
4929
4930
|
withMiddleware: configMiddleware.default("true"),
|
|
4930
4931
|
withShield: configShield.default("true"),
|
|
4931
4932
|
withZod: configBoolean.default("true"),
|
|
@@ -4940,6 +4941,12 @@ var configSchema = z.object({
|
|
|
4940
4941
|
// src/helpers.ts
|
|
4941
4942
|
init_cjs_shims();
|
|
4942
4943
|
|
|
4944
|
+
// ../string-format/src/lower-case-first.ts
|
|
4945
|
+
init_cjs_shims();
|
|
4946
|
+
var lowerCaseFirst = /* @__PURE__ */ __name((input) => {
|
|
4947
|
+
return input ? input.charAt(0).toLowerCase() + input.slice(1) : input;
|
|
4948
|
+
}, "lowerCaseFirst");
|
|
4949
|
+
|
|
4943
4950
|
// src/utils/get-prisma-internals.ts
|
|
4944
4951
|
init_cjs_shims();
|
|
4945
4952
|
|
|
@@ -5714,12 +5721,6 @@ function getRelativePath(outputPath, filePath, isOutsideOutputPath, schemaPath)
|
|
|
5714
5721
|
}
|
|
5715
5722
|
__name(getRelativePath, "getRelativePath");
|
|
5716
5723
|
|
|
5717
|
-
// src/utils/uncapitalize-first-letter.ts
|
|
5718
|
-
init_cjs_shims();
|
|
5719
|
-
var uncapitalizeFirstLetter = /* @__PURE__ */ __name((str) => {
|
|
5720
|
-
return !str ? "" : str.charAt(0).toLowerCase() + str.slice(1);
|
|
5721
|
-
}, "uncapitalizeFirstLetter");
|
|
5722
|
-
|
|
5723
5724
|
// src/helpers.ts
|
|
5724
5725
|
var getProcedureName = /* @__PURE__ */ __name((config) => {
|
|
5725
5726
|
return config.withShield ? "shieldedProcedure" : config.withMiddleware ? "protectedProcedure" : "publicProcedure";
|
|
@@ -5876,7 +5877,7 @@ function generateProcedure(sourceFile, name, typeName, modelName, opType, baseOp
|
|
|
5876
5877
|
/* ts */
|
|
5877
5878
|
`${config.showModelNameInProcedure ? name : nameWithoutModel}: ${getProcedureName(config)}
|
|
5878
5879
|
${config.withZod ? `.input(${typeName})` : ""}.${getProcedureTypeByOpName(baseOpType)}(async ({ ctx, input }) => {
|
|
5879
|
-
const ${name} = await ctx.prisma.${
|
|
5880
|
+
const ${name} = await ctx.prisma.${lowerCaseFirst(modelName)}.${opType.replace("One", "")}(${input});
|
|
5880
5881
|
return ${name};
|
|
5881
5882
|
}),`
|
|
5882
5883
|
);
|
|
@@ -6208,22 +6209,34 @@ var project = new import_ts_morph.Project({
|
|
|
6208
6209
|
|
|
6209
6210
|
// src/prisma-generator.ts
|
|
6210
6211
|
async function generate(options) {
|
|
6212
|
+
console.log("[STORM]: Running the Storm Software - Prisma tRPC generator with options: \n", JSON.stringify(options, null, 2));
|
|
6211
6213
|
const internals = await getPrismaInternals();
|
|
6214
|
+
console.log(`[STORM]: Validating configuration options`);
|
|
6212
6215
|
const outputDir = internals.parseEnvValue(options.generator.output);
|
|
6213
6216
|
const results = configSchema.safeParse(options.generator.config);
|
|
6214
6217
|
if (!results.success) {
|
|
6215
6218
|
throw new Error("Invalid options passed");
|
|
6216
6219
|
}
|
|
6217
6220
|
const config = results.data;
|
|
6221
|
+
const consoleLog = /* @__PURE__ */ __name((message) => {
|
|
6222
|
+
if (config.debug) {
|
|
6223
|
+
console.log(`[STORM]: ${message}`);
|
|
6224
|
+
}
|
|
6225
|
+
}, "consoleLog");
|
|
6226
|
+
consoleLog(`Preparing output directory: ${outputDir}`);
|
|
6218
6227
|
await import_node_fs6.promises.mkdir(outputDir, {
|
|
6219
6228
|
recursive: true
|
|
6220
6229
|
});
|
|
6221
6230
|
await removeDir(outputDir, true);
|
|
6222
6231
|
if (config.withZod !== false) {
|
|
6232
|
+
consoleLog("Generating Zod schemas");
|
|
6223
6233
|
const prismaZodGenerator = await getJiti().import(getJiti().esmResolve("prisma-zod-generator/lib/prisma-generator"));
|
|
6224
6234
|
await prismaZodGenerator.generate(options);
|
|
6235
|
+
} else {
|
|
6236
|
+
consoleLog("Skipping Zod schemas generation");
|
|
6225
6237
|
}
|
|
6226
6238
|
if (config.withShield !== false) {
|
|
6239
|
+
consoleLog("Generating tRPC Shield");
|
|
6227
6240
|
const shieldOutputPath = import_node_path7.default.join(outputDir, "./shield");
|
|
6228
6241
|
await generateShield({
|
|
6229
6242
|
...options,
|
|
@@ -6240,8 +6253,15 @@ async function generate(options) {
|
|
|
6240
6253
|
}
|
|
6241
6254
|
}
|
|
6242
6255
|
});
|
|
6256
|
+
} else {
|
|
6257
|
+
consoleLog("Skipping tRPC Shield generation");
|
|
6243
6258
|
}
|
|
6259
|
+
consoleLog("Finding Prisma Client generator");
|
|
6244
6260
|
const prismaClientProvider = options.otherGenerators.find((it) => internals.parseEnvValue(it.provider) === "prisma-client-js");
|
|
6261
|
+
if (!prismaClientProvider) {
|
|
6262
|
+
throw new Error("No Prisma Client generator found. Please add `prisma-client-js` to your generator list.");
|
|
6263
|
+
}
|
|
6264
|
+
consoleLog("Generating Prisma Client DMMF");
|
|
6245
6265
|
const prismaClientDmmf = await internals.getDMMF({
|
|
6246
6266
|
datamodel: options.datamodel,
|
|
6247
6267
|
previewFeatures: prismaClientProvider?.previewFeatures
|
|
@@ -6249,14 +6269,17 @@ async function generate(options) {
|
|
|
6249
6269
|
const modelOperations = prismaClientDmmf.mappings.modelOperations;
|
|
6250
6270
|
const models = prismaClientDmmf.datamodel.models;
|
|
6251
6271
|
const hiddenModels = [];
|
|
6272
|
+
consoleLog(`Generating tRPC source code for ${models.length} models`);
|
|
6252
6273
|
resolveModelsComments(models, hiddenModels);
|
|
6253
6274
|
const createRouter = project.createSourceFile(import_node_path7.default.resolve(outputDir, "routers", "helpers", "createRouter.ts"), void 0, {
|
|
6254
6275
|
overwrite: true
|
|
6255
6276
|
});
|
|
6277
|
+
consoleLog("Generating tRPC imports");
|
|
6256
6278
|
generateRPCImport(createRouter);
|
|
6257
6279
|
if (config.withShield) {
|
|
6258
6280
|
await generateShieldImport(createRouter, options, config.withShield);
|
|
6259
6281
|
}
|
|
6282
|
+
consoleLog("Generating tRPC base router");
|
|
6260
6283
|
await generateBaseRouter(createRouter, config, options);
|
|
6261
6284
|
createRouter.formatText({
|
|
6262
6285
|
indentSize: 2
|
|
@@ -6264,16 +6287,24 @@ async function generate(options) {
|
|
|
6264
6287
|
const appRouter = project.createSourceFile(import_node_path7.default.resolve(outputDir, "routers", `index.ts`), void 0, {
|
|
6265
6288
|
overwrite: true
|
|
6266
6289
|
});
|
|
6290
|
+
consoleLog("Generating tRPC router imports");
|
|
6267
6291
|
generateCreateRouterImport({
|
|
6268
6292
|
sourceFile: appRouter
|
|
6269
6293
|
});
|
|
6270
6294
|
const routerStatements = [];
|
|
6271
6295
|
for (const modelOperation of modelOperations) {
|
|
6272
6296
|
const { model, ...operations } = modelOperation;
|
|
6273
|
-
if (hiddenModels.includes(model))
|
|
6297
|
+
if (hiddenModels.includes(model)) {
|
|
6298
|
+
consoleLog(`Skipping model ${model} as it is hidden`);
|
|
6299
|
+
continue;
|
|
6300
|
+
}
|
|
6274
6301
|
const modelActions = Object.keys(operations).filter((opType) => config.generateModelActions.includes(opType.replace("One", "")));
|
|
6275
|
-
if (!modelActions.length)
|
|
6302
|
+
if (!modelActions.length) {
|
|
6303
|
+
consoleLog(`Skipping model ${model} as it has no actions to generate`);
|
|
6304
|
+
continue;
|
|
6305
|
+
}
|
|
6276
6306
|
const plural = (0, import_pluralize.default)(model.toLowerCase());
|
|
6307
|
+
consoleLog(`Generating tRPC router for model ${model}`);
|
|
6277
6308
|
generateRouterImport(appRouter, plural, model);
|
|
6278
6309
|
const modelRouter = project.createSourceFile(import_node_path7.default.resolve(outputDir, "routers", `${model}.router.ts`), void 0, {
|
|
6279
6310
|
overwrite: true
|
|
@@ -6283,6 +6314,7 @@ async function generate(options) {
|
|
|
6283
6314
|
config
|
|
6284
6315
|
});
|
|
6285
6316
|
if (config.withZod) {
|
|
6317
|
+
consoleLog("Generating Zod schemas imports");
|
|
6286
6318
|
generateRouterSchemaImports(modelRouter, model, modelActions);
|
|
6287
6319
|
}
|
|
6288
6320
|
modelRouter.addStatements(
|
|
@@ -6308,7 +6340,9 @@ async function generate(options) {
|
|
|
6308
6340
|
`
|
|
6309
6341
|
${model.toLowerCase()}: ${plural}Router`
|
|
6310
6342
|
);
|
|
6343
|
+
consoleLog(`Generated tRPC router for model ${model} with ${modelActions.length} actions`);
|
|
6311
6344
|
}
|
|
6345
|
+
consoleLog("Generating tRPC app router");
|
|
6312
6346
|
appRouter.addStatements(
|
|
6313
6347
|
/* ts */
|
|
6314
6348
|
`
|
|
@@ -6318,7 +6352,9 @@ async function generate(options) {
|
|
|
6318
6352
|
appRouter.formatText({
|
|
6319
6353
|
indentSize: 2
|
|
6320
6354
|
});
|
|
6355
|
+
consoleLog("Saving tRPC router source files to disk");
|
|
6321
6356
|
await project.save();
|
|
6357
|
+
consoleLog("Storm Software - Prisma tRPC generator completed successfully");
|
|
6322
6358
|
}
|
|
6323
6359
|
__name(generate, "generate");
|
|
6324
6360
|
|
package/dist/generator.js
CHANGED
|
@@ -4931,6 +4931,7 @@ var configShield = z.union([
|
|
|
4931
4931
|
]);
|
|
4932
4932
|
var modelActionEnum = z.nativeEnum(ModelAction);
|
|
4933
4933
|
var configSchema = z.object({
|
|
4934
|
+
debug: configBoolean.default("false"),
|
|
4934
4935
|
withMiddleware: configMiddleware.default("true"),
|
|
4935
4936
|
withShield: configShield.default("true"),
|
|
4936
4937
|
withZod: configBoolean.default("true"),
|
|
@@ -4945,6 +4946,12 @@ var configSchema = z.object({
|
|
|
4945
4946
|
// src/helpers.ts
|
|
4946
4947
|
init_esm_shims();
|
|
4947
4948
|
|
|
4949
|
+
// ../string-format/src/lower-case-first.ts
|
|
4950
|
+
init_esm_shims();
|
|
4951
|
+
var lowerCaseFirst = /* @__PURE__ */ __name((input) => {
|
|
4952
|
+
return input ? input.charAt(0).toLowerCase() + input.slice(1) : input;
|
|
4953
|
+
}, "lowerCaseFirst");
|
|
4954
|
+
|
|
4948
4955
|
// src/utils/get-prisma-internals.ts
|
|
4949
4956
|
init_esm_shims();
|
|
4950
4957
|
|
|
@@ -5719,12 +5726,6 @@ function getRelativePath(outputPath, filePath, isOutsideOutputPath, schemaPath)
|
|
|
5719
5726
|
}
|
|
5720
5727
|
__name(getRelativePath, "getRelativePath");
|
|
5721
5728
|
|
|
5722
|
-
// src/utils/uncapitalize-first-letter.ts
|
|
5723
|
-
init_esm_shims();
|
|
5724
|
-
var uncapitalizeFirstLetter = /* @__PURE__ */ __name((str) => {
|
|
5725
|
-
return !str ? "" : str.charAt(0).toLowerCase() + str.slice(1);
|
|
5726
|
-
}, "uncapitalizeFirstLetter");
|
|
5727
|
-
|
|
5728
5729
|
// src/helpers.ts
|
|
5729
5730
|
var getProcedureName = /* @__PURE__ */ __name((config) => {
|
|
5730
5731
|
return config.withShield ? "shieldedProcedure" : config.withMiddleware ? "protectedProcedure" : "publicProcedure";
|
|
@@ -5881,7 +5882,7 @@ function generateProcedure(sourceFile, name, typeName, modelName, opType, baseOp
|
|
|
5881
5882
|
/* ts */
|
|
5882
5883
|
`${config.showModelNameInProcedure ? name : nameWithoutModel}: ${getProcedureName(config)}
|
|
5883
5884
|
${config.withZod ? `.input(${typeName})` : ""}.${getProcedureTypeByOpName(baseOpType)}(async ({ ctx, input }) => {
|
|
5884
|
-
const ${name} = await ctx.prisma.${
|
|
5885
|
+
const ${name} = await ctx.prisma.${lowerCaseFirst(modelName)}.${opType.replace("One", "")}(${input});
|
|
5885
5886
|
return ${name};
|
|
5886
5887
|
}),`
|
|
5887
5888
|
);
|
|
@@ -6213,22 +6214,34 @@ var project = new Project({
|
|
|
6213
6214
|
|
|
6214
6215
|
// src/prisma-generator.ts
|
|
6215
6216
|
async function generate(options) {
|
|
6217
|
+
console.log("[STORM]: Running the Storm Software - Prisma tRPC generator with options: \n", JSON.stringify(options, null, 2));
|
|
6216
6218
|
const internals = await getPrismaInternals();
|
|
6219
|
+
console.log(`[STORM]: Validating configuration options`);
|
|
6217
6220
|
const outputDir = internals.parseEnvValue(options.generator.output);
|
|
6218
6221
|
const results = configSchema.safeParse(options.generator.config);
|
|
6219
6222
|
if (!results.success) {
|
|
6220
6223
|
throw new Error("Invalid options passed");
|
|
6221
6224
|
}
|
|
6222
6225
|
const config = results.data;
|
|
6226
|
+
const consoleLog = /* @__PURE__ */ __name((message) => {
|
|
6227
|
+
if (config.debug) {
|
|
6228
|
+
console.log(`[STORM]: ${message}`);
|
|
6229
|
+
}
|
|
6230
|
+
}, "consoleLog");
|
|
6231
|
+
consoleLog(`Preparing output directory: ${outputDir}`);
|
|
6223
6232
|
await fs4.mkdir(outputDir, {
|
|
6224
6233
|
recursive: true
|
|
6225
6234
|
});
|
|
6226
6235
|
await removeDir(outputDir, true);
|
|
6227
6236
|
if (config.withZod !== false) {
|
|
6237
|
+
consoleLog("Generating Zod schemas");
|
|
6228
6238
|
const prismaZodGenerator = await getJiti().import(getJiti().esmResolve("prisma-zod-generator/lib/prisma-generator"));
|
|
6229
6239
|
await prismaZodGenerator.generate(options);
|
|
6240
|
+
} else {
|
|
6241
|
+
consoleLog("Skipping Zod schemas generation");
|
|
6230
6242
|
}
|
|
6231
6243
|
if (config.withShield !== false) {
|
|
6244
|
+
consoleLog("Generating tRPC Shield");
|
|
6232
6245
|
const shieldOutputPath = path6.join(outputDir, "./shield");
|
|
6233
6246
|
await generateShield({
|
|
6234
6247
|
...options,
|
|
@@ -6245,8 +6258,15 @@ async function generate(options) {
|
|
|
6245
6258
|
}
|
|
6246
6259
|
}
|
|
6247
6260
|
});
|
|
6261
|
+
} else {
|
|
6262
|
+
consoleLog("Skipping tRPC Shield generation");
|
|
6248
6263
|
}
|
|
6264
|
+
consoleLog("Finding Prisma Client generator");
|
|
6249
6265
|
const prismaClientProvider = options.otherGenerators.find((it) => internals.parseEnvValue(it.provider) === "prisma-client-js");
|
|
6266
|
+
if (!prismaClientProvider) {
|
|
6267
|
+
throw new Error("No Prisma Client generator found. Please add `prisma-client-js` to your generator list.");
|
|
6268
|
+
}
|
|
6269
|
+
consoleLog("Generating Prisma Client DMMF");
|
|
6250
6270
|
const prismaClientDmmf = await internals.getDMMF({
|
|
6251
6271
|
datamodel: options.datamodel,
|
|
6252
6272
|
previewFeatures: prismaClientProvider?.previewFeatures
|
|
@@ -6254,14 +6274,17 @@ async function generate(options) {
|
|
|
6254
6274
|
const modelOperations = prismaClientDmmf.mappings.modelOperations;
|
|
6255
6275
|
const models = prismaClientDmmf.datamodel.models;
|
|
6256
6276
|
const hiddenModels = [];
|
|
6277
|
+
consoleLog(`Generating tRPC source code for ${models.length} models`);
|
|
6257
6278
|
resolveModelsComments(models, hiddenModels);
|
|
6258
6279
|
const createRouter = project.createSourceFile(path6.resolve(outputDir, "routers", "helpers", "createRouter.ts"), void 0, {
|
|
6259
6280
|
overwrite: true
|
|
6260
6281
|
});
|
|
6282
|
+
consoleLog("Generating tRPC imports");
|
|
6261
6283
|
generateRPCImport(createRouter);
|
|
6262
6284
|
if (config.withShield) {
|
|
6263
6285
|
await generateShieldImport(createRouter, options, config.withShield);
|
|
6264
6286
|
}
|
|
6287
|
+
consoleLog("Generating tRPC base router");
|
|
6265
6288
|
await generateBaseRouter(createRouter, config, options);
|
|
6266
6289
|
createRouter.formatText({
|
|
6267
6290
|
indentSize: 2
|
|
@@ -6269,16 +6292,24 @@ async function generate(options) {
|
|
|
6269
6292
|
const appRouter = project.createSourceFile(path6.resolve(outputDir, "routers", `index.ts`), void 0, {
|
|
6270
6293
|
overwrite: true
|
|
6271
6294
|
});
|
|
6295
|
+
consoleLog("Generating tRPC router imports");
|
|
6272
6296
|
generateCreateRouterImport({
|
|
6273
6297
|
sourceFile: appRouter
|
|
6274
6298
|
});
|
|
6275
6299
|
const routerStatements = [];
|
|
6276
6300
|
for (const modelOperation of modelOperations) {
|
|
6277
6301
|
const { model, ...operations } = modelOperation;
|
|
6278
|
-
if (hiddenModels.includes(model))
|
|
6302
|
+
if (hiddenModels.includes(model)) {
|
|
6303
|
+
consoleLog(`Skipping model ${model} as it is hidden`);
|
|
6304
|
+
continue;
|
|
6305
|
+
}
|
|
6279
6306
|
const modelActions = Object.keys(operations).filter((opType) => config.generateModelActions.includes(opType.replace("One", "")));
|
|
6280
|
-
if (!modelActions.length)
|
|
6307
|
+
if (!modelActions.length) {
|
|
6308
|
+
consoleLog(`Skipping model ${model} as it has no actions to generate`);
|
|
6309
|
+
continue;
|
|
6310
|
+
}
|
|
6281
6311
|
const plural = (0, import_pluralize.default)(model.toLowerCase());
|
|
6312
|
+
consoleLog(`Generating tRPC router for model ${model}`);
|
|
6282
6313
|
generateRouterImport(appRouter, plural, model);
|
|
6283
6314
|
const modelRouter = project.createSourceFile(path6.resolve(outputDir, "routers", `${model}.router.ts`), void 0, {
|
|
6284
6315
|
overwrite: true
|
|
@@ -6288,6 +6319,7 @@ async function generate(options) {
|
|
|
6288
6319
|
config
|
|
6289
6320
|
});
|
|
6290
6321
|
if (config.withZod) {
|
|
6322
|
+
consoleLog("Generating Zod schemas imports");
|
|
6291
6323
|
generateRouterSchemaImports(modelRouter, model, modelActions);
|
|
6292
6324
|
}
|
|
6293
6325
|
modelRouter.addStatements(
|
|
@@ -6313,7 +6345,9 @@ async function generate(options) {
|
|
|
6313
6345
|
`
|
|
6314
6346
|
${model.toLowerCase()}: ${plural}Router`
|
|
6315
6347
|
);
|
|
6348
|
+
consoleLog(`Generated tRPC router for model ${model} with ${modelActions.length} actions`);
|
|
6316
6349
|
}
|
|
6350
|
+
consoleLog("Generating tRPC app router");
|
|
6317
6351
|
appRouter.addStatements(
|
|
6318
6352
|
/* ts */
|
|
6319
6353
|
`
|
|
@@ -6323,7 +6357,9 @@ async function generate(options) {
|
|
|
6323
6357
|
appRouter.formatText({
|
|
6324
6358
|
indentSize: 2
|
|
6325
6359
|
});
|
|
6360
|
+
consoleLog("Saving tRPC router source files to disk");
|
|
6326
6361
|
await project.save();
|
|
6362
|
+
consoleLog("Storm Software - Prisma tRPC generator completed successfully");
|
|
6327
6363
|
}
|
|
6328
6364
|
__name(generate, "generate");
|
|
6329
6365
|
|
package/dist/index.cjs
CHANGED
|
@@ -4922,6 +4922,7 @@ var configShield = z.union([
|
|
|
4922
4922
|
]);
|
|
4923
4923
|
var modelActionEnum = z.nativeEnum(ModelAction);
|
|
4924
4924
|
var configSchema = z.object({
|
|
4925
|
+
debug: configBoolean.default("false"),
|
|
4925
4926
|
withMiddleware: configMiddleware.default("true"),
|
|
4926
4927
|
withShield: configShield.default("true"),
|
|
4927
4928
|
withZod: configBoolean.default("true"),
|
|
@@ -4936,6 +4937,12 @@ var configSchema = z.object({
|
|
|
4936
4937
|
// src/helpers.ts
|
|
4937
4938
|
init_cjs_shims();
|
|
4938
4939
|
|
|
4940
|
+
// ../string-format/src/lower-case-first.ts
|
|
4941
|
+
init_cjs_shims();
|
|
4942
|
+
var lowerCaseFirst = /* @__PURE__ */ __name((input) => {
|
|
4943
|
+
return input ? input.charAt(0).toLowerCase() + input.slice(1) : input;
|
|
4944
|
+
}, "lowerCaseFirst");
|
|
4945
|
+
|
|
4939
4946
|
// src/utils/get-prisma-internals.ts
|
|
4940
4947
|
init_cjs_shims();
|
|
4941
4948
|
|
|
@@ -5710,12 +5717,6 @@ function getRelativePath(outputPath, filePath, isOutsideOutputPath, schemaPath)
|
|
|
5710
5717
|
}
|
|
5711
5718
|
__name(getRelativePath, "getRelativePath");
|
|
5712
5719
|
|
|
5713
|
-
// src/utils/uncapitalize-first-letter.ts
|
|
5714
|
-
init_cjs_shims();
|
|
5715
|
-
var uncapitalizeFirstLetter = /* @__PURE__ */ __name((str) => {
|
|
5716
|
-
return !str ? "" : str.charAt(0).toLowerCase() + str.slice(1);
|
|
5717
|
-
}, "uncapitalizeFirstLetter");
|
|
5718
|
-
|
|
5719
5720
|
// src/helpers.ts
|
|
5720
5721
|
var getProcedureName = /* @__PURE__ */ __name((config) => {
|
|
5721
5722
|
return config.withShield ? "shieldedProcedure" : config.withMiddleware ? "protectedProcedure" : "publicProcedure";
|
|
@@ -5872,7 +5873,7 @@ function generateProcedure(sourceFile, name, typeName, modelName, opType, baseOp
|
|
|
5872
5873
|
/* ts */
|
|
5873
5874
|
`${config.showModelNameInProcedure ? name : nameWithoutModel}: ${getProcedureName(config)}
|
|
5874
5875
|
${config.withZod ? `.input(${typeName})` : ""}.${getProcedureTypeByOpName(baseOpType)}(async ({ ctx, input }) => {
|
|
5875
|
-
const ${name} = await ctx.prisma.${
|
|
5876
|
+
const ${name} = await ctx.prisma.${lowerCaseFirst(modelName)}.${opType.replace("One", "")}(${input});
|
|
5876
5877
|
return ${name};
|
|
5877
5878
|
}),`
|
|
5878
5879
|
);
|
|
@@ -6204,22 +6205,34 @@ var project = new import_ts_morph.Project({
|
|
|
6204
6205
|
|
|
6205
6206
|
// src/prisma-generator.ts
|
|
6206
6207
|
async function generate(options) {
|
|
6208
|
+
console.log("[STORM]: Running the Storm Software - Prisma tRPC generator with options: \n", JSON.stringify(options, null, 2));
|
|
6207
6209
|
const internals = await getPrismaInternals();
|
|
6210
|
+
console.log(`[STORM]: Validating configuration options`);
|
|
6208
6211
|
const outputDir = internals.parseEnvValue(options.generator.output);
|
|
6209
6212
|
const results = configSchema.safeParse(options.generator.config);
|
|
6210
6213
|
if (!results.success) {
|
|
6211
6214
|
throw new Error("Invalid options passed");
|
|
6212
6215
|
}
|
|
6213
6216
|
const config = results.data;
|
|
6217
|
+
const consoleLog = /* @__PURE__ */ __name((message) => {
|
|
6218
|
+
if (config.debug) {
|
|
6219
|
+
console.log(`[STORM]: ${message}`);
|
|
6220
|
+
}
|
|
6221
|
+
}, "consoleLog");
|
|
6222
|
+
consoleLog(`Preparing output directory: ${outputDir}`);
|
|
6214
6223
|
await import_node_fs6.promises.mkdir(outputDir, {
|
|
6215
6224
|
recursive: true
|
|
6216
6225
|
});
|
|
6217
6226
|
await removeDir(outputDir, true);
|
|
6218
6227
|
if (config.withZod !== false) {
|
|
6228
|
+
consoleLog("Generating Zod schemas");
|
|
6219
6229
|
const prismaZodGenerator = await getJiti().import(getJiti().esmResolve("prisma-zod-generator/lib/prisma-generator"));
|
|
6220
6230
|
await prismaZodGenerator.generate(options);
|
|
6231
|
+
} else {
|
|
6232
|
+
consoleLog("Skipping Zod schemas generation");
|
|
6221
6233
|
}
|
|
6222
6234
|
if (config.withShield !== false) {
|
|
6235
|
+
consoleLog("Generating tRPC Shield");
|
|
6223
6236
|
const shieldOutputPath = import_node_path7.default.join(outputDir, "./shield");
|
|
6224
6237
|
await generateShield({
|
|
6225
6238
|
...options,
|
|
@@ -6236,8 +6249,15 @@ async function generate(options) {
|
|
|
6236
6249
|
}
|
|
6237
6250
|
}
|
|
6238
6251
|
});
|
|
6252
|
+
} else {
|
|
6253
|
+
consoleLog("Skipping tRPC Shield generation");
|
|
6239
6254
|
}
|
|
6255
|
+
consoleLog("Finding Prisma Client generator");
|
|
6240
6256
|
const prismaClientProvider = options.otherGenerators.find((it) => internals.parseEnvValue(it.provider) === "prisma-client-js");
|
|
6257
|
+
if (!prismaClientProvider) {
|
|
6258
|
+
throw new Error("No Prisma Client generator found. Please add `prisma-client-js` to your generator list.");
|
|
6259
|
+
}
|
|
6260
|
+
consoleLog("Generating Prisma Client DMMF");
|
|
6241
6261
|
const prismaClientDmmf = await internals.getDMMF({
|
|
6242
6262
|
datamodel: options.datamodel,
|
|
6243
6263
|
previewFeatures: prismaClientProvider?.previewFeatures
|
|
@@ -6245,14 +6265,17 @@ async function generate(options) {
|
|
|
6245
6265
|
const modelOperations = prismaClientDmmf.mappings.modelOperations;
|
|
6246
6266
|
const models = prismaClientDmmf.datamodel.models;
|
|
6247
6267
|
const hiddenModels = [];
|
|
6268
|
+
consoleLog(`Generating tRPC source code for ${models.length} models`);
|
|
6248
6269
|
resolveModelsComments(models, hiddenModels);
|
|
6249
6270
|
const createRouter = project.createSourceFile(import_node_path7.default.resolve(outputDir, "routers", "helpers", "createRouter.ts"), void 0, {
|
|
6250
6271
|
overwrite: true
|
|
6251
6272
|
});
|
|
6273
|
+
consoleLog("Generating tRPC imports");
|
|
6252
6274
|
generateRPCImport(createRouter);
|
|
6253
6275
|
if (config.withShield) {
|
|
6254
6276
|
await generateShieldImport(createRouter, options, config.withShield);
|
|
6255
6277
|
}
|
|
6278
|
+
consoleLog("Generating tRPC base router");
|
|
6256
6279
|
await generateBaseRouter(createRouter, config, options);
|
|
6257
6280
|
createRouter.formatText({
|
|
6258
6281
|
indentSize: 2
|
|
@@ -6260,16 +6283,24 @@ async function generate(options) {
|
|
|
6260
6283
|
const appRouter = project.createSourceFile(import_node_path7.default.resolve(outputDir, "routers", `index.ts`), void 0, {
|
|
6261
6284
|
overwrite: true
|
|
6262
6285
|
});
|
|
6286
|
+
consoleLog("Generating tRPC router imports");
|
|
6263
6287
|
generateCreateRouterImport({
|
|
6264
6288
|
sourceFile: appRouter
|
|
6265
6289
|
});
|
|
6266
6290
|
const routerStatements = [];
|
|
6267
6291
|
for (const modelOperation of modelOperations) {
|
|
6268
6292
|
const { model, ...operations } = modelOperation;
|
|
6269
|
-
if (hiddenModels.includes(model))
|
|
6293
|
+
if (hiddenModels.includes(model)) {
|
|
6294
|
+
consoleLog(`Skipping model ${model} as it is hidden`);
|
|
6295
|
+
continue;
|
|
6296
|
+
}
|
|
6270
6297
|
const modelActions = Object.keys(operations).filter((opType) => config.generateModelActions.includes(opType.replace("One", "")));
|
|
6271
|
-
if (!modelActions.length)
|
|
6298
|
+
if (!modelActions.length) {
|
|
6299
|
+
consoleLog(`Skipping model ${model} as it has no actions to generate`);
|
|
6300
|
+
continue;
|
|
6301
|
+
}
|
|
6272
6302
|
const plural = (0, import_pluralize.default)(model.toLowerCase());
|
|
6303
|
+
consoleLog(`Generating tRPC router for model ${model}`);
|
|
6273
6304
|
generateRouterImport(appRouter, plural, model);
|
|
6274
6305
|
const modelRouter = project.createSourceFile(import_node_path7.default.resolve(outputDir, "routers", `${model}.router.ts`), void 0, {
|
|
6275
6306
|
overwrite: true
|
|
@@ -6279,6 +6310,7 @@ async function generate(options) {
|
|
|
6279
6310
|
config
|
|
6280
6311
|
});
|
|
6281
6312
|
if (config.withZod) {
|
|
6313
|
+
consoleLog("Generating Zod schemas imports");
|
|
6282
6314
|
generateRouterSchemaImports(modelRouter, model, modelActions);
|
|
6283
6315
|
}
|
|
6284
6316
|
modelRouter.addStatements(
|
|
@@ -6304,7 +6336,9 @@ async function generate(options) {
|
|
|
6304
6336
|
`
|
|
6305
6337
|
${model.toLowerCase()}: ${plural}Router`
|
|
6306
6338
|
);
|
|
6339
|
+
consoleLog(`Generated tRPC router for model ${model} with ${modelActions.length} actions`);
|
|
6307
6340
|
}
|
|
6341
|
+
consoleLog("Generating tRPC app router");
|
|
6308
6342
|
appRouter.addStatements(
|
|
6309
6343
|
/* ts */
|
|
6310
6344
|
`
|
|
@@ -6314,7 +6348,9 @@ async function generate(options) {
|
|
|
6314
6348
|
appRouter.formatText({
|
|
6315
6349
|
indentSize: 2
|
|
6316
6350
|
});
|
|
6351
|
+
consoleLog("Saving tRPC router source files to disk");
|
|
6317
6352
|
await project.save();
|
|
6353
|
+
consoleLog("Storm Software - Prisma tRPC generator completed successfully");
|
|
6318
6354
|
}
|
|
6319
6355
|
__name(generate, "generate");
|
|
6320
6356
|
|
package/dist/index.js
CHANGED
|
@@ -4927,6 +4927,7 @@ var configShield = z.union([
|
|
|
4927
4927
|
]);
|
|
4928
4928
|
var modelActionEnum = z.nativeEnum(ModelAction);
|
|
4929
4929
|
var configSchema = z.object({
|
|
4930
|
+
debug: configBoolean.default("false"),
|
|
4930
4931
|
withMiddleware: configMiddleware.default("true"),
|
|
4931
4932
|
withShield: configShield.default("true"),
|
|
4932
4933
|
withZod: configBoolean.default("true"),
|
|
@@ -4941,6 +4942,12 @@ var configSchema = z.object({
|
|
|
4941
4942
|
// src/helpers.ts
|
|
4942
4943
|
init_esm_shims();
|
|
4943
4944
|
|
|
4945
|
+
// ../string-format/src/lower-case-first.ts
|
|
4946
|
+
init_esm_shims();
|
|
4947
|
+
var lowerCaseFirst = /* @__PURE__ */ __name((input) => {
|
|
4948
|
+
return input ? input.charAt(0).toLowerCase() + input.slice(1) : input;
|
|
4949
|
+
}, "lowerCaseFirst");
|
|
4950
|
+
|
|
4944
4951
|
// src/utils/get-prisma-internals.ts
|
|
4945
4952
|
init_esm_shims();
|
|
4946
4953
|
|
|
@@ -5715,12 +5722,6 @@ function getRelativePath(outputPath, filePath, isOutsideOutputPath, schemaPath)
|
|
|
5715
5722
|
}
|
|
5716
5723
|
__name(getRelativePath, "getRelativePath");
|
|
5717
5724
|
|
|
5718
|
-
// src/utils/uncapitalize-first-letter.ts
|
|
5719
|
-
init_esm_shims();
|
|
5720
|
-
var uncapitalizeFirstLetter = /* @__PURE__ */ __name((str) => {
|
|
5721
|
-
return !str ? "" : str.charAt(0).toLowerCase() + str.slice(1);
|
|
5722
|
-
}, "uncapitalizeFirstLetter");
|
|
5723
|
-
|
|
5724
5725
|
// src/helpers.ts
|
|
5725
5726
|
var getProcedureName = /* @__PURE__ */ __name((config) => {
|
|
5726
5727
|
return config.withShield ? "shieldedProcedure" : config.withMiddleware ? "protectedProcedure" : "publicProcedure";
|
|
@@ -5877,7 +5878,7 @@ function generateProcedure(sourceFile, name, typeName, modelName, opType, baseOp
|
|
|
5877
5878
|
/* ts */
|
|
5878
5879
|
`${config.showModelNameInProcedure ? name : nameWithoutModel}: ${getProcedureName(config)}
|
|
5879
5880
|
${config.withZod ? `.input(${typeName})` : ""}.${getProcedureTypeByOpName(baseOpType)}(async ({ ctx, input }) => {
|
|
5880
|
-
const ${name} = await ctx.prisma.${
|
|
5881
|
+
const ${name} = await ctx.prisma.${lowerCaseFirst(modelName)}.${opType.replace("One", "")}(${input});
|
|
5881
5882
|
return ${name};
|
|
5882
5883
|
}),`
|
|
5883
5884
|
);
|
|
@@ -6209,22 +6210,34 @@ var project = new Project({
|
|
|
6209
6210
|
|
|
6210
6211
|
// src/prisma-generator.ts
|
|
6211
6212
|
async function generate(options) {
|
|
6213
|
+
console.log("[STORM]: Running the Storm Software - Prisma tRPC generator with options: \n", JSON.stringify(options, null, 2));
|
|
6212
6214
|
const internals = await getPrismaInternals();
|
|
6215
|
+
console.log(`[STORM]: Validating configuration options`);
|
|
6213
6216
|
const outputDir = internals.parseEnvValue(options.generator.output);
|
|
6214
6217
|
const results = configSchema.safeParse(options.generator.config);
|
|
6215
6218
|
if (!results.success) {
|
|
6216
6219
|
throw new Error("Invalid options passed");
|
|
6217
6220
|
}
|
|
6218
6221
|
const config = results.data;
|
|
6222
|
+
const consoleLog = /* @__PURE__ */ __name((message) => {
|
|
6223
|
+
if (config.debug) {
|
|
6224
|
+
console.log(`[STORM]: ${message}`);
|
|
6225
|
+
}
|
|
6226
|
+
}, "consoleLog");
|
|
6227
|
+
consoleLog(`Preparing output directory: ${outputDir}`);
|
|
6219
6228
|
await fs4.mkdir(outputDir, {
|
|
6220
6229
|
recursive: true
|
|
6221
6230
|
});
|
|
6222
6231
|
await removeDir(outputDir, true);
|
|
6223
6232
|
if (config.withZod !== false) {
|
|
6233
|
+
consoleLog("Generating Zod schemas");
|
|
6224
6234
|
const prismaZodGenerator = await getJiti().import(getJiti().esmResolve("prisma-zod-generator/lib/prisma-generator"));
|
|
6225
6235
|
await prismaZodGenerator.generate(options);
|
|
6236
|
+
} else {
|
|
6237
|
+
consoleLog("Skipping Zod schemas generation");
|
|
6226
6238
|
}
|
|
6227
6239
|
if (config.withShield !== false) {
|
|
6240
|
+
consoleLog("Generating tRPC Shield");
|
|
6228
6241
|
const shieldOutputPath = path6.join(outputDir, "./shield");
|
|
6229
6242
|
await generateShield({
|
|
6230
6243
|
...options,
|
|
@@ -6241,8 +6254,15 @@ async function generate(options) {
|
|
|
6241
6254
|
}
|
|
6242
6255
|
}
|
|
6243
6256
|
});
|
|
6257
|
+
} else {
|
|
6258
|
+
consoleLog("Skipping tRPC Shield generation");
|
|
6244
6259
|
}
|
|
6260
|
+
consoleLog("Finding Prisma Client generator");
|
|
6245
6261
|
const prismaClientProvider = options.otherGenerators.find((it) => internals.parseEnvValue(it.provider) === "prisma-client-js");
|
|
6262
|
+
if (!prismaClientProvider) {
|
|
6263
|
+
throw new Error("No Prisma Client generator found. Please add `prisma-client-js` to your generator list.");
|
|
6264
|
+
}
|
|
6265
|
+
consoleLog("Generating Prisma Client DMMF");
|
|
6246
6266
|
const prismaClientDmmf = await internals.getDMMF({
|
|
6247
6267
|
datamodel: options.datamodel,
|
|
6248
6268
|
previewFeatures: prismaClientProvider?.previewFeatures
|
|
@@ -6250,14 +6270,17 @@ async function generate(options) {
|
|
|
6250
6270
|
const modelOperations = prismaClientDmmf.mappings.modelOperations;
|
|
6251
6271
|
const models = prismaClientDmmf.datamodel.models;
|
|
6252
6272
|
const hiddenModels = [];
|
|
6273
|
+
consoleLog(`Generating tRPC source code for ${models.length} models`);
|
|
6253
6274
|
resolveModelsComments(models, hiddenModels);
|
|
6254
6275
|
const createRouter = project.createSourceFile(path6.resolve(outputDir, "routers", "helpers", "createRouter.ts"), void 0, {
|
|
6255
6276
|
overwrite: true
|
|
6256
6277
|
});
|
|
6278
|
+
consoleLog("Generating tRPC imports");
|
|
6257
6279
|
generateRPCImport(createRouter);
|
|
6258
6280
|
if (config.withShield) {
|
|
6259
6281
|
await generateShieldImport(createRouter, options, config.withShield);
|
|
6260
6282
|
}
|
|
6283
|
+
consoleLog("Generating tRPC base router");
|
|
6261
6284
|
await generateBaseRouter(createRouter, config, options);
|
|
6262
6285
|
createRouter.formatText({
|
|
6263
6286
|
indentSize: 2
|
|
@@ -6265,16 +6288,24 @@ async function generate(options) {
|
|
|
6265
6288
|
const appRouter = project.createSourceFile(path6.resolve(outputDir, "routers", `index.ts`), void 0, {
|
|
6266
6289
|
overwrite: true
|
|
6267
6290
|
});
|
|
6291
|
+
consoleLog("Generating tRPC router imports");
|
|
6268
6292
|
generateCreateRouterImport({
|
|
6269
6293
|
sourceFile: appRouter
|
|
6270
6294
|
});
|
|
6271
6295
|
const routerStatements = [];
|
|
6272
6296
|
for (const modelOperation of modelOperations) {
|
|
6273
6297
|
const { model, ...operations } = modelOperation;
|
|
6274
|
-
if (hiddenModels.includes(model))
|
|
6298
|
+
if (hiddenModels.includes(model)) {
|
|
6299
|
+
consoleLog(`Skipping model ${model} as it is hidden`);
|
|
6300
|
+
continue;
|
|
6301
|
+
}
|
|
6275
6302
|
const modelActions = Object.keys(operations).filter((opType) => config.generateModelActions.includes(opType.replace("One", "")));
|
|
6276
|
-
if (!modelActions.length)
|
|
6303
|
+
if (!modelActions.length) {
|
|
6304
|
+
consoleLog(`Skipping model ${model} as it has no actions to generate`);
|
|
6305
|
+
continue;
|
|
6306
|
+
}
|
|
6277
6307
|
const plural = (0, import_pluralize.default)(model.toLowerCase());
|
|
6308
|
+
consoleLog(`Generating tRPC router for model ${model}`);
|
|
6278
6309
|
generateRouterImport(appRouter, plural, model);
|
|
6279
6310
|
const modelRouter = project.createSourceFile(path6.resolve(outputDir, "routers", `${model}.router.ts`), void 0, {
|
|
6280
6311
|
overwrite: true
|
|
@@ -6284,6 +6315,7 @@ async function generate(options) {
|
|
|
6284
6315
|
config
|
|
6285
6316
|
});
|
|
6286
6317
|
if (config.withZod) {
|
|
6318
|
+
consoleLog("Generating Zod schemas imports");
|
|
6287
6319
|
generateRouterSchemaImports(modelRouter, model, modelActions);
|
|
6288
6320
|
}
|
|
6289
6321
|
modelRouter.addStatements(
|
|
@@ -6309,7 +6341,9 @@ async function generate(options) {
|
|
|
6309
6341
|
`
|
|
6310
6342
|
${model.toLowerCase()}: ${plural}Router`
|
|
6311
6343
|
);
|
|
6344
|
+
consoleLog(`Generated tRPC router for model ${model} with ${modelActions.length} actions`);
|
|
6312
6345
|
}
|
|
6346
|
+
consoleLog("Generating tRPC app router");
|
|
6313
6347
|
appRouter.addStatements(
|
|
6314
6348
|
/* ts */
|
|
6315
6349
|
`
|
|
@@ -6319,7 +6353,9 @@ async function generate(options) {
|
|
|
6319
6353
|
appRouter.formatText({
|
|
6320
6354
|
indentSize: 2
|
|
6321
6355
|
});
|
|
6356
|
+
consoleLog("Saving tRPC router source files to disk");
|
|
6322
6357
|
await project.save();
|
|
6358
|
+
consoleLog("Storm Software - Prisma tRPC generator completed successfully");
|
|
6323
6359
|
}
|
|
6324
6360
|
__name(generate, "generate");
|
|
6325
6361
|
|