Skip to content

Commit

Permalink
imports and seperate initiliaze
Browse files Browse the repository at this point in the history
  • Loading branch information
dlgn2 committed May 3, 2024
1 parent 4889193 commit 8ece2e9
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 25 deletions.
3 changes: 1 addition & 2 deletions src/implementations/CrunchDB.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,9 @@ export class CrunchDB implements ICrunchDB {

constructor(@inject(IIndexedDBType) dbService: IIndexedDB) {
this.dbService = dbService;
this.initializeDatabase();
}

private async initializeDatabase(): Promise<void> {
async initializeDatabase(): Promise<void> {
this.dbService
.init()
.map(() => {
Expand Down
12 changes: 6 additions & 6 deletions src/implementations/business/IndexedDB.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { injectable } from 'inversify';
import { ResultAsync } from 'neverthrow';
import { IDBConfig } from '../../objects/business/IDBConfig';
import { VolatileObject } from '../../objects/business/VolatileObject';
import { IIndexedDB } from '../../interfaces/business/IIndexedDB';
import { IDBConfig } from 'crunchDB/objects/business/IDBConfig';
import { VolatileObject } from 'crunchDB/objects/business/SimpleObject';
import { IIndexedDB } from 'crunchDB/interfaces/business/IIndexedDB';

@injectable()
export class IndexedDB implements IIndexedDB {
Expand Down Expand Up @@ -39,7 +39,7 @@ export class IndexedDB implements IIndexedDB {
);
}

addVolatileObject(
addObject(
storeName: string,
VolatileObject: VolatileObject
): ResultAsync<void, Error> {
Expand All @@ -48,14 +48,14 @@ export class IndexedDB implements IIndexedDB {
).map(() => undefined);
}

getVolatileObject(
getObject(
storeName: string,
id: number
): ResultAsync<VolatileObject, Error> {
return this.transaction(storeName, 'readonly', store => store.get(id));
}

getAllVolatileObjects(
getAllObjects(
storeName: string
): ResultAsync<VolatileObject[], Error> {
return ResultAsync.fromPromise(
Expand Down
19 changes: 7 additions & 12 deletions src/interfaces/business/IIndexedDB.ts
Original file line number Diff line number Diff line change
@@ -1,25 +1,20 @@
// IIndexedDB.ts
import { ResultAsync } from 'neverthrow';
import { VolatileObject } from '../../objects/business/VolatileObject';
import { SimpleObject } from '../../objects/business/SimpleObject';

export interface IIndexedDB {
init(): ResultAsync<void, Error>;

addVolatileObject(
addObject(
storeName: string,
VolatileObject: VolatileObject
VolatileObject: SimpleObject
): ResultAsync<void, Error>;

getVolatileObject(
storeName: string,
id: number
): ResultAsync<VolatileObject, Error>;
getObject(storeName: string, id: number): ResultAsync<SimpleObject, Error>;

getAllVolatileObjects(
storeName: string
): ResultAsync<VolatileObject[], Error>;
getAllObjects(storeName: string): ResultAsync<SimpleObject[], Error>;

getAllItems(storeName: string): ResultAsync<VolatileObject[], Error>;
getAllItems(storeName: string): ResultAsync<SimpleObject[], Error>;
}

export const IIndexedDBType = Symbol.for("IIndexedDB");
export const IIndexedDBType = Symbol.for('IIndexedDB');
6 changes: 6 additions & 0 deletions src/objects/business/SimpleObject.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
//@TODO add properties and rename the file to VolatileObject.ts
export interface SimpleObject {
id: number;
name: string;
value: string;
}
5 changes: 0 additions & 5 deletions src/objects/business/VolatileObject.ts

This file was deleted.

0 comments on commit 8ece2e9

Please sign in to comment.