refactor: TypedHandler[T] — typed params for all task handlers#48
Merged
refactor: TypedHandler[T] — typed params for all task handlers#48
Conversation
Introduce engine.TypedHandler[T] — a generic helper that wraps typed handler functions into TaskHandler. Each handler now receives its own typed params struct instead of parsing map[string]any. The TypedHandler bridges map[string]any → json.Marshal → json.Unmarshal → typed struct, giving handlers compile-time type safety without changing the engine, store, server, or client. All manual parse functions removed: parseSnapshotConfig, parseUploadConfig, parseExportConfig, parseAssembleConfig, parseNodeNames, parseArtifactUploadConfig, parseGenesisPeersConfig, parseGenesisS3Config, intentFromParams, extractStringMap, parseSources, parseEC2TagsSource, parseStaticSource, toStringMap, toStringSlice, parseTargetHeight The float64/int64/json.Number type switches in await_condition and statesync are eliminated — json.Unmarshal into int64 handles it. 20 files changed, net -241 lines. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
… tests Rename all task param structs from xConfig/xParams to xRequest: SnapshotConfig → SnapshotRestoreRequest SnapshotUploadConfig → SnapshotUploadRequest configPatchParams → ConfigPatchRequest ResultExportConfig → ResultExportRequest StateSyncParams → StateSyncRequest awaitConditionParams → AwaitConditionRequest genesisParams → ConfigureGenesisRequest genesisPeersConfig → SetGenesisPeersRequest identityParams → GenerateIdentityRequest gentxParams → GenerateGentxRequest assembleConfig → AssembleGenesisRequest artifactUploadConfig → UploadArtifactsRequest peerDiscoverParams → DiscoverPeersRequest configReloadParams → ConfigReloadRequest peerSourceConfig → PeerSourceEntry All structs now exported for external consumers. Add exhaustive TypedHandler tests: - Happy path, malformed JSON, nil params, nested structs, float64→int64 - Integration tests for all 15 handler deserialization paths Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Introduces
engine.TypedHandler[T]— a generic helper that gives every task handler compile-time typed params without changing the engine, store, server, or client.All 17 handlers converted. Manual parse functions eliminated. Net -216 lines.
How it works
What's removed
All manual parse functions:
parseSnapshotConfig,parseUploadConfig,parseExportConfig,parseAssembleConfig,parseNodeNames,parseArtifactUploadConfig,parseGenesisPeersConfig,parseGenesisS3Config,intentFromParams,extractStringMap,parseSources,parseEC2TagsSource,parseStaticSource,toStringMap,toStringSlice,parseTargetHeightWhat's unchanged
Engine, SQLite store, HTTP server, client, OpenAPI spec, serve.go registration.
🤖 Generated with Claude Code