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.
53 lines
1.5 KiB
TypeScript
53 lines
1.5 KiB
TypeScript
import { RhizomeNode } from '@src';
|
|
import { Lossless } from '@src/views/lossless';
|
|
import { Delta } from '@src/core/delta';
|
|
import { createDelta } from '@src/core/delta-builder';
|
|
import { CustomResolver } from '@src/views/resolvers/custom-resolvers';
|
|
import { ResolverPlugin } from '@src/views/resolvers/custom-resolvers/plugin';
|
|
|
|
// Define a test plugin map that enforces string dependencies
|
|
type TestPluginMap = {
|
|
[key: string]: ResolverPlugin<unknown, string>;
|
|
};
|
|
|
|
interface TestHelperOptions<T extends TestPluginMap> {
|
|
entityId?: string;
|
|
plugins: T;
|
|
deltas: Delta[];
|
|
}
|
|
|
|
export async function testResolverWithPlugins<T extends TestPluginMap>(
|
|
options: TestHelperOptions<T>
|
|
) {
|
|
const {
|
|
entityId = 'test-entity',
|
|
plugins,
|
|
deltas,
|
|
} = options;
|
|
|
|
// Setup test environment
|
|
const node = new RhizomeNode();
|
|
const lossless = new Lossless(node);
|
|
const view = new CustomResolver(lossless, plugins);
|
|
|
|
// Ingest all deltas through the lossless instance
|
|
for (const delta of deltas) {
|
|
lossless.ingestDelta(delta);
|
|
}
|
|
|
|
// Get the resolved view
|
|
const resolvedView = view.resolve([entityId]);
|
|
if (!resolvedView) throw new Error(`Resolved view for entity ${entityId} is undefined`);
|
|
return resolvedView[entityId];
|
|
}
|
|
|
|
/**
|
|
* Helper to create a test delta with proper typing
|
|
* @param creator The creator of the delta
|
|
* @param host The host of the delta
|
|
* @returns A test delta
|
|
*/
|
|
export function createTestDelta(creator = 'user1', host = 'host1') {
|
|
return createDelta(creator, host);
|
|
}
|