@@ -14,6 +14,7 @@ console = hub("*", "debug", { fileLine: true });
1414
1515const CI = Deno . env . has ( "CI" ) ;
1616const DB = await dbInit ( getProvider ( ) ) ;
17+ const BASE = import . meta. dirname + "/../" ;
1718
1819// Generator function is declared here so that it does not go into the published module
1920DDL . generator = async function ( classFiles : Record < string , string > , base ?: string ) {
@@ -28,8 +29,7 @@ DDL.generator = async function (classFiles: Record<string, string>, base?: strin
2829import staticSchema from "../resources/account.json" with { type : "json" } ;
2930
3031// Generate dynamic schema to make sure it's the same result
31- // const classFiles = { "Account": "resources/account.ts", "Point": "resources/point.ts" };
32- const classFiles = { "Account" : "resources/account.ts" } ;
32+ const classFiles : Record < string , string > = { "Account" : "resources/account.ts" , "Point" : "resources/point.ts" } ;
3333
3434// Track bug https://github.com/denoland/deno/issues/28206
3535// const { Account: dynamicSchema } = await DDL.generateSchemas(classFiles, import.meta.dirname! + "/../", true);
@@ -175,13 +175,41 @@ Deno.test("Schema Generation", async function () {
175175 await delay ( 1000 - ( new Date ( ) ) . getMilliseconds ( ) ) ;
176176
177177 // Generate two schemas in a row, they should be identical
178- const first = await DDL . generateSchemas ( classFiles , import . meta . dirname ! + "/../" , true ) ;
178+ const first = await DDL . generateSchemas ( classFiles , BASE , true ) ;
179179 assertExists ( first ) ;
180- const second = await DDL . generateSchemas ( classFiles , import . meta . dirname ! + "/../" , true ) ;
180+ const second = await DDL . generateSchemas ( classFiles , BASE , true ) ;
181181 assertNotEquals ( first , second ) ;
182182 assertEquals ( JSON . stringify ( first ) , JSON . stringify ( second ) ) ;
183183} ) ;
184184
185+ // Execute the table creation on the provided platform
186+ Deno . test . only ( "Schema Outdated" , async function ( ) {
187+ // Generate schemas and save it
188+ let schemas = await DDL . generateSchemas ( classFiles , BASE , true ) ;
189+ Deno . writeTextFileSync ( "/tmp/schemas.json" , JSON . stringify ( schemas , null , 2 ) ) ;
190+
191+ // Is it outdated from the get-go?
192+ assertEquals ( await DDL . outdatedSchemas ( schemas , BASE ) , [ ] ) ;
193+
194+ // Create other specific classes called Point2D/Point3D and add to schema (with error)
195+ Deno . writeTextFileSync ( "/tmp/point2d.ts" , "export default class Point2D { x = 0; y = 0; }" ) ;
196+ Deno . writeTextFileSync ( "/tmp/point3d.ts" , "export default class Point3D { x = 0; y = 0; }" ) ;
197+ classFiles [ "Point2D" ] = "/tmp/point2d.ts" ;
198+ classFiles [ "Point3D" ] = "/tmp/point3d.ts" ;
199+ Deno . writeTextFileSync ( "/tmp/schemas.json" , JSON . stringify ( await DDL . generateSchemas ( classFiles , BASE , true ) , null , 2 ) ) ;
200+
201+ // Load the schema with a random query string to force a reload
202+ schemas = ( await import ( "/tmp/schemas.json?force=" + Date . now ( ) , { with : { type : "json" } } ) ) . default as Record < string , Schema > ;
203+ // console.log(JSON.stringify(schemas, null, 2));
204+
205+ // They should not be outdated
206+ assertEquals ( await DDL . outdatedSchemas ( schemas , BASE ) , [ ] ) ;
207+
208+ // Now correct initial mistake and check again
209+ Deno . writeTextFileSync ( "/tmp/point3d.ts" , "export default class Point3D { x = 0; y = 0; z = 0; }" ) ;
210+ assertEquals ( await DDL . outdatedSchemas ( schemas , BASE ) , [ "Point3D" ] ) ;
211+ } ) ;
212+
185213// Execute the table creation on the provided platform
186214Deno . test ( "Disconnect" , { sanitizeResources : false , sanitizeOps : false } , async function ( ) {
187215 await DB . disconnect ( ) ;
0 commit comments