@@ -22,72 +22,72 @@ class User {
2222}
2323
2424describe ( 'IndexedDB Indexing' , ( ) => {
25- let db : Database ;
25+ let db : any ;
2626
2727 beforeAll ( async ( ) => {
2828 db = await Database . build ( 'IndexingTestDB' , [ User ] ) ;
2929 } ) ;
3030
3131 beforeEach ( async ( ) => {
3232 // Clear existing data
33- const users = await db . list ( User ) ;
33+ const users = await db . User . list ( ) ;
3434 for ( const user of users ) {
35- await db . delete ( User , user . id ) ;
35+ await db . User . delete ( user . id ) ;
3636 }
3737
3838 // Add test data
39- await db . create ( User , new User ( 'u1' , 'alice@example.com' , 30 , 'Alice' ) ) ;
40- await db . create ( User , new User ( 'u2' , 'bob@example.com' , 25 , 'Bob' ) ) ;
41- await db . create ( User , new User ( 'u3' , 'charlie@example.com' , 30 , 'Charlie' ) ) ;
42- await db . create ( User , new User ( 'u4' , 'alice@work.com' , 28 , 'Alice Smith' ) ) ;
39+ await db . User . create ( new User ( 'u1' , 'alice@example.com' , 30 , 'Alice' ) ) ;
40+ await db . User . create ( new User ( 'u2' , 'bob@example.com' , 25 , 'Bob' ) ) ;
41+ await db . User . create ( new User ( 'u3' , 'charlie@example.com' , 30 , 'Charlie' ) ) ;
42+ await db . User . create ( new User ( 'u4' , 'alice@work.com' , 28 , 'Alice Smith' ) ) ;
4343 } ) ;
4444
4545 it ( 'should find users by email index' , async ( ) => {
46- const users = await db . findByIndex ( User , 'email' , 'alice@example.com' ) ;
46+ const users = await db . User . findByIndex ( 'email' , 'alice@example.com' ) ;
4747 expect ( users . length ) . toBe ( 1 ) ;
4848 expect ( users [ 0 ] . name ) . toBe ( 'Alice' ) ;
4949 expect ( users [ 0 ] . email ) . toBe ( 'alice@example.com' ) ;
5050 } ) ;
5151
5252 it ( 'should find multiple users by age index' , async ( ) => {
53- const users = await db . findByIndex ( User , 'age' , 30 ) ;
53+ const users = await db . User . findByIndex ( 'age' , 30 ) ;
5454 expect ( users . length ) . toBe ( 2 ) ;
55- const names = users . map ( u => u . name ) . sort ( ) ;
55+ const names = users . map ( ( u : User ) => u . name ) . sort ( ) ;
5656 expect ( names ) . toEqual ( [ 'Alice' , 'Charlie' ] ) ;
5757 } ) ;
5858
5959 it ( 'should find single user by email index' , async ( ) => {
60- const user = await db . findOneByIndex ( User , 'email' , 'bob@example.com' ) ;
60+ const user = await db . User . findOneByIndex ( 'email' , 'bob@example.com' ) ;
6161 expect ( user ) . toBeDefined ( ) ;
6262 expect ( user ! . name ) . toBe ( 'Bob' ) ;
6363 expect ( user ! . age ) . toBe ( 25 ) ;
6464 } ) ;
6565
6666 it ( 'should return undefined when no user found by index' , async ( ) => {
67- const user = await db . findOneByIndex ( User , 'email' , 'nonexistent@example.com' ) ;
67+ const user = await db . User . findOneByIndex ( 'email' , 'nonexistent@example.com' ) ;
6868 expect ( user ) . toBeUndefined ( ) ;
6969 } ) ;
7070
7171 it ( 'should return empty array when no users found by index' , async ( ) => {
72- const users = await db . findByIndex ( User , 'age' , 99 ) ;
72+ const users = await db . User . findByIndex ( 'age' , 99 ) ;
7373 expect ( users ) . toEqual ( [ ] ) ;
7474 } ) ;
7575
7676 it ( 'should throw error when querying non-existent index' , async ( ) => {
77- await expect ( db . findByIndex ( User , 'nonexistent' , 'value' ) ) . rejects . toThrow (
77+ await expect ( db . User . findByIndex ( 'nonexistent' , 'value' ) ) . rejects . toThrow (
7878 "Index 'nonexistent' does not exist on User"
7979 ) ;
8080 } ) ;
8181
8282 it ( 'should throw error when querying non-existent index with findOneByIndex' , async ( ) => {
83- await expect ( db . findOneByIndex ( User , 'nonexistent' , 'value' ) ) . rejects . toThrow (
83+ await expect ( db . User . findOneByIndex ( 'nonexistent' , 'value' ) ) . rejects . toThrow (
8484 "Index 'nonexistent' does not exist on User"
8585 ) ;
8686 } ) ;
8787
8888 it ( 'should work with non-indexed fields not being queryable by index' , async ( ) => {
8989 // name field is not indexed, so this should throw an error
90- await expect ( db . findByIndex ( User , 'name' , 'Alice' ) ) . rejects . toThrow (
90+ await expect ( db . User . findByIndex ( 'name' , 'Alice' ) ) . rejects . toThrow (
9191 "Index 'name' does not exist on User"
9292 ) ;
9393 } ) ;
0 commit comments