Extract shared type guards and schema type from formatters#46
Merged
Conversation
There was a problem hiding this comment.
1 issue found across 4 files
Prompt for AI agents (unresolved issues)
Check if these issues are valid — if so, understand the root cause of each and fix them. If appropriate, use sub-agents to investigate and fix each issue separately.
<file name="src/shared/utils/type-guards.ts">
<violation number="1" location="src/shared/utils/type-guards.ts:14">
P2: `toRecordOrNull` accepts arrays as records; add the same `Array.isArray` exclusion used by `toRecord` to keep object-guard behavior consistent.</violation>
</file>
Reply with feedback, questions, or to request a fix. Tag @cubic-dev-ai to re-run a review.
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
Extract duplicated type definitions and type-guard utility functions from both platform formatter files into shared modules. Both
notion/formatters.tsandnotionbot/formatters.tsdefined identical (or near-identical) helpers for narrowingunknownvalues — these now live insrc/shared/and are imported by both platforms.Changes
New shared modules
src/shared/types/schema.tsSimplifiedSchemaPropertytype — was defined identically in both formatter files.src/shared/utils/type-guards.tstoRecord,toRecordOrNull,toStringValue/toStringOrEmpty,toOptionalString/toCursor,toStringArray— unified type-guard helpers with separate exports to preserve null vs undefined return type differences.Formatter updates
src/platforms/notion/formatters.tstoRecord,toStringArray,toStringValue,toOptionalString) and theSimplifiedSchemaPropertytype definition. Import all from shared modules.src/platforms/notionbot/formatters.tstoRecord,toStringOrEmpty,toCursor) and theSimplifiedSchemaPropertytype definition. Import from shared modules, aliasingtoRecordOrNull as toRecordto preserve the null-returning contract without changing call sites.Context
The two platform formatters evolved independently, each accumulating their own
toRecord,toString*, andSimplifiedSchemaPropertydefinitions. The implementations were functionally identical but differed in return types (undefinedvsnull) — a consequence of the unofficial API usingundefinedand the official API usingnullfor absent values. The shared module preserves both contracts viatoRecord(returnsundefined) andtoRecordOrNull(returnsnull), so no call-site changes are needed.Testing
All 599 tests pass, typecheck clean. No behavioral changes — pure refactor.
Summary by cubic
Extracted shared type guards and the
SimplifiedSchemaPropertytype tosrc/sharedand updated both Notion formatters to use them. Removes duplication and preservesnullvsundefinedreturn contracts; no behavior changes.SimplifiedSchemaPropertytosrc/shared/types/schema.ts.src/shared/utils/type-guards.tswithtoRecord/toRecordOrNull(both ignore arrays),toStringValue/toStringOrEmpty,toOptionalString/toCursor,toStringArray.notion/formatters.tsandnotionbot/formatters.tsto import shared helpers; in NotionBot, aliasedtoRecordOrNullastoRecordto keep thenullcontract.Written for commit 0c39d90. Summary will update on new commits.