Repository navigation
refactor(batch): use z.infer for schema-driven types across batch destinations - #5315
Conversation
|
Note Reviews pausedIt looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the Use the following commands to manage reviews:
Use the checkboxes below for quick actions:
Note
|
| Layer / File(s) | Summary |
|---|---|
Shared schema inference types src/services/destination/nativeBatching/types.ts, src/services/destination/nativeBatching/batchDestination.ts |
types.ts adds schema extraction helpers, and batchDestination.ts re-exports the schema-driven public types. |
BatchDestination contract src/services/destination/nativeBatching/batchDestination.ts |
BatchDestinationConstructor, stored destination and connection fields, transformEvent, getInputSchema, and transformEvents now use schema-derived input typing instead of separate config generics. |
Batched processing wiring src/services/destination/nativeBatching/processBatchedDestination.ts |
validateInputs and processBatchedDestination drop the extra config and connection generics and construct integrations with the simplified constructor typing. |
Custom Audience batching setup src/v0/destinations/custom_audience/types.ts, src/v0/destinations/custom_audience/utils.ts, src/v0/destinations/custom_audience/routerTransform.ts |
Custom Audience adds schema-backed config types, updates action lookup behavior, and switches router transform input validation to the shared input schema. |
CustomerIO schema plumbing src/v0/destinations/customerio/v2/types.ts, src/v0/destinations/customerio/routerTransform.ts, src/v0/destinations/customerio/routerTransform.test.ts |
CustomerIO v2 exports a schema constant with destination and connection fields, and the router transform and test types switch to the schema-inferred input shape. |
GAEC and PostHog schema updates src/v0/destinations/google_adwords_enhanced_conversions/routerTransform.ts, src/v0/destinations/posthog/routerTransform.ts, src/v0/destinations/posthog/types.ts, src/v0/destinations/google_adwords_enhanced_conversions/routerTransform.test.ts, src/v0/destinations/posthog/routerTransform.test.ts |
GAEC and PostHog switch getInputSchema() to shared module-level Zod schemas, update transform input typing, and align config schema exports and tests. |
Iterable schema and input typing src/v0/destinations/iterable_audience/types.ts, src/v0/destinations/iterable_audience/routerTransform.ts, src/v0/destinations/iterable_audience/__tests__/routerTransform.test.ts |
Iterable Audience updates action validation and router request schema shape, then uses the inferred input type in the integration and test fixture. |
Estimated code review effort
🎯 4 (Complex) | ⏱️ ~60 minutes
Possibly related PRs
- rudderlabs/rudder-transformer#5187 — Updates the native batching type surface in
src/services/destination/nativeBatching/*, which this PR also refactors. - rudderlabs/rudder-transformer#5230 — Touches the Iterable Audience router transform and schema typing path that is updated here.
- rudderlabs/rudder-transformer#5311 — Updates CustomerIO router transformation wiring to the same schema-driven batching contract used here.
Suggested reviewers
- arpl
- ItsSudip
🚥 Pre-merge checks | ✅ 3 | ❌ 2
❌ Failed checks (2 warnings)
| Check name | Status | Explanation | Resolution |
|---|---|---|---|
| Docstring Coverage | Docstring coverage is 50.00% which is insufficient. The required threshold is 80.00%. | Write docstrings for the functions missing them to satisfy the coverage threshold. | |
| Description check | It covers the high-level summary and test plan, but it omits several required template sections, including the Linear task and checklist items. | Add the missing template sections: related Linear task, objectives details, dependency/performance notes, and the developer/reviewer checklists. |
✅ Passed checks (3 passed)
| Check name | Status | Explanation |
|---|---|---|
| Linked Issues check | ✅ Passed | Check skipped because no linked issues were found for this pull request. |
| Out of Scope Changes check | ✅ Passed | Check skipped because no linked issues were found for this pull request. |
| Title check | ✅ Passed | It clearly summarizes the main refactor from framework-specific input types to z.infer-based schema-driven typing. |
✨ Finishing Touches
📝 Generate docstrings
- Create stacked PR
- Commit on current branch
🧪 Generate unit tests (beta)
- Create PR with unit tests
- Commit unit tests in branch
refactor/batch-destination-schema-driven-types
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.
Comment @coderabbitai help to get the list of available commands.
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## develop #5315 +/- ##
========================================
Coverage 92.73% 92.74%
========================================
Files 701 703 +2
Lines 38213 38255 +42
Branches 8937 8947 +10
========================================
+ Hits 35438 35479 +41
- Misses 2565 2566 +1
Partials 210 210 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
There was a problem hiding this comment.
Actionable comments posted: 2
🧹 Nitpick comments (1)
src/v0/destinations/customerio/routerTransform.test.ts (1)
90-90: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick winAvoid masking the batching input contract with
any.Line 90's
as anysidesteps the schema-derived typing this PR is introducing, so this test will still pass even iftransformEvents()and the inferred Customer.io router input drift apart later. Please type the fixture to the method’s expected input shape instead of suppressing the mismatch at the call site.🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@src/v0/destinations/customerio/routerTransform.test.ts` at line 90, The `transformEvents()` test is masking the batching input contract by casting `inputs` to `any`, which bypasses the schema-derived type safety this PR is meant to enforce. Update the fixture in `routerTransform.test.ts` to use the actual expected input type for `CustomerioRouterTransform`/`transformEvents()` instead of suppressing the mismatch at the call site, so the test will fail if the inferred Customer.io router input drifts.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@src/services/destination/nativeBatching/processBatchedDestination.ts`:
- Around line 260-273: The batching flow is passing raw inputs into
transformEvents because validateInputs discards safeParse’s parsed data and
later the casts on batchableEvents/nonBatchableEvent hide the mismatch. Update
validateInputs to store and return parseResult.data for each valid item, or
otherwise map the validated list to parsed values before constructing
batchableEvents and invoking integration.transformEvents. Keep the fix centered
on validateInputs, batchableEvents, and the transformEvents calls so Zod
coercions/transforms/defaults are preserved.
In `@src/services/destination/nativeBatching/types.ts`:
- Around line 22-26: The ExtractConnectionConfig conditional type is matching
too broadly through the optional connection branch and inferring unknown instead
of falling back to Record<string, unknown>. Update ExtractConnectionConfig in
types.ts to first require that T actually has a connection key before inferring
connection.config, and keep the existing fallback for types where connection is
absent; use the ExtractConnectionConfig symbol to locate and adjust the
conditional branches.
---
Nitpick comments:
In `@src/v0/destinations/customerio/routerTransform.test.ts`:
- Line 90: The `transformEvents()` test is masking the batching input contract
by casting `inputs` to `any`, which bypasses the schema-derived type safety this
PR is meant to enforce. Update the fixture in `routerTransform.test.ts` to use
the actual expected input type for
`CustomerioRouterTransform`/`transformEvents()` instead of suppressing the
mismatch at the call site, so the test will fail if the inferred Customer.io
router input drifts.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
Run ID: 141d2709-1f4f-49a3-87bc-86b889bf91eb
📒 Files selected for processing (10)
src/services/destination/nativeBatching/batchDestination.tssrc/services/destination/nativeBatching/processBatchedDestination.tssrc/services/destination/nativeBatching/types.tssrc/v0/destinations/custom_audience/routerTransform.tssrc/v0/destinations/customerio/routerTransform.test.tssrc/v0/destinations/customerio/routerTransform.tssrc/v0/destinations/customerio/v2/types.tssrc/v0/destinations/google_adwords_enhanced_conversions/routerTransform.tssrc/v0/destinations/iterable_audience/routerTransform.tssrc/v0/destinations/posthog/routerTransform.ts
5ced26d to
5a9433f
Compare
061ecf5 to
217d551
Compare
There was a problem hiding this comment.
Actionable comments posted: 1
🧹 Nitpick comments (2)
src/services/destination/nativeBatching/batchDestination.ts (1)
34-38: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick winPreserve
TInputSchemaon the constructor contract.Erasing the schema here makes downstream code see only
BatchDestination<TBody>, sogetInputSchema()andtransformEvents()lose their shared schema type. Keeping the second generic defaulted preserves inference without forcing callers to specify it.♻️ Suggested type shape
export type BatchDestinationConstructor< TBody extends Record<string, unknown> = Record<string, unknown>, -> = new (destination: Destination, connection?: Connection) => BatchDestination<TBody>; + TInputSchema extends ZodType = ZodType, +> = new (destination: Destination, connection?: Connection) => BatchDestination<TBody, TInputSchema>;Then thread
TInputSchemathroughvalidateInputs/processBatchedDestinationso validated outputs can be typed asInferRouterInput<TInputSchema>[].🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@src/services/destination/nativeBatching/batchDestination.ts` around lines 34 - 38, Preserve the schema generic on the BatchDestination constructor contract: BatchDestinationConstructor currently erases TInputSchema by returning only BatchDestination<TBody>, which breaks shared typing between getInputSchema() and transformEvents(). Update the constructor type in batchDestination.ts to thread both TBody and the defaulted TInputSchema through the instance type, then propagate that generic through validateInputs and processBatchedDestination so validated batches can be typed as InferRouterInput<TInputSchema>[]src/v0/destinations/custom_audience/routerTransform.ts (1)
58-58: 📐 Maintainability & Code Quality | 🔵 TrivialBind the input schema generic to
BatchDestinationinCustomAudienceIntegration.Although
getInputSchema()returnscustomAudienceInputSchema, theCustomAudienceIntegrationclass extendsBatchDestination<Record<string, unknown>>without binding the second generic type argument for the schema. This omits the schema-derived input typing defined in the base class.Update the class declaration at lines 58 and 174 to explicitly bind the schema:
Proposed diff
-class CustomAudienceIntegration extends BatchDestination<Record<string, unknown>> { +class CustomAudienceIntegration extends BatchDestination< + Record<string, unknown>, + typeof customAudienceInputSchema +> {🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@src/v0/destinations/custom_audience/routerTransform.ts` at line 58, `CustomAudienceIntegration` is extending `BatchDestination` with only the record generic, so the input schema type from `getInputSchema()` is not being carried through. Update the class declaration to bind the second generic argument to `customAudienceInputSchema` (or its inferred schema type) in the `CustomAudienceIntegration` definition, and make sure any related base-class typing at the other referenced location stays consistent so the schema-derived input type is preserved.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@src/v0/destinations/posthog/routerTransform.ts`:
- Around line 13-27: The postHog input validation in routerTransform.ts rejects
valid numeric identifiers because the refinement on postHogInputSchema.message
uses truthiness for userId/anonymousId. Update the refine predicate to check for
null or undefined explicitly instead of using !!msg.userId and
!!msg.anonymousId, so numeric 0 is accepted when either identifier is provided.
---
Nitpick comments:
In `@src/services/destination/nativeBatching/batchDestination.ts`:
- Around line 34-38: Preserve the schema generic on the BatchDestination
constructor contract: BatchDestinationConstructor currently erases TInputSchema
by returning only BatchDestination<TBody>, which breaks shared typing between
getInputSchema() and transformEvents(). Update the constructor type in
batchDestination.ts to thread both TBody and the defaulted TInputSchema through
the instance type, then propagate that generic through validateInputs and
processBatchedDestination so validated batches can be typed as
InferRouterInput<TInputSchema>[]
In `@src/v0/destinations/custom_audience/routerTransform.ts`:
- Line 58: `CustomAudienceIntegration` is extending `BatchDestination` with only
the record generic, so the input schema type from `getInputSchema()` is not
being carried through. Update the class declaration to bind the second generic
argument to `customAudienceInputSchema` (or its inferred schema type) in the
`CustomAudienceIntegration` definition, and make sure any related base-class
typing at the other referenced location stays consistent so the schema-derived
input type is preserved.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
Run ID: 1be88e29-7c96-40cd-b5b2-9a10c372122e
📒 Files selected for processing (10)
src/services/destination/nativeBatching/batchDestination.tssrc/services/destination/nativeBatching/processBatchedDestination.tssrc/services/destination/nativeBatching/types.tssrc/v0/destinations/custom_audience/routerTransform.tssrc/v0/destinations/customerio/routerTransform.tssrc/v0/destinations/customerio/v2/types.tssrc/v0/destinations/google_adwords_enhanced_conversions/routerTransform.test.tssrc/v0/destinations/google_adwords_enhanced_conversions/routerTransform.tssrc/v0/destinations/iterable_audience/routerTransform.tssrc/v0/destinations/posthog/routerTransform.ts
✅ Files skipped from review due to trivial changes (1)
- src/v0/destinations/google_adwords_enhanced_conversions/routerTransform.test.ts
🚧 Files skipped from review as they are similar to previous changes (3)
- src/v0/destinations/customerio/v2/types.ts
- src/v0/destinations/iterable_audience/routerTransform.ts
- src/services/destination/nativeBatching/types.ts
There was a problem hiding this comment.
🧹 Nitpick comments (1)
src/v0/destinations/custom_audience/types.ts (1)
53-55: 📐 Maintainability & Code Quality | 🔵 TrivialUse
z.nativeEnumto remove the manual tuple cast
AUTHENTICATION_TYPESis anas constobject. Switching toz.nativeEnum(AUTHENTICATION_TYPES)directly infers the union of literal values, eliminating the unsafe assertion and reducing maintenance overhead.♻️ Proposed change
- authenticationType: z.enum( - Object.values(AUTHENTICATION_TYPES) as [AuthenticationType, ...AuthenticationType[]], - ), + authenticationType: z.nativeEnum(AUTHENTICATION_TYPES),🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@src/v0/destinations/custom_audience/types.ts` around lines 53 - 55, The authenticationType schema in the custom audience types definition is using a manual tuple cast with z.enum even though AUTHENTICATION_TYPES is an as const object. Update the schema in types.ts to use z.nativeEnum(AUTHENTICATION_TYPES) instead, so the literal union is inferred directly and the unsafe assertion can be removed.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Nitpick comments:
In `@src/v0/destinations/custom_audience/types.ts`:
- Around line 53-55: The authenticationType schema in the custom audience types
definition is using a manual tuple cast with z.enum even though
AUTHENTICATION_TYPES is an as const object. Update the schema in types.ts to use
z.nativeEnum(AUTHENTICATION_TYPES) instead, so the literal union is inferred
directly and the unsafe assertion can be removed.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
Run ID: 90bbc94b-aca6-4ad8-8841-0b7d5e98138e
⛔ Files ignored due to path filters (1)
test/integrations/destinations/iterable_audience/common.tsis excluded by!**/test/**
📒 Files selected for processing (9)
src/v0/destinations/custom_audience/routerTransform.tssrc/v0/destinations/custom_audience/types.tssrc/v0/destinations/custom_audience/utils.tssrc/v0/destinations/customerio/routerTransform.test.tssrc/v0/destinations/customerio/routerTransform.tssrc/v0/destinations/customerio/v2/types.tssrc/v0/destinations/iterable_audience/__tests__/routerTransform.test.tssrc/v0/destinations/iterable_audience/routerTransform.tssrc/v0/destinations/iterable_audience/types.ts
✅ Files skipped from review due to trivial changes (1)
- src/v0/destinations/iterable_audience/tests/routerTransform.test.ts
🚧 Files skipped from review as they are similar to previous changes (1)
- src/v0/destinations/iterable_audience/routerTransform.ts
f72a0be to
46c6df4
Compare
There was a problem hiding this comment.
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (1)
src/services/destination/nativeBatching/batchDestination.ts (1)
55-67: 🗄️ Data Integrity & Integration | 🟠 MajorCorrect
z.inferinput typing to match runtime validation behaviorThe contract mismatch confirmed:
batchDestination.tslines 55‑67 typetransformEvent/transformEventsarguments asz.infer<TInputSchema>(post‑parse Zod output), whileprocessBatchedDestination.tslines 53 pushes the original raw input despite successful parsing. This causes runtime shapes to diverge whenever schemas usez.preprocess,.default,.transform, or coercion (e.g.,survicate/types.tsline 65;dub/types.tsline 190).Remediate by either:
- Changing parameter types to
z.input<TInputSchema>(pre‑parse shape), or- Updating
processBatchedDestination.tsline 53 to pushparseResult.datainstead ofinput.Runtime vs Type Mismatch
// src/services/destination/nativeBatching/processBatchedDestination.ts ... - valid.push(input); + valid.push(parseResult.data);🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@src/services/destination/nativeBatching/batchDestination.ts` around lines 55 - 67, The batching contract in transformEvent/transformEvents is typed as z.infer<TInputSchema>, but processBatchedDestination still passes the raw input after parsing, so the runtime value can differ from the declared shape. Fix this by aligning the types and call site: either change the abstract method parameters in batchDestination.ts to z.input<TInputSchema>, or update processBatchedDestination to pass parseResult.data into transformEvent/transformEvents instead of the original input. Use the existing transformEvent, transformEvents, and getInputSchema symbols to keep the contract consistent.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Outside diff comments:
In `@src/services/destination/nativeBatching/batchDestination.ts`:
- Around line 55-67: The batching contract in transformEvent/transformEvents is
typed as z.infer<TInputSchema>, but processBatchedDestination still passes the
raw input after parsing, so the runtime value can differ from the declared
shape. Fix this by aligning the types and call site: either change the abstract
method parameters in batchDestination.ts to z.input<TInputSchema>, or update
processBatchedDestination to pass parseResult.data into
transformEvent/transformEvents instead of the original input. Use the existing
transformEvent, transformEvents, and getInputSchema symbols to keep the contract
consistent.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
Run ID: 7e840b67-0f7b-473b-b6a7-502b6a8211da
📒 Files selected for processing (12)
src/services/destination/nativeBatching/batchDestination.tssrc/services/destination/nativeBatching/types.tssrc/v0/destinations/custom_audience/routerTransform.tssrc/v0/destinations/customerio/routerTransform.test.tssrc/v0/destinations/customerio/routerTransform.tssrc/v0/destinations/google_adwords_enhanced_conversions/routerTransform.test.tssrc/v0/destinations/google_adwords_enhanced_conversions/routerTransform.tssrc/v0/destinations/iterable_audience/routerTransform.tssrc/v0/destinations/iterable_audience/types.tssrc/v0/destinations/posthog/routerTransform.test.tssrc/v0/destinations/posthog/routerTransform.tssrc/v0/destinations/posthog/types.ts
💤 Files with no reviewable changes (1)
- src/services/destination/nativeBatching/types.ts
🚧 Files skipped from review as they are similar to previous changes (4)
- src/v0/destinations/customerio/routerTransform.test.ts
- src/v0/destinations/google_adwords_enhanced_conversions/routerTransform.ts
- src/v0/destinations/customerio/routerTransform.ts
- src/v0/destinations/custom_audience/routerTransform.ts
38cef5d to
039f3a4
Compare
…tinations - Replace InferRouterInput with z.infer<typeof schema> in all BatchDestination transformEvent signatures — integrations no longer need to understand framework-specific utility types - Remove InferRouterInput, ExtractMessage, and SchemaOutput from the batching framework (ExtractDestinationConfig/ExtractConnectionConfig remain for this.destination/this.connection typing) - Add PostHogDestinationConfigSchema and enrich PostHog/GAEC input schemas with destination config for schema-driven typing - Remove unused name field from IterableDestinationConfigSchema - Zero runtime behavior change Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>
7b656e8 to
ae72f1a
Compare
|
|
LGTM |
…spatch Reconcile the record-dispatch framework with develop's schema-driven BatchDestination refactor (#5315) and the customerio event-stream schema fix (#5331): - Re-base VDMV2ObjectDestination onto BatchDestination<TBody, TInputSchema>, deriving connection/destination config types from the Zod input schema instead of the retired TConfig/TConnectionConfig generics. - Point customerio's router transform at the schema-driven customerIOInputSchema (which now carries the #5331 record-vs-event-stream union) while keeping the PR's transformObjectRecord / transformEventStream dispatch. - Update the framework's VDMV2ObjectDestination tests to the new generic signature. Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>



Summary
InferRouterInputwithz.infer<typeof schema>in allBatchDestinationtransformEventsignatures — integrations no longer need to understand framework-specific utility typesInferRouterInput,ExtractMessage, andSchemaOutputfrom the batching framework (ExtractDestinationConfig/ExtractConnectionConfigremain forthis.destination/this.connectiontyping)makeRouterInputSchemabuilder that validates the router envelope (message, destination config, connection config) and supports multiple message variants, so hybrid destinations (record + event-stream) validate each message type against its own connection schemaPostHogDestinationConfigSchemaand enriches PostHog/GAEC input schemas with destination config for schema-driven typingnamefield fromIterableDestinationConfigSchemaTest plan
tsc --noEmitclean🤖 Generated with Claude Code