@@ -55,6 +55,7 @@ export type TsSchemaGeneratorOptions = {
5555 outDir : string ;
5656 lite ?: boolean ;
5757 liteOnly ?: boolean ;
58+ importWithFileExtension ?: string ;
5859} ;
5960
6061export class TsSchemaGenerator {
@@ -117,6 +118,7 @@ export class TsSchemaGenerator {
117118 const schemaObject = this . createSchemaObject ( model , lite ) ;
118119
119120 // Now generate the import declaration with the correct imports
121+ // import { type SchemaDef, type OperandExpression, ExpressionUtils } from '@zenstackhq/orm/schema';
120122 const runtimeImportDecl = ts . factory . createImportDeclaration (
121123 undefined ,
122124 ts . factory . createImportClause (
@@ -1290,7 +1292,15 @@ export class TsSchemaGenerator {
12901292 const statements : ts . Statement [ ] = [ ] ;
12911293
12921294 // generate: import { schema as $schema, type SchemaType as $Schema } from './schema';
1293- statements . push ( this . generateSchemaImport ( model , true , true , ! ! ( options . lite || options . liteOnly ) ) ) ;
1295+ statements . push (
1296+ this . generateSchemaImport (
1297+ model ,
1298+ true ,
1299+ true ,
1300+ ! ! ( options . lite || options . liteOnly ) ,
1301+ options . importWithFileExtension ,
1302+ ) ,
1303+ ) ;
12941304
12951305 // generate: import type { ModelResult as $ModelResult } from '@zenstackhq/orm';
12961306 statements . push (
@@ -1416,7 +1426,13 @@ export class TsSchemaGenerator {
14161426 fs . writeFileSync ( outputFile , result ) ;
14171427 }
14181428
1419- private generateSchemaImport ( model : Model , schemaObject : boolean , schemaType : boolean , useLite : boolean ) {
1429+ private generateSchemaImport (
1430+ model : Model ,
1431+ schemaObject : boolean ,
1432+ schemaType : boolean ,
1433+ useLite : boolean ,
1434+ importWithFileExtension : string | undefined ,
1435+ ) {
14201436 const importSpecifiers = [ ] ;
14211437
14221438 if ( schemaObject ) {
@@ -1442,10 +1458,18 @@ export class TsSchemaGenerator {
14421458 ) ;
14431459 }
14441460
1461+ let importFrom = useLite ? './schema-lite' : './schema' ;
1462+ if ( importWithFileExtension ) {
1463+ importFrom += importWithFileExtension . startsWith ( '.' )
1464+ ? importWithFileExtension
1465+ : `.${ importWithFileExtension } ` ;
1466+ }
1467+
1468+ // import { schema as $schema, type SchemaType as $Schema } from './schema';
14451469 return ts . factory . createImportDeclaration (
14461470 undefined ,
14471471 ts . factory . createImportClause ( false , undefined , ts . factory . createNamedImports ( importSpecifiers ) ) ,
1448- ts . factory . createStringLiteral ( useLite ? './schema-lite' : './schema' ) ,
1472+ ts . factory . createStringLiteral ( importFrom ) ,
14491473 ) ;
14501474 }
14511475
@@ -1466,7 +1490,15 @@ export class TsSchemaGenerator {
14661490 const statements : ts . Statement [ ] = [ ] ;
14671491
14681492 // generate: import { SchemaType as $Schema } from './schema';
1469- statements . push ( this . generateSchemaImport ( model , false , true , ! ! ( options . lite || options . liteOnly ) ) ) ;
1493+ statements . push (
1494+ this . generateSchemaImport (
1495+ model ,
1496+ false ,
1497+ true ,
1498+ ! ! ( options . lite || options . liteOnly ) ,
1499+ options . importWithFileExtension ,
1500+ ) ,
1501+ ) ;
14701502
14711503 // generate: import { CreateArgs as $CreateArgs, ... } from '@zenstackhq/orm';
14721504 const inputTypes = [
0 commit comments