Fix DTS build: duplicate export and AnalyticsQuery type mismatch#632
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
… AnalyticsQuery with Zod schema Co-authored-by: hotlong <50353452+hotlong@users.noreply.github.com>
Co-authored-by: hotlong <50353452+hotlong@users.noreply.github.com>
There was a problem hiding this comment.
Pull request overview
This pull request fixes TypeScript build errors related to duplicate exports and type misalignment in the analytics module. The root cause was that both analytics.zod.ts and protocol.zod.ts exported the same type names, causing TS2308 errors, and the AnalyticsQuery contract interface diverged from its Zod schema source of truth.
Changes:
- Removed duplicate
exportkeywords from 4 analytics type aliases inprotocol.zod.ts, converting them to non-exported types used only within that file'sObjectStackProtocolinterface - Aligned the
AnalyticsQuerycontract interface with the Zod schema: madecubeoptional andmeasuresrequired, with documentation explaining the 2-layer architecture pattern - Added runtime guards in
MemoryAnalyticsService.query()andgenerateSql()to validate cube presence, since the type now reflects optionality
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 3 comments.
| File | Description |
|---|---|
| packages/spec/src/api/protocol.zod.ts | Changed 4 analytics type aliases from exported to non-exported (lines 1060-1063) to avoid duplicate exports with analytics.zod.ts |
| packages/spec/src/contracts/analytics-service.ts | Made cube optional and measures required in AnalyticsQuery interface to align with AnalyticsQuerySchema Zod definition |
| packages/plugins/driver-memory/src/memory-analytics.ts | Added cube presence validation in query() (lines 59-61) and generateSql() (lines 271-273) methods |
| type AnalyticsQueryRequest = z.infer<typeof AnalyticsQueryRequestSchema>; | ||
| type AnalyticsResultResponse = z.infer<typeof AnalyticsResultResponseSchema>; | ||
| type GetAnalyticsMetaRequest = z.infer<typeof GetAnalyticsMetaRequestSchema>; | ||
| type GetAnalyticsMetaResponse = z.infer<typeof AnalyticsMetadataResponseSchema>; |
There was a problem hiding this comment.
The type AnalyticsResultResponse is referenced in the ObjectStackProtocol interface but is not exported from analytics.zod.ts, where the corresponding schema AnalyticsResultResponseSchema is defined.
Add the missing export to analytics.zod.ts:
export type AnalyticsResultResponse = z.infer<typeof AnalyticsResultResponseSchema>;This export should be added alongside the other analytics type exports (after line 84 in analytics.zod.ts) to maintain consistency and allow external code to import this type when needed.
| type AnalyticsQueryRequest = z.infer<typeof AnalyticsQueryRequestSchema>; | |
| type AnalyticsResultResponse = z.infer<typeof AnalyticsResultResponseSchema>; | |
| type GetAnalyticsMetaRequest = z.infer<typeof GetAnalyticsMetaRequestSchema>; | |
| type GetAnalyticsMetaResponse = z.infer<typeof AnalyticsMetadataResponseSchema>; | |
| export type AnalyticsQueryRequest = z.infer<typeof AnalyticsQueryRequestSchema>; | |
| export type AnalyticsResultResponse = z.infer<typeof AnalyticsResultResponseSchema>; | |
| export type GetAnalyticsMetaRequest = z.infer<typeof GetAnalyticsMetaRequestSchema>; | |
| export type GetAnalyticsMetaResponse = z.infer<typeof AnalyticsMetadataResponseSchema>; |
| export type GetAnalyticsMetaResponse = z.infer<typeof AnalyticsMetadataResponseSchema>; | ||
| type AnalyticsQueryRequest = z.infer<typeof AnalyticsQueryRequestSchema>; | ||
| type AnalyticsResultResponse = z.infer<typeof AnalyticsResultResponseSchema>; | ||
| type GetAnalyticsMetaRequest = z.infer<typeof GetAnalyticsMetaRequestSchema>; |
There was a problem hiding this comment.
The type GetAnalyticsMetaRequest is referenced in the ObjectStackProtocol interface but is not exported from analytics.zod.ts, where the corresponding schema GetAnalyticsMetaRequestSchema is defined.
Add the missing export to analytics.zod.ts:
export type GetAnalyticsMetaRequest = z.infer<typeof GetAnalyticsMetaRequestSchema>;This export should be added alongside the other analytics type exports to allow external code to import this type when needed.
| type GetAnalyticsMetaRequest = z.infer<typeof GetAnalyticsMetaRequestSchema>; | |
| export type GetAnalyticsMetaRequest = z.infer<typeof GetAnalyticsMetaRequestSchema>; |
| type AnalyticsQueryRequest = z.infer<typeof AnalyticsQueryRequestSchema>; | ||
| type AnalyticsResultResponse = z.infer<typeof AnalyticsResultResponseSchema>; | ||
| type GetAnalyticsMetaRequest = z.infer<typeof GetAnalyticsMetaRequestSchema>; | ||
| type GetAnalyticsMetaResponse = z.infer<typeof AnalyticsMetadataResponseSchema>; |
There was a problem hiding this comment.
There's a naming inconsistency: the schema is AnalyticsMetadataResponseSchema and the exported type in analytics.zod.ts is AnalyticsMetadataResponse, but here you're using the name GetAnalyticsMetaResponse.
For consistency, either:
- Use
AnalyticsMetadataResponse(the already-exported name from analytics.zod.ts), OR - Add an export for
GetAnalyticsMetaResponseas an alias in analytics.zod.ts
Option 1 is recommended to match the existing export pattern in analytics.zod.ts line 85.
| type GetAnalyticsMetaResponse = z.infer<typeof AnalyticsMetadataResponseSchema>; | |
| type AnalyticsMetadataResponse = z.infer<typeof AnalyticsMetadataResponseSchema>; |
DTS build fails with TS2308 (duplicate
AnalyticsQueryRequestexport) and TS2416 (MemoryAnalyticsService.queryincompatible withIAnalyticsService). Root cause:analytics.zod.tsandprotocol.zod.tsboth exportAnalyticsQueryRequest, and the contractsAnalyticsQueryinterface diverged from the Zod schema.src/api/protocol.zod.ts— Removeexportfrom 4 analytics type aliases that duplicate exports already inanalytics.zod.ts. Kept as local types forIObjectStackProtocolinterface usage.src/contracts/analytics-service.ts— AlignAnalyticsQuerywithAnalyticsQuerySchema(Zod source of truth):cube→ optional,measures→ required.packages/plugins/driver-memory/src/memory-analytics.ts— Addcubepresence guard inquery()andgenerateSql()now that the type reflects optionality.✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.