Fixing some bugs and changing subscribe behaviour
This commit is contained in:
parent
405e589328
commit
518d46f410
4
.env
Normal file
4
.env
Normal file
@ -0,0 +1,4 @@
|
||||
PORT = 5000
|
||||
ADMIN_KEY = test
|
||||
ACCESS_LOG = true
|
||||
DEV = true
|
@ -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;
|
@ -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;
|
||||
}
|
||||
|
||||
|
@ -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]) {
|
||||
|
Reference in New Issue
Block a user