removed old comments

This commit is contained in:
Ladd Hoffman 2025-01-01 22:26:51 -06:00
parent 4eec3b294c
commit e89d07c127
1 changed files with 1 additions and 28 deletions

View File

@ -1,9 +1,6 @@
// We have the lossless transformation of the delta stream. // We have the lossless transformation of the delta stream.
// We want to enable transformations from the lossless view, // We want to enable transformations from the lossless view,
// into various possible "lossy" views that combine or exclude some information. // into various possible "lossy" views that combine or exclude some information.
//
// We can achieve this via functional expression, encoded as JSON-Logic.
// Fields in the output can be described as transformations
import Debug from 'debug'; import Debug from 'debug';
import {DeltaFilter, DeltaID} from "./delta.js"; import {DeltaFilter, DeltaID} from "./delta.js";
@ -29,9 +26,7 @@ export function valueFromCollapsedDelta(
} }
} }
// TODO: Incremental updates of lossy models. For example, with last-write-wins, // We support incremental updates of lossy models.
// we keep the timeUpdated for each field. A second stage resolver can rearrange
// the data structure to a preferred shape and may discard the timeUpdated info.
export class Lossy<Accumulator, Result> { export class Lossy<Accumulator, Result> {
deltaFilter?: DeltaFilter; deltaFilter?: DeltaFilter;
accumulator?: Accumulator; accumulator?: Accumulator;
@ -50,26 +45,18 @@ export class Lossy<Accumulator, Result> {
} }
ingestUpdate(id: DomainEntityID, deltaIds: DeltaID[]) { ingestUpdate(id: DomainEntityID, deltaIds: DeltaID[]) {
debug(`[${this.lossless.rhizomeNode.config.peerId}] prior to ingesting update, deltaIds:`, deltaIds);
const losslessPartial = this.lossless.viewSpecific(id, deltaIds, this.deltaFilter); const losslessPartial = this.lossless.viewSpecific(id, deltaIds, this.deltaFilter);
debug(`[${this.lossless.rhizomeNode.config.peerId}] prior to ingesting update, lossless partial:`,
JSON.stringify(losslessPartial, null, 2));
if (!losslessPartial) return; if (!losslessPartial) return;
const latest = this.accumulator || this.initializer(losslessPartial); const latest = this.accumulator || this.initializer(losslessPartial);
this.accumulator = this.reducer(latest, losslessPartial); this.accumulator = this.reducer(latest, losslessPartial);
debug(`[${this.lossless.rhizomeNode.config.peerId}] after ingesting update, entity ${id} accumulator:`,
JSON.stringify(this.accumulator, null, 2));
} }
// Using the lossless view of some given domain entities, // Using the lossless view of some given domain entities,
// apply a filter to the deltas composing that lossless view, // apply a filter to the deltas composing that lossless view,
// and then apply a supplied resolver function which receives // and then apply a supplied resolver function which receives
// the filtered lossless view as input. // the filtered lossless view as input.
// resolve<T = ResolvedViewOne>(fn?: Resolver<T> | Resolver, entityIds?: DomainEntityID[], deltaFilter?: DeltaFilter): T {
resolve(entityIds?: DomainEntityID[]): Result | undefined { resolve(entityIds?: DomainEntityID[]): Result | undefined {
if (!entityIds) { if (!entityIds) {
entityIds = Array.from(this.lossless.domainEntities.keys()); entityIds = Array.from(this.lossless.domainEntities.keys());
@ -81,17 +68,3 @@ export class Lossy<Accumulator, Result> {
} }
} }
// Generate a rule
// Apply the rule -- When?
// - Maybe we shard a set of deltas and map/reduce the results --
// We are trying to implement CRDT, so the results
// must be composable to preserve that feature.
// That also seems to imply we want to stick with
// the lossless view until the delta set is chosen
// - So, in general on a set of deltas
// at times which seem opportune
// the results of which can be recorded
// and indexed such that the results can be reused
// i.e. you want to compute the result of a set which
// contains a prior one