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:
Jeremy Letto 2021-11-25 21:12:23 -06:00 committed by GitHub
parent 37879c4255
commit 6ce346af4a
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
54 changed files with 1381 additions and 1291 deletions

View file

@ -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);

View file

@ -16,4 +16,4 @@ export class SetDTO extends Set {
}
};
dexieService.cards.mapToClass(SetDTO);
dexieService.sets.mapToClass(SetDTO);

View 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);

View file

@ -1,4 +1,5 @@
export * from './CardDTO';
export * from './SetDTO';
export * from './SettingDTO';
export * from './TokenDTO';
export * from './HostDTO';

View 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',
});
}

View file

@ -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() {

View file

@ -0,0 +1 @@
export * from './DexieDTOs';

View file

@ -1,2 +1,2 @@
export * from './CardImporterService';
export * from './DexieDTOs';
export * from './dexie';