@stryke/prisma-trpc-generator 0.10.3 → 0.10.5
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 +26 -25
- package/dist/generator.js +26 -25
- package/dist/index.cjs +26 -25
- package/dist/index.js +26 -25
- package/package.json +1 -1
package/dist/generator.cjs
CHANGED
|
@@ -7611,7 +7611,7 @@ var generateCreateRouterImport = /* @__PURE__ */ __name(({ sourceFile, config })
|
|
|
7611
7611
|
}, "generateCreateRouterImport");
|
|
7612
7612
|
var generateRouterImport = /* @__PURE__ */ __name((sourceFile, modelNamePlural, modelNameCamelCase) => {
|
|
7613
7613
|
sourceFile.addImportDeclaration({
|
|
7614
|
-
moduleSpecifier: `./${modelNameCamelCase}.router`,
|
|
7614
|
+
moduleSpecifier: `./${lowerCaseFirst(modelNameCamelCase)}.router`,
|
|
7615
7615
|
namedImports: [
|
|
7616
7616
|
`${modelNamePlural}Router`
|
|
7617
7617
|
]
|
|
@@ -7641,7 +7641,8 @@ async function generateTRPCExports(sourceFile, config, options, outputDir) {
|
|
|
7641
7641
|
/* ts */
|
|
7642
7642
|
`import { createContext } from '${relativePath(outputDir, joinPaths(outputDir, config.contextPath))}';
|
|
7643
7643
|
import { initTRPC } from '@trpc/server';
|
|
7644
|
-
import { createTRPCServerActionHandler } from '@stryke/trpc-next/action-handler'
|
|
7644
|
+
import { createTRPCServerActionHandler } from '@stryke/trpc-next/action-handler';
|
|
7645
|
+
import { cookies } from "next/headers";`
|
|
7645
7646
|
);
|
|
7646
7647
|
}
|
|
7647
7648
|
sourceFile.addStatements(
|
|
@@ -7738,7 +7739,7 @@ export const ${procName} = t.procedure`
|
|
|
7738
7739
|
/* ts */
|
|
7739
7740
|
`
|
|
7740
7741
|
export const createAction: ReturnType<typeof createTRPCServerActionHandler> =
|
|
7741
|
-
createTRPCServerActionHandler(t, createContext);
|
|
7742
|
+
createTRPCServerActionHandler(cookies, t, createContext);
|
|
7742
7743
|
`
|
|
7743
7744
|
);
|
|
7744
7745
|
}
|
|
@@ -7776,7 +7777,7 @@ __name(generateRouterSchemaImports, "generateRouterSchemaImports");
|
|
|
7776
7777
|
var getRouterSchemaImportByOpName = /* @__PURE__ */ __name((opName, modelName) => {
|
|
7777
7778
|
const opType = opName.replace("OrThrow", "").replace("ManyAndReturn", "");
|
|
7778
7779
|
const inputType = getInputTypeByOpName(opType, modelName);
|
|
7779
|
-
return inputType ? `import { ${inputType} } from "../schemas/${opType}${modelName}.schema"; ` : "";
|
|
7780
|
+
return inputType ? `import { ${lowerCaseFirst(inputType)} } from "../schemas/${lowerCaseFirst(opType)}${modelName}.schema"; ` : "";
|
|
7780
7781
|
}, "getRouterSchemaImportByOpName");
|
|
7781
7782
|
var getInputTypeByOpName = /* @__PURE__ */ __name((opName, modelName) => {
|
|
7782
7783
|
let inputType;
|
|
@@ -10643,8 +10644,8 @@ var Transformer = class _Transformer {
|
|
|
10643
10644
|
hasJson = false;
|
|
10644
10645
|
static prismaClientOutputPath = "@prisma/client";
|
|
10645
10646
|
static isCustomPrismaClientOutputPath = false;
|
|
10646
|
-
static isGenerateSelect =
|
|
10647
|
-
static isGenerateInclude =
|
|
10647
|
+
static isGenerateSelect = true;
|
|
10648
|
+
static isGenerateInclude = true;
|
|
10648
10649
|
constructor(params) {
|
|
10649
10650
|
this.name = params.name ?? "";
|
|
10650
10651
|
this.fields = params.fields ?? [];
|
|
@@ -10676,21 +10677,21 @@ var Transformer = class _Transformer {
|
|
|
10676
10677
|
async generateEnumSchemas() {
|
|
10677
10678
|
for (const enumType2 of this.enumTypes) {
|
|
10678
10679
|
const { name, values } = enumType2;
|
|
10679
|
-
await writeFileSafely(import_node_path4.default.join(_Transformer.outputPath, `schemas/enums/${name}.schema.ts`), `${this.generateImportZodStatement()}
|
|
10680
|
-
${this.generateExportSchemaStatement(`${name}`, `z.enum(${JSON.stringify(values)})`)}`);
|
|
10680
|
+
await writeFileSafely(import_node_path4.default.join(_Transformer.outputPath, `schemas/enums/${lowerCaseFirst(name)}.schema.ts`), `${this.generateImportZodStatement()}
|
|
10681
|
+
${this.generateExportSchemaStatement(`${lowerCaseFirst(name)}`, `z.enum(${JSON.stringify(values)})`)}`);
|
|
10681
10682
|
}
|
|
10682
10683
|
}
|
|
10683
10684
|
generateImportZodStatement() {
|
|
10684
10685
|
return "import { z } from 'zod';\n";
|
|
10685
10686
|
}
|
|
10686
10687
|
generateExportSchemaStatement(name, schema) {
|
|
10687
|
-
return `export const ${name}Schema = ${schema}`;
|
|
10688
|
+
return `export const ${lowerCaseFirst(name)}Schema = ${schema}`;
|
|
10688
10689
|
}
|
|
10689
10690
|
async generateObjectSchema() {
|
|
10690
10691
|
const zodObjectSchemaFields = this.generateObjectSchemaFields();
|
|
10691
10692
|
const objectSchema = this.prepareObjectSchema(zodObjectSchemaFields);
|
|
10692
10693
|
const objectSchemaName = this.resolveObjectSchemaName();
|
|
10693
|
-
await writeFileSafely(import_node_path4.default.join(_Transformer.outputPath, `schemas/objects/${objectSchemaName}.schema.ts`), objectSchema);
|
|
10694
|
+
await writeFileSafely(import_node_path4.default.join(_Transformer.outputPath, `schemas/objects/${lowerCaseFirst(objectSchemaName)}.schema.ts`), objectSchema);
|
|
10694
10695
|
}
|
|
10695
10696
|
generateObjectSchemaFields() {
|
|
10696
10697
|
const zodObjectSchemaFields = this.fields.map((field) => this.generateObjectSchemaField(field)).flatMap((item) => item).map((item) => {
|
|
@@ -10811,7 +10812,7 @@ ${this.generateExportSchemaStatement(`${name}`, `z.enum(${JSON.stringify(values)
|
|
|
10811
10812
|
if (isAggregateInputType(name)) {
|
|
10812
10813
|
name = `${name}Type`;
|
|
10813
10814
|
}
|
|
10814
|
-
const end = `export const ${exportName}ObjectSchema = Schema`;
|
|
10815
|
+
const end = `export const ${lowerCaseFirst(exportName)}ObjectSchema = Schema`;
|
|
10815
10816
|
return `const Schema: z.ZodType<Prisma.${name}> = ${schema};
|
|
10816
10817
|
|
|
10817
10818
|
${end}`;
|
|
@@ -10867,9 +10868,9 @@ ${this.generateExportSchemaStatement(`${name}`, `z.enum(${JSON.stringify(values)
|
|
|
10867
10868
|
if (isModelQueryType) {
|
|
10868
10869
|
return `import { ${this.resolveModelQuerySchemaName(modelName, queryName)} } from '../${queryName}${modelName}.schema'`;
|
|
10869
10870
|
} else if (_Transformer.enumNames.includes(name)) {
|
|
10870
|
-
return `import { ${name}Schema } from '../enums/${name}.schema'`;
|
|
10871
|
+
return `import { ${lowerCaseFirst(name)}Schema } from '../enums/${lowerCaseFirst(name)}.schema'`;
|
|
10871
10872
|
} else {
|
|
10872
|
-
return `import { ${name}ObjectSchema } from './${name}.schema'`;
|
|
10873
|
+
return `import { ${lowerCaseFirst(name)}ObjectSchema } from './${lowerCaseFirst(name)}.schema'`;
|
|
10873
10874
|
}
|
|
10874
10875
|
}).join(";\r\n");
|
|
10875
10876
|
}
|
|
@@ -10894,9 +10895,9 @@ ${this.generateExportSchemaStatement(`${name}`, `z.enum(${JSON.stringify(values)
|
|
|
10894
10895
|
};
|
|
10895
10896
|
}
|
|
10896
10897
|
resolveModelQuerySchemaName(modelName, queryName) {
|
|
10897
|
-
const
|
|
10898
|
+
const modelNameUncapitalized = lowerCaseFirst(modelName);
|
|
10898
10899
|
const queryNameCapitalized = upperCaseFirst(queryName);
|
|
10899
|
-
return `${
|
|
10900
|
+
return `${modelNameUncapitalized}${queryNameCapitalized}Schema`;
|
|
10900
10901
|
}
|
|
10901
10902
|
wrapWithZodUnion(zodStringFields) {
|
|
10902
10903
|
let wrapped = "";
|
|
@@ -10923,12 +10924,11 @@ ${this.generateExportSchemaStatement(`${name}`, `z.enum(${JSON.stringify(values)
|
|
|
10923
10924
|
name = _Transformer.rawOpsMap[name];
|
|
10924
10925
|
exportName = name.replace("Args", "");
|
|
10925
10926
|
}
|
|
10926
|
-
return exportName;
|
|
10927
|
+
return lowerCaseFirst(exportName);
|
|
10927
10928
|
}
|
|
10928
10929
|
async generateModelSchemas() {
|
|
10929
10930
|
for (const modelOperation of this.modelOperations) {
|
|
10930
10931
|
const {
|
|
10931
|
-
model: modelName,
|
|
10932
10932
|
findUnique,
|
|
10933
10933
|
findFirst,
|
|
10934
10934
|
findMany,
|
|
@@ -10948,7 +10948,8 @@ ${this.generateExportSchemaStatement(`${name}`, `z.enum(${JSON.stringify(values)
|
|
|
10948
10948
|
aggregate,
|
|
10949
10949
|
groupBy
|
|
10950
10950
|
} = modelOperation;
|
|
10951
|
-
const model = findModelByName(this.models,
|
|
10951
|
+
const model = findModelByName(this.models, modelOperation.model);
|
|
10952
|
+
const modelName = lowerCaseFirst(modelOperation.model);
|
|
10952
10953
|
const { selectImport, includeImport, selectZodSchemaLine, includeZodSchemaLine, selectZodSchemaLineLazy, includeZodSchemaLineLazy } = this.resolveSelectIncludeImportAndZodSchemaLine(model);
|
|
10953
10954
|
const { orderByImport, orderByZodSchemaLine } = this.resolveOrderByWithRelationImportAndZodSchemaLine(model);
|
|
10954
10955
|
if (findUnique) {
|
|
@@ -11102,19 +11103,19 @@ ${this.generateExportSchemaStatement(`${name}`, `z.enum(${JSON.stringify(values)
|
|
|
11102
11103
|
resolveSelectIncludeImportAndZodSchemaLine(model) {
|
|
11103
11104
|
const { name: modelName } = model;
|
|
11104
11105
|
const hasRelationToAnotherModel = checkModelHasModelRelation(model);
|
|
11105
|
-
const selectImport = _Transformer.isGenerateSelect ? `import { ${modelName}SelectObjectSchema } from './objects/${modelName}Select.schema'` : "";
|
|
11106
|
-
const includeImport = _Transformer.isGenerateInclude && hasRelationToAnotherModel ? `import { ${modelName}IncludeObjectSchema } from './objects/${modelName}Include.schema'` : "";
|
|
11106
|
+
const selectImport = _Transformer.isGenerateSelect ? `import { ${lowerCaseFirst(modelName)}SelectObjectSchema } from './objects/${lowerCaseFirst(modelName)}Select.schema'` : "";
|
|
11107
|
+
const includeImport = _Transformer.isGenerateInclude && hasRelationToAnotherModel ? `import { ${lowerCaseFirst(modelName)}IncludeObjectSchema } from './objects/${lowerCaseFirst(modelName)}Include.schema'` : "";
|
|
11107
11108
|
let selectZodSchemaLine = "";
|
|
11108
11109
|
let includeZodSchemaLine = "";
|
|
11109
11110
|
let selectZodSchemaLineLazy = "";
|
|
11110
11111
|
let includeZodSchemaLineLazy = "";
|
|
11111
11112
|
if (_Transformer.isGenerateSelect) {
|
|
11112
|
-
const zodSelectObjectSchema = `${modelName}SelectObjectSchema.optional()`;
|
|
11113
|
+
const zodSelectObjectSchema = `${lowerCaseFirst(modelName)}SelectObjectSchema.optional()`;
|
|
11113
11114
|
selectZodSchemaLine = `select: ${zodSelectObjectSchema},`;
|
|
11114
11115
|
selectZodSchemaLineLazy = `select: z.lazy(() => ${zodSelectObjectSchema}),`;
|
|
11115
11116
|
}
|
|
11116
11117
|
if (_Transformer.isGenerateInclude && hasRelationToAnotherModel) {
|
|
11117
|
-
const zodIncludeObjectSchema = `${modelName}IncludeObjectSchema.optional()`;
|
|
11118
|
+
const zodIncludeObjectSchema = `${lowerCaseFirst(modelName)}IncludeObjectSchema.optional()`;
|
|
11118
11119
|
includeZodSchemaLine = `include: ${zodIncludeObjectSchema},`;
|
|
11119
11120
|
includeZodSchemaLineLazy = `include: z.lazy(() => ${zodIncludeObjectSchema}),`;
|
|
11120
11121
|
}
|
|
@@ -11134,9 +11135,9 @@ ${this.generateExportSchemaStatement(`${name}`, `z.enum(${JSON.stringify(values)
|
|
|
11134
11135
|
"postgresql",
|
|
11135
11136
|
"mysql"
|
|
11136
11137
|
].includes(_Transformer.provider) && _Transformer.previewFeatures?.includes("fullTextSearch")) {
|
|
11137
|
-
modelOrderBy = `${modelName}OrderByWithRelationAndSearchRelevanceInput`;
|
|
11138
|
+
modelOrderBy = `${lowerCaseFirst(modelName)}OrderByWithRelationAndSearchRelevanceInput`;
|
|
11138
11139
|
} else {
|
|
11139
|
-
modelOrderBy = `${modelName}OrderByWithRelationInput`;
|
|
11140
|
+
modelOrderBy = `${lowerCaseFirst(modelName)}OrderByWithRelationInput`;
|
|
11140
11141
|
}
|
|
11141
11142
|
const orderByImport = `import { ${modelOrderBy}ObjectSchema } from './objects/${modelOrderBy}.schema'`;
|
|
11142
11143
|
const orderByZodSchemaLine = `orderBy: z.union([${modelOrderBy}ObjectSchema, ${modelOrderBy}ObjectSchema.array()]).optional(),`;
|
|
@@ -11680,7 +11681,7 @@ ${JSON.stringify(config)}`);
|
|
|
11680
11681
|
const plural = (0, import_pluralize.default)(lowerCaseFirst(model));
|
|
11681
11682
|
consoleLog(`Generating tRPC router for model ${model}`);
|
|
11682
11683
|
generateRouterImport(appRouter, plural, model);
|
|
11683
|
-
const modelRouter = project.createSourceFile(import_node_path5.default.resolve(outputDir, "routers", `${model}.router.ts`), void 0, {
|
|
11684
|
+
const modelRouter = project.createSourceFile(import_node_path5.default.resolve(outputDir, "routers", `${lowerCaseFirst(model)}.router.ts`), void 0, {
|
|
11684
11685
|
overwrite: true
|
|
11685
11686
|
});
|
|
11686
11687
|
generateCreateRouterImport({
|
package/dist/generator.js
CHANGED
|
@@ -7616,7 +7616,7 @@ var generateCreateRouterImport = /* @__PURE__ */ __name(({ sourceFile, config })
|
|
|
7616
7616
|
}, "generateCreateRouterImport");
|
|
7617
7617
|
var generateRouterImport = /* @__PURE__ */ __name((sourceFile, modelNamePlural, modelNameCamelCase) => {
|
|
7618
7618
|
sourceFile.addImportDeclaration({
|
|
7619
|
-
moduleSpecifier: `./${modelNameCamelCase}.router`,
|
|
7619
|
+
moduleSpecifier: `./${lowerCaseFirst(modelNameCamelCase)}.router`,
|
|
7620
7620
|
namedImports: [
|
|
7621
7621
|
`${modelNamePlural}Router`
|
|
7622
7622
|
]
|
|
@@ -7646,7 +7646,8 @@ async function generateTRPCExports(sourceFile, config, options, outputDir) {
|
|
|
7646
7646
|
/* ts */
|
|
7647
7647
|
`import { createContext } from '${relativePath(outputDir, joinPaths(outputDir, config.contextPath))}';
|
|
7648
7648
|
import { initTRPC } from '@trpc/server';
|
|
7649
|
-
import { createTRPCServerActionHandler } from '@stryke/trpc-next/action-handler'
|
|
7649
|
+
import { createTRPCServerActionHandler } from '@stryke/trpc-next/action-handler';
|
|
7650
|
+
import { cookies } from "next/headers";`
|
|
7650
7651
|
);
|
|
7651
7652
|
}
|
|
7652
7653
|
sourceFile.addStatements(
|
|
@@ -7743,7 +7744,7 @@ export const ${procName} = t.procedure`
|
|
|
7743
7744
|
/* ts */
|
|
7744
7745
|
`
|
|
7745
7746
|
export const createAction: ReturnType<typeof createTRPCServerActionHandler> =
|
|
7746
|
-
createTRPCServerActionHandler(t, createContext);
|
|
7747
|
+
createTRPCServerActionHandler(cookies, t, createContext);
|
|
7747
7748
|
`
|
|
7748
7749
|
);
|
|
7749
7750
|
}
|
|
@@ -7781,7 +7782,7 @@ __name(generateRouterSchemaImports, "generateRouterSchemaImports");
|
|
|
7781
7782
|
var getRouterSchemaImportByOpName = /* @__PURE__ */ __name((opName, modelName) => {
|
|
7782
7783
|
const opType = opName.replace("OrThrow", "").replace("ManyAndReturn", "");
|
|
7783
7784
|
const inputType = getInputTypeByOpName(opType, modelName);
|
|
7784
|
-
return inputType ? `import { ${inputType} } from "../schemas/${opType}${modelName}.schema"; ` : "";
|
|
7785
|
+
return inputType ? `import { ${lowerCaseFirst(inputType)} } from "../schemas/${lowerCaseFirst(opType)}${modelName}.schema"; ` : "";
|
|
7785
7786
|
}, "getRouterSchemaImportByOpName");
|
|
7786
7787
|
var getInputTypeByOpName = /* @__PURE__ */ __name((opName, modelName) => {
|
|
7787
7788
|
let inputType;
|
|
@@ -10648,8 +10649,8 @@ var Transformer = class _Transformer {
|
|
|
10648
10649
|
hasJson = false;
|
|
10649
10650
|
static prismaClientOutputPath = "@prisma/client";
|
|
10650
10651
|
static isCustomPrismaClientOutputPath = false;
|
|
10651
|
-
static isGenerateSelect =
|
|
10652
|
-
static isGenerateInclude =
|
|
10652
|
+
static isGenerateSelect = true;
|
|
10653
|
+
static isGenerateInclude = true;
|
|
10653
10654
|
constructor(params) {
|
|
10654
10655
|
this.name = params.name ?? "";
|
|
10655
10656
|
this.fields = params.fields ?? [];
|
|
@@ -10681,21 +10682,21 @@ var Transformer = class _Transformer {
|
|
|
10681
10682
|
async generateEnumSchemas() {
|
|
10682
10683
|
for (const enumType2 of this.enumTypes) {
|
|
10683
10684
|
const { name, values } = enumType2;
|
|
10684
|
-
await writeFileSafely(path3.join(_Transformer.outputPath, `schemas/enums/${name}.schema.ts`), `${this.generateImportZodStatement()}
|
|
10685
|
-
${this.generateExportSchemaStatement(`${name}`, `z.enum(${JSON.stringify(values)})`)}`);
|
|
10685
|
+
await writeFileSafely(path3.join(_Transformer.outputPath, `schemas/enums/${lowerCaseFirst(name)}.schema.ts`), `${this.generateImportZodStatement()}
|
|
10686
|
+
${this.generateExportSchemaStatement(`${lowerCaseFirst(name)}`, `z.enum(${JSON.stringify(values)})`)}`);
|
|
10686
10687
|
}
|
|
10687
10688
|
}
|
|
10688
10689
|
generateImportZodStatement() {
|
|
10689
10690
|
return "import { z } from 'zod';\n";
|
|
10690
10691
|
}
|
|
10691
10692
|
generateExportSchemaStatement(name, schema) {
|
|
10692
|
-
return `export const ${name}Schema = ${schema}`;
|
|
10693
|
+
return `export const ${lowerCaseFirst(name)}Schema = ${schema}`;
|
|
10693
10694
|
}
|
|
10694
10695
|
async generateObjectSchema() {
|
|
10695
10696
|
const zodObjectSchemaFields = this.generateObjectSchemaFields();
|
|
10696
10697
|
const objectSchema = this.prepareObjectSchema(zodObjectSchemaFields);
|
|
10697
10698
|
const objectSchemaName = this.resolveObjectSchemaName();
|
|
10698
|
-
await writeFileSafely(path3.join(_Transformer.outputPath, `schemas/objects/${objectSchemaName}.schema.ts`), objectSchema);
|
|
10699
|
+
await writeFileSafely(path3.join(_Transformer.outputPath, `schemas/objects/${lowerCaseFirst(objectSchemaName)}.schema.ts`), objectSchema);
|
|
10699
10700
|
}
|
|
10700
10701
|
generateObjectSchemaFields() {
|
|
10701
10702
|
const zodObjectSchemaFields = this.fields.map((field) => this.generateObjectSchemaField(field)).flatMap((item) => item).map((item) => {
|
|
@@ -10816,7 +10817,7 @@ ${this.generateExportSchemaStatement(`${name}`, `z.enum(${JSON.stringify(values)
|
|
|
10816
10817
|
if (isAggregateInputType(name)) {
|
|
10817
10818
|
name = `${name}Type`;
|
|
10818
10819
|
}
|
|
10819
|
-
const end = `export const ${exportName}ObjectSchema = Schema`;
|
|
10820
|
+
const end = `export const ${lowerCaseFirst(exportName)}ObjectSchema = Schema`;
|
|
10820
10821
|
return `const Schema: z.ZodType<Prisma.${name}> = ${schema};
|
|
10821
10822
|
|
|
10822
10823
|
${end}`;
|
|
@@ -10872,9 +10873,9 @@ ${this.generateExportSchemaStatement(`${name}`, `z.enum(${JSON.stringify(values)
|
|
|
10872
10873
|
if (isModelQueryType) {
|
|
10873
10874
|
return `import { ${this.resolveModelQuerySchemaName(modelName, queryName)} } from '../${queryName}${modelName}.schema'`;
|
|
10874
10875
|
} else if (_Transformer.enumNames.includes(name)) {
|
|
10875
|
-
return `import { ${name}Schema } from '../enums/${name}.schema'`;
|
|
10876
|
+
return `import { ${lowerCaseFirst(name)}Schema } from '../enums/${lowerCaseFirst(name)}.schema'`;
|
|
10876
10877
|
} else {
|
|
10877
|
-
return `import { ${name}ObjectSchema } from './${name}.schema'`;
|
|
10878
|
+
return `import { ${lowerCaseFirst(name)}ObjectSchema } from './${lowerCaseFirst(name)}.schema'`;
|
|
10878
10879
|
}
|
|
10879
10880
|
}).join(";\r\n");
|
|
10880
10881
|
}
|
|
@@ -10899,9 +10900,9 @@ ${this.generateExportSchemaStatement(`${name}`, `z.enum(${JSON.stringify(values)
|
|
|
10899
10900
|
};
|
|
10900
10901
|
}
|
|
10901
10902
|
resolveModelQuerySchemaName(modelName, queryName) {
|
|
10902
|
-
const
|
|
10903
|
+
const modelNameUncapitalized = lowerCaseFirst(modelName);
|
|
10903
10904
|
const queryNameCapitalized = upperCaseFirst(queryName);
|
|
10904
|
-
return `${
|
|
10905
|
+
return `${modelNameUncapitalized}${queryNameCapitalized}Schema`;
|
|
10905
10906
|
}
|
|
10906
10907
|
wrapWithZodUnion(zodStringFields) {
|
|
10907
10908
|
let wrapped = "";
|
|
@@ -10928,12 +10929,11 @@ ${this.generateExportSchemaStatement(`${name}`, `z.enum(${JSON.stringify(values)
|
|
|
10928
10929
|
name = _Transformer.rawOpsMap[name];
|
|
10929
10930
|
exportName = name.replace("Args", "");
|
|
10930
10931
|
}
|
|
10931
|
-
return exportName;
|
|
10932
|
+
return lowerCaseFirst(exportName);
|
|
10932
10933
|
}
|
|
10933
10934
|
async generateModelSchemas() {
|
|
10934
10935
|
for (const modelOperation of this.modelOperations) {
|
|
10935
10936
|
const {
|
|
10936
|
-
model: modelName,
|
|
10937
10937
|
findUnique,
|
|
10938
10938
|
findFirst,
|
|
10939
10939
|
findMany,
|
|
@@ -10953,7 +10953,8 @@ ${this.generateExportSchemaStatement(`${name}`, `z.enum(${JSON.stringify(values)
|
|
|
10953
10953
|
aggregate,
|
|
10954
10954
|
groupBy
|
|
10955
10955
|
} = modelOperation;
|
|
10956
|
-
const model = findModelByName(this.models,
|
|
10956
|
+
const model = findModelByName(this.models, modelOperation.model);
|
|
10957
|
+
const modelName = lowerCaseFirst(modelOperation.model);
|
|
10957
10958
|
const { selectImport, includeImport, selectZodSchemaLine, includeZodSchemaLine, selectZodSchemaLineLazy, includeZodSchemaLineLazy } = this.resolveSelectIncludeImportAndZodSchemaLine(model);
|
|
10958
10959
|
const { orderByImport, orderByZodSchemaLine } = this.resolveOrderByWithRelationImportAndZodSchemaLine(model);
|
|
10959
10960
|
if (findUnique) {
|
|
@@ -11107,19 +11108,19 @@ ${this.generateExportSchemaStatement(`${name}`, `z.enum(${JSON.stringify(values)
|
|
|
11107
11108
|
resolveSelectIncludeImportAndZodSchemaLine(model) {
|
|
11108
11109
|
const { name: modelName } = model;
|
|
11109
11110
|
const hasRelationToAnotherModel = checkModelHasModelRelation(model);
|
|
11110
|
-
const selectImport = _Transformer.isGenerateSelect ? `import { ${modelName}SelectObjectSchema } from './objects/${modelName}Select.schema'` : "";
|
|
11111
|
-
const includeImport = _Transformer.isGenerateInclude && hasRelationToAnotherModel ? `import { ${modelName}IncludeObjectSchema } from './objects/${modelName}Include.schema'` : "";
|
|
11111
|
+
const selectImport = _Transformer.isGenerateSelect ? `import { ${lowerCaseFirst(modelName)}SelectObjectSchema } from './objects/${lowerCaseFirst(modelName)}Select.schema'` : "";
|
|
11112
|
+
const includeImport = _Transformer.isGenerateInclude && hasRelationToAnotherModel ? `import { ${lowerCaseFirst(modelName)}IncludeObjectSchema } from './objects/${lowerCaseFirst(modelName)}Include.schema'` : "";
|
|
11112
11113
|
let selectZodSchemaLine = "";
|
|
11113
11114
|
let includeZodSchemaLine = "";
|
|
11114
11115
|
let selectZodSchemaLineLazy = "";
|
|
11115
11116
|
let includeZodSchemaLineLazy = "";
|
|
11116
11117
|
if (_Transformer.isGenerateSelect) {
|
|
11117
|
-
const zodSelectObjectSchema = `${modelName}SelectObjectSchema.optional()`;
|
|
11118
|
+
const zodSelectObjectSchema = `${lowerCaseFirst(modelName)}SelectObjectSchema.optional()`;
|
|
11118
11119
|
selectZodSchemaLine = `select: ${zodSelectObjectSchema},`;
|
|
11119
11120
|
selectZodSchemaLineLazy = `select: z.lazy(() => ${zodSelectObjectSchema}),`;
|
|
11120
11121
|
}
|
|
11121
11122
|
if (_Transformer.isGenerateInclude && hasRelationToAnotherModel) {
|
|
11122
|
-
const zodIncludeObjectSchema = `${modelName}IncludeObjectSchema.optional()`;
|
|
11123
|
+
const zodIncludeObjectSchema = `${lowerCaseFirst(modelName)}IncludeObjectSchema.optional()`;
|
|
11123
11124
|
includeZodSchemaLine = `include: ${zodIncludeObjectSchema},`;
|
|
11124
11125
|
includeZodSchemaLineLazy = `include: z.lazy(() => ${zodIncludeObjectSchema}),`;
|
|
11125
11126
|
}
|
|
@@ -11139,9 +11140,9 @@ ${this.generateExportSchemaStatement(`${name}`, `z.enum(${JSON.stringify(values)
|
|
|
11139
11140
|
"postgresql",
|
|
11140
11141
|
"mysql"
|
|
11141
11142
|
].includes(_Transformer.provider) && _Transformer.previewFeatures?.includes("fullTextSearch")) {
|
|
11142
|
-
modelOrderBy = `${modelName}OrderByWithRelationAndSearchRelevanceInput`;
|
|
11143
|
+
modelOrderBy = `${lowerCaseFirst(modelName)}OrderByWithRelationAndSearchRelevanceInput`;
|
|
11143
11144
|
} else {
|
|
11144
|
-
modelOrderBy = `${modelName}OrderByWithRelationInput`;
|
|
11145
|
+
modelOrderBy = `${lowerCaseFirst(modelName)}OrderByWithRelationInput`;
|
|
11145
11146
|
}
|
|
11146
11147
|
const orderByImport = `import { ${modelOrderBy}ObjectSchema } from './objects/${modelOrderBy}.schema'`;
|
|
11147
11148
|
const orderByZodSchemaLine = `orderBy: z.union([${modelOrderBy}ObjectSchema, ${modelOrderBy}ObjectSchema.array()]).optional(),`;
|
|
@@ -11685,7 +11686,7 @@ ${JSON.stringify(config)}`);
|
|
|
11685
11686
|
const plural = (0, import_pluralize.default)(lowerCaseFirst(model));
|
|
11686
11687
|
consoleLog(`Generating tRPC router for model ${model}`);
|
|
11687
11688
|
generateRouterImport(appRouter, plural, model);
|
|
11688
|
-
const modelRouter = project.createSourceFile(path4.resolve(outputDir, "routers", `${model}.router.ts`), void 0, {
|
|
11689
|
+
const modelRouter = project.createSourceFile(path4.resolve(outputDir, "routers", `${lowerCaseFirst(model)}.router.ts`), void 0, {
|
|
11689
11690
|
overwrite: true
|
|
11690
11691
|
});
|
|
11691
11692
|
generateCreateRouterImport({
|
package/dist/index.cjs
CHANGED
|
@@ -7607,7 +7607,7 @@ var generateCreateRouterImport = /* @__PURE__ */ __name(({ sourceFile, config })
|
|
|
7607
7607
|
}, "generateCreateRouterImport");
|
|
7608
7608
|
var generateRouterImport = /* @__PURE__ */ __name((sourceFile, modelNamePlural, modelNameCamelCase) => {
|
|
7609
7609
|
sourceFile.addImportDeclaration({
|
|
7610
|
-
moduleSpecifier: `./${modelNameCamelCase}.router`,
|
|
7610
|
+
moduleSpecifier: `./${lowerCaseFirst(modelNameCamelCase)}.router`,
|
|
7611
7611
|
namedImports: [
|
|
7612
7612
|
`${modelNamePlural}Router`
|
|
7613
7613
|
]
|
|
@@ -7637,7 +7637,8 @@ async function generateTRPCExports(sourceFile, config, options, outputDir) {
|
|
|
7637
7637
|
/* ts */
|
|
7638
7638
|
`import { createContext } from '${relativePath(outputDir, joinPaths(outputDir, config.contextPath))}';
|
|
7639
7639
|
import { initTRPC } from '@trpc/server';
|
|
7640
|
-
import { createTRPCServerActionHandler } from '@stryke/trpc-next/action-handler'
|
|
7640
|
+
import { createTRPCServerActionHandler } from '@stryke/trpc-next/action-handler';
|
|
7641
|
+
import { cookies } from "next/headers";`
|
|
7641
7642
|
);
|
|
7642
7643
|
}
|
|
7643
7644
|
sourceFile.addStatements(
|
|
@@ -7734,7 +7735,7 @@ export const ${procName} = t.procedure`
|
|
|
7734
7735
|
/* ts */
|
|
7735
7736
|
`
|
|
7736
7737
|
export const createAction: ReturnType<typeof createTRPCServerActionHandler> =
|
|
7737
|
-
createTRPCServerActionHandler(t, createContext);
|
|
7738
|
+
createTRPCServerActionHandler(cookies, t, createContext);
|
|
7738
7739
|
`
|
|
7739
7740
|
);
|
|
7740
7741
|
}
|
|
@@ -7772,7 +7773,7 @@ __name(generateRouterSchemaImports, "generateRouterSchemaImports");
|
|
|
7772
7773
|
var getRouterSchemaImportByOpName = /* @__PURE__ */ __name((opName, modelName) => {
|
|
7773
7774
|
const opType = opName.replace("OrThrow", "").replace("ManyAndReturn", "");
|
|
7774
7775
|
const inputType = getInputTypeByOpName(opType, modelName);
|
|
7775
|
-
return inputType ? `import { ${inputType} } from "../schemas/${opType}${modelName}.schema"; ` : "";
|
|
7776
|
+
return inputType ? `import { ${lowerCaseFirst(inputType)} } from "../schemas/${lowerCaseFirst(opType)}${modelName}.schema"; ` : "";
|
|
7776
7777
|
}, "getRouterSchemaImportByOpName");
|
|
7777
7778
|
var getInputTypeByOpName = /* @__PURE__ */ __name((opName, modelName) => {
|
|
7778
7779
|
let inputType;
|
|
@@ -10639,8 +10640,8 @@ var Transformer = class _Transformer {
|
|
|
10639
10640
|
hasJson = false;
|
|
10640
10641
|
static prismaClientOutputPath = "@prisma/client";
|
|
10641
10642
|
static isCustomPrismaClientOutputPath = false;
|
|
10642
|
-
static isGenerateSelect =
|
|
10643
|
-
static isGenerateInclude =
|
|
10643
|
+
static isGenerateSelect = true;
|
|
10644
|
+
static isGenerateInclude = true;
|
|
10644
10645
|
constructor(params) {
|
|
10645
10646
|
this.name = params.name ?? "";
|
|
10646
10647
|
this.fields = params.fields ?? [];
|
|
@@ -10672,21 +10673,21 @@ var Transformer = class _Transformer {
|
|
|
10672
10673
|
async generateEnumSchemas() {
|
|
10673
10674
|
for (const enumType2 of this.enumTypes) {
|
|
10674
10675
|
const { name, values } = enumType2;
|
|
10675
|
-
await writeFileSafely(import_node_path4.default.join(_Transformer.outputPath, `schemas/enums/${name}.schema.ts`), `${this.generateImportZodStatement()}
|
|
10676
|
-
${this.generateExportSchemaStatement(`${name}`, `z.enum(${JSON.stringify(values)})`)}`);
|
|
10676
|
+
await writeFileSafely(import_node_path4.default.join(_Transformer.outputPath, `schemas/enums/${lowerCaseFirst(name)}.schema.ts`), `${this.generateImportZodStatement()}
|
|
10677
|
+
${this.generateExportSchemaStatement(`${lowerCaseFirst(name)}`, `z.enum(${JSON.stringify(values)})`)}`);
|
|
10677
10678
|
}
|
|
10678
10679
|
}
|
|
10679
10680
|
generateImportZodStatement() {
|
|
10680
10681
|
return "import { z } from 'zod';\n";
|
|
10681
10682
|
}
|
|
10682
10683
|
generateExportSchemaStatement(name, schema) {
|
|
10683
|
-
return `export const ${name}Schema = ${schema}`;
|
|
10684
|
+
return `export const ${lowerCaseFirst(name)}Schema = ${schema}`;
|
|
10684
10685
|
}
|
|
10685
10686
|
async generateObjectSchema() {
|
|
10686
10687
|
const zodObjectSchemaFields = this.generateObjectSchemaFields();
|
|
10687
10688
|
const objectSchema = this.prepareObjectSchema(zodObjectSchemaFields);
|
|
10688
10689
|
const objectSchemaName = this.resolveObjectSchemaName();
|
|
10689
|
-
await writeFileSafely(import_node_path4.default.join(_Transformer.outputPath, `schemas/objects/${objectSchemaName}.schema.ts`), objectSchema);
|
|
10690
|
+
await writeFileSafely(import_node_path4.default.join(_Transformer.outputPath, `schemas/objects/${lowerCaseFirst(objectSchemaName)}.schema.ts`), objectSchema);
|
|
10690
10691
|
}
|
|
10691
10692
|
generateObjectSchemaFields() {
|
|
10692
10693
|
const zodObjectSchemaFields = this.fields.map((field) => this.generateObjectSchemaField(field)).flatMap((item) => item).map((item) => {
|
|
@@ -10807,7 +10808,7 @@ ${this.generateExportSchemaStatement(`${name}`, `z.enum(${JSON.stringify(values)
|
|
|
10807
10808
|
if (isAggregateInputType(name)) {
|
|
10808
10809
|
name = `${name}Type`;
|
|
10809
10810
|
}
|
|
10810
|
-
const end = `export const ${exportName}ObjectSchema = Schema`;
|
|
10811
|
+
const end = `export const ${lowerCaseFirst(exportName)}ObjectSchema = Schema`;
|
|
10811
10812
|
return `const Schema: z.ZodType<Prisma.${name}> = ${schema};
|
|
10812
10813
|
|
|
10813
10814
|
${end}`;
|
|
@@ -10863,9 +10864,9 @@ ${this.generateExportSchemaStatement(`${name}`, `z.enum(${JSON.stringify(values)
|
|
|
10863
10864
|
if (isModelQueryType) {
|
|
10864
10865
|
return `import { ${this.resolveModelQuerySchemaName(modelName, queryName)} } from '../${queryName}${modelName}.schema'`;
|
|
10865
10866
|
} else if (_Transformer.enumNames.includes(name)) {
|
|
10866
|
-
return `import { ${name}Schema } from '../enums/${name}.schema'`;
|
|
10867
|
+
return `import { ${lowerCaseFirst(name)}Schema } from '../enums/${lowerCaseFirst(name)}.schema'`;
|
|
10867
10868
|
} else {
|
|
10868
|
-
return `import { ${name}ObjectSchema } from './${name}.schema'`;
|
|
10869
|
+
return `import { ${lowerCaseFirst(name)}ObjectSchema } from './${lowerCaseFirst(name)}.schema'`;
|
|
10869
10870
|
}
|
|
10870
10871
|
}).join(";\r\n");
|
|
10871
10872
|
}
|
|
@@ -10890,9 +10891,9 @@ ${this.generateExportSchemaStatement(`${name}`, `z.enum(${JSON.stringify(values)
|
|
|
10890
10891
|
};
|
|
10891
10892
|
}
|
|
10892
10893
|
resolveModelQuerySchemaName(modelName, queryName) {
|
|
10893
|
-
const
|
|
10894
|
+
const modelNameUncapitalized = lowerCaseFirst(modelName);
|
|
10894
10895
|
const queryNameCapitalized = upperCaseFirst(queryName);
|
|
10895
|
-
return `${
|
|
10896
|
+
return `${modelNameUncapitalized}${queryNameCapitalized}Schema`;
|
|
10896
10897
|
}
|
|
10897
10898
|
wrapWithZodUnion(zodStringFields) {
|
|
10898
10899
|
let wrapped = "";
|
|
@@ -10919,12 +10920,11 @@ ${this.generateExportSchemaStatement(`${name}`, `z.enum(${JSON.stringify(values)
|
|
|
10919
10920
|
name = _Transformer.rawOpsMap[name];
|
|
10920
10921
|
exportName = name.replace("Args", "");
|
|
10921
10922
|
}
|
|
10922
|
-
return exportName;
|
|
10923
|
+
return lowerCaseFirst(exportName);
|
|
10923
10924
|
}
|
|
10924
10925
|
async generateModelSchemas() {
|
|
10925
10926
|
for (const modelOperation of this.modelOperations) {
|
|
10926
10927
|
const {
|
|
10927
|
-
model: modelName,
|
|
10928
10928
|
findUnique,
|
|
10929
10929
|
findFirst,
|
|
10930
10930
|
findMany,
|
|
@@ -10944,7 +10944,8 @@ ${this.generateExportSchemaStatement(`${name}`, `z.enum(${JSON.stringify(values)
|
|
|
10944
10944
|
aggregate,
|
|
10945
10945
|
groupBy
|
|
10946
10946
|
} = modelOperation;
|
|
10947
|
-
const model = findModelByName(this.models,
|
|
10947
|
+
const model = findModelByName(this.models, modelOperation.model);
|
|
10948
|
+
const modelName = lowerCaseFirst(modelOperation.model);
|
|
10948
10949
|
const { selectImport, includeImport, selectZodSchemaLine, includeZodSchemaLine, selectZodSchemaLineLazy, includeZodSchemaLineLazy } = this.resolveSelectIncludeImportAndZodSchemaLine(model);
|
|
10949
10950
|
const { orderByImport, orderByZodSchemaLine } = this.resolveOrderByWithRelationImportAndZodSchemaLine(model);
|
|
10950
10951
|
if (findUnique) {
|
|
@@ -11098,19 +11099,19 @@ ${this.generateExportSchemaStatement(`${name}`, `z.enum(${JSON.stringify(values)
|
|
|
11098
11099
|
resolveSelectIncludeImportAndZodSchemaLine(model) {
|
|
11099
11100
|
const { name: modelName } = model;
|
|
11100
11101
|
const hasRelationToAnotherModel = checkModelHasModelRelation(model);
|
|
11101
|
-
const selectImport = _Transformer.isGenerateSelect ? `import { ${modelName}SelectObjectSchema } from './objects/${modelName}Select.schema'` : "";
|
|
11102
|
-
const includeImport = _Transformer.isGenerateInclude && hasRelationToAnotherModel ? `import { ${modelName}IncludeObjectSchema } from './objects/${modelName}Include.schema'` : "";
|
|
11102
|
+
const selectImport = _Transformer.isGenerateSelect ? `import { ${lowerCaseFirst(modelName)}SelectObjectSchema } from './objects/${lowerCaseFirst(modelName)}Select.schema'` : "";
|
|
11103
|
+
const includeImport = _Transformer.isGenerateInclude && hasRelationToAnotherModel ? `import { ${lowerCaseFirst(modelName)}IncludeObjectSchema } from './objects/${lowerCaseFirst(modelName)}Include.schema'` : "";
|
|
11103
11104
|
let selectZodSchemaLine = "";
|
|
11104
11105
|
let includeZodSchemaLine = "";
|
|
11105
11106
|
let selectZodSchemaLineLazy = "";
|
|
11106
11107
|
let includeZodSchemaLineLazy = "";
|
|
11107
11108
|
if (_Transformer.isGenerateSelect) {
|
|
11108
|
-
const zodSelectObjectSchema = `${modelName}SelectObjectSchema.optional()`;
|
|
11109
|
+
const zodSelectObjectSchema = `${lowerCaseFirst(modelName)}SelectObjectSchema.optional()`;
|
|
11109
11110
|
selectZodSchemaLine = `select: ${zodSelectObjectSchema},`;
|
|
11110
11111
|
selectZodSchemaLineLazy = `select: z.lazy(() => ${zodSelectObjectSchema}),`;
|
|
11111
11112
|
}
|
|
11112
11113
|
if (_Transformer.isGenerateInclude && hasRelationToAnotherModel) {
|
|
11113
|
-
const zodIncludeObjectSchema = `${modelName}IncludeObjectSchema.optional()`;
|
|
11114
|
+
const zodIncludeObjectSchema = `${lowerCaseFirst(modelName)}IncludeObjectSchema.optional()`;
|
|
11114
11115
|
includeZodSchemaLine = `include: ${zodIncludeObjectSchema},`;
|
|
11115
11116
|
includeZodSchemaLineLazy = `include: z.lazy(() => ${zodIncludeObjectSchema}),`;
|
|
11116
11117
|
}
|
|
@@ -11130,9 +11131,9 @@ ${this.generateExportSchemaStatement(`${name}`, `z.enum(${JSON.stringify(values)
|
|
|
11130
11131
|
"postgresql",
|
|
11131
11132
|
"mysql"
|
|
11132
11133
|
].includes(_Transformer.provider) && _Transformer.previewFeatures?.includes("fullTextSearch")) {
|
|
11133
|
-
modelOrderBy = `${modelName}OrderByWithRelationAndSearchRelevanceInput`;
|
|
11134
|
+
modelOrderBy = `${lowerCaseFirst(modelName)}OrderByWithRelationAndSearchRelevanceInput`;
|
|
11134
11135
|
} else {
|
|
11135
|
-
modelOrderBy = `${modelName}OrderByWithRelationInput`;
|
|
11136
|
+
modelOrderBy = `${lowerCaseFirst(modelName)}OrderByWithRelationInput`;
|
|
11136
11137
|
}
|
|
11137
11138
|
const orderByImport = `import { ${modelOrderBy}ObjectSchema } from './objects/${modelOrderBy}.schema'`;
|
|
11138
11139
|
const orderByZodSchemaLine = `orderBy: z.union([${modelOrderBy}ObjectSchema, ${modelOrderBy}ObjectSchema.array()]).optional(),`;
|
|
@@ -11676,7 +11677,7 @@ ${JSON.stringify(config)}`);
|
|
|
11676
11677
|
const plural = (0, import_pluralize.default)(lowerCaseFirst(model));
|
|
11677
11678
|
consoleLog(`Generating tRPC router for model ${model}`);
|
|
11678
11679
|
generateRouterImport(appRouter, plural, model);
|
|
11679
|
-
const modelRouter = project.createSourceFile(import_node_path5.default.resolve(outputDir, "routers", `${model}.router.ts`), void 0, {
|
|
11680
|
+
const modelRouter = project.createSourceFile(import_node_path5.default.resolve(outputDir, "routers", `${lowerCaseFirst(model)}.router.ts`), void 0, {
|
|
11680
11681
|
overwrite: true
|
|
11681
11682
|
});
|
|
11682
11683
|
generateCreateRouterImport({
|
package/dist/index.js
CHANGED
|
@@ -7612,7 +7612,7 @@ var generateCreateRouterImport = /* @__PURE__ */ __name(({ sourceFile, config })
|
|
|
7612
7612
|
}, "generateCreateRouterImport");
|
|
7613
7613
|
var generateRouterImport = /* @__PURE__ */ __name((sourceFile, modelNamePlural, modelNameCamelCase) => {
|
|
7614
7614
|
sourceFile.addImportDeclaration({
|
|
7615
|
-
moduleSpecifier: `./${modelNameCamelCase}.router`,
|
|
7615
|
+
moduleSpecifier: `./${lowerCaseFirst(modelNameCamelCase)}.router`,
|
|
7616
7616
|
namedImports: [
|
|
7617
7617
|
`${modelNamePlural}Router`
|
|
7618
7618
|
]
|
|
@@ -7642,7 +7642,8 @@ async function generateTRPCExports(sourceFile, config, options, outputDir) {
|
|
|
7642
7642
|
/* ts */
|
|
7643
7643
|
`import { createContext } from '${relativePath(outputDir, joinPaths(outputDir, config.contextPath))}';
|
|
7644
7644
|
import { initTRPC } from '@trpc/server';
|
|
7645
|
-
import { createTRPCServerActionHandler } from '@stryke/trpc-next/action-handler'
|
|
7645
|
+
import { createTRPCServerActionHandler } from '@stryke/trpc-next/action-handler';
|
|
7646
|
+
import { cookies } from "next/headers";`
|
|
7646
7647
|
);
|
|
7647
7648
|
}
|
|
7648
7649
|
sourceFile.addStatements(
|
|
@@ -7739,7 +7740,7 @@ export const ${procName} = t.procedure`
|
|
|
7739
7740
|
/* ts */
|
|
7740
7741
|
`
|
|
7741
7742
|
export const createAction: ReturnType<typeof createTRPCServerActionHandler> =
|
|
7742
|
-
createTRPCServerActionHandler(t, createContext);
|
|
7743
|
+
createTRPCServerActionHandler(cookies, t, createContext);
|
|
7743
7744
|
`
|
|
7744
7745
|
);
|
|
7745
7746
|
}
|
|
@@ -7777,7 +7778,7 @@ __name(generateRouterSchemaImports, "generateRouterSchemaImports");
|
|
|
7777
7778
|
var getRouterSchemaImportByOpName = /* @__PURE__ */ __name((opName, modelName) => {
|
|
7778
7779
|
const opType = opName.replace("OrThrow", "").replace("ManyAndReturn", "");
|
|
7779
7780
|
const inputType = getInputTypeByOpName(opType, modelName);
|
|
7780
|
-
return inputType ? `import { ${inputType} } from "../schemas/${opType}${modelName}.schema"; ` : "";
|
|
7781
|
+
return inputType ? `import { ${lowerCaseFirst(inputType)} } from "../schemas/${lowerCaseFirst(opType)}${modelName}.schema"; ` : "";
|
|
7781
7782
|
}, "getRouterSchemaImportByOpName");
|
|
7782
7783
|
var getInputTypeByOpName = /* @__PURE__ */ __name((opName, modelName) => {
|
|
7783
7784
|
let inputType;
|
|
@@ -10644,8 +10645,8 @@ var Transformer = class _Transformer {
|
|
|
10644
10645
|
hasJson = false;
|
|
10645
10646
|
static prismaClientOutputPath = "@prisma/client";
|
|
10646
10647
|
static isCustomPrismaClientOutputPath = false;
|
|
10647
|
-
static isGenerateSelect =
|
|
10648
|
-
static isGenerateInclude =
|
|
10648
|
+
static isGenerateSelect = true;
|
|
10649
|
+
static isGenerateInclude = true;
|
|
10649
10650
|
constructor(params) {
|
|
10650
10651
|
this.name = params.name ?? "";
|
|
10651
10652
|
this.fields = params.fields ?? [];
|
|
@@ -10677,21 +10678,21 @@ var Transformer = class _Transformer {
|
|
|
10677
10678
|
async generateEnumSchemas() {
|
|
10678
10679
|
for (const enumType2 of this.enumTypes) {
|
|
10679
10680
|
const { name, values } = enumType2;
|
|
10680
|
-
await writeFileSafely(path3.join(_Transformer.outputPath, `schemas/enums/${name}.schema.ts`), `${this.generateImportZodStatement()}
|
|
10681
|
-
${this.generateExportSchemaStatement(`${name}`, `z.enum(${JSON.stringify(values)})`)}`);
|
|
10681
|
+
await writeFileSafely(path3.join(_Transformer.outputPath, `schemas/enums/${lowerCaseFirst(name)}.schema.ts`), `${this.generateImportZodStatement()}
|
|
10682
|
+
${this.generateExportSchemaStatement(`${lowerCaseFirst(name)}`, `z.enum(${JSON.stringify(values)})`)}`);
|
|
10682
10683
|
}
|
|
10683
10684
|
}
|
|
10684
10685
|
generateImportZodStatement() {
|
|
10685
10686
|
return "import { z } from 'zod';\n";
|
|
10686
10687
|
}
|
|
10687
10688
|
generateExportSchemaStatement(name, schema) {
|
|
10688
|
-
return `export const ${name}Schema = ${schema}`;
|
|
10689
|
+
return `export const ${lowerCaseFirst(name)}Schema = ${schema}`;
|
|
10689
10690
|
}
|
|
10690
10691
|
async generateObjectSchema() {
|
|
10691
10692
|
const zodObjectSchemaFields = this.generateObjectSchemaFields();
|
|
10692
10693
|
const objectSchema = this.prepareObjectSchema(zodObjectSchemaFields);
|
|
10693
10694
|
const objectSchemaName = this.resolveObjectSchemaName();
|
|
10694
|
-
await writeFileSafely(path3.join(_Transformer.outputPath, `schemas/objects/${objectSchemaName}.schema.ts`), objectSchema);
|
|
10695
|
+
await writeFileSafely(path3.join(_Transformer.outputPath, `schemas/objects/${lowerCaseFirst(objectSchemaName)}.schema.ts`), objectSchema);
|
|
10695
10696
|
}
|
|
10696
10697
|
generateObjectSchemaFields() {
|
|
10697
10698
|
const zodObjectSchemaFields = this.fields.map((field) => this.generateObjectSchemaField(field)).flatMap((item) => item).map((item) => {
|
|
@@ -10812,7 +10813,7 @@ ${this.generateExportSchemaStatement(`${name}`, `z.enum(${JSON.stringify(values)
|
|
|
10812
10813
|
if (isAggregateInputType(name)) {
|
|
10813
10814
|
name = `${name}Type`;
|
|
10814
10815
|
}
|
|
10815
|
-
const end = `export const ${exportName}ObjectSchema = Schema`;
|
|
10816
|
+
const end = `export const ${lowerCaseFirst(exportName)}ObjectSchema = Schema`;
|
|
10816
10817
|
return `const Schema: z.ZodType<Prisma.${name}> = ${schema};
|
|
10817
10818
|
|
|
10818
10819
|
${end}`;
|
|
@@ -10868,9 +10869,9 @@ ${this.generateExportSchemaStatement(`${name}`, `z.enum(${JSON.stringify(values)
|
|
|
10868
10869
|
if (isModelQueryType) {
|
|
10869
10870
|
return `import { ${this.resolveModelQuerySchemaName(modelName, queryName)} } from '../${queryName}${modelName}.schema'`;
|
|
10870
10871
|
} else if (_Transformer.enumNames.includes(name)) {
|
|
10871
|
-
return `import { ${name}Schema } from '../enums/${name}.schema'`;
|
|
10872
|
+
return `import { ${lowerCaseFirst(name)}Schema } from '../enums/${lowerCaseFirst(name)}.schema'`;
|
|
10872
10873
|
} else {
|
|
10873
|
-
return `import { ${name}ObjectSchema } from './${name}.schema'`;
|
|
10874
|
+
return `import { ${lowerCaseFirst(name)}ObjectSchema } from './${lowerCaseFirst(name)}.schema'`;
|
|
10874
10875
|
}
|
|
10875
10876
|
}).join(";\r\n");
|
|
10876
10877
|
}
|
|
@@ -10895,9 +10896,9 @@ ${this.generateExportSchemaStatement(`${name}`, `z.enum(${JSON.stringify(values)
|
|
|
10895
10896
|
};
|
|
10896
10897
|
}
|
|
10897
10898
|
resolveModelQuerySchemaName(modelName, queryName) {
|
|
10898
|
-
const
|
|
10899
|
+
const modelNameUncapitalized = lowerCaseFirst(modelName);
|
|
10899
10900
|
const queryNameCapitalized = upperCaseFirst(queryName);
|
|
10900
|
-
return `${
|
|
10901
|
+
return `${modelNameUncapitalized}${queryNameCapitalized}Schema`;
|
|
10901
10902
|
}
|
|
10902
10903
|
wrapWithZodUnion(zodStringFields) {
|
|
10903
10904
|
let wrapped = "";
|
|
@@ -10924,12 +10925,11 @@ ${this.generateExportSchemaStatement(`${name}`, `z.enum(${JSON.stringify(values)
|
|
|
10924
10925
|
name = _Transformer.rawOpsMap[name];
|
|
10925
10926
|
exportName = name.replace("Args", "");
|
|
10926
10927
|
}
|
|
10927
|
-
return exportName;
|
|
10928
|
+
return lowerCaseFirst(exportName);
|
|
10928
10929
|
}
|
|
10929
10930
|
async generateModelSchemas() {
|
|
10930
10931
|
for (const modelOperation of this.modelOperations) {
|
|
10931
10932
|
const {
|
|
10932
|
-
model: modelName,
|
|
10933
10933
|
findUnique,
|
|
10934
10934
|
findFirst,
|
|
10935
10935
|
findMany,
|
|
@@ -10949,7 +10949,8 @@ ${this.generateExportSchemaStatement(`${name}`, `z.enum(${JSON.stringify(values)
|
|
|
10949
10949
|
aggregate,
|
|
10950
10950
|
groupBy
|
|
10951
10951
|
} = modelOperation;
|
|
10952
|
-
const model = findModelByName(this.models,
|
|
10952
|
+
const model = findModelByName(this.models, modelOperation.model);
|
|
10953
|
+
const modelName = lowerCaseFirst(modelOperation.model);
|
|
10953
10954
|
const { selectImport, includeImport, selectZodSchemaLine, includeZodSchemaLine, selectZodSchemaLineLazy, includeZodSchemaLineLazy } = this.resolveSelectIncludeImportAndZodSchemaLine(model);
|
|
10954
10955
|
const { orderByImport, orderByZodSchemaLine } = this.resolveOrderByWithRelationImportAndZodSchemaLine(model);
|
|
10955
10956
|
if (findUnique) {
|
|
@@ -11103,19 +11104,19 @@ ${this.generateExportSchemaStatement(`${name}`, `z.enum(${JSON.stringify(values)
|
|
|
11103
11104
|
resolveSelectIncludeImportAndZodSchemaLine(model) {
|
|
11104
11105
|
const { name: modelName } = model;
|
|
11105
11106
|
const hasRelationToAnotherModel = checkModelHasModelRelation(model);
|
|
11106
|
-
const selectImport = _Transformer.isGenerateSelect ? `import { ${modelName}SelectObjectSchema } from './objects/${modelName}Select.schema'` : "";
|
|
11107
|
-
const includeImport = _Transformer.isGenerateInclude && hasRelationToAnotherModel ? `import { ${modelName}IncludeObjectSchema } from './objects/${modelName}Include.schema'` : "";
|
|
11107
|
+
const selectImport = _Transformer.isGenerateSelect ? `import { ${lowerCaseFirst(modelName)}SelectObjectSchema } from './objects/${lowerCaseFirst(modelName)}Select.schema'` : "";
|
|
11108
|
+
const includeImport = _Transformer.isGenerateInclude && hasRelationToAnotherModel ? `import { ${lowerCaseFirst(modelName)}IncludeObjectSchema } from './objects/${lowerCaseFirst(modelName)}Include.schema'` : "";
|
|
11108
11109
|
let selectZodSchemaLine = "";
|
|
11109
11110
|
let includeZodSchemaLine = "";
|
|
11110
11111
|
let selectZodSchemaLineLazy = "";
|
|
11111
11112
|
let includeZodSchemaLineLazy = "";
|
|
11112
11113
|
if (_Transformer.isGenerateSelect) {
|
|
11113
|
-
const zodSelectObjectSchema = `${modelName}SelectObjectSchema.optional()`;
|
|
11114
|
+
const zodSelectObjectSchema = `${lowerCaseFirst(modelName)}SelectObjectSchema.optional()`;
|
|
11114
11115
|
selectZodSchemaLine = `select: ${zodSelectObjectSchema},`;
|
|
11115
11116
|
selectZodSchemaLineLazy = `select: z.lazy(() => ${zodSelectObjectSchema}),`;
|
|
11116
11117
|
}
|
|
11117
11118
|
if (_Transformer.isGenerateInclude && hasRelationToAnotherModel) {
|
|
11118
|
-
const zodIncludeObjectSchema = `${modelName}IncludeObjectSchema.optional()`;
|
|
11119
|
+
const zodIncludeObjectSchema = `${lowerCaseFirst(modelName)}IncludeObjectSchema.optional()`;
|
|
11119
11120
|
includeZodSchemaLine = `include: ${zodIncludeObjectSchema},`;
|
|
11120
11121
|
includeZodSchemaLineLazy = `include: z.lazy(() => ${zodIncludeObjectSchema}),`;
|
|
11121
11122
|
}
|
|
@@ -11135,9 +11136,9 @@ ${this.generateExportSchemaStatement(`${name}`, `z.enum(${JSON.stringify(values)
|
|
|
11135
11136
|
"postgresql",
|
|
11136
11137
|
"mysql"
|
|
11137
11138
|
].includes(_Transformer.provider) && _Transformer.previewFeatures?.includes("fullTextSearch")) {
|
|
11138
|
-
modelOrderBy = `${modelName}OrderByWithRelationAndSearchRelevanceInput`;
|
|
11139
|
+
modelOrderBy = `${lowerCaseFirst(modelName)}OrderByWithRelationAndSearchRelevanceInput`;
|
|
11139
11140
|
} else {
|
|
11140
|
-
modelOrderBy = `${modelName}OrderByWithRelationInput`;
|
|
11141
|
+
modelOrderBy = `${lowerCaseFirst(modelName)}OrderByWithRelationInput`;
|
|
11141
11142
|
}
|
|
11142
11143
|
const orderByImport = `import { ${modelOrderBy}ObjectSchema } from './objects/${modelOrderBy}.schema'`;
|
|
11143
11144
|
const orderByZodSchemaLine = `orderBy: z.union([${modelOrderBy}ObjectSchema, ${modelOrderBy}ObjectSchema.array()]).optional(),`;
|
|
@@ -11681,7 +11682,7 @@ ${JSON.stringify(config)}`);
|
|
|
11681
11682
|
const plural = (0, import_pluralize.default)(lowerCaseFirst(model));
|
|
11682
11683
|
consoleLog(`Generating tRPC router for model ${model}`);
|
|
11683
11684
|
generateRouterImport(appRouter, plural, model);
|
|
11684
|
-
const modelRouter = project.createSourceFile(path4.resolve(outputDir, "routers", `${model}.router.ts`), void 0, {
|
|
11685
|
+
const modelRouter = project.createSourceFile(path4.resolve(outputDir, "routers", `${lowerCaseFirst(model)}.router.ts`), void 0, {
|
|
11685
11686
|
overwrite: true
|
|
11686
11687
|
});
|
|
11687
11688
|
generateCreateRouterImport({
|