zenstack
Version:
FullStack enhancement for Prisma ORM: seamless integration from database to UI
76 lines (75 loc) • 3.51 kB
TypeScript
import { type PluginOptions } from '@zenstackhq/sdk';
import { DataModel, DataModelField, type Model } from '@zenstackhq/sdk/ast';
import { type DMMF as PrismaDMMF } from '@zenstackhq/sdk/prisma';
import type { SourceFile } from 'ts-morph';
import { AggregateOperationSupport, TransformerParams } from './types';
export default class Transformer {
name: string;
originalName: string;
fields: readonly PrismaDMMF.SchemaArg[];
schemaImports: Set<string>;
models: readonly PrismaDMMF.Model[];
modelOperations: PrismaDMMF.ModelMapping[];
aggregateOperationSupport: AggregateOperationSupport;
enumTypes: readonly PrismaDMMF.SchemaEnum[];
static enumNames: string[];
static rawOpsMap: {
[name: string]: string;
};
private static outputPath;
private hasJson;
private hasDecimal;
private project;
private inputObjectTypes;
sourceFiles: SourceFile[];
private zmodel;
private mode;
constructor(params: TransformerParams);
static setOutputPath(outPath: string): void;
static getOutputPath(): string;
generateEnumSchemas(): Promise<void>;
generateImportZodStatement(): string;
generateExportSchemaStatement(name: string, schema: string): string;
generateObjectSchema(generateUnchecked: boolean, options: PluginOptions): string;
private createUpdateInputRegex;
generateObjectSchemaFields(generateUnchecked: boolean): {
schemaFields: string[];
extraImports: string[];
};
generateObjectSchemaField(field: PrismaDMMF.SchemaArg, contextDataModel: DataModel | undefined, generateUnchecked: boolean, replaceJsonWithTypeDef?: boolean): [string, PrismaDMMF.SchemaArg, boolean][];
private mapDelegateInputType;
wrapWithZodValidators(mainValidators: string | string[], field: PrismaDMMF.SchemaArg, inputType: PrismaDMMF.InputTypeRef): string;
addSchemaImport(name: string): void;
generatePrismaStringLine(field: PrismaDMMF.SchemaArg, inputType: PrismaDMMF.InputTypeRef, inputsLength: number, contextField: DataModelField | undefined): string;
private isFieldOptional;
generateFieldValidators(zodStringWithMainType: string, field: PrismaDMMF.SchemaArg): string;
prepareObjectSchema(zodObjectSchemaFields: string[], options: PluginOptions): string;
generateExportObjectSchemaStatement(schema: string): string;
generateImportPrismaStatement(options: PluginOptions): string;
generateJsonSchemaImplementation(): string;
generateObjectSchemaImportStatements(): string;
generateSchemaImports(): string;
private generateCommonImport;
checkIsModelQueryType(type: string): {
isModelQueryType: boolean;
modelName: string;
queryName: string;
} | {
isModelQueryType: boolean;
modelName?: undefined;
queryName?: undefined;
};
resolveModelQuerySchemaName(modelName: string, queryName: string): string;
wrapWithZodObject(zodStringFields: string | string[], mode?: string): string;
wrapWithSmartUnion(...schemas: string[]): string;
generateInputSchemas(options: PluginOptions, zmodel: Model): Promise<void>;
generateImportStatements(imports: (string | undefined)[]): string;
resolveSelectIncludeImportAndZodSchemaLine(model: PrismaDMMF.Model): {
selectImport: string;
includeImport: string;
selectZodSchemaLine: string;
includeZodSchemaLine: string;
selectZodSchemaLineLazy: string;
includeZodSchemaLineLazy: string;
};
}