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 {Negation} from '../features/negation';
|
||||
import {NegationHelper} from '../features/negation';
|
||||
import { createDelta } from '../core/delta-builder';
|
||||
const debug = Debug('rz:lossless');
|
||||
|
||||
export type CollapsedPointer = {[key: PropertyID]: PropertyTypes};
|
||||
@ -199,31 +200,35 @@ export class Lossless {
|
||||
for (const delta of deltas) {
|
||||
if (!seenDeltaIds.has(delta.id)) {
|
||||
seenDeltaIds.add(delta.id);
|
||||
// Convert CollapsedDelta back to Delta
|
||||
const fullDelta = new Delta({
|
||||
id: delta.id,
|
||||
creator: delta.creator,
|
||||
host: delta.host,
|
||||
timeCreated: delta.timeCreated,
|
||||
pointers: delta.pointers.map(pointer => {
|
||||
// Convert back to V1 pointer format for Delta constructor
|
||||
|
||||
// Create a new delta using DeltaBuilder
|
||||
const builder = createDelta(delta.creator, delta.host)
|
||||
.withId(delta.id)
|
||||
.withTimestamp(delta.timeCreated);
|
||||
|
||||
// Add all pointers from the collapsed delta
|
||||
for (const pointer of delta.pointers) {
|
||||
const pointerEntries = Object.entries(pointer);
|
||||
if (pointerEntries.length === 1) {
|
||||
const [localContext, target] = pointerEntries[0];
|
||||
if (target === null || target === undefined) {
|
||||
continue; // Skip null/undefined targets
|
||||
}
|
||||
if (typeof target === 'string' && this.domainEntities.has(target)) {
|
||||
// This is a reference pointer to an entity
|
||||
// The targetContext is the property ID this delta appears under
|
||||
return { localContext, target, targetContext: propertyId };
|
||||
builder.addPointer(localContext, target, propertyId);
|
||||
} else if (typeof target === 'string' || typeof target === 'number' || typeof target === 'boolean') {
|
||||
// Scalar pointer with valid type
|
||||
builder.addPointer(localContext, target);
|
||||
} else {
|
||||
// Scalar pointer
|
||||
return { localContext, target: target as PropertyTypes };
|
||||
// For other types (objects, arrays), convert to string
|
||||
builder.addPointer(localContext, JSON.stringify(target));
|
||||
}
|
||||
}
|
||||
// Fallback for unexpected pointer structure
|
||||
return { localContext: 'unknown', target: 'unknown' };
|
||||
})
|
||||
});
|
||||
allDeltas.push(fullDelta);
|
||||
}
|
||||
|
||||
// Build the delta and add to results
|
||||
allDeltas.push(builder.buildV1());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user