@stryke/prisma-trpc-generator 0.5.2 → 0.6.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 +48 -50
- package/dist/generator.js +48 -50
- package/dist/index.cjs +48 -50
- package/dist/index.js +48 -50
- 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
|
})
|
|
@@ -7632,14 +7632,14 @@ var generateCreateRouterImport = /* @__PURE__ */ __name(({ sourceFile, config })
|
|
|
7632
7632
|
imports.push(getProcedureName(config));
|
|
7633
7633
|
}
|
|
7634
7634
|
sourceFile.addImportDeclaration({
|
|
7635
|
-
moduleSpecifier: "
|
|
7635
|
+
moduleSpecifier: "../trpc",
|
|
7636
7636
|
namedImports: imports
|
|
7637
7637
|
});
|
|
7638
7638
|
}, "generateCreateRouterImport");
|
|
7639
7639
|
var generateShieldImport = /* @__PURE__ */ __name(async (sourceFile, options, value) => {
|
|
7640
7640
|
const internals = await getPrismaInternals();
|
|
7641
7641
|
const outputDir = internals.parseEnvValue(options.generator.output);
|
|
7642
|
-
let shieldPath = getRelativePath(outputDir, "shield
|
|
7642
|
+
let shieldPath = getRelativePath(outputDir, "shield");
|
|
7643
7643
|
if (typeof value === "string") {
|
|
7644
7644
|
shieldPath = getRelativePath(outputDir, value, true, options.schemaPath);
|
|
7645
7645
|
}
|
|
@@ -7676,7 +7676,7 @@ async function generateBaseRouter(sourceFile, config, options) {
|
|
|
7676
7676
|
`
|
|
7677
7677
|
);
|
|
7678
7678
|
}
|
|
7679
|
-
if (config.
|
|
7679
|
+
if (config.withNext) {
|
|
7680
7680
|
sourceFile.addStatements(
|
|
7681
7681
|
/* ts */
|
|
7682
7682
|
`
|
|
@@ -7759,7 +7759,7 @@ export const createCallerFactory = t.createCallerFactory;`
|
|
|
7759
7759
|
`
|
|
7760
7760
|
export const publicProcedure = t.procedure; `
|
|
7761
7761
|
);
|
|
7762
|
-
if (config.
|
|
7762
|
+
if (config.withNext) {
|
|
7763
7763
|
sourceFile.addStatements(
|
|
7764
7764
|
/* ts */
|
|
7765
7765
|
`
|
|
@@ -11602,49 +11602,47 @@ async function generate(options) {
|
|
|
11602
11602
|
} else {
|
|
11603
11603
|
consoleLog("Skipping Zod schemas generation");
|
|
11604
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();
|
|
11605
11643
|
if (config.withShield !== false) {
|
|
11606
11644
|
consoleLog("Generating tRPC Shield");
|
|
11607
|
-
const shieldOutputDir =
|
|
11608
|
-
consoleLog("Preparing tRPC Shield output directory");
|
|
11609
|
-
await createDirectory(shieldOutputDir);
|
|
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();
|
|
11645
|
+
const shieldOutputDir = outputDir;
|
|
11648
11646
|
consoleLog("Constructing tRPC Shield source file");
|
|
11649
11647
|
const shieldText = await constructShield({
|
|
11650
11648
|
queries,
|
|
@@ -11674,9 +11672,9 @@ async function generate(options) {
|
|
|
11674
11672
|
if (config.trpcOptions && typeof config.trpcOptions === "boolean") {
|
|
11675
11673
|
const trpcOptionsOutputPath = joinPaths(outputDir, "options.ts");
|
|
11676
11674
|
consoleLog("Generating tRPC options source file");
|
|
11677
|
-
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";' : ""}
|
|
11678
11676
|
|
|
11679
|
-
export default {${config.
|
|
11677
|
+
export default {${config.withNext ? "\n transformer," : ""}
|
|
11680
11678
|
errorFormatter({ shape, error }) {
|
|
11681
11679
|
return {
|
|
11682
11680
|
...shape,
|
|
@@ -11693,7 +11691,7 @@ export default {${config.useTRPCNext ? "\n transformer," : ""}
|
|
|
11693
11691
|
`);
|
|
11694
11692
|
}
|
|
11695
11693
|
resolveModelsComments(models, hiddenModels);
|
|
11696
|
-
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, {
|
|
11697
11695
|
overwrite: true
|
|
11698
11696
|
});
|
|
11699
11697
|
consoleLog("Generating tRPC imports");
|
|
@@ -11768,7 +11766,7 @@ export default {${config.useTRPCNext ? "\n transformer," : ""}
|
|
|
11768
11766
|
routerStatements.push(
|
|
11769
11767
|
/* ts */
|
|
11770
11768
|
`
|
|
11771
|
-
${model
|
|
11769
|
+
${lowerCaseFirst(model)}: ${plural}Router`
|
|
11772
11770
|
);
|
|
11773
11771
|
consoleLog(`Generated tRPC router for model ${model} with ${modelActions.length} actions`);
|
|
11774
11772
|
}
|
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
|
})
|
|
@@ -7637,14 +7637,14 @@ var generateCreateRouterImport = /* @__PURE__ */ __name(({ sourceFile, config })
|
|
|
7637
7637
|
imports.push(getProcedureName(config));
|
|
7638
7638
|
}
|
|
7639
7639
|
sourceFile.addImportDeclaration({
|
|
7640
|
-
moduleSpecifier: "
|
|
7640
|
+
moduleSpecifier: "../trpc",
|
|
7641
7641
|
namedImports: imports
|
|
7642
7642
|
});
|
|
7643
7643
|
}, "generateCreateRouterImport");
|
|
7644
7644
|
var generateShieldImport = /* @__PURE__ */ __name(async (sourceFile, options, value) => {
|
|
7645
7645
|
const internals = await getPrismaInternals();
|
|
7646
7646
|
const outputDir = internals.parseEnvValue(options.generator.output);
|
|
7647
|
-
let shieldPath = getRelativePath(outputDir, "shield
|
|
7647
|
+
let shieldPath = getRelativePath(outputDir, "shield");
|
|
7648
7648
|
if (typeof value === "string") {
|
|
7649
7649
|
shieldPath = getRelativePath(outputDir, value, true, options.schemaPath);
|
|
7650
7650
|
}
|
|
@@ -7681,7 +7681,7 @@ async function generateBaseRouter(sourceFile, config, options) {
|
|
|
7681
7681
|
`
|
|
7682
7682
|
);
|
|
7683
7683
|
}
|
|
7684
|
-
if (config.
|
|
7684
|
+
if (config.withNext) {
|
|
7685
7685
|
sourceFile.addStatements(
|
|
7686
7686
|
/* ts */
|
|
7687
7687
|
`
|
|
@@ -7764,7 +7764,7 @@ export const createCallerFactory = t.createCallerFactory;`
|
|
|
7764
7764
|
`
|
|
7765
7765
|
export const publicProcedure = t.procedure; `
|
|
7766
7766
|
);
|
|
7767
|
-
if (config.
|
|
7767
|
+
if (config.withNext) {
|
|
7768
7768
|
sourceFile.addStatements(
|
|
7769
7769
|
/* ts */
|
|
7770
7770
|
`
|
|
@@ -11607,49 +11607,47 @@ async function generate(options) {
|
|
|
11607
11607
|
} else {
|
|
11608
11608
|
consoleLog("Skipping Zod schemas generation");
|
|
11609
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();
|
|
11610
11648
|
if (config.withShield !== false) {
|
|
11611
11649
|
consoleLog("Generating tRPC Shield");
|
|
11612
|
-
const shieldOutputDir =
|
|
11613
|
-
consoleLog("Preparing tRPC Shield output directory");
|
|
11614
|
-
await createDirectory(shieldOutputDir);
|
|
11615
|
-
const queries = [];
|
|
11616
|
-
const mutations = [];
|
|
11617
|
-
const subscriptions = [];
|
|
11618
|
-
prismaClientDmmf.mappings.modelOperations.forEach((modelOperation) => {
|
|
11619
|
-
const { model: _model, plural: _plural, ...operations } = modelOperation;
|
|
11620
|
-
for (const [opType, opNameWithModel] of Object.entries(operations)) {
|
|
11621
|
-
if ([
|
|
11622
|
-
"findUnique",
|
|
11623
|
-
"findUniqueOrThrow",
|
|
11624
|
-
"findFirst",
|
|
11625
|
-
"findFirstOrThrow",
|
|
11626
|
-
"findRaw",
|
|
11627
|
-
"findMany",
|
|
11628
|
-
"aggregateRaw",
|
|
11629
|
-
"count",
|
|
11630
|
-
"aggregate",
|
|
11631
|
-
"groupBy"
|
|
11632
|
-
].includes(opType)) {
|
|
11633
|
-
queries.push(opNameWithModel);
|
|
11634
|
-
}
|
|
11635
|
-
if ([
|
|
11636
|
-
"createOne",
|
|
11637
|
-
"createMany",
|
|
11638
|
-
"createManyAndReturn",
|
|
11639
|
-
"deleteOne",
|
|
11640
|
-
"deleteMany",
|
|
11641
|
-
"updateOne",
|
|
11642
|
-
"updateMany",
|
|
11643
|
-
"updateManyAndReturn",
|
|
11644
|
-
"upsertOne"
|
|
11645
|
-
].includes(opType)) {
|
|
11646
|
-
mutations.push(opNameWithModel);
|
|
11647
|
-
}
|
|
11648
|
-
}
|
|
11649
|
-
});
|
|
11650
|
-
queries.sort();
|
|
11651
|
-
mutations.sort();
|
|
11652
|
-
subscriptions.sort();
|
|
11650
|
+
const shieldOutputDir = outputDir;
|
|
11653
11651
|
consoleLog("Constructing tRPC Shield source file");
|
|
11654
11652
|
const shieldText = await constructShield({
|
|
11655
11653
|
queries,
|
|
@@ -11679,9 +11677,9 @@ async function generate(options) {
|
|
|
11679
11677
|
if (config.trpcOptions && typeof config.trpcOptions === "boolean") {
|
|
11680
11678
|
const trpcOptionsOutputPath = joinPaths(outputDir, "options.ts");
|
|
11681
11679
|
consoleLog("Generating tRPC options source file");
|
|
11682
|
-
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";' : ""}
|
|
11683
11681
|
|
|
11684
|
-
export default {${config.
|
|
11682
|
+
export default {${config.withNext ? "\n transformer," : ""}
|
|
11685
11683
|
errorFormatter({ shape, error }) {
|
|
11686
11684
|
return {
|
|
11687
11685
|
...shape,
|
|
@@ -11698,7 +11696,7 @@ export default {${config.useTRPCNext ? "\n transformer," : ""}
|
|
|
11698
11696
|
`);
|
|
11699
11697
|
}
|
|
11700
11698
|
resolveModelsComments(models, hiddenModels);
|
|
11701
|
-
const createRouter = project.createSourceFile(path5.resolve(outputDir, "
|
|
11699
|
+
const createRouter = project.createSourceFile(path5.resolve(outputDir, "trpc.ts"), void 0, {
|
|
11702
11700
|
overwrite: true
|
|
11703
11701
|
});
|
|
11704
11702
|
consoleLog("Generating tRPC imports");
|
|
@@ -11773,7 +11771,7 @@ export default {${config.useTRPCNext ? "\n transformer," : ""}
|
|
|
11773
11771
|
routerStatements.push(
|
|
11774
11772
|
/* ts */
|
|
11775
11773
|
`
|
|
11776
|
-
${model
|
|
11774
|
+
${lowerCaseFirst(model)}: ${plural}Router`
|
|
11777
11775
|
);
|
|
11778
11776
|
consoleLog(`Generated tRPC router for model ${model} with ${modelActions.length} actions`);
|
|
11779
11777
|
}
|
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
|
})
|
|
@@ -7628,14 +7628,14 @@ var generateCreateRouterImport = /* @__PURE__ */ __name(({ sourceFile, config })
|
|
|
7628
7628
|
imports.push(getProcedureName(config));
|
|
7629
7629
|
}
|
|
7630
7630
|
sourceFile.addImportDeclaration({
|
|
7631
|
-
moduleSpecifier: "
|
|
7631
|
+
moduleSpecifier: "../trpc",
|
|
7632
7632
|
namedImports: imports
|
|
7633
7633
|
});
|
|
7634
7634
|
}, "generateCreateRouterImport");
|
|
7635
7635
|
var generateShieldImport = /* @__PURE__ */ __name(async (sourceFile, options, value) => {
|
|
7636
7636
|
const internals = await getPrismaInternals();
|
|
7637
7637
|
const outputDir = internals.parseEnvValue(options.generator.output);
|
|
7638
|
-
let shieldPath = getRelativePath(outputDir, "shield
|
|
7638
|
+
let shieldPath = getRelativePath(outputDir, "shield");
|
|
7639
7639
|
if (typeof value === "string") {
|
|
7640
7640
|
shieldPath = getRelativePath(outputDir, value, true, options.schemaPath);
|
|
7641
7641
|
}
|
|
@@ -7672,7 +7672,7 @@ async function generateBaseRouter(sourceFile, config, options) {
|
|
|
7672
7672
|
`
|
|
7673
7673
|
);
|
|
7674
7674
|
}
|
|
7675
|
-
if (config.
|
|
7675
|
+
if (config.withNext) {
|
|
7676
7676
|
sourceFile.addStatements(
|
|
7677
7677
|
/* ts */
|
|
7678
7678
|
`
|
|
@@ -7755,7 +7755,7 @@ export const createCallerFactory = t.createCallerFactory;`
|
|
|
7755
7755
|
`
|
|
7756
7756
|
export const publicProcedure = t.procedure; `
|
|
7757
7757
|
);
|
|
7758
|
-
if (config.
|
|
7758
|
+
if (config.withNext) {
|
|
7759
7759
|
sourceFile.addStatements(
|
|
7760
7760
|
/* ts */
|
|
7761
7761
|
`
|
|
@@ -11598,49 +11598,47 @@ async function generate(options) {
|
|
|
11598
11598
|
} else {
|
|
11599
11599
|
consoleLog("Skipping Zod schemas generation");
|
|
11600
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();
|
|
11601
11639
|
if (config.withShield !== false) {
|
|
11602
11640
|
consoleLog("Generating tRPC Shield");
|
|
11603
|
-
const shieldOutputDir =
|
|
11604
|
-
consoleLog("Preparing tRPC Shield output directory");
|
|
11605
|
-
await createDirectory(shieldOutputDir);
|
|
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();
|
|
11641
|
+
const shieldOutputDir = outputDir;
|
|
11644
11642
|
consoleLog("Constructing tRPC Shield source file");
|
|
11645
11643
|
const shieldText = await constructShield({
|
|
11646
11644
|
queries,
|
|
@@ -11670,9 +11668,9 @@ async function generate(options) {
|
|
|
11670
11668
|
if (config.trpcOptions && typeof config.trpcOptions === "boolean") {
|
|
11671
11669
|
const trpcOptionsOutputPath = joinPaths(outputDir, "options.ts");
|
|
11672
11670
|
consoleLog("Generating tRPC options source file");
|
|
11673
|
-
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";' : ""}
|
|
11674
11672
|
|
|
11675
|
-
export default {${config.
|
|
11673
|
+
export default {${config.withNext ? "\n transformer," : ""}
|
|
11676
11674
|
errorFormatter({ shape, error }) {
|
|
11677
11675
|
return {
|
|
11678
11676
|
...shape,
|
|
@@ -11689,7 +11687,7 @@ export default {${config.useTRPCNext ? "\n transformer," : ""}
|
|
|
11689
11687
|
`);
|
|
11690
11688
|
}
|
|
11691
11689
|
resolveModelsComments(models, hiddenModels);
|
|
11692
|
-
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, {
|
|
11693
11691
|
overwrite: true
|
|
11694
11692
|
});
|
|
11695
11693
|
consoleLog("Generating tRPC imports");
|
|
@@ -11764,7 +11762,7 @@ export default {${config.useTRPCNext ? "\n transformer," : ""}
|
|
|
11764
11762
|
routerStatements.push(
|
|
11765
11763
|
/* ts */
|
|
11766
11764
|
`
|
|
11767
|
-
${model
|
|
11765
|
+
${lowerCaseFirst(model)}: ${plural}Router`
|
|
11768
11766
|
);
|
|
11769
11767
|
consoleLog(`Generated tRPC router for model ${model} with ${modelActions.length} actions`);
|
|
11770
11768
|
}
|
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
|
})
|
|
@@ -7633,14 +7633,14 @@ var generateCreateRouterImport = /* @__PURE__ */ __name(({ sourceFile, config })
|
|
|
7633
7633
|
imports.push(getProcedureName(config));
|
|
7634
7634
|
}
|
|
7635
7635
|
sourceFile.addImportDeclaration({
|
|
7636
|
-
moduleSpecifier: "
|
|
7636
|
+
moduleSpecifier: "../trpc",
|
|
7637
7637
|
namedImports: imports
|
|
7638
7638
|
});
|
|
7639
7639
|
}, "generateCreateRouterImport");
|
|
7640
7640
|
var generateShieldImport = /* @__PURE__ */ __name(async (sourceFile, options, value) => {
|
|
7641
7641
|
const internals = await getPrismaInternals();
|
|
7642
7642
|
const outputDir = internals.parseEnvValue(options.generator.output);
|
|
7643
|
-
let shieldPath = getRelativePath(outputDir, "shield
|
|
7643
|
+
let shieldPath = getRelativePath(outputDir, "shield");
|
|
7644
7644
|
if (typeof value === "string") {
|
|
7645
7645
|
shieldPath = getRelativePath(outputDir, value, true, options.schemaPath);
|
|
7646
7646
|
}
|
|
@@ -7677,7 +7677,7 @@ async function generateBaseRouter(sourceFile, config, options) {
|
|
|
7677
7677
|
`
|
|
7678
7678
|
);
|
|
7679
7679
|
}
|
|
7680
|
-
if (config.
|
|
7680
|
+
if (config.withNext) {
|
|
7681
7681
|
sourceFile.addStatements(
|
|
7682
7682
|
/* ts */
|
|
7683
7683
|
`
|
|
@@ -7760,7 +7760,7 @@ export const createCallerFactory = t.createCallerFactory;`
|
|
|
7760
7760
|
`
|
|
7761
7761
|
export const publicProcedure = t.procedure; `
|
|
7762
7762
|
);
|
|
7763
|
-
if (config.
|
|
7763
|
+
if (config.withNext) {
|
|
7764
7764
|
sourceFile.addStatements(
|
|
7765
7765
|
/* ts */
|
|
7766
7766
|
`
|
|
@@ -11603,49 +11603,47 @@ async function generate(options) {
|
|
|
11603
11603
|
} else {
|
|
11604
11604
|
consoleLog("Skipping Zod schemas generation");
|
|
11605
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();
|
|
11606
11644
|
if (config.withShield !== false) {
|
|
11607
11645
|
consoleLog("Generating tRPC Shield");
|
|
11608
|
-
const shieldOutputDir =
|
|
11609
|
-
consoleLog("Preparing tRPC Shield output directory");
|
|
11610
|
-
await createDirectory(shieldOutputDir);
|
|
11611
|
-
const queries = [];
|
|
11612
|
-
const mutations = [];
|
|
11613
|
-
const subscriptions = [];
|
|
11614
|
-
prismaClientDmmf.mappings.modelOperations.forEach((modelOperation) => {
|
|
11615
|
-
const { model: _model, plural: _plural, ...operations } = modelOperation;
|
|
11616
|
-
for (const [opType, opNameWithModel] of Object.entries(operations)) {
|
|
11617
|
-
if ([
|
|
11618
|
-
"findUnique",
|
|
11619
|
-
"findUniqueOrThrow",
|
|
11620
|
-
"findFirst",
|
|
11621
|
-
"findFirstOrThrow",
|
|
11622
|
-
"findRaw",
|
|
11623
|
-
"findMany",
|
|
11624
|
-
"aggregateRaw",
|
|
11625
|
-
"count",
|
|
11626
|
-
"aggregate",
|
|
11627
|
-
"groupBy"
|
|
11628
|
-
].includes(opType)) {
|
|
11629
|
-
queries.push(opNameWithModel);
|
|
11630
|
-
}
|
|
11631
|
-
if ([
|
|
11632
|
-
"createOne",
|
|
11633
|
-
"createMany",
|
|
11634
|
-
"createManyAndReturn",
|
|
11635
|
-
"deleteOne",
|
|
11636
|
-
"deleteMany",
|
|
11637
|
-
"updateOne",
|
|
11638
|
-
"updateMany",
|
|
11639
|
-
"updateManyAndReturn",
|
|
11640
|
-
"upsertOne"
|
|
11641
|
-
].includes(opType)) {
|
|
11642
|
-
mutations.push(opNameWithModel);
|
|
11643
|
-
}
|
|
11644
|
-
}
|
|
11645
|
-
});
|
|
11646
|
-
queries.sort();
|
|
11647
|
-
mutations.sort();
|
|
11648
|
-
subscriptions.sort();
|
|
11646
|
+
const shieldOutputDir = outputDir;
|
|
11649
11647
|
consoleLog("Constructing tRPC Shield source file");
|
|
11650
11648
|
const shieldText = await constructShield({
|
|
11651
11649
|
queries,
|
|
@@ -11675,9 +11673,9 @@ async function generate(options) {
|
|
|
11675
11673
|
if (config.trpcOptions && typeof config.trpcOptions === "boolean") {
|
|
11676
11674
|
const trpcOptionsOutputPath = joinPaths(outputDir, "options.ts");
|
|
11677
11675
|
consoleLog("Generating tRPC options source file");
|
|
11678
|
-
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";' : ""}
|
|
11679
11677
|
|
|
11680
|
-
export default {${config.
|
|
11678
|
+
export default {${config.withNext ? "\n transformer," : ""}
|
|
11681
11679
|
errorFormatter({ shape, error }) {
|
|
11682
11680
|
return {
|
|
11683
11681
|
...shape,
|
|
@@ -11694,7 +11692,7 @@ export default {${config.useTRPCNext ? "\n transformer," : ""}
|
|
|
11694
11692
|
`);
|
|
11695
11693
|
}
|
|
11696
11694
|
resolveModelsComments(models, hiddenModels);
|
|
11697
|
-
const createRouter = project.createSourceFile(path5.resolve(outputDir, "
|
|
11695
|
+
const createRouter = project.createSourceFile(path5.resolve(outputDir, "trpc.ts"), void 0, {
|
|
11698
11696
|
overwrite: true
|
|
11699
11697
|
});
|
|
11700
11698
|
consoleLog("Generating tRPC imports");
|
|
@@ -11769,7 +11767,7 @@ export default {${config.useTRPCNext ? "\n transformer," : ""}
|
|
|
11769
11767
|
routerStatements.push(
|
|
11770
11768
|
/* ts */
|
|
11771
11769
|
`
|
|
11772
|
-
${model
|
|
11770
|
+
${lowerCaseFirst(model)}: ${plural}Router`
|
|
11773
11771
|
);
|
|
11774
11772
|
consoleLog(`Generated tRPC router for model ${model} with ${modelActions.length} actions`);
|
|
11775
11773
|
}
|