moved lossless from collection to node, as we can reuse it for different kinds of data structures
This commit is contained in:
parent
ad3c00638c
commit
870c1a62b6
|
@ -8,7 +8,7 @@ import {randomUUID} from "node:crypto";
|
||||||
import EventEmitter from "node:events";
|
import EventEmitter from "node:events";
|
||||||
import {Delta, DeltaID} from "./delta";
|
import {Delta, DeltaID} from "./delta";
|
||||||
import {Entity, EntityProperties} from "./entity";
|
import {Entity, EntityProperties} from "./entity";
|
||||||
import {Lossless, LosslessViewMany} from "./lossless";
|
import {LosslessViewMany} from "./lossless";
|
||||||
import {firstValueFromLosslessViewOne, Lossy, LossyViewMany, LossyViewOne} from "./lossy";
|
import {firstValueFromLosslessViewOne, Lossy, LossyViewMany, LossyViewOne} from "./lossy";
|
||||||
import {RhizomeNode} from "./node";
|
import {RhizomeNode} from "./node";
|
||||||
import {DomainEntityID} from "./types";
|
import {DomainEntityID} from "./types";
|
||||||
|
@ -19,16 +19,15 @@ export class Collection {
|
||||||
name: string;
|
name: string;
|
||||||
entities = new Map<string, Entity>();
|
entities = new Map<string, Entity>();
|
||||||
eventStream = new EventEmitter();
|
eventStream = new EventEmitter();
|
||||||
lossless = new Lossless(); // TODO: Really just need one global Lossless instance
|
|
||||||
lossy: Lossy;
|
|
||||||
|
|
||||||
constructor(name: string) {
|
constructor(name: string) {
|
||||||
this.name = name;
|
this.name = name;
|
||||||
this.lossy = new Lossy(this.lossless);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
ingestDelta(delta: Delta) {
|
ingestDelta(delta: Delta) {
|
||||||
const updated = this.lossless.ingestDelta(delta);
|
if (!this.rhizomeNode) return;
|
||||||
|
|
||||||
|
const updated = this.rhizomeNode.lossless.ingestDelta(delta);
|
||||||
|
|
||||||
this.eventStream.emit('ingested', delta);
|
this.eventStream.emit('ingested', delta);
|
||||||
this.eventStream.emit('updated', updated);
|
this.eventStream.emit('updated', updated);
|
||||||
|
@ -194,12 +193,14 @@ export class Collection {
|
||||||
// Now with lossy view approach, instead of just returning what we already have,
|
// Now with lossy view approach, instead of just returning what we already have,
|
||||||
// let's compute our view now.
|
// let's compute our view now.
|
||||||
// return this.entities.get(id);
|
// return this.entities.get(id);
|
||||||
const res = this.lossy.resolve((view) => this.defaultResolver(view), [id]);
|
if (!this.rhizomeNode) return undefined;
|
||||||
|
const lossy = new Lossy(this.rhizomeNode.lossless);
|
||||||
|
const res = lossy.resolve((view) => this.defaultResolver(view), [id]);
|
||||||
return res[id];
|
return res[id];
|
||||||
}
|
}
|
||||||
|
|
||||||
getIds(): string[] {
|
getIds(): string[] {
|
||||||
// return Array.from(this.entities.keys());
|
if (!this.rhizomeNode) return [];
|
||||||
return Array.from(this.lossless.domainEntities.keys());
|
return Array.from(this.rhizomeNode.lossless.domainEntities.keys());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,6 +2,7 @@ import Debug from 'debug';
|
||||||
import {CREATOR, HTTP_API_ADDR, HTTP_API_ENABLE, HTTP_API_PORT, PEER_ID, PUBLISH_BIND_ADDR, PUBLISH_BIND_HOST, PUBLISH_BIND_PORT, REQUEST_BIND_ADDR, REQUEST_BIND_HOST, REQUEST_BIND_PORT, SEED_PEERS} from './config';
|
import {CREATOR, HTTP_API_ADDR, HTTP_API_ENABLE, HTTP_API_PORT, PEER_ID, PUBLISH_BIND_ADDR, PUBLISH_BIND_HOST, PUBLISH_BIND_PORT, REQUEST_BIND_ADDR, REQUEST_BIND_HOST, REQUEST_BIND_PORT, SEED_PEERS} from './config';
|
||||||
import {DeltaStream} from './deltas';
|
import {DeltaStream} from './deltas';
|
||||||
import {HttpServer} from './http';
|
import {HttpServer} from './http';
|
||||||
|
import {Lossless} from './lossless';
|
||||||
import {Peers} from './peers';
|
import {Peers} from './peers';
|
||||||
import {PubSub} from './pub-sub';
|
import {PubSub} from './pub-sub';
|
||||||
import {RequestReply} from './request-reply';
|
import {RequestReply} from './request-reply';
|
||||||
|
@ -30,6 +31,7 @@ export class RhizomeNode {
|
||||||
requestReply: RequestReply;
|
requestReply: RequestReply;
|
||||||
httpServer: HttpServer;
|
httpServer: HttpServer;
|
||||||
deltaStream: DeltaStream;
|
deltaStream: DeltaStream;
|
||||||
|
lossless = new Lossless();
|
||||||
peers: Peers;
|
peers: Peers;
|
||||||
myRequestAddr: PeerAddress;
|
myRequestAddr: PeerAddress;
|
||||||
myPublishAddr: PeerAddress;
|
myPublishAddr: PeerAddress;
|
||||||
|
|
Loading…
Reference in New Issue