File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -22,4 +22,20 @@ describe("DatabaseClient", () => {
2222 } as unknown as ( typeof client . create . arguments ) [ 1 ] )
2323 ) . rejects . toThrow ( "'is_schema' and 'schema' cannot both be provided" ) ;
2424 } ) ;
25+
26+ it ( 'throws error if seed type is "database" and name is missing' , async ( ) => {
27+ const options = { seed : { type : "database" } } ;
28+ // @ts -expect-error
29+ await expect ( client . create ( "testDB" , options ) ) . rejects . toThrow (
30+ "Seed name is required when type is 'database'"
31+ ) ;
32+ } ) ;
33+
34+ it ( 'throws error if seed type is "dump" and url is missing' , async ( ) => {
35+ const options = { seed : { type : "dump" } } ;
36+ // @ts -expect-error
37+ await expect ( client . create ( "testDB" , options ) ) . rejects . toThrow (
38+ "Seed URL is required when type is 'dump'"
39+ ) ;
40+ } ) ;
2541} ) ;
Original file line number Diff line number Diff line change @@ -72,7 +72,20 @@ export interface DatabaseInstance {
7272
7373type MultiDBSchemaOptions =
7474 | { is_schema : boolean ; schema ?: never }
75- | { is_schema ?: never ; schema : string } ;
75+ | { is_schema ?: never ; schema : string }
76+ | { } ;
77+
78+ function hasIsSchemaOption (
79+ options : any
80+ ) : options is { is_schema : boolean ; schema ?: never } {
81+ return options !== undefined && options . is_schema !== undefined ;
82+ }
83+
84+ function hasSchemaOption (
85+ options : any
86+ ) : options is { is_schema ?: never ; schema : string } {
87+ return options !== undefined && options . schema !== undefined ;
88+ }
7689
7790export class DatabaseClient {
7891 constructor ( private config : TursoConfig ) { }
@@ -106,7 +119,7 @@ export class DatabaseClient {
106119 } ;
107120 } & MultiDBSchemaOptions
108121 ) : Promise < DatabaseCreateResponse > {
109- if ( options ?. is_schema !== undefined && options ?. schema !== undefined ) {
122+ if ( hasIsSchemaOption ( options ) && hasSchemaOption ( options ) ) {
110123 throw new Error ( "'is_schema' and 'schema' cannot both be provided" ) ;
111124 }
112125
You can’t perform that action at this time.
0 commit comments