mirror of
https://github.com/Cockatrice/Cockatrice.git
synced 2026-06-10 00:04:48 -07:00
Webatrice: KnownHosts component (#4456)
* refactor dexie services for future schema updates Co-authored-by: Jeremy Letto <jeremy.letto@datasite.com>
This commit is contained in:
parent
37879c4255
commit
6ce346af4a
54 changed files with 1381 additions and 1291 deletions
|
|
@ -8,11 +8,11 @@ export class HostDTO extends Host {
|
|||
return dexieService.hosts.put(this);
|
||||
}
|
||||
|
||||
static add(host: HostDTO): Promise<IndexableType> {
|
||||
static add(host: Host): Promise<IndexableType> {
|
||||
return dexieService.hosts.add(host);
|
||||
}
|
||||
|
||||
static get(id): Promise<HostDTO> {
|
||||
static get(id: number): Promise<HostDTO> {
|
||||
return dexieService.hosts.where('id').equals(id).first();
|
||||
}
|
||||
|
||||
|
|
@ -23,6 +23,10 @@ export class HostDTO extends Host {
|
|||
static bulkAdd(hosts: Host[]): Promise<IndexableType> {
|
||||
return dexieService.hosts.bulkAdd(hosts);
|
||||
}
|
||||
|
||||
static delete(id: string): Promise<void> {
|
||||
return dexieService.hosts.delete(id);
|
||||
}
|
||||
};
|
||||
|
||||
dexieService.hosts.mapToClass(HostDTO);
|
||||
|
|
@ -16,4 +16,4 @@ export class SetDTO extends Set {
|
|||
}
|
||||
};
|
||||
|
||||
dexieService.cards.mapToClass(SetDTO);
|
||||
dexieService.sets.mapToClass(SetDTO);
|
||||
22
webclient/src/services/dexie/DexieDTOs/SettingDTO.ts
Normal file
22
webclient/src/services/dexie/DexieDTOs/SettingDTO.ts
Normal file
|
|
@ -0,0 +1,22 @@
|
|||
import { Setting } from 'types';
|
||||
|
||||
import { dexieService } from '../DexieService';
|
||||
|
||||
export class SettingDTO extends Setting {
|
||||
constructor(user) {
|
||||
super();
|
||||
|
||||
this.user = user;
|
||||
this.autoConnect = false;
|
||||
}
|
||||
|
||||
save() {
|
||||
return dexieService.settings.put(this);
|
||||
}
|
||||
|
||||
static get(user) {
|
||||
return dexieService.settings.where('user').equalsIgnoreCase(user).first();
|
||||
}
|
||||
};
|
||||
|
||||
dexieService.settings.mapToClass(SettingDTO);
|
||||
|
|
@ -1,4 +1,5 @@
|
|||
export * from './CardDTO';
|
||||
export * from './SetDTO';
|
||||
export * from './SettingDTO';
|
||||
export * from './TokenDTO';
|
||||
export * from './HostDTO';
|
||||
17
webclient/src/services/dexie/DexieSchemas/v1.schema.ts
Normal file
17
webclient/src/services/dexie/DexieSchemas/v1.schema.ts
Normal file
|
|
@ -0,0 +1,17 @@
|
|||
export enum Stores {
|
||||
SETTINGS = 'settings',
|
||||
CARDS = 'cards',
|
||||
SETS = 'sets',
|
||||
TOKENS = 'tokens',
|
||||
HOSTS = 'hosts',
|
||||
}
|
||||
|
||||
export const schemaV1 = (db) => {
|
||||
db.version(1).stores({
|
||||
[Stores.CARDS]: 'name',
|
||||
[Stores.SETS]: 'code',
|
||||
[Stores.SETTINGS]: 'user',
|
||||
[Stores.TOKENS]: 'name.value',
|
||||
[Stores.HOSTS]: '++id',
|
||||
});
|
||||
}
|
||||
|
|
@ -1,24 +1,16 @@
|
|||
import Dexie from 'dexie';
|
||||
|
||||
enum Stores {
|
||||
CARDS = 'cards',
|
||||
SETS = 'sets',
|
||||
TOKENS = 'tokens',
|
||||
HOSTS = 'hosts',
|
||||
}
|
||||
|
||||
const StoreKeyIndexes = {
|
||||
[Stores.CARDS]: 'name',
|
||||
[Stores.SETS]: 'code',
|
||||
[Stores.TOKENS]: 'name.value',
|
||||
[Stores.HOSTS]: '++id,name',
|
||||
};
|
||||
import { Stores, schemaV1 } from './DexieSchemas/v1.schema';
|
||||
|
||||
class DexieService {
|
||||
private db: Dexie = new Dexie('Webatrice');
|
||||
|
||||
constructor() {
|
||||
this.db.version(1).stores(StoreKeyIndexes);
|
||||
schemaV1(this.db);
|
||||
}
|
||||
|
||||
get settings() {
|
||||
return this.db.table(Stores.SETTINGS);
|
||||
}
|
||||
|
||||
get cards() {
|
||||
1
webclient/src/services/dexie/index.ts
Normal file
1
webclient/src/services/dexie/index.ts
Normal file
|
|
@ -0,0 +1 @@
|
|||
export * from './DexieDTOs';
|
||||
|
|
@ -1,2 +1,2 @@
|
|||
export * from './CardImporterService';
|
||||
export * from './DexieDTOs';
|
||||
export * from './dexie';
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue