11import { Savegame } from "core/model/Savegame" ;
22
3- /**
4- * Utility type that converts object keys to their literal types,
5- * excluding string and number index signatures.
6- */
7- type LiteralKeysOnly < T > = {
8- [ K in keyof T ] : string extends K ? never : number extends K ? never : K ;
3+ type KeysAsValues < Type > = {
4+ [ Key in keyof Type ] : string extends Key ? never : number extends Key ? never : Key ;
95} ;
106
11- /**
12- * Extracts all value types from an object type.
13- */
14- type ValueTypes < T > = T [ keyof T ] ;
7+ type ValuesOf < Type > = Type extends { [ Key in keyof Type ] : infer Value } ? Value : never ;
8+ type KeysOf < Type > = ValuesOf < KeysAsValues < Type > > extends keyof Type ? ValuesOf < KeysAsValues < Type > > : never ;
159
16- /**
17- * Extracts literal keys from a type.
18- */
19- type LiteralKeys < T > = ValueTypes < LiteralKeysOnly < T > > ;
20-
21- /**
22- * Represents the composite key structure for a database store.
23- */
24- interface StoreKey {
10+ interface DatabaseKeys {
2511 [ name : string ] : IDBValidKey ;
2612}
2713
28- /**
29- * Defines the structure of a database store.
30- */
31- interface StoreDefinition {
32- key : StoreKey ;
14+ interface DatabaseStore {
15+ key : DatabaseKeys ;
3316 type : unknown ;
3417}
3518
36- /**
37- * Base schema interface for IndexedDB databases.
38- */
3919interface DatabaseSchema {
40- [ storeName : string ] : StoreDefinition ;
20+ [ store : string ] : DatabaseStore ;
4121}
4222
43- /**
44- * Application-specific database schema.
45- */
4623export interface LocalDatabaseSchema extends DatabaseSchema {
4724 savegames : {
4825 key : {
@@ -52,7 +29,6 @@ export interface LocalDatabaseSchema extends DatabaseSchema {
5229 } ;
5330}
5431
55- // Type helpers for working with stores
56- export type StoreNames = LiteralKeys < LocalDatabaseSchema > ;
32+ export type StoreNames = KeysOf < LocalDatabaseSchema > ;
5733export type StoreType < Name extends StoreNames > = LocalDatabaseSchema [ Name ] [ "type" ] ;
58- export type StoreProperties < Name extends StoreNames > = LiteralKeys < StoreType < Name > > ;
34+ export type StoreProperties < Name extends StoreNames > = KeysOf < StoreType < Name > > ;
0 commit comments