@stryke/prisma-trpc-generator 0.5.1 → 0.6.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/generator.cjs +55 -66
- package/dist/generator.js +55 -66
- package/dist/index.cjs +55 -66
- package/dist/index.js +55 -66
- package/package.json +1 -1
package/dist/generator.cjs
CHANGED
|
@@ -6891,10 +6891,10 @@ var configSchema = z.object({
|
|
|
6891
6891
|
withMiddleware: configMiddleware.default("true"),
|
|
6892
6892
|
withShield: configShield.default("true"),
|
|
6893
6893
|
withZod: configBoolean.default("true"),
|
|
6894
|
+
withNext: configBoolean.default("true"),
|
|
6894
6895
|
contextPath: z.string().default("../src/trpc/context"),
|
|
6895
6896
|
trpcOptions: z.boolean().or(z.string()).optional(),
|
|
6896
6897
|
showModelNameInProcedure: configBoolean.default("true"),
|
|
6897
|
-
useTRPCNext: configBoolean.default("false"),
|
|
6898
6898
|
generateModelActions: z.string().default(Object.values(ModelAction).join(",")).transform((arg) => {
|
|
6899
6899
|
return arg.split(",").map((action) => modelActionEnum.parse(action.trim()));
|
|
6900
6900
|
})
|
|
@@ -7636,12 +7636,6 @@ var generateCreateRouterImport = /* @__PURE__ */ __name(({ sourceFile, config })
|
|
|
7636
7636
|
namedImports: imports
|
|
7637
7637
|
});
|
|
7638
7638
|
}, "generateCreateRouterImport");
|
|
7639
|
-
var generateRPCImport = /* @__PURE__ */ __name((sourceFile) => {
|
|
7640
|
-
sourceFile.addImportDeclaration({
|
|
7641
|
-
moduleSpecifier: "@trpc/server",
|
|
7642
|
-
namespaceImport: "trpc"
|
|
7643
|
-
});
|
|
7644
|
-
}, "generateRPCImport");
|
|
7645
7639
|
var generateShieldImport = /* @__PURE__ */ __name(async (sourceFile, options, value) => {
|
|
7646
7640
|
const internals = await getPrismaInternals();
|
|
7647
7641
|
const outputDir = internals.parseEnvValue(options.generator.output);
|
|
@@ -7682,7 +7676,7 @@ async function generateBaseRouter(sourceFile, config, options) {
|
|
|
7682
7676
|
`
|
|
7683
7677
|
);
|
|
7684
7678
|
}
|
|
7685
|
-
if (config.
|
|
7679
|
+
if (config.withNext) {
|
|
7686
7680
|
sourceFile.addStatements(
|
|
7687
7681
|
/* ts */
|
|
7688
7682
|
`
|
|
@@ -7765,7 +7759,7 @@ export const createCallerFactory = t.createCallerFactory;`
|
|
|
7765
7759
|
`
|
|
7766
7760
|
export const publicProcedure = t.procedure; `
|
|
7767
7761
|
);
|
|
7768
|
-
if (config.
|
|
7762
|
+
if (config.withNext) {
|
|
7769
7763
|
sourceFile.addStatements(
|
|
7770
7764
|
/* ts */
|
|
7771
7765
|
`
|
|
@@ -7837,7 +7831,7 @@ function generateRouterSchemaImports(sourceFile, modelName, modelActions) {
|
|
|
7837
7831
|
}
|
|
7838
7832
|
__name(generateRouterSchemaImports, "generateRouterSchemaImports");
|
|
7839
7833
|
var getRouterSchemaImportByOpName = /* @__PURE__ */ __name((opName, modelName) => {
|
|
7840
|
-
const opType = opName.replace("OrThrow", "");
|
|
7834
|
+
const opType = opName.replace("OrThrow", "").replace("ManyAndReturn", "");
|
|
7841
7835
|
const inputType = getInputTypeByOpName(opType, modelName);
|
|
7842
7836
|
return inputType ? `import { ${inputType} } from "../schemas/${opType}${modelName}.schema"; ` : "";
|
|
7843
7837
|
}, "getRouterSchemaImportByOpName");
|
|
@@ -7863,22 +7857,22 @@ var getInputTypeByOpName = /* @__PURE__ */ __name((opName, modelName) => {
|
|
|
7863
7857
|
inputType = `${modelName}CreateManySchema`;
|
|
7864
7858
|
break;
|
|
7865
7859
|
case "createManyAndReturn":
|
|
7866
|
-
inputType = `${modelName}
|
|
7860
|
+
inputType = `${modelName}CreateManySchema`;
|
|
7867
7861
|
break;
|
|
7868
7862
|
case "deleteOne":
|
|
7869
7863
|
inputType = `${modelName}DeleteOneSchema`;
|
|
7870
7864
|
break;
|
|
7871
|
-
case "updateOne":
|
|
7872
|
-
inputType = `${modelName}UpdateOneSchema`;
|
|
7873
|
-
break;
|
|
7874
7865
|
case "deleteMany":
|
|
7875
7866
|
inputType = `${modelName}DeleteManySchema`;
|
|
7876
7867
|
break;
|
|
7868
|
+
case "updateOne":
|
|
7869
|
+
inputType = `${modelName}UpdateOneSchema`;
|
|
7870
|
+
break;
|
|
7877
7871
|
case "updateMany":
|
|
7878
7872
|
inputType = `${modelName}UpdateManySchema`;
|
|
7879
7873
|
break;
|
|
7880
7874
|
case "updateManyAndReturn":
|
|
7881
|
-
inputType = `${modelName}
|
|
7875
|
+
inputType = `${modelName}UpdateManySchema`;
|
|
7882
7876
|
break;
|
|
7883
7877
|
case "upsertOne":
|
|
7884
7878
|
inputType = `${modelName}UpsertSchema`;
|
|
@@ -7963,7 +7957,7 @@ var getImports = /* @__PURE__ */ __name((type, newPath) => {
|
|
|
7963
7957
|
} else if (type === "trpc-shield") {
|
|
7964
7958
|
statement = "import { shield, allow } from 'trpc-shield';\n";
|
|
7965
7959
|
} else if (type === "context") {
|
|
7966
|
-
statement = `import { Context } from '${newPath}';
|
|
7960
|
+
statement = `import type { Context } from '${newPath}';
|
|
7967
7961
|
`;
|
|
7968
7962
|
}
|
|
7969
7963
|
return statement;
|
|
@@ -7987,7 +7981,7 @@ var wrapWithTrpcShieldCall = /* @__PURE__ */ __name(({ shieldObjectTextWrapped }
|
|
|
7987
7981
|
var wrapWithExport = /* @__PURE__ */ __name(({ shieldObjectText }) => {
|
|
7988
7982
|
return `export const permissions = ${shieldObjectText};`;
|
|
7989
7983
|
}, "wrapWithExport");
|
|
7990
|
-
var constructShield = /* @__PURE__ */ __name(async ({ queries, mutations, subscriptions }, config, options) => {
|
|
7984
|
+
var constructShield = /* @__PURE__ */ __name(async ({ queries, mutations, subscriptions }, config, options, shieldOutputDir) => {
|
|
7991
7985
|
if (queries.length === 0 && mutations.length === 0 && subscriptions.length === 0) {
|
|
7992
7986
|
return "";
|
|
7993
7987
|
}
|
|
@@ -8014,9 +8008,7 @@ var constructShield = /* @__PURE__ */ __name(async ({ queries, mutations, subscr
|
|
|
8014
8008
|
return "";
|
|
8015
8009
|
}
|
|
8016
8010
|
let shieldText = getImports("trpc-shield");
|
|
8017
|
-
|
|
8018
|
-
const outputDir = internals.parseEnvValue(options.generator.output);
|
|
8019
|
-
shieldText += getImports("context", relativePath(outputDir, joinPaths(options.schemaPath, config.contextPath)));
|
|
8011
|
+
shieldText += getImports("context", relativePath(shieldOutputDir, joinPaths(options.schemaPath, config.contextPath)));
|
|
8020
8012
|
shieldText += "\n\n";
|
|
8021
8013
|
shieldText += wrapWithExport({
|
|
8022
8014
|
shieldObjectText: wrapWithTrpcShieldCall({
|
|
@@ -11610,49 +11602,47 @@ async function generate(options) {
|
|
|
11610
11602
|
} else {
|
|
11611
11603
|
consoleLog("Skipping Zod schemas generation");
|
|
11612
11604
|
}
|
|
11605
|
+
const queries = [];
|
|
11606
|
+
const mutations = [];
|
|
11607
|
+
const subscriptions = [];
|
|
11608
|
+
prismaClientDmmf.mappings.modelOperations.forEach((modelOperation) => {
|
|
11609
|
+
const { model: _model, plural: _plural, ...operations } = modelOperation;
|
|
11610
|
+
for (const [opType, opNameWithModel] of Object.entries(operations)) {
|
|
11611
|
+
if ([
|
|
11612
|
+
"findUnique",
|
|
11613
|
+
"findUniqueOrThrow",
|
|
11614
|
+
"findFirst",
|
|
11615
|
+
"findFirstOrThrow",
|
|
11616
|
+
"findRaw",
|
|
11617
|
+
"findMany",
|
|
11618
|
+
"aggregateRaw",
|
|
11619
|
+
"count",
|
|
11620
|
+
"aggregate",
|
|
11621
|
+
"groupBy"
|
|
11622
|
+
].includes(opType)) {
|
|
11623
|
+
queries.push(opNameWithModel);
|
|
11624
|
+
}
|
|
11625
|
+
if ([
|
|
11626
|
+
"createOne",
|
|
11627
|
+
"createMany",
|
|
11628
|
+
"createManyAndReturn",
|
|
11629
|
+
"deleteOne",
|
|
11630
|
+
"deleteMany",
|
|
11631
|
+
"updateOne",
|
|
11632
|
+
"updateMany",
|
|
11633
|
+
"updateManyAndReturn",
|
|
11634
|
+
"upsertOne"
|
|
11635
|
+
].includes(opType)) {
|
|
11636
|
+
mutations.push(opNameWithModel);
|
|
11637
|
+
}
|
|
11638
|
+
}
|
|
11639
|
+
});
|
|
11640
|
+
queries.sort();
|
|
11641
|
+
mutations.sort();
|
|
11642
|
+
subscriptions.sort();
|
|
11613
11643
|
if (config.withShield !== false) {
|
|
11614
11644
|
consoleLog("Generating tRPC Shield");
|
|
11615
|
-
const shieldOutputDir =
|
|
11616
|
-
consoleLog("Preparing tRPC Shield output directory");
|
|
11617
|
-
await createDirectory(shieldOutputDir);
|
|
11618
|
-
const queries = [];
|
|
11619
|
-
const mutations = [];
|
|
11620
|
-
const subscriptions = [];
|
|
11621
|
-
prismaClientDmmf.mappings.modelOperations.forEach((modelOperation) => {
|
|
11622
|
-
const { model: _model, plural: _plural, ...operations } = modelOperation;
|
|
11623
|
-
for (const [opType, opNameWithModel] of Object.entries(operations)) {
|
|
11624
|
-
if ([
|
|
11625
|
-
"findUnique",
|
|
11626
|
-
"findUniqueOrThrow",
|
|
11627
|
-
"findFirst",
|
|
11628
|
-
"findFirstOrThrow",
|
|
11629
|
-
"findRaw",
|
|
11630
|
-
"findMany",
|
|
11631
|
-
"aggregateRaw",
|
|
11632
|
-
"count",
|
|
11633
|
-
"aggregate",
|
|
11634
|
-
"groupBy"
|
|
11635
|
-
].includes(opType)) {
|
|
11636
|
-
queries.push(opNameWithModel);
|
|
11637
|
-
}
|
|
11638
|
-
if ([
|
|
11639
|
-
"createOne",
|
|
11640
|
-
"createMany",
|
|
11641
|
-
"createManyAndReturn",
|
|
11642
|
-
"deleteOne",
|
|
11643
|
-
"deleteMany",
|
|
11644
|
-
"updateOne",
|
|
11645
|
-
"updateMany",
|
|
11646
|
-
"updateManyAndReturn",
|
|
11647
|
-
"upsertOne"
|
|
11648
|
-
].includes(opType)) {
|
|
11649
|
-
mutations.push(opNameWithModel);
|
|
11650
|
-
}
|
|
11651
|
-
}
|
|
11652
|
-
});
|
|
11653
|
-
queries.sort();
|
|
11654
|
-
mutations.sort();
|
|
11655
|
-
subscriptions.sort();
|
|
11645
|
+
const shieldOutputDir = outputDir;
|
|
11656
11646
|
consoleLog("Constructing tRPC Shield source file");
|
|
11657
11647
|
const shieldText = await constructShield({
|
|
11658
11648
|
queries,
|
|
@@ -11672,7 +11662,7 @@ async function generate(options) {
|
|
|
11672
11662
|
contextPath: config.contextPath
|
|
11673
11663
|
}
|
|
11674
11664
|
}
|
|
11675
|
-
});
|
|
11665
|
+
}, shieldOutputDir);
|
|
11676
11666
|
consoleLog("Saving tRPC Shield source file to disk");
|
|
11677
11667
|
await writeFileSafely(joinPaths(shieldOutputDir, "shield.ts"), shieldText);
|
|
11678
11668
|
} else {
|
|
@@ -11682,9 +11672,9 @@ async function generate(options) {
|
|
|
11682
11672
|
if (config.trpcOptions && typeof config.trpcOptions === "boolean") {
|
|
11683
11673
|
const trpcOptionsOutputPath = joinPaths(outputDir, "options.ts");
|
|
11684
11674
|
consoleLog("Generating tRPC options source file");
|
|
11685
|
-
await writeFileSafely(trpcOptionsOutputPath, `import { ZodError } from 'zod';${config.
|
|
11675
|
+
await writeFileSafely(trpcOptionsOutputPath, `import { ZodError } from 'zod';${config.withNext ? '\nimport { transformer } from "@stryke/trpc-next/shared";' : ""}
|
|
11686
11676
|
|
|
11687
|
-
export default {${config.
|
|
11677
|
+
export default {${config.withNext ? "\n transformer," : ""}
|
|
11688
11678
|
errorFormatter({ shape, error }) {
|
|
11689
11679
|
return {
|
|
11690
11680
|
...shape,
|
|
@@ -11701,11 +11691,10 @@ export default {${config.useTRPCNext ? "\n transformer," : ""}
|
|
|
11701
11691
|
`);
|
|
11702
11692
|
}
|
|
11703
11693
|
resolveModelsComments(models, hiddenModels);
|
|
11704
|
-
const createRouter = project.createSourceFile(import_node_path6.default.resolve(outputDir, "
|
|
11694
|
+
const createRouter = project.createSourceFile(import_node_path6.default.resolve(outputDir, "trpc.ts"), void 0, {
|
|
11705
11695
|
overwrite: true
|
|
11706
11696
|
});
|
|
11707
11697
|
consoleLog("Generating tRPC imports");
|
|
11708
|
-
generateRPCImport(createRouter);
|
|
11709
11698
|
if (config.withShield) {
|
|
11710
11699
|
await generateShieldImport(createRouter, options, config.withShield);
|
|
11711
11700
|
}
|
package/dist/generator.js
CHANGED
|
@@ -6896,10 +6896,10 @@ var configSchema = z.object({
|
|
|
6896
6896
|
withMiddleware: configMiddleware.default("true"),
|
|
6897
6897
|
withShield: configShield.default("true"),
|
|
6898
6898
|
withZod: configBoolean.default("true"),
|
|
6899
|
+
withNext: configBoolean.default("true"),
|
|
6899
6900
|
contextPath: z.string().default("../src/trpc/context"),
|
|
6900
6901
|
trpcOptions: z.boolean().or(z.string()).optional(),
|
|
6901
6902
|
showModelNameInProcedure: configBoolean.default("true"),
|
|
6902
|
-
useTRPCNext: configBoolean.default("false"),
|
|
6903
6903
|
generateModelActions: z.string().default(Object.values(ModelAction).join(",")).transform((arg) => {
|
|
6904
6904
|
return arg.split(",").map((action) => modelActionEnum.parse(action.trim()));
|
|
6905
6905
|
})
|
|
@@ -7641,12 +7641,6 @@ var generateCreateRouterImport = /* @__PURE__ */ __name(({ sourceFile, config })
|
|
|
7641
7641
|
namedImports: imports
|
|
7642
7642
|
});
|
|
7643
7643
|
}, "generateCreateRouterImport");
|
|
7644
|
-
var generateRPCImport = /* @__PURE__ */ __name((sourceFile) => {
|
|
7645
|
-
sourceFile.addImportDeclaration({
|
|
7646
|
-
moduleSpecifier: "@trpc/server",
|
|
7647
|
-
namespaceImport: "trpc"
|
|
7648
|
-
});
|
|
7649
|
-
}, "generateRPCImport");
|
|
7650
7644
|
var generateShieldImport = /* @__PURE__ */ __name(async (sourceFile, options, value) => {
|
|
7651
7645
|
const internals = await getPrismaInternals();
|
|
7652
7646
|
const outputDir = internals.parseEnvValue(options.generator.output);
|
|
@@ -7687,7 +7681,7 @@ async function generateBaseRouter(sourceFile, config, options) {
|
|
|
7687
7681
|
`
|
|
7688
7682
|
);
|
|
7689
7683
|
}
|
|
7690
|
-
if (config.
|
|
7684
|
+
if (config.withNext) {
|
|
7691
7685
|
sourceFile.addStatements(
|
|
7692
7686
|
/* ts */
|
|
7693
7687
|
`
|
|
@@ -7770,7 +7764,7 @@ export const createCallerFactory = t.createCallerFactory;`
|
|
|
7770
7764
|
`
|
|
7771
7765
|
export const publicProcedure = t.procedure; `
|
|
7772
7766
|
);
|
|
7773
|
-
if (config.
|
|
7767
|
+
if (config.withNext) {
|
|
7774
7768
|
sourceFile.addStatements(
|
|
7775
7769
|
/* ts */
|
|
7776
7770
|
`
|
|
@@ -7842,7 +7836,7 @@ function generateRouterSchemaImports(sourceFile, modelName, modelActions) {
|
|
|
7842
7836
|
}
|
|
7843
7837
|
__name(generateRouterSchemaImports, "generateRouterSchemaImports");
|
|
7844
7838
|
var getRouterSchemaImportByOpName = /* @__PURE__ */ __name((opName, modelName) => {
|
|
7845
|
-
const opType = opName.replace("OrThrow", "");
|
|
7839
|
+
const opType = opName.replace("OrThrow", "").replace("ManyAndReturn", "");
|
|
7846
7840
|
const inputType = getInputTypeByOpName(opType, modelName);
|
|
7847
7841
|
return inputType ? `import { ${inputType} } from "../schemas/${opType}${modelName}.schema"; ` : "";
|
|
7848
7842
|
}, "getRouterSchemaImportByOpName");
|
|
@@ -7868,22 +7862,22 @@ var getInputTypeByOpName = /* @__PURE__ */ __name((opName, modelName) => {
|
|
|
7868
7862
|
inputType = `${modelName}CreateManySchema`;
|
|
7869
7863
|
break;
|
|
7870
7864
|
case "createManyAndReturn":
|
|
7871
|
-
inputType = `${modelName}
|
|
7865
|
+
inputType = `${modelName}CreateManySchema`;
|
|
7872
7866
|
break;
|
|
7873
7867
|
case "deleteOne":
|
|
7874
7868
|
inputType = `${modelName}DeleteOneSchema`;
|
|
7875
7869
|
break;
|
|
7876
|
-
case "updateOne":
|
|
7877
|
-
inputType = `${modelName}UpdateOneSchema`;
|
|
7878
|
-
break;
|
|
7879
7870
|
case "deleteMany":
|
|
7880
7871
|
inputType = `${modelName}DeleteManySchema`;
|
|
7881
7872
|
break;
|
|
7873
|
+
case "updateOne":
|
|
7874
|
+
inputType = `${modelName}UpdateOneSchema`;
|
|
7875
|
+
break;
|
|
7882
7876
|
case "updateMany":
|
|
7883
7877
|
inputType = `${modelName}UpdateManySchema`;
|
|
7884
7878
|
break;
|
|
7885
7879
|
case "updateManyAndReturn":
|
|
7886
|
-
inputType = `${modelName}
|
|
7880
|
+
inputType = `${modelName}UpdateManySchema`;
|
|
7887
7881
|
break;
|
|
7888
7882
|
case "upsertOne":
|
|
7889
7883
|
inputType = `${modelName}UpsertSchema`;
|
|
@@ -7968,7 +7962,7 @@ var getImports = /* @__PURE__ */ __name((type, newPath) => {
|
|
|
7968
7962
|
} else if (type === "trpc-shield") {
|
|
7969
7963
|
statement = "import { shield, allow } from 'trpc-shield';\n";
|
|
7970
7964
|
} else if (type === "context") {
|
|
7971
|
-
statement = `import { Context } from '${newPath}';
|
|
7965
|
+
statement = `import type { Context } from '${newPath}';
|
|
7972
7966
|
`;
|
|
7973
7967
|
}
|
|
7974
7968
|
return statement;
|
|
@@ -7992,7 +7986,7 @@ var wrapWithTrpcShieldCall = /* @__PURE__ */ __name(({ shieldObjectTextWrapped }
|
|
|
7992
7986
|
var wrapWithExport = /* @__PURE__ */ __name(({ shieldObjectText }) => {
|
|
7993
7987
|
return `export const permissions = ${shieldObjectText};`;
|
|
7994
7988
|
}, "wrapWithExport");
|
|
7995
|
-
var constructShield = /* @__PURE__ */ __name(async ({ queries, mutations, subscriptions }, config, options) => {
|
|
7989
|
+
var constructShield = /* @__PURE__ */ __name(async ({ queries, mutations, subscriptions }, config, options, shieldOutputDir) => {
|
|
7996
7990
|
if (queries.length === 0 && mutations.length === 0 && subscriptions.length === 0) {
|
|
7997
7991
|
return "";
|
|
7998
7992
|
}
|
|
@@ -8019,9 +8013,7 @@ var constructShield = /* @__PURE__ */ __name(async ({ queries, mutations, subscr
|
|
|
8019
8013
|
return "";
|
|
8020
8014
|
}
|
|
8021
8015
|
let shieldText = getImports("trpc-shield");
|
|
8022
|
-
|
|
8023
|
-
const outputDir = internals.parseEnvValue(options.generator.output);
|
|
8024
|
-
shieldText += getImports("context", relativePath(outputDir, joinPaths(options.schemaPath, config.contextPath)));
|
|
8016
|
+
shieldText += getImports("context", relativePath(shieldOutputDir, joinPaths(options.schemaPath, config.contextPath)));
|
|
8025
8017
|
shieldText += "\n\n";
|
|
8026
8018
|
shieldText += wrapWithExport({
|
|
8027
8019
|
shieldObjectText: wrapWithTrpcShieldCall({
|
|
@@ -11615,49 +11607,47 @@ async function generate(options) {
|
|
|
11615
11607
|
} else {
|
|
11616
11608
|
consoleLog("Skipping Zod schemas generation");
|
|
11617
11609
|
}
|
|
11610
|
+
const queries = [];
|
|
11611
|
+
const mutations = [];
|
|
11612
|
+
const subscriptions = [];
|
|
11613
|
+
prismaClientDmmf.mappings.modelOperations.forEach((modelOperation) => {
|
|
11614
|
+
const { model: _model, plural: _plural, ...operations } = modelOperation;
|
|
11615
|
+
for (const [opType, opNameWithModel] of Object.entries(operations)) {
|
|
11616
|
+
if ([
|
|
11617
|
+
"findUnique",
|
|
11618
|
+
"findUniqueOrThrow",
|
|
11619
|
+
"findFirst",
|
|
11620
|
+
"findFirstOrThrow",
|
|
11621
|
+
"findRaw",
|
|
11622
|
+
"findMany",
|
|
11623
|
+
"aggregateRaw",
|
|
11624
|
+
"count",
|
|
11625
|
+
"aggregate",
|
|
11626
|
+
"groupBy"
|
|
11627
|
+
].includes(opType)) {
|
|
11628
|
+
queries.push(opNameWithModel);
|
|
11629
|
+
}
|
|
11630
|
+
if ([
|
|
11631
|
+
"createOne",
|
|
11632
|
+
"createMany",
|
|
11633
|
+
"createManyAndReturn",
|
|
11634
|
+
"deleteOne",
|
|
11635
|
+
"deleteMany",
|
|
11636
|
+
"updateOne",
|
|
11637
|
+
"updateMany",
|
|
11638
|
+
"updateManyAndReturn",
|
|
11639
|
+
"upsertOne"
|
|
11640
|
+
].includes(opType)) {
|
|
11641
|
+
mutations.push(opNameWithModel);
|
|
11642
|
+
}
|
|
11643
|
+
}
|
|
11644
|
+
});
|
|
11645
|
+
queries.sort();
|
|
11646
|
+
mutations.sort();
|
|
11647
|
+
subscriptions.sort();
|
|
11618
11648
|
if (config.withShield !== false) {
|
|
11619
11649
|
consoleLog("Generating tRPC Shield");
|
|
11620
|
-
const shieldOutputDir =
|
|
11621
|
-
consoleLog("Preparing tRPC Shield output directory");
|
|
11622
|
-
await createDirectory(shieldOutputDir);
|
|
11623
|
-
const queries = [];
|
|
11624
|
-
const mutations = [];
|
|
11625
|
-
const subscriptions = [];
|
|
11626
|
-
prismaClientDmmf.mappings.modelOperations.forEach((modelOperation) => {
|
|
11627
|
-
const { model: _model, plural: _plural, ...operations } = modelOperation;
|
|
11628
|
-
for (const [opType, opNameWithModel] of Object.entries(operations)) {
|
|
11629
|
-
if ([
|
|
11630
|
-
"findUnique",
|
|
11631
|
-
"findUniqueOrThrow",
|
|
11632
|
-
"findFirst",
|
|
11633
|
-
"findFirstOrThrow",
|
|
11634
|
-
"findRaw",
|
|
11635
|
-
"findMany",
|
|
11636
|
-
"aggregateRaw",
|
|
11637
|
-
"count",
|
|
11638
|
-
"aggregate",
|
|
11639
|
-
"groupBy"
|
|
11640
|
-
].includes(opType)) {
|
|
11641
|
-
queries.push(opNameWithModel);
|
|
11642
|
-
}
|
|
11643
|
-
if ([
|
|
11644
|
-
"createOne",
|
|
11645
|
-
"createMany",
|
|
11646
|
-
"createManyAndReturn",
|
|
11647
|
-
"deleteOne",
|
|
11648
|
-
"deleteMany",
|
|
11649
|
-
"updateOne",
|
|
11650
|
-
"updateMany",
|
|
11651
|
-
"updateManyAndReturn",
|
|
11652
|
-
"upsertOne"
|
|
11653
|
-
].includes(opType)) {
|
|
11654
|
-
mutations.push(opNameWithModel);
|
|
11655
|
-
}
|
|
11656
|
-
}
|
|
11657
|
-
});
|
|
11658
|
-
queries.sort();
|
|
11659
|
-
mutations.sort();
|
|
11660
|
-
subscriptions.sort();
|
|
11650
|
+
const shieldOutputDir = outputDir;
|
|
11661
11651
|
consoleLog("Constructing tRPC Shield source file");
|
|
11662
11652
|
const shieldText = await constructShield({
|
|
11663
11653
|
queries,
|
|
@@ -11677,7 +11667,7 @@ async function generate(options) {
|
|
|
11677
11667
|
contextPath: config.contextPath
|
|
11678
11668
|
}
|
|
11679
11669
|
}
|
|
11680
|
-
});
|
|
11670
|
+
}, shieldOutputDir);
|
|
11681
11671
|
consoleLog("Saving tRPC Shield source file to disk");
|
|
11682
11672
|
await writeFileSafely(joinPaths(shieldOutputDir, "shield.ts"), shieldText);
|
|
11683
11673
|
} else {
|
|
@@ -11687,9 +11677,9 @@ async function generate(options) {
|
|
|
11687
11677
|
if (config.trpcOptions && typeof config.trpcOptions === "boolean") {
|
|
11688
11678
|
const trpcOptionsOutputPath = joinPaths(outputDir, "options.ts");
|
|
11689
11679
|
consoleLog("Generating tRPC options source file");
|
|
11690
|
-
await writeFileSafely(trpcOptionsOutputPath, `import { ZodError } from 'zod';${config.
|
|
11680
|
+
await writeFileSafely(trpcOptionsOutputPath, `import { ZodError } from 'zod';${config.withNext ? '\nimport { transformer } from "@stryke/trpc-next/shared";' : ""}
|
|
11691
11681
|
|
|
11692
|
-
export default {${config.
|
|
11682
|
+
export default {${config.withNext ? "\n transformer," : ""}
|
|
11693
11683
|
errorFormatter({ shape, error }) {
|
|
11694
11684
|
return {
|
|
11695
11685
|
...shape,
|
|
@@ -11706,11 +11696,10 @@ export default {${config.useTRPCNext ? "\n transformer," : ""}
|
|
|
11706
11696
|
`);
|
|
11707
11697
|
}
|
|
11708
11698
|
resolveModelsComments(models, hiddenModels);
|
|
11709
|
-
const createRouter = project.createSourceFile(path5.resolve(outputDir, "
|
|
11699
|
+
const createRouter = project.createSourceFile(path5.resolve(outputDir, "trpc.ts"), void 0, {
|
|
11710
11700
|
overwrite: true
|
|
11711
11701
|
});
|
|
11712
11702
|
consoleLog("Generating tRPC imports");
|
|
11713
|
-
generateRPCImport(createRouter);
|
|
11714
11703
|
if (config.withShield) {
|
|
11715
11704
|
await generateShieldImport(createRouter, options, config.withShield);
|
|
11716
11705
|
}
|
package/dist/index.cjs
CHANGED
|
@@ -6887,10 +6887,10 @@ var configSchema = z.object({
|
|
|
6887
6887
|
withMiddleware: configMiddleware.default("true"),
|
|
6888
6888
|
withShield: configShield.default("true"),
|
|
6889
6889
|
withZod: configBoolean.default("true"),
|
|
6890
|
+
withNext: configBoolean.default("true"),
|
|
6890
6891
|
contextPath: z.string().default("../src/trpc/context"),
|
|
6891
6892
|
trpcOptions: z.boolean().or(z.string()).optional(),
|
|
6892
6893
|
showModelNameInProcedure: configBoolean.default("true"),
|
|
6893
|
-
useTRPCNext: configBoolean.default("false"),
|
|
6894
6894
|
generateModelActions: z.string().default(Object.values(ModelAction).join(",")).transform((arg) => {
|
|
6895
6895
|
return arg.split(",").map((action) => modelActionEnum.parse(action.trim()));
|
|
6896
6896
|
})
|
|
@@ -7632,12 +7632,6 @@ var generateCreateRouterImport = /* @__PURE__ */ __name(({ sourceFile, config })
|
|
|
7632
7632
|
namedImports: imports
|
|
7633
7633
|
});
|
|
7634
7634
|
}, "generateCreateRouterImport");
|
|
7635
|
-
var generateRPCImport = /* @__PURE__ */ __name((sourceFile) => {
|
|
7636
|
-
sourceFile.addImportDeclaration({
|
|
7637
|
-
moduleSpecifier: "@trpc/server",
|
|
7638
|
-
namespaceImport: "trpc"
|
|
7639
|
-
});
|
|
7640
|
-
}, "generateRPCImport");
|
|
7641
7635
|
var generateShieldImport = /* @__PURE__ */ __name(async (sourceFile, options, value) => {
|
|
7642
7636
|
const internals = await getPrismaInternals();
|
|
7643
7637
|
const outputDir = internals.parseEnvValue(options.generator.output);
|
|
@@ -7678,7 +7672,7 @@ async function generateBaseRouter(sourceFile, config, options) {
|
|
|
7678
7672
|
`
|
|
7679
7673
|
);
|
|
7680
7674
|
}
|
|
7681
|
-
if (config.
|
|
7675
|
+
if (config.withNext) {
|
|
7682
7676
|
sourceFile.addStatements(
|
|
7683
7677
|
/* ts */
|
|
7684
7678
|
`
|
|
@@ -7761,7 +7755,7 @@ export const createCallerFactory = t.createCallerFactory;`
|
|
|
7761
7755
|
`
|
|
7762
7756
|
export const publicProcedure = t.procedure; `
|
|
7763
7757
|
);
|
|
7764
|
-
if (config.
|
|
7758
|
+
if (config.withNext) {
|
|
7765
7759
|
sourceFile.addStatements(
|
|
7766
7760
|
/* ts */
|
|
7767
7761
|
`
|
|
@@ -7833,7 +7827,7 @@ function generateRouterSchemaImports(sourceFile, modelName, modelActions) {
|
|
|
7833
7827
|
}
|
|
7834
7828
|
__name(generateRouterSchemaImports, "generateRouterSchemaImports");
|
|
7835
7829
|
var getRouterSchemaImportByOpName = /* @__PURE__ */ __name((opName, modelName) => {
|
|
7836
|
-
const opType = opName.replace("OrThrow", "");
|
|
7830
|
+
const opType = opName.replace("OrThrow", "").replace("ManyAndReturn", "");
|
|
7837
7831
|
const inputType = getInputTypeByOpName(opType, modelName);
|
|
7838
7832
|
return inputType ? `import { ${inputType} } from "../schemas/${opType}${modelName}.schema"; ` : "";
|
|
7839
7833
|
}, "getRouterSchemaImportByOpName");
|
|
@@ -7859,22 +7853,22 @@ var getInputTypeByOpName = /* @__PURE__ */ __name((opName, modelName) => {
|
|
|
7859
7853
|
inputType = `${modelName}CreateManySchema`;
|
|
7860
7854
|
break;
|
|
7861
7855
|
case "createManyAndReturn":
|
|
7862
|
-
inputType = `${modelName}
|
|
7856
|
+
inputType = `${modelName}CreateManySchema`;
|
|
7863
7857
|
break;
|
|
7864
7858
|
case "deleteOne":
|
|
7865
7859
|
inputType = `${modelName}DeleteOneSchema`;
|
|
7866
7860
|
break;
|
|
7867
|
-
case "updateOne":
|
|
7868
|
-
inputType = `${modelName}UpdateOneSchema`;
|
|
7869
|
-
break;
|
|
7870
7861
|
case "deleteMany":
|
|
7871
7862
|
inputType = `${modelName}DeleteManySchema`;
|
|
7872
7863
|
break;
|
|
7864
|
+
case "updateOne":
|
|
7865
|
+
inputType = `${modelName}UpdateOneSchema`;
|
|
7866
|
+
break;
|
|
7873
7867
|
case "updateMany":
|
|
7874
7868
|
inputType = `${modelName}UpdateManySchema`;
|
|
7875
7869
|
break;
|
|
7876
7870
|
case "updateManyAndReturn":
|
|
7877
|
-
inputType = `${modelName}
|
|
7871
|
+
inputType = `${modelName}UpdateManySchema`;
|
|
7878
7872
|
break;
|
|
7879
7873
|
case "upsertOne":
|
|
7880
7874
|
inputType = `${modelName}UpsertSchema`;
|
|
@@ -7959,7 +7953,7 @@ var getImports = /* @__PURE__ */ __name((type, newPath) => {
|
|
|
7959
7953
|
} else if (type === "trpc-shield") {
|
|
7960
7954
|
statement = "import { shield, allow } from 'trpc-shield';\n";
|
|
7961
7955
|
} else if (type === "context") {
|
|
7962
|
-
statement = `import { Context } from '${newPath}';
|
|
7956
|
+
statement = `import type { Context } from '${newPath}';
|
|
7963
7957
|
`;
|
|
7964
7958
|
}
|
|
7965
7959
|
return statement;
|
|
@@ -7983,7 +7977,7 @@ var wrapWithTrpcShieldCall = /* @__PURE__ */ __name(({ shieldObjectTextWrapped }
|
|
|
7983
7977
|
var wrapWithExport = /* @__PURE__ */ __name(({ shieldObjectText }) => {
|
|
7984
7978
|
return `export const permissions = ${shieldObjectText};`;
|
|
7985
7979
|
}, "wrapWithExport");
|
|
7986
|
-
var constructShield = /* @__PURE__ */ __name(async ({ queries, mutations, subscriptions }, config, options) => {
|
|
7980
|
+
var constructShield = /* @__PURE__ */ __name(async ({ queries, mutations, subscriptions }, config, options, shieldOutputDir) => {
|
|
7987
7981
|
if (queries.length === 0 && mutations.length === 0 && subscriptions.length === 0) {
|
|
7988
7982
|
return "";
|
|
7989
7983
|
}
|
|
@@ -8010,9 +8004,7 @@ var constructShield = /* @__PURE__ */ __name(async ({ queries, mutations, subscr
|
|
|
8010
8004
|
return "";
|
|
8011
8005
|
}
|
|
8012
8006
|
let shieldText = getImports("trpc-shield");
|
|
8013
|
-
|
|
8014
|
-
const outputDir = internals.parseEnvValue(options.generator.output);
|
|
8015
|
-
shieldText += getImports("context", relativePath(outputDir, joinPaths(options.schemaPath, config.contextPath)));
|
|
8007
|
+
shieldText += getImports("context", relativePath(shieldOutputDir, joinPaths(options.schemaPath, config.contextPath)));
|
|
8016
8008
|
shieldText += "\n\n";
|
|
8017
8009
|
shieldText += wrapWithExport({
|
|
8018
8010
|
shieldObjectText: wrapWithTrpcShieldCall({
|
|
@@ -11606,49 +11598,47 @@ async function generate(options) {
|
|
|
11606
11598
|
} else {
|
|
11607
11599
|
consoleLog("Skipping Zod schemas generation");
|
|
11608
11600
|
}
|
|
11601
|
+
const queries = [];
|
|
11602
|
+
const mutations = [];
|
|
11603
|
+
const subscriptions = [];
|
|
11604
|
+
prismaClientDmmf.mappings.modelOperations.forEach((modelOperation) => {
|
|
11605
|
+
const { model: _model, plural: _plural, ...operations } = modelOperation;
|
|
11606
|
+
for (const [opType, opNameWithModel] of Object.entries(operations)) {
|
|
11607
|
+
if ([
|
|
11608
|
+
"findUnique",
|
|
11609
|
+
"findUniqueOrThrow",
|
|
11610
|
+
"findFirst",
|
|
11611
|
+
"findFirstOrThrow",
|
|
11612
|
+
"findRaw",
|
|
11613
|
+
"findMany",
|
|
11614
|
+
"aggregateRaw",
|
|
11615
|
+
"count",
|
|
11616
|
+
"aggregate",
|
|
11617
|
+
"groupBy"
|
|
11618
|
+
].includes(opType)) {
|
|
11619
|
+
queries.push(opNameWithModel);
|
|
11620
|
+
}
|
|
11621
|
+
if ([
|
|
11622
|
+
"createOne",
|
|
11623
|
+
"createMany",
|
|
11624
|
+
"createManyAndReturn",
|
|
11625
|
+
"deleteOne",
|
|
11626
|
+
"deleteMany",
|
|
11627
|
+
"updateOne",
|
|
11628
|
+
"updateMany",
|
|
11629
|
+
"updateManyAndReturn",
|
|
11630
|
+
"upsertOne"
|
|
11631
|
+
].includes(opType)) {
|
|
11632
|
+
mutations.push(opNameWithModel);
|
|
11633
|
+
}
|
|
11634
|
+
}
|
|
11635
|
+
});
|
|
11636
|
+
queries.sort();
|
|
11637
|
+
mutations.sort();
|
|
11638
|
+
subscriptions.sort();
|
|
11609
11639
|
if (config.withShield !== false) {
|
|
11610
11640
|
consoleLog("Generating tRPC Shield");
|
|
11611
|
-
const shieldOutputDir =
|
|
11612
|
-
consoleLog("Preparing tRPC Shield output directory");
|
|
11613
|
-
await createDirectory(shieldOutputDir);
|
|
11614
|
-
const queries = [];
|
|
11615
|
-
const mutations = [];
|
|
11616
|
-
const subscriptions = [];
|
|
11617
|
-
prismaClientDmmf.mappings.modelOperations.forEach((modelOperation) => {
|
|
11618
|
-
const { model: _model, plural: _plural, ...operations } = modelOperation;
|
|
11619
|
-
for (const [opType, opNameWithModel] of Object.entries(operations)) {
|
|
11620
|
-
if ([
|
|
11621
|
-
"findUnique",
|
|
11622
|
-
"findUniqueOrThrow",
|
|
11623
|
-
"findFirst",
|
|
11624
|
-
"findFirstOrThrow",
|
|
11625
|
-
"findRaw",
|
|
11626
|
-
"findMany",
|
|
11627
|
-
"aggregateRaw",
|
|
11628
|
-
"count",
|
|
11629
|
-
"aggregate",
|
|
11630
|
-
"groupBy"
|
|
11631
|
-
].includes(opType)) {
|
|
11632
|
-
queries.push(opNameWithModel);
|
|
11633
|
-
}
|
|
11634
|
-
if ([
|
|
11635
|
-
"createOne",
|
|
11636
|
-
"createMany",
|
|
11637
|
-
"createManyAndReturn",
|
|
11638
|
-
"deleteOne",
|
|
11639
|
-
"deleteMany",
|
|
11640
|
-
"updateOne",
|
|
11641
|
-
"updateMany",
|
|
11642
|
-
"updateManyAndReturn",
|
|
11643
|
-
"upsertOne"
|
|
11644
|
-
].includes(opType)) {
|
|
11645
|
-
mutations.push(opNameWithModel);
|
|
11646
|
-
}
|
|
11647
|
-
}
|
|
11648
|
-
});
|
|
11649
|
-
queries.sort();
|
|
11650
|
-
mutations.sort();
|
|
11651
|
-
subscriptions.sort();
|
|
11641
|
+
const shieldOutputDir = outputDir;
|
|
11652
11642
|
consoleLog("Constructing tRPC Shield source file");
|
|
11653
11643
|
const shieldText = await constructShield({
|
|
11654
11644
|
queries,
|
|
@@ -11668,7 +11658,7 @@ async function generate(options) {
|
|
|
11668
11658
|
contextPath: config.contextPath
|
|
11669
11659
|
}
|
|
11670
11660
|
}
|
|
11671
|
-
});
|
|
11661
|
+
}, shieldOutputDir);
|
|
11672
11662
|
consoleLog("Saving tRPC Shield source file to disk");
|
|
11673
11663
|
await writeFileSafely(joinPaths(shieldOutputDir, "shield.ts"), shieldText);
|
|
11674
11664
|
} else {
|
|
@@ -11678,9 +11668,9 @@ async function generate(options) {
|
|
|
11678
11668
|
if (config.trpcOptions && typeof config.trpcOptions === "boolean") {
|
|
11679
11669
|
const trpcOptionsOutputPath = joinPaths(outputDir, "options.ts");
|
|
11680
11670
|
consoleLog("Generating tRPC options source file");
|
|
11681
|
-
await writeFileSafely(trpcOptionsOutputPath, `import { ZodError } from 'zod';${config.
|
|
11671
|
+
await writeFileSafely(trpcOptionsOutputPath, `import { ZodError } from 'zod';${config.withNext ? '\nimport { transformer } from "@stryke/trpc-next/shared";' : ""}
|
|
11682
11672
|
|
|
11683
|
-
export default {${config.
|
|
11673
|
+
export default {${config.withNext ? "\n transformer," : ""}
|
|
11684
11674
|
errorFormatter({ shape, error }) {
|
|
11685
11675
|
return {
|
|
11686
11676
|
...shape,
|
|
@@ -11697,11 +11687,10 @@ export default {${config.useTRPCNext ? "\n transformer," : ""}
|
|
|
11697
11687
|
`);
|
|
11698
11688
|
}
|
|
11699
11689
|
resolveModelsComments(models, hiddenModels);
|
|
11700
|
-
const createRouter = project.createSourceFile(import_node_path6.default.resolve(outputDir, "
|
|
11690
|
+
const createRouter = project.createSourceFile(import_node_path6.default.resolve(outputDir, "trpc.ts"), void 0, {
|
|
11701
11691
|
overwrite: true
|
|
11702
11692
|
});
|
|
11703
11693
|
consoleLog("Generating tRPC imports");
|
|
11704
|
-
generateRPCImport(createRouter);
|
|
11705
11694
|
if (config.withShield) {
|
|
11706
11695
|
await generateShieldImport(createRouter, options, config.withShield);
|
|
11707
11696
|
}
|
package/dist/index.js
CHANGED
|
@@ -6892,10 +6892,10 @@ var configSchema = z.object({
|
|
|
6892
6892
|
withMiddleware: configMiddleware.default("true"),
|
|
6893
6893
|
withShield: configShield.default("true"),
|
|
6894
6894
|
withZod: configBoolean.default("true"),
|
|
6895
|
+
withNext: configBoolean.default("true"),
|
|
6895
6896
|
contextPath: z.string().default("../src/trpc/context"),
|
|
6896
6897
|
trpcOptions: z.boolean().or(z.string()).optional(),
|
|
6897
6898
|
showModelNameInProcedure: configBoolean.default("true"),
|
|
6898
|
-
useTRPCNext: configBoolean.default("false"),
|
|
6899
6899
|
generateModelActions: z.string().default(Object.values(ModelAction).join(",")).transform((arg) => {
|
|
6900
6900
|
return arg.split(",").map((action) => modelActionEnum.parse(action.trim()));
|
|
6901
6901
|
})
|
|
@@ -7637,12 +7637,6 @@ var generateCreateRouterImport = /* @__PURE__ */ __name(({ sourceFile, config })
|
|
|
7637
7637
|
namedImports: imports
|
|
7638
7638
|
});
|
|
7639
7639
|
}, "generateCreateRouterImport");
|
|
7640
|
-
var generateRPCImport = /* @__PURE__ */ __name((sourceFile) => {
|
|
7641
|
-
sourceFile.addImportDeclaration({
|
|
7642
|
-
moduleSpecifier: "@trpc/server",
|
|
7643
|
-
namespaceImport: "trpc"
|
|
7644
|
-
});
|
|
7645
|
-
}, "generateRPCImport");
|
|
7646
7640
|
var generateShieldImport = /* @__PURE__ */ __name(async (sourceFile, options, value) => {
|
|
7647
7641
|
const internals = await getPrismaInternals();
|
|
7648
7642
|
const outputDir = internals.parseEnvValue(options.generator.output);
|
|
@@ -7683,7 +7677,7 @@ async function generateBaseRouter(sourceFile, config, options) {
|
|
|
7683
7677
|
`
|
|
7684
7678
|
);
|
|
7685
7679
|
}
|
|
7686
|
-
if (config.
|
|
7680
|
+
if (config.withNext) {
|
|
7687
7681
|
sourceFile.addStatements(
|
|
7688
7682
|
/* ts */
|
|
7689
7683
|
`
|
|
@@ -7766,7 +7760,7 @@ export const createCallerFactory = t.createCallerFactory;`
|
|
|
7766
7760
|
`
|
|
7767
7761
|
export const publicProcedure = t.procedure; `
|
|
7768
7762
|
);
|
|
7769
|
-
if (config.
|
|
7763
|
+
if (config.withNext) {
|
|
7770
7764
|
sourceFile.addStatements(
|
|
7771
7765
|
/* ts */
|
|
7772
7766
|
`
|
|
@@ -7838,7 +7832,7 @@ function generateRouterSchemaImports(sourceFile, modelName, modelActions) {
|
|
|
7838
7832
|
}
|
|
7839
7833
|
__name(generateRouterSchemaImports, "generateRouterSchemaImports");
|
|
7840
7834
|
var getRouterSchemaImportByOpName = /* @__PURE__ */ __name((opName, modelName) => {
|
|
7841
|
-
const opType = opName.replace("OrThrow", "");
|
|
7835
|
+
const opType = opName.replace("OrThrow", "").replace("ManyAndReturn", "");
|
|
7842
7836
|
const inputType = getInputTypeByOpName(opType, modelName);
|
|
7843
7837
|
return inputType ? `import { ${inputType} } from "../schemas/${opType}${modelName}.schema"; ` : "";
|
|
7844
7838
|
}, "getRouterSchemaImportByOpName");
|
|
@@ -7864,22 +7858,22 @@ var getInputTypeByOpName = /* @__PURE__ */ __name((opName, modelName) => {
|
|
|
7864
7858
|
inputType = `${modelName}CreateManySchema`;
|
|
7865
7859
|
break;
|
|
7866
7860
|
case "createManyAndReturn":
|
|
7867
|
-
inputType = `${modelName}
|
|
7861
|
+
inputType = `${modelName}CreateManySchema`;
|
|
7868
7862
|
break;
|
|
7869
7863
|
case "deleteOne":
|
|
7870
7864
|
inputType = `${modelName}DeleteOneSchema`;
|
|
7871
7865
|
break;
|
|
7872
|
-
case "updateOne":
|
|
7873
|
-
inputType = `${modelName}UpdateOneSchema`;
|
|
7874
|
-
break;
|
|
7875
7866
|
case "deleteMany":
|
|
7876
7867
|
inputType = `${modelName}DeleteManySchema`;
|
|
7877
7868
|
break;
|
|
7869
|
+
case "updateOne":
|
|
7870
|
+
inputType = `${modelName}UpdateOneSchema`;
|
|
7871
|
+
break;
|
|
7878
7872
|
case "updateMany":
|
|
7879
7873
|
inputType = `${modelName}UpdateManySchema`;
|
|
7880
7874
|
break;
|
|
7881
7875
|
case "updateManyAndReturn":
|
|
7882
|
-
inputType = `${modelName}
|
|
7876
|
+
inputType = `${modelName}UpdateManySchema`;
|
|
7883
7877
|
break;
|
|
7884
7878
|
case "upsertOne":
|
|
7885
7879
|
inputType = `${modelName}UpsertSchema`;
|
|
@@ -7964,7 +7958,7 @@ var getImports = /* @__PURE__ */ __name((type, newPath) => {
|
|
|
7964
7958
|
} else if (type === "trpc-shield") {
|
|
7965
7959
|
statement = "import { shield, allow } from 'trpc-shield';\n";
|
|
7966
7960
|
} else if (type === "context") {
|
|
7967
|
-
statement = `import { Context } from '${newPath}';
|
|
7961
|
+
statement = `import type { Context } from '${newPath}';
|
|
7968
7962
|
`;
|
|
7969
7963
|
}
|
|
7970
7964
|
return statement;
|
|
@@ -7988,7 +7982,7 @@ var wrapWithTrpcShieldCall = /* @__PURE__ */ __name(({ shieldObjectTextWrapped }
|
|
|
7988
7982
|
var wrapWithExport = /* @__PURE__ */ __name(({ shieldObjectText }) => {
|
|
7989
7983
|
return `export const permissions = ${shieldObjectText};`;
|
|
7990
7984
|
}, "wrapWithExport");
|
|
7991
|
-
var constructShield = /* @__PURE__ */ __name(async ({ queries, mutations, subscriptions }, config, options) => {
|
|
7985
|
+
var constructShield = /* @__PURE__ */ __name(async ({ queries, mutations, subscriptions }, config, options, shieldOutputDir) => {
|
|
7992
7986
|
if (queries.length === 0 && mutations.length === 0 && subscriptions.length === 0) {
|
|
7993
7987
|
return "";
|
|
7994
7988
|
}
|
|
@@ -8015,9 +8009,7 @@ var constructShield = /* @__PURE__ */ __name(async ({ queries, mutations, subscr
|
|
|
8015
8009
|
return "";
|
|
8016
8010
|
}
|
|
8017
8011
|
let shieldText = getImports("trpc-shield");
|
|
8018
|
-
|
|
8019
|
-
const outputDir = internals.parseEnvValue(options.generator.output);
|
|
8020
|
-
shieldText += getImports("context", relativePath(outputDir, joinPaths(options.schemaPath, config.contextPath)));
|
|
8012
|
+
shieldText += getImports("context", relativePath(shieldOutputDir, joinPaths(options.schemaPath, config.contextPath)));
|
|
8021
8013
|
shieldText += "\n\n";
|
|
8022
8014
|
shieldText += wrapWithExport({
|
|
8023
8015
|
shieldObjectText: wrapWithTrpcShieldCall({
|
|
@@ -11611,49 +11603,47 @@ async function generate(options) {
|
|
|
11611
11603
|
} else {
|
|
11612
11604
|
consoleLog("Skipping Zod schemas generation");
|
|
11613
11605
|
}
|
|
11606
|
+
const queries = [];
|
|
11607
|
+
const mutations = [];
|
|
11608
|
+
const subscriptions = [];
|
|
11609
|
+
prismaClientDmmf.mappings.modelOperations.forEach((modelOperation) => {
|
|
11610
|
+
const { model: _model, plural: _plural, ...operations } = modelOperation;
|
|
11611
|
+
for (const [opType, opNameWithModel] of Object.entries(operations)) {
|
|
11612
|
+
if ([
|
|
11613
|
+
"findUnique",
|
|
11614
|
+
"findUniqueOrThrow",
|
|
11615
|
+
"findFirst",
|
|
11616
|
+
"findFirstOrThrow",
|
|
11617
|
+
"findRaw",
|
|
11618
|
+
"findMany",
|
|
11619
|
+
"aggregateRaw",
|
|
11620
|
+
"count",
|
|
11621
|
+
"aggregate",
|
|
11622
|
+
"groupBy"
|
|
11623
|
+
].includes(opType)) {
|
|
11624
|
+
queries.push(opNameWithModel);
|
|
11625
|
+
}
|
|
11626
|
+
if ([
|
|
11627
|
+
"createOne",
|
|
11628
|
+
"createMany",
|
|
11629
|
+
"createManyAndReturn",
|
|
11630
|
+
"deleteOne",
|
|
11631
|
+
"deleteMany",
|
|
11632
|
+
"updateOne",
|
|
11633
|
+
"updateMany",
|
|
11634
|
+
"updateManyAndReturn",
|
|
11635
|
+
"upsertOne"
|
|
11636
|
+
].includes(opType)) {
|
|
11637
|
+
mutations.push(opNameWithModel);
|
|
11638
|
+
}
|
|
11639
|
+
}
|
|
11640
|
+
});
|
|
11641
|
+
queries.sort();
|
|
11642
|
+
mutations.sort();
|
|
11643
|
+
subscriptions.sort();
|
|
11614
11644
|
if (config.withShield !== false) {
|
|
11615
11645
|
consoleLog("Generating tRPC Shield");
|
|
11616
|
-
const shieldOutputDir =
|
|
11617
|
-
consoleLog("Preparing tRPC Shield output directory");
|
|
11618
|
-
await createDirectory(shieldOutputDir);
|
|
11619
|
-
const queries = [];
|
|
11620
|
-
const mutations = [];
|
|
11621
|
-
const subscriptions = [];
|
|
11622
|
-
prismaClientDmmf.mappings.modelOperations.forEach((modelOperation) => {
|
|
11623
|
-
const { model: _model, plural: _plural, ...operations } = modelOperation;
|
|
11624
|
-
for (const [opType, opNameWithModel] of Object.entries(operations)) {
|
|
11625
|
-
if ([
|
|
11626
|
-
"findUnique",
|
|
11627
|
-
"findUniqueOrThrow",
|
|
11628
|
-
"findFirst",
|
|
11629
|
-
"findFirstOrThrow",
|
|
11630
|
-
"findRaw",
|
|
11631
|
-
"findMany",
|
|
11632
|
-
"aggregateRaw",
|
|
11633
|
-
"count",
|
|
11634
|
-
"aggregate",
|
|
11635
|
-
"groupBy"
|
|
11636
|
-
].includes(opType)) {
|
|
11637
|
-
queries.push(opNameWithModel);
|
|
11638
|
-
}
|
|
11639
|
-
if ([
|
|
11640
|
-
"createOne",
|
|
11641
|
-
"createMany",
|
|
11642
|
-
"createManyAndReturn",
|
|
11643
|
-
"deleteOne",
|
|
11644
|
-
"deleteMany",
|
|
11645
|
-
"updateOne",
|
|
11646
|
-
"updateMany",
|
|
11647
|
-
"updateManyAndReturn",
|
|
11648
|
-
"upsertOne"
|
|
11649
|
-
].includes(opType)) {
|
|
11650
|
-
mutations.push(opNameWithModel);
|
|
11651
|
-
}
|
|
11652
|
-
}
|
|
11653
|
-
});
|
|
11654
|
-
queries.sort();
|
|
11655
|
-
mutations.sort();
|
|
11656
|
-
subscriptions.sort();
|
|
11646
|
+
const shieldOutputDir = outputDir;
|
|
11657
11647
|
consoleLog("Constructing tRPC Shield source file");
|
|
11658
11648
|
const shieldText = await constructShield({
|
|
11659
11649
|
queries,
|
|
@@ -11673,7 +11663,7 @@ async function generate(options) {
|
|
|
11673
11663
|
contextPath: config.contextPath
|
|
11674
11664
|
}
|
|
11675
11665
|
}
|
|
11676
|
-
});
|
|
11666
|
+
}, shieldOutputDir);
|
|
11677
11667
|
consoleLog("Saving tRPC Shield source file to disk");
|
|
11678
11668
|
await writeFileSafely(joinPaths(shieldOutputDir, "shield.ts"), shieldText);
|
|
11679
11669
|
} else {
|
|
@@ -11683,9 +11673,9 @@ async function generate(options) {
|
|
|
11683
11673
|
if (config.trpcOptions && typeof config.trpcOptions === "boolean") {
|
|
11684
11674
|
const trpcOptionsOutputPath = joinPaths(outputDir, "options.ts");
|
|
11685
11675
|
consoleLog("Generating tRPC options source file");
|
|
11686
|
-
await writeFileSafely(trpcOptionsOutputPath, `import { ZodError } from 'zod';${config.
|
|
11676
|
+
await writeFileSafely(trpcOptionsOutputPath, `import { ZodError } from 'zod';${config.withNext ? '\nimport { transformer } from "@stryke/trpc-next/shared";' : ""}
|
|
11687
11677
|
|
|
11688
|
-
export default {${config.
|
|
11678
|
+
export default {${config.withNext ? "\n transformer," : ""}
|
|
11689
11679
|
errorFormatter({ shape, error }) {
|
|
11690
11680
|
return {
|
|
11691
11681
|
...shape,
|
|
@@ -11702,11 +11692,10 @@ export default {${config.useTRPCNext ? "\n transformer," : ""}
|
|
|
11702
11692
|
`);
|
|
11703
11693
|
}
|
|
11704
11694
|
resolveModelsComments(models, hiddenModels);
|
|
11705
|
-
const createRouter = project.createSourceFile(path5.resolve(outputDir, "
|
|
11695
|
+
const createRouter = project.createSourceFile(path5.resolve(outputDir, "trpc.ts"), void 0, {
|
|
11706
11696
|
overwrite: true
|
|
11707
11697
|
});
|
|
11708
11698
|
consoleLog("Generating tRPC imports");
|
|
11709
|
-
generateRPCImport(createRouter);
|
|
11710
11699
|
if (config.withShield) {
|
|
11711
11700
|
await generateShieldImport(createRouter, options, config.withShield);
|
|
11712
11701
|
}
|