11import type {
2+ Config ,
23 TransformedSchema ,
34 ZeroModel ,
45 ZeroRelationship ,
56 ZeroRelationshipLink ,
67 ZeroTypeMapping ,
78} from '../types' ;
89
9- function generateImports ( schema : TransformedSchema ) : string {
10+ function generateImports ( schema : TransformedSchema , config : Config ) : string {
1011 const usedImports = new Set < string > ( ) ;
1112
1213 // These are always used
1314 usedImports . add ( 'table' ) ;
1415 usedImports . add ( 'createSchema' ) ;
15- usedImports . add ( 'createBuilder' ) ;
16+
17+ // Only add createBuilder if not skipped
18+ if ( ! config . skipBuilder ) {
19+ usedImports . add ( 'createBuilder' ) ;
20+ }
1621
1722 // Check which type functions are used in the schema
1823 schema . models . forEach ( model => {
@@ -150,7 +155,7 @@ ${relationshipsStr}
150155 return filteredRelationships . length > 0 ? filteredRelationships . join ( '' ) : '' ;
151156}
152157
153- function generateSchema ( schema : TransformedSchema ) : string {
158+ function generateSchema ( schema : TransformedSchema , config : Config ) : string {
154159 let output = '/**\n' ;
155160 output += ' * The Zero schema object.\n' ;
156161 output +=
@@ -178,6 +183,15 @@ function generateSchema(schema: TransformedSchema): string {
178183 output += ' ],\n' ;
179184 }
180185
186+ // Add legacy options if enabled
187+ if ( config . enableLegacyMutators ) {
188+ output += ' enableLegacyMutators: true,\n' ;
189+ }
190+
191+ if ( config . enableLegacyQueries ) {
192+ output += ' enableLegacyQueries: true,\n' ;
193+ }
194+
181195 output += '});\n\n' ;
182196
183197 // Add types
@@ -188,36 +202,45 @@ function generateSchema(schema: TransformedSchema): string {
188202 output += ' */\n' ;
189203 output += 'export type Schema = typeof schema;\n' ;
190204
191- output += '/**\n' ;
192- output += ' * Represents the ZQL query builder.\n' ;
193- output +=
194- ' * This type is auto-generated from your Prisma schema definition.\n' ;
195- output += ' */\n' ;
196- output += 'export const zql = createBuilder(schema);\n' ;
197-
198- output += '/**\n' ;
199- output += ' * Represents the Zero schema query builder.\n' ;
200- output +=
201- ' * This type is auto-generated from your Prisma schema definition.\n' ;
202- output += ' *\n' ;
203- output += ' * @deprecated Use `zql` instead.\n' ;
204- output += ' */\n' ;
205- output += 'export const builder = zql;\n' ;
205+ // Only generate builder if not skipped
206+ if ( ! config . skipBuilder ) {
207+ output += '/**\n' ;
208+ output += ' * Represents the ZQL query builder.\n' ;
209+ output +=
210+ ' * This type is auto-generated from your Prisma schema definition.\n' ;
211+ output += ' */\n' ;
212+ output += 'export const zql = createBuilder(schema);\n' ;
213+
214+ output += '/**\n' ;
215+ output += ' * Represents the Zero schema query builder.\n' ;
216+ output +=
217+ ' * This type is auto-generated from your Prisma schema definition.\n' ;
218+ output += ' *\n' ;
219+ output += ' * @deprecated Use `zql` instead.\n' ;
220+ output += ' */\n' ;
221+ output += 'export const builder = zql;\n' ;
222+ }
206223
207- output += '/** Defines the default types for Zero */\n' ;
208- output += 'declare module "@rocicorp/zero" {\n' ;
209- output += ' interface DefaultTypes {\n' ;
210- output += ' schema: Schema;\n' ;
211- output += ' }\n' ;
212- output += '}\n' ;
224+ // Only generate declare module if not skipped
225+ if ( ! config . skipDeclare ) {
226+ output += '/** Defines the default types for Zero */\n' ;
227+ output += 'declare module "@rocicorp/zero" {\n' ;
228+ output += ' interface DefaultTypes {\n' ;
229+ output += ' schema: Schema;\n' ;
230+ output += ' }\n' ;
231+ output += '}\n' ;
232+ }
213233
214234 return output ;
215235}
216236
217- export function generateCode ( schema : TransformedSchema ) : string {
237+ export function generateCode (
238+ schema : TransformedSchema ,
239+ config : Config ,
240+ ) : string {
218241 let output = `${ HEADER_PREFIX } \n\n` ;
219242
220- output += generateImports ( schema ) ;
243+ output += generateImports ( schema , config ) ;
221244
222245 output += generateUnionTypes ( schema ) ;
223246
@@ -227,7 +250,7 @@ export function generateCode(schema: TransformedSchema): string {
227250
228251 output += generateRelationships ( schema . models ) ;
229252
230- output += generateSchema ( schema ) ;
253+ output += generateSchema ( schema , config ) ;
231254
232255 return output ;
233256}
0 commit comments