refactor(core): data 层 types.ts + impl/ 布局与硬编码字符串/错误码收敛 - #278
Merged
Merged
Conversation
Call sites for SCALE_/FOOTPRINT_/AVWAP_/INDICATOR_/HEATMAP_/MTF_/CHART_TYPE_/REPLAY_/DEPTH_ error codes referenced *_ERROR_CODES.* objects that errors.ts did not export, so the package failed to type-check. Add the missing constant objects and normalize the file to the repo's Biome formatting (it had been committed with semicolons / double quotes / 4-space indent).
…ants Magic strings in packages/core/src/data were duplicated or untyped: - 'auto' -> AUTO_SOURCE_ID (moved to provider/types.ts so router does not depend on buffer, which would invert the layer) - 'latest' -> LATEST_TRADING_DATE - 'exhausted' -> OLDER_DATA_STATUS.EXHAUSTED - '/api/v1/market-data/...' endpoint paths -> V1_ENDPOINTS - Content-Type/application/json header -> JSON_HEADERS - 'CN' session id -> CN_SESSION_ID
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.
目的
把
packages/core/src/data/整层按仓库约定(<module>/types.ts契约 +<module>/impl/实现)重构,并收敛其中的硬编码字符串与错误码。纯结构性改动,不改变运行时行为与包级公共 API。改动概览
1. 模块布局:
types.ts+impl/(5365e3fe)provider/buffer/depth/live统一为「契约在模块根types.ts,实现在impl/」。MarketDataSourceConfig/MarketDataSourceConfigPatch/SourceCapabilityQuery(原registry.ts)与SourceRouterInstrumentIdentity/SourceRouter*Request/SourceRouteAttempt/RoutedMarketData(原router.ts)移入provider/types.ts;types.ts不再依赖impl/。buffer/dataBufferTypes.ts→buffer/types.ts,depth/depthTypes.ts→depth/types.ts。protocol/作为子模块:protocol/types.ts是 wire 契约,httpTransport.ts/provider.ts进入protocol/impl/。./market-data/sources的 key 不变,仅 target 指向dist/data/provider/impl/sources/*(外部导入路径不变,非破坏性)。2. 错误码具名常量(5365e3fe + e4b19db)
ERROR_CODES(fetch 族)改为as const satisfies,保留字面量类型以支持error.code收窄比较。GENERIC_ERROR_CODES(INVALID_PARAM/INVALID_STATE/DISPOSED/NOT_REGISTERED)。SCALE_/FOOTPRINT_/AVWAP_/INDICATOR_/HEATMAP_/MTF_/CHART_TYPE_/REPLAY_/DEPTH_ERROR_CODES。errors.ts顺带做 Biome 格式归一(此前以非仓库格式提交,导致pnpm lint为红)。3. data 层硬编码字符串收敛(980dde97)
'auto'AUTO_SOURCE_ID(上提到provider/types.ts,避免 provider → buffer 反向依赖)'latest'LATEST_TRADING_DATE'exhausted'OLDER_DATA_STATUS.EXHAUSTED/api/v1/market-data/...端点路径V1_ENDPOINTS.*Content-Type: application/jsonJSON_HEADERS'CN'CN_SESSION_ID刻意保留
MarketDataErrorCode(data 层独立领域词汇,UPSTREAM_UNAVAILABLE/ABORTED/UNKNOWN等)不是KLineChartError码,无对应常量对象。errors-help的「码 → 提示」表、测试断言。兼容性
SourceRouterTimeShareRangeRequest与V1_ENDPOINTS(均为增量)。验证
pnpm -C packages/core test:245 文件 / 2645 用例通过pnpm -C packages/core build+publint --strict:产物与 exports 一致biome check(改动文件):无 errortsc -p tsconfig.build.json --noEmit:通过设计文档
docs/design/data-layer-module-layout.md需要贡献者验证
图表加载 / 数据源切换 / 实时 K 线 / 深度热力图的 E2E 与视觉回归。