Changing sender to session in Query
This commit is contained in:
parent
e42f0d3991
commit
10f3b4fa50
@ -117,7 +117,7 @@ export class ConnectionManager {
|
|||||||
if (!handler)
|
if (!handler)
|
||||||
throw new Error("Invalid Request!");
|
throw new Error("Invalid Request!");
|
||||||
|
|
||||||
let query = db.getQuery(path || [], session.sessionid, isDoc ? "document" : "collection");
|
let query = db.getQuery(path || [], session.id, isDoc ? "document" : "collection");
|
||||||
let res = await handler({
|
let res = await handler({
|
||||||
id,
|
id,
|
||||||
data,
|
data,
|
||||||
@ -156,7 +156,7 @@ export class ConnectionManager {
|
|||||||
})
|
})
|
||||||
|
|
||||||
socket.on("close", () => {
|
socket.on("close", () => {
|
||||||
Logging.log(`${session.sessionid} has disconnected!`);
|
Logging.log(`${session.id} has disconnected!`);
|
||||||
Logging.debug("Clearing stored:", stored);
|
Logging.debug("Clearing stored:", stored);
|
||||||
stored.forEach(query => (query as DocumentQuery | CollectionQuery).unsubscribe());
|
stored.forEach(query => (query as DocumentQuery | CollectionQuery).unsubscribe());
|
||||||
stored.clear();
|
stored.clear();
|
||||||
|
@ -3,6 +3,7 @@ import { resNull } from "../storage";
|
|||||||
import nanoid = require("nanoid/generate");
|
import nanoid = require("nanoid/generate");
|
||||||
import Logging from "@hibas123/nodelogging";
|
import Logging from "@hibas123/nodelogging";
|
||||||
import * as MSGPack from "what-the-pack";
|
import * as MSGPack from "what-the-pack";
|
||||||
|
import Session from "./session";
|
||||||
|
|
||||||
export const MP = MSGPack.initialize(2 ** 20);
|
export const MP = MSGPack.initialize(2 ** 20);
|
||||||
|
|
||||||
@ -23,7 +24,7 @@ export class Query {
|
|||||||
return path.every(e => (e.match(/[^a-zA-Z0-9_\-\<\>]/g) || []).length === 0);
|
return path.every(e => (e.match(/[^a-zA-Z0-9_\-\<\>]/g) || []).length === 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
constructor(protected database: Database, protected path: string[], protected sender: string) {
|
constructor(protected database: Database, protected path: string[], protected session: Session) {
|
||||||
if (path.length > 10) {
|
if (path.length > 10) {
|
||||||
throw new Error("Path is to long. Path is only allowed to be 10 Layers deep!");
|
throw new Error("Path is to long. Path is only allowed to be 10 Layers deep!");
|
||||||
}
|
}
|
||||||
@ -73,7 +74,7 @@ export class Query {
|
|||||||
type,
|
type,
|
||||||
document,
|
document,
|
||||||
data,
|
data,
|
||||||
sender: this.sender
|
sender: this.session.id
|
||||||
}
|
}
|
||||||
|
|
||||||
let s = this.database.changes.get(this.getKey(collection, document))
|
let s = this.database.changes.get(this.getKey(collection, document))
|
||||||
@ -86,8 +87,8 @@ export class Query {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
protected static getConstructorParams(query: Query): [Database, string[], string] {
|
protected static getConstructorParams(query: Query): [Database, string[], Session] {
|
||||||
return [query.database, query.path, query.sender];
|
return [query.database, query.path, query.session];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -98,8 +99,8 @@ interface UpdateData {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
export class DocumentQuery extends Query {
|
export class DocumentQuery extends Query {
|
||||||
constructor(database: Database, path: string[], sender: string) {
|
constructor(database: Database, path: string[], session: Session) {
|
||||||
super(database, path, sender);
|
super(database, path, session);
|
||||||
this.onChange = this.onChange.bind(this);
|
this.onChange = this.onChange.bind(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -308,8 +309,8 @@ interface DocRes {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export class CollectionQuery extends Query {
|
export class CollectionQuery extends Query {
|
||||||
constructor(database: Database, path: string[], sender: string) {
|
constructor(database: Database, path: string[], session: Session) {
|
||||||
super(database, path, sender);
|
super(database, path, session);
|
||||||
this.onChange = this.onChange.bind(this);
|
this.onChange = this.onChange.bind(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -319,7 +320,7 @@ export class CollectionQuery extends Query {
|
|||||||
|
|
||||||
public async add(value: any) {
|
public async add(value: any) {
|
||||||
let id = nanoid(ALPHABET, 32);
|
let id = nanoid(ALPHABET, 32);
|
||||||
let q = new DocumentQuery(this.database, [...this.path, id], this.sender);
|
let q = new DocumentQuery(this.database, [...this.path, id], this.session);
|
||||||
await q.set(value, {});
|
await q.set(value, {});
|
||||||
return id;
|
return id;
|
||||||
}
|
}
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
export default class Session {
|
export default class Session {
|
||||||
constructor(private _sessionid: string) { }
|
constructor(private _sessionid: string) { }
|
||||||
get sessionid() {
|
get id() {
|
||||||
return this._sessionid;
|
return this._sessionid;
|
||||||
}
|
}
|
||||||
root: boolean = false;
|
root: boolean = false;
|
||||||
|
Reference in New Issue
Block a user