Fixing some bugs and changing subscribe behaviour

This commit is contained in:
Fabian 2019-10-01 18:24:26 +02:00
parent 405e589328
commit 518d46f410
4 changed files with 15 additions and 4 deletions

4
.env Normal file
View File

@ -0,0 +1,4 @@
PORT = 5000
ADMIN_KEY = test
ACCESS_LOG = true
DEV = true

View File

@ -1,5 +1,7 @@
import Logging from "@hibas123/nodelogging";
import * as dotenv from "dotenv";
dotenv.config()
interface IConfig {
port: number;
@ -15,6 +17,4 @@ const config: IConfig = {
dev: (process.env.DEV || "").toLowerCase() === "true"
}
dotenv.config()
export default config;

View File

@ -4,6 +4,7 @@ import { DatabaseManager } from "./database/database";
import Logging from "@hibas123/logging";
import Query from "./database/query";
import Session from "./database/session";
import shortid = require("shortid");
type QueryTypes = "get" | "set" | "push" | "subscribe" | "unsubscribe";
@ -16,6 +17,7 @@ export class ConnectionManager {
}
private static onConnection(socket: io.Socket) {
Logging.debug("New Connection:", socket.id);
const reqMap = new Map<string, [number, number]>();
const stored = new Map<string, Query>();
const session = new Session();
@ -62,14 +64,19 @@ export class ConnectionManager {
case "subscribe":
if (!perms.read)
throw noperm;
let subscriptionID = shortid.generate();
query.subscribe(data, (data) => {
answer(id, data);
socket.emit("event", subscriptionID, data);
});
stored.set(id, query);
answer(id, subscriptionID);
return;
case "unsubscribe":
query.unsubscribe();
stored.delete(id);
answer(id, true);
return;
}

View File

@ -230,7 +230,7 @@ export default class Query {
if (type === change.type) {
Logging.debug("Path", this.path, change.path);
if (this.path.length === change.path.length - (type === ChangeTypes.PUSH ? 1 : 0)) {
if (this.path.length <= change.path.length - (type === ChangeTypes.PUSH ? 1 : 0)) {
let valid = true;
for (let i = 0; i < this.path.length; i++) {
if (this.path[i] !== change.path[i]) {