1- import { existsSync } from "@std/fs" ;
21import { eTag } from "@std/http/etag" ;
32import type { Column , Constraint , Index , Relation , Schema } from "./types.ts" ;
43import DB from "./db.ts" ;
@@ -58,17 +57,19 @@ export class DDL {
5857 */
5958 static generator : ( classFiles : Record < string , string > , base ?: string , extensions ?: string [ ] ) => Promise < Record < string , Schema > > ;
6059
61- static async ensureSchemas ( schemasFile : string , classFiles : Record < string , string > , base ?: string , enhance = false ) : Promise < Record < string , Schema > > {
62- const sfn = base + schemasFile ;
63-
64- // Try reading schemas from file
65- let schemas = existsSync ( schemasFile ) ? ( await import ( sfn ) ) . default : undefined ;
66- const outdated = ! schemas ? true : await DDL . #outdatedSchemas( schemas , base ) ;
60+ static async ensureSchemas (
61+ schemas : Record < string , Schema > ,
62+ classFiles : Record < string , string > ,
63+ base ?: string ,
64+ enhance = false ,
65+ schemasFile ?: string ,
66+ ) : Promise < Record < string , Schema > > {
67+ const outdated = ! schemas ? true : await DDL . outdatedSchemas ( schemas , base ) ;
6768 if ( ! outdated ) return schemas ;
6869
6970 // Generate and save
7071 schemas = await DDL . generateSchemas ( classFiles , base , enhance ) ;
71- await Deno . writeTextFile ( sfn , JSON . stringify ( schemas , null , 2 ) ) ;
72+ if ( schemasFile ) await Deno . writeTextFile ( schemasFile , JSON . stringify ( schemas , null , 2 ) ) ;
7273 return schemas ;
7374 }
7475
@@ -116,9 +117,9 @@ export class DDL {
116117 return schema ;
117118 }
118119
119- static async # outdatedSchemas( schemas : Record < string , Schema > | Schema [ ] , base = "" ) {
120+ static async outdatedSchemas ( schemas : Record < string , Schema > | Schema [ ] , base = "" ) : Promise < boolean > {
120121 for ( const schema of Array . isArray ( schemas ) ? schemas : Object . values ( schemas ) ) {
121- const outdated = await DDL . # outdatedSchema( schema , base ) ;
122+ const outdated = await DDL . outdatedSchema ( schema , base ) ;
122123 if ( outdated ) return true ;
123124 }
124125 return false ;
@@ -130,7 +131,7 @@ export class DDL {
130131 * @param schema - the schema to check
131132 * @param base - the directory where the schema file is located
132133 */
133- static async # outdatedSchema( schema : Schema , base = "" ) {
134+ static async outdatedSchema ( schema : Schema , base = "" ) : Promise < boolean > {
134135 if ( ! schema . $id ) throw new Error ( "Schema must have an '$id' property to test if it is outdated" ) ;
135136
136137 // Get file and schema create date from $id
0 commit comments