Use deltaBuilder in lossless.decompose
This commit is contained in:
parent
8043b67258
commit
4542c4ce83
6
.windsurf/workflows/delta-builder.md
Normal file
6
.windsurf/workflows/delta-builder.md
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
---
|
||||||
|
description: Update the current file to use delta builder
|
||||||
|
---
|
||||||
|
|
||||||
|
Replace each deltav2 instantiation with a fluent call to createDelta from delta builder, using the following process:
|
||||||
|
- pass creator and host as arguments to createDelta
|
@ -1,7 +0,0 @@
|
|||||||
---
|
|
||||||
description: Update deltas to use the object style for pointers
|
|
||||||
---
|
|
||||||
|
|
||||||
- in the current file, for each v1 delta, rewrite it as a v2 delta
|
|
||||||
- make sure the new delta is isomorphic to the original
|
|
||||||
- do not include a timestamp
|
|
@ -9,6 +9,7 @@ import {Transactions} from '../features/transactions';
|
|||||||
import {DomainEntityID, PropertyID, PropertyTypes, TransactionID, ViewMany} from "../core/types";
|
import {DomainEntityID, PropertyID, PropertyTypes, TransactionID, ViewMany} from "../core/types";
|
||||||
import {Negation} from '../features/negation';
|
import {Negation} from '../features/negation';
|
||||||
import {NegationHelper} from '../features/negation';
|
import {NegationHelper} from '../features/negation';
|
||||||
|
import { createDelta } from '../core/delta-builder';
|
||||||
const debug = Debug('rz:lossless');
|
const debug = Debug('rz:lossless');
|
||||||
|
|
||||||
export type CollapsedPointer = {[key: PropertyID]: PropertyTypes};
|
export type CollapsedPointer = {[key: PropertyID]: PropertyTypes};
|
||||||
@ -199,31 +200,35 @@ export class Lossless {
|
|||||||
for (const delta of deltas) {
|
for (const delta of deltas) {
|
||||||
if (!seenDeltaIds.has(delta.id)) {
|
if (!seenDeltaIds.has(delta.id)) {
|
||||||
seenDeltaIds.add(delta.id);
|
seenDeltaIds.add(delta.id);
|
||||||
// Convert CollapsedDelta back to Delta
|
|
||||||
const fullDelta = new Delta({
|
// Create a new delta using DeltaBuilder
|
||||||
id: delta.id,
|
const builder = createDelta(delta.creator, delta.host)
|
||||||
creator: delta.creator,
|
.withId(delta.id)
|
||||||
host: delta.host,
|
.withTimestamp(delta.timeCreated);
|
||||||
timeCreated: delta.timeCreated,
|
|
||||||
pointers: delta.pointers.map(pointer => {
|
// Add all pointers from the collapsed delta
|
||||||
// Convert back to V1 pointer format for Delta constructor
|
for (const pointer of delta.pointers) {
|
||||||
const pointerEntries = Object.entries(pointer);
|
const pointerEntries = Object.entries(pointer);
|
||||||
if (pointerEntries.length === 1) {
|
if (pointerEntries.length === 1) {
|
||||||
const [localContext, target] = pointerEntries[0];
|
const [localContext, target] = pointerEntries[0];
|
||||||
|
if (target === null || target === undefined) {
|
||||||
|
continue; // Skip null/undefined targets
|
||||||
|
}
|
||||||
if (typeof target === 'string' && this.domainEntities.has(target)) {
|
if (typeof target === 'string' && this.domainEntities.has(target)) {
|
||||||
// This is a reference pointer to an entity
|
// This is a reference pointer to an entity
|
||||||
// The targetContext is the property ID this delta appears under
|
builder.addPointer(localContext, target, propertyId);
|
||||||
return { localContext, target, targetContext: propertyId };
|
} else if (typeof target === 'string' || typeof target === 'number' || typeof target === 'boolean') {
|
||||||
|
// Scalar pointer with valid type
|
||||||
|
builder.addPointer(localContext, target);
|
||||||
} else {
|
} else {
|
||||||
// Scalar pointer
|
// For other types (objects, arrays), convert to string
|
||||||
return { localContext, target: target as PropertyTypes };
|
builder.addPointer(localContext, JSON.stringify(target));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// Fallback for unexpected pointer structure
|
}
|
||||||
return { localContext: 'unknown', target: 'unknown' };
|
|
||||||
})
|
// Build the delta and add to results
|
||||||
});
|
allDeltas.push(builder.buildV1());
|
||||||
allDeltas.push(fullDelta);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user