Skip to content

Commit c049bb3

Browse files
committed
fix build
1 parent 898cc81 commit c049bb3

File tree

3 files changed

+25
-13
lines changed

3 files changed

+25
-13
lines changed

packages/plugins/openapi/src/rpc-generator.ts

Lines changed: 21 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,16 @@
11
// Inspired by: https://github.com/omar-dulaimi/prisma-trpc-generator
22

33
import { PluginError, PluginOptions, analyzePolicies, requireOption, resolvePath } from '@zenstackhq/sdk';
4-
import { DataModel, Model, TypeDef, TypeDefField, TypeDefFieldType, isDataModel, isEnum, isTypeDef } from '@zenstackhq/sdk/ast';
4+
import {
5+
DataModel,
6+
Model,
7+
TypeDef,
8+
TypeDefField,
9+
TypeDefFieldType,
10+
isDataModel,
11+
isEnum,
12+
isTypeDef,
13+
} from '@zenstackhq/sdk/ast';
514
import {
615
AggregateOperationSupport,
716
addMissingInputObjectTypesForAggregate,
@@ -48,7 +57,7 @@ export class RPCOpenAPIGenerator extends OpenAPIGeneratorBase {
4857
output = resolvePath(output, this.options);
4958

5059
// input types
51-
this.inputObjectTypes.push(...this.dmmf.schema.inputObjectTypes.prisma);
60+
this.inputObjectTypes.push(...(this.dmmf.schema.inputObjectTypes.prisma ?? []));
5261
this.outputObjectTypes.push(...this.dmmf.schema.outputObjectTypes.prisma);
5362

5463
// add input object types that are missing from Prisma dmmf
@@ -649,13 +658,13 @@ export class RPCOpenAPIGenerator extends OpenAPIGeneratorBase {
649658
for (const _enum of [...(this.dmmf.schema.enumTypes.model ?? []), ...this.dmmf.schema.enumTypes.prisma]) {
650659
schemas[upperCaseFirst(_enum.name)] = this.generateEnumComponent(_enum);
651660
}
652-
661+
653662
// Also add enums from AST that might not be in DMMF (e.g., only used in TypeDefs)
654663
for (const enumDecl of this.model.declarations.filter(isEnum)) {
655664
if (!schemas[upperCaseFirst(enumDecl.name)]) {
656665
schemas[upperCaseFirst(enumDecl.name)] = {
657666
type: 'string',
658-
enum: enumDecl.fields.map(f => f.name)
667+
enum: enumDecl.fields.map((f) => f.name),
659668
};
660669
}
661670
}
@@ -765,12 +774,15 @@ export class RPCOpenAPIGenerator extends OpenAPIGeneratorBase {
765774
return result;
766775
}
767776

768-
private generateField(def: { kind: DMMF.FieldKind; type: string; isList: boolean; isRequired: boolean; name?: string }, modelName?: string) {
777+
private generateField(
778+
def: { kind: DMMF.FieldKind; type: string; isList: boolean; isRequired: boolean; name?: string },
779+
modelName?: string
780+
) {
769781
// For Json fields, check if there's a corresponding TypeDef in the original model
770782
if (def.kind === 'scalar' && def.type === 'Json' && modelName && def.name) {
771-
const dataModel = this.model.declarations.find(d => isDataModel(d) && d.name === modelName) as DataModel;
783+
const dataModel = this.model.declarations.find((d) => isDataModel(d) && d.name === modelName) as DataModel;
772784
if (dataModel) {
773-
const field = dataModel.fields.find(f => f.name === def.name);
785+
const field = dataModel.fields.find((f) => f.name === def.name);
774786
if (field?.type.reference?.ref && isTypeDef(field.type.reference.ref)) {
775787
// This Json field references a TypeDef
776788
return this.wrapArray(
@@ -876,7 +888,7 @@ export class RPCOpenAPIGenerator extends OpenAPIGeneratorBase {
876888
if (type.reference?.ref) {
877889
return this.ref(type.reference.ref.name, true);
878890
}
879-
891+
880892
// For scalar types, reuse the existing mapping logic
881893
// Note: Json type is handled as empty schema for consistency
882894
return match(type.type)
@@ -913,7 +925,7 @@ export class RPCOpenAPIGenerator extends OpenAPIGeneratorBase {
913925
.with(P.union('JSON', 'Json'), () => {
914926
// For Json fields, check if there's a specific TypeDef reference
915927
// Otherwise, return empty schema for arbitrary JSON
916-
const isTypeDefType = this.model.declarations.some(d => isTypeDef(d) && d.name === type);
928+
const isTypeDefType = this.model.declarations.some((d) => isTypeDef(d) && d.name === type);
917929
return isTypeDefType ? this.ref(type, false) : {};
918930
})
919931
.otherwise((type) => this.ref(type.toString(), false));

packages/schema/src/plugins/enhancer/enhance/index.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -479,7 +479,7 @@ export type Enhanced<Client> =
479479
// they may be incorrectly represented as required, we need to fix that for input types
480480
// also, if a FK field is of such case, its corresponding relation field should be optional
481481
const createInputPattern = new RegExp(`^(.+?)(Unchecked)?Create.*Input$`);
482-
for (const inputType of dmmf.schema.inputObjectTypes.prisma) {
482+
for (const inputType of dmmf.schema.inputObjectTypes.prisma ?? []) {
483483
const match = inputType.name.match(createInputPattern);
484484
const modelName = this.resolveName(match?.[1]);
485485
if (modelName) {
@@ -570,8 +570,8 @@ export type Enhanced<Client> =
570570
const project = new Project();
571571

572572
// remove delegate_aux_* fields from the prismaNamespace.ts
573-
const internalFilename = `${prismaClientDir}/internal/prismaNamespace.ts`
574-
const internalFilenameFixed = `${prismaClientDir}/internal/prismaNamespace-fixed.ts`
573+
const internalFilename = `${prismaClientDir}/internal/prismaNamespace.ts`;
574+
const internalFilenameFixed = `${prismaClientDir}/internal/prismaNamespace-fixed.ts`;
575575
const internalSf = project.addSourceFileAtPath(internalFilename);
576576
const syntaxList = internalSf.getChildren()[0];
577577
if (!Node.isSyntaxList(syntaxList)) {

packages/schema/src/plugins/zod/generator.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ export class ZodSchemaGenerator {
8989
(o) => !excludeModels.find((e) => e === o.model)
9090
);
9191

92-
const inputObjectTypes = prismaClientDmmf.schema.inputObjectTypes.prisma.filter(
92+
const inputObjectTypes = (prismaClientDmmf.schema.inputObjectTypes.prisma ?? []).filter(
9393
(type) =>
9494
!excludeModels.some((e) => type.name.toLowerCase().startsWith(e.toLocaleLowerCase())) &&
9595
// exclude delegate aux related types

0 commit comments

Comments
 (0)