Skip to content

Commit e81a62a

Browse files
committed
op invalidation is complete
1 parent d9f6722 commit e81a62a

File tree

12 files changed

+256
-75
lines changed

12 files changed

+256
-75
lines changed

src/data/model/CascadedInvalidateOp.ts

Lines changed: 21 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,9 @@
11
import { HashedObject } from "data/model";
2-
import { Context } from "./Context";
32
import { HashedSet } from "./HashedSet";
43
import { Hash } from "./Hashing";
54
import { HashReference } from "./HashReference";
65
import { InvalidateAfterOp } from "./InvalidateAfterOp";
76
import { MutationOp } from "./MutationOp";
8-
import { RedoOp } from "./RedoOp";
9-
import { UndoOp } from "./UndoOp";
107

118
/*
129
* Op0 <-
@@ -85,13 +82,15 @@ import { UndoOp } from "./UndoOp";
8582
*
8683
*/
8784

88-
abstract class CascadedInvalidateOp extends MutationOp {
85+
class CascadedInvalidateOp extends MutationOp {
86+
87+
static className = 'hhs/v0/CascadedInvalidateOp';
8988

9089
undo?: boolean;
9190
targetOp?: MutationOp;
9291

9392

94-
constructor(undo?: boolean, causalOp?: InvalidateAfterOp|CascadedInvalidateOp, targetOp?: MutationOp) {
93+
constructor(undo?: boolean, targetOp?: MutationOp, causalOp?: InvalidateAfterOp|CascadedInvalidateOp) {
9594
super(targetOp?.targetObject, causalOp === undefined? undefined : [causalOp].values());
9695

9796
if (undo !== undefined) {
@@ -263,7 +262,7 @@ abstract class CascadedInvalidateOp extends MutationOp {
263262
return this.targetOp;
264263
}
265264

266-
literalizeInContext(context: Context, path: string, flags?: Array<string>) : Hash {
265+
/*literalizeInContext(context: Context, path: string, flags?: Array<string>) : Hash {
267266
268267
if (flags === undefined) {
269268
flags = [];
@@ -278,16 +277,29 @@ abstract class CascadedInvalidateOp extends MutationOp {
278277
279278
return super.literalizeInContext(context, path, flags);
280279
280+
}*/
281+
282+
getClassName(): string {
283+
return CascadedInvalidateOp.className;
284+
}
285+
286+
init(): void {
287+
281288
}
282289

283-
static createFromBoolean(undo: boolean, causalOp: InvalidateAfterOp|CascadedInvalidateOp, targetOp: MutationOp): CascadedInvalidateOp {
290+
static create(targetOp: MutationOp, causalOp: InvalidateAfterOp|CascadedInvalidateOp) {
291+
292+
const undo = (targetOp instanceof CascadedInvalidateOp)? !targetOp.undo : true;
293+
284294
if (undo) {
285-
return new UndoOp(causalOp, targetOp);
295+
return new CascadedInvalidateOp(true, targetOp, causalOp);
286296
} else {
287-
return new RedoOp(causalOp, targetOp);
297+
return new CascadedInvalidateOp(false, targetOp, causalOp);
288298
}
289299
}
290300

291301
}
292302

303+
HashedObject.registerClass(CascadedInvalidateOp.className, CascadedInvalidateOp);
304+
293305
export { CascadedInvalidateOp };

src/data/model/InvalidateAfterOp.ts

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,13 @@
1+
import { MutationOp } from './MutationOp';
12
import { CascadedInvalidateOp } from './CascadedInvalidateOp';
23
import { HashedObject } from './HashedObject';
34
import { HashedSet } from './HashedSet';
45
import { Hash } from './Hashing';
56
import { HashReference } from './HashReference';
6-
import { MutationOp } from './MutationOp';
77

88

9-
class InvalidateAfterOp extends MutationOp {
109

11-
static className = 'hhs/v0/InvalidateAfterOp';
10+
abstract class InvalidateAfterOp extends MutationOp {
1211

1312
targetOp?: MutationOp;
1413
terminalOps?: HashedSet<HashReference<MutationOp>>;
@@ -17,8 +16,8 @@ class InvalidateAfterOp extends MutationOp {
1716
// have targetOp in causalOps but are not contained in the set of ops that
1817
// come up to {terminalOps}.
1918

20-
constructor(targetOp?: MutationOp, terminalOps?: IterableIterator<MutationOp>) {
21-
super(targetOp?.targetObject);
19+
constructor(targetOp?: MutationOp, terminalOps?: IterableIterator<MutationOp>, causalOps?: IterableIterator<MutationOp>) {
20+
super(targetOp?.targetObject, causalOps);
2221

2322
if (targetOp !== undefined) {
2423
this.targetOp = targetOp;
@@ -81,10 +80,6 @@ class InvalidateAfterOp extends MutationOp {
8180

8281
}
8382

84-
getClassName(): string {
85-
return InvalidateAfterOp.className;
86-
}
87-
8883
getTargetOp(): MutationOp {
8984
if (this.targetOp === undefined) {
9085
throw new Error('Trying to get targetOp for InvalidateAfterOp ' + this.hash() + ', but it is not present.');
@@ -93,8 +88,15 @@ class InvalidateAfterOp extends MutationOp {
9388
return this.targetOp;
9489
}
9590

91+
getTerminalOps() {
92+
if (this.terminalOps === undefined) {
93+
throw new Error('Trying to get terminalOps for InvalidateAfterOp ' + this.hash() + ', but it is not present.');
94+
}
95+
96+
return this.terminalOps;
97+
}
98+
9699
}
97100

98-
HashedObject.registerClass(InvalidateAfterOp.className, InvalidateAfterOp);
99101

100102
export { InvalidateAfterOp };

src/data/model/MutableObject.ts

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -104,12 +104,12 @@ abstract class MutableObject extends HashedObject {
104104

105105
private bindToStore() {
106106
// NOTE: watchReferences is idempotent
107-
this.getStore().watchReferences('target', this.getLastHash(), this._opCallback);
107+
this.getStore().watchReferences('targetObject', this.getLastHash(), this._opCallback);
108108
this._boundToStore = true;
109109
}
110110

111111
private unbindFromStore() {
112-
this.getStore().removeReferencesWatch('target', this.getLastHash(), this._opCallback);
112+
this.getStore().removeReferencesWatch('targetObject', this.getLastHash(), this._opCallback);
113113
this._boundToStore = false;
114114
}
115115

@@ -144,7 +144,7 @@ abstract class MutableObject extends HashedObject {
144144

145145
let results = await this.getStore()
146146
.loadByReference(
147-
'target',
147+
'targetObject',
148148
this.getLastHash(),
149149
{
150150
order: 'asc',
@@ -154,13 +154,14 @@ abstract class MutableObject extends HashedObject {
154154
while (results.objects.length > 0) {
155155

156156
for (const obj of results.objects) {
157-
const op = obj as MutationOp;
158-
await this.apply(op, false);
157+
if (obj instanceof MutationOp) {
158+
await this.apply(obj, false);
159+
}
159160
}
160161

161162
results = await this.getStore()
162163
.loadByReference(
163-
'target',
164+
'targetObject',
164165
this.getLastHash(),
165166
{
166167
order: 'asc',
@@ -185,7 +186,7 @@ abstract class MutableObject extends HashedObject {
185186

186187
let results = await this.getStore()
187188
.loadByReference(
188-
'target',
189+
'targetObject',
189190
this.getLastHash(),
190191
params);
191192

src/data/model/MutationOp.ts

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,20 +5,18 @@ import { HashedSet } from './HashedSet';
55
import { Hash } from './Hashing';
66
import { HashReference } from './HashReference';
77
import { OpCausalHistory, OpCausalHistoryProps } from 'data/history/OpCausalHistory';
8-
import { InvalidateAfterOp } from './InvalidateAfterOp';
9-
import { CascadedInvalidateOp } from './CascadedInvalidateOp';
108

119
abstract class MutationOp extends HashedObject {
1210

1311
targetObject? : MutableObject;
1412
prevOps? : HashedSet<HashReference<MutationOp>>;
1513
causalOps?: HashedSet<HashReference<MutationOp>>;
1614

17-
constructor(target?: MutableObject, causalOps?: IterableIterator<MutationOp>) {
15+
constructor(targetObject?: MutableObject, causalOps?: IterableIterator<MutationOp>) {
1816
super();
1917

20-
if (target !== undefined) {
21-
this.targetObject = target;
18+
if (targetObject !== undefined) {
19+
this.targetObject = targetObject;
2220
if (causalOps !== undefined) {
2321
this.causalOps = new HashedSet(Array.from(causalOps).map((op: MutationOp) => op.createReference()).values());
2422
}
@@ -70,13 +68,13 @@ abstract class MutationOp extends HashedObject {
7068
return false;
7169
}
7270

73-
const thisIsACascade = this instanceof CascadedInvalidateOp;
71+
/*const thisIsACascade = this instanceof CascadedInvalidateOp;
7472
7573
if (causalOp instanceof CascadedInvalidateOp) {
7674
if (!thisIsACascade) {
7775
return false;
7876
}
79-
}
77+
}*/
8078
}
8179
}
8280

@@ -107,7 +105,7 @@ abstract class MutationOp extends HashedObject {
107105
return this.causalOps === undefined;
108106
}
109107

110-
shouldAcceptInvalidateAfterOp(op: InvalidateAfterOp): boolean {
108+
shouldAcceptInvalidateAfterOp(op: MutationOp): boolean {
111109
op;
112110
return false;
113111
}

src/data/model/RedoOp.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@ class RedoOp extends CascadedInvalidateOp {
1111

1212
targetOp?: MutationOp; // the op that will be undone
1313

14-
constructor(causalOp?: InvalidateAfterOp|UndoOp|RedoOp, targetOp?: MutationOp) {
15-
super(false, causalOp, targetOp);
14+
constructor(targetOp?: MutationOp, causalOp?: InvalidateAfterOp|UndoOp|RedoOp) {
15+
super(false, targetOp, causalOp);
1616
}
1717

1818

src/data/model/UndoOp.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@ class UndoOp extends CascadedInvalidateOp {
1010

1111
targetOp?: MutationOp; // the op that will be undone
1212

13-
constructor(causalOp?: InvalidateAfterOp|UndoOp|RedoOp, targetOp?: MutationOp) {
14-
super(true, causalOp, targetOp);
13+
constructor(targetOp?: MutationOp, causalOp?: InvalidateAfterOp|UndoOp|RedoOp) {
14+
super(true, targetOp, causalOp);
1515
}
1616

1717
getClassName() {

src/mesh/agents/state/CausalHistorySyncAgent.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -165,11 +165,11 @@ class CausalHistorySyncAgent extends PeeringAgentBase implements StateSyncAgent
165165
// Monitoring local state for changes:
166166

167167
watchStoreForOps() {
168-
this.store.watchReferences('target', this.mutableObj, this.opCallback);
168+
this.store.watchReferences('targetObject', this.mutableObj, this.opCallback);
169169
}
170170

171171
unwatchStoreForOps() {
172-
this.store.removeReferencesWatch('target', this.mutableObj, this.opCallback);
172+
this.store.removeReferencesWatch('targetObject', this.mutableObj, this.opCallback);
173173
}
174174

175175
async opCallback(opHash: Hash): Promise<void> {
@@ -191,7 +191,7 @@ class CausalHistorySyncAgent extends PeeringAgentBase implements StateSyncAgent
191191
const fields = LiteralUtils.getFields(literal);
192192
const className = LiteralUtils.getClassName(literal);
193193

194-
if (fields['target'] !== undefined && fields['target']._hash === this.mutableObj &&
194+
if (fields['targetObject'] !== undefined && fields['targetObject']._hash === this.mutableObj &&
195195
this.acceptedMutationOpClasses.indexOf(className) >= 0) {
196196

197197
valid = true;
@@ -250,7 +250,7 @@ class CausalHistorySyncAgent extends PeeringAgentBase implements StateSyncAgent
250250

251251
async lastStoredOpsDescription(limit=25) {
252252

253-
const load = await this.store.loadByReference('target', this.mutableObj, { order: 'desc', limit: limit});
253+
const load = await this.store.loadByReference('targetObject', this.mutableObj, { order: 'desc', limit: limit});
254254

255255
const last = load.objects.length === limit? 'last ' : '';
256256

src/mesh/agents/state/TerminalOpsSyncAgent.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -408,11 +408,11 @@ class TerminalOpsSyncAgent extends PeeringAgentBase implements StateSyncAgent {
408408
}
409409

410410
watchStoreForOps() {
411-
this.store.watchReferences('target', this.objHash, this.opCallback);
411+
this.store.watchReferences('targetObject', this.objHash, this.opCallback);
412412
}
413413

414414
unwatchStoreForOps() {
415-
this.store.removeReferencesWatch('target', this.objHash, this.opCallback);
415+
this.store.removeReferencesWatch('targetObject', this.objHash, this.opCallback);
416416
}
417417

418418
getObjectHash(): string {
@@ -830,7 +830,7 @@ class TerminalOpsSyncAgent extends PeeringAgentBase implements StateSyncAgent {
830830
}
831831

832832
private shouldAcceptMutationOpLiteral(op: Literal): boolean {
833-
return this.objHash === LiteralUtils.getFields(op)['target']._hash &&
833+
return this.objHash === LiteralUtils.getFields(op)['targetObject']._hash &&
834834
this.acceptedMutationOpClasses.indexOf(op.value._class) >= 0;
835835
}
836836

src/mesh/service/Mesh.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -616,7 +616,7 @@ class Mesh {
616616
private async trackOps(gossip: StateGossipAgent, mut: MutableObject, root: Hash) {
617617

618618
let validOpClasses = mut.getAcceptedMutationOpClasses();
619-
let refs = await mut.getStore().loadByReference('target', mut.hash());
619+
let refs = await mut.getStore().loadByReference('targetObject', mut.hash());
620620

621621

622622
for (let obj of refs.objects) {
@@ -659,7 +659,7 @@ class Mesh {
659659

660660
newOpCallbacks.set(hash, callback);
661661

662-
mut.getStore().watchReferences('target', mut.hash(), callback);
662+
mut.getStore().watchReferences('targetObject', mut.hash(), callback);
663663
}
664664
}
665665

@@ -669,7 +669,7 @@ class Mesh {
669669
const callback = newOpCallbacks?.get(mutHash);
670670

671671
if (callback !== undefined) {
672-
store.removeReferencesWatch('target', mutHash, callback);
672+
store.removeReferencesWatch('targetObject', mutHash, callback);
673673
newOpCallbacks?.delete(mutHash);
674674
}
675675
}

src/storage/backends/IdbBackend.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,7 @@ class IdbBackend implements Backend {
164164

165165
await tx.objectStore(IdbBackend.OP_CAUSAL_HISTORY_STORE).put(history);
166166

167-
const mutableHash = LiteralUtils.getFields(storable.literal)['target']['_hash'];
167+
const mutableHash = LiteralUtils.getFields(storable.literal)['targetObject']['_hash'];
168168

169169
const prevOpHashes = HashedSet.elementsFromLiteral(LiteralUtils.getFields(storable.literal)['prevOps']).map(HashReference.hashFromLiteral);
170170

0 commit comments

Comments
 (0)