Fixing several bugs and adding very basic rule support

This commit is contained in:
Fabian
2019-09-19 16:24:35 +02:00
parent 429ba7e291
commit a7f7edcd0b
8 changed files with 163 additions and 73 deletions

View File

@ -3,6 +3,8 @@ import Settings from "../settings";
import getLevelDB from "../storage";
import PathLock from "./lock";
import Query from "./query";
import { Observable } from "@hibas123/utils";
import Logging from "@hibas123/logging";
export class DatabaseManager {
static databases = new Map<string, Database>();
@ -16,10 +18,11 @@ export class DatabaseManager {
})
}
static addDatabase(name: string) {
static async addDatabase(name: string) {
if (this.databases.has(name))
throw new Error("Database already exists!");
await Settings.addDatabase(name);
let database = new Database(name);
this.databases.set(name, database);
return database;
@ -39,11 +42,23 @@ export class DatabaseManager {
}
}
export enum ChangeTypes {
SET,
PUSH
}
export type Change = {
type: ChangeTypes;
path: string[]
}
export class Database {
public level = getLevelDB(this.name);
private rules: Rules;
public rules: Rules;
public locks = new PathLock()
public changeObservable = new Observable<Change>();
toJSON() {
return {
name: this.name,