Core Changes: - Completely rewrote CustomResolver reducer with dependency-ordered processing - Enhanced plugin initialization with proper dependency injection - Improved delta processing and property value tracking - Added robust error handling for duplicate property IDs Resolver Improvements: - Updated to use new accumulator structure - Implemented execution order processing for plugins - Enhanced debug logging and error reporting - Simplified TimestampResolver by removing unused initializer Configuration Updates: - Added TypeScript path aliases for test helpers - Improved module resolution paths Key Benefits: - More robust plugin dependency management - More efficient state updates - Enhanced type safety - Better error messages and debugging - More consistent plugin initialization This refactoring focuses on improving the robustness of the resolver, especially around plugin lifecycle management and dependency handling. The changes ensure better separation of concerns and more predictable behavior when dealing with complex plugin dependencies.
78 lines
2.2 KiB
TypeScript
78 lines
2.2 KiB
TypeScript
import { describe, test, expect, beforeEach } from '@jest/globals';
|
|
import { RhizomeNode, Lossless, createDelta } from '@src';
|
|
import { CollapsedDelta } from '@src/views/lossless';
|
|
import { CustomResolver, ResolverPlugin } from '@src/views/resolvers/custom-resolvers';
|
|
|
|
type PropertyTypes = string | number | boolean | null;
|
|
|
|
describe('Basic Dependency Resolution', () => {
|
|
let node: RhizomeNode;
|
|
let lossless: Lossless;
|
|
|
|
beforeEach(() => {
|
|
node = new RhizomeNode();
|
|
lossless = new Lossless(node);
|
|
});
|
|
|
|
test('should resolve dependencies in correct order', () => {
|
|
// Define a simple plugin that depends on another
|
|
class FirstPlugin implements ResolverPlugin<{ value: string }, string> {
|
|
readonly dependencies = [] as const;
|
|
|
|
initialize() {
|
|
return { value: '' };
|
|
}
|
|
|
|
update(_currentState: { value: string }, newValue: PropertyTypes) {
|
|
return { value: String(newValue) };
|
|
}
|
|
|
|
resolve(state: { value: string }) {
|
|
return state.value.toUpperCase();
|
|
}
|
|
}
|
|
|
|
|
|
class SecondPlugin implements ResolverPlugin<{ value: string }, string> {
|
|
readonly dependencies = ['first'] as const;
|
|
|
|
initialize() {
|
|
return { value: '' };
|
|
}
|
|
|
|
update(_currentState: { value: string }, newValue: PropertyTypes, _delta: CollapsedDelta, dependencies: { first: string }) {
|
|
return { value: `${dependencies.first}_${newValue}` };
|
|
}
|
|
|
|
resolve(state: { value: string }) {
|
|
return state.value;
|
|
}
|
|
}
|
|
|
|
const resolver = new CustomResolver(lossless, {
|
|
first: new FirstPlugin(),
|
|
second: new SecondPlugin()
|
|
});
|
|
|
|
// Add some data
|
|
lossless.ingestDelta(
|
|
createDelta('user1', 'host1')
|
|
.withTimestamp(1000)
|
|
.setProperty('test1', 'first', 'hello', 'test')
|
|
.buildV1()
|
|
);
|
|
|
|
lossless.ingestDelta(
|
|
createDelta('user1', 'host1')
|
|
.withTimestamp(2000)
|
|
.setProperty('test1', 'second', 'world', 'test')
|
|
.buildV1()
|
|
);
|
|
|
|
const result = resolver.resolve();
|
|
expect(result).toBeDefined();
|
|
expect(result!['test1'].properties.first).toBe('HELLO');
|
|
expect(result!['test1'].properties.second).toBe('HELLO_world');
|
|
});
|
|
});
|