640 conditional routes correction#641
Conversation
|
Important Review skippedToo many files! This PR contains 169 files, which is 19 over the limit of 150. ⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Run ID: ⛔ Files ignored due to path filters (1)
📒 Files selected for processing (169)
You can disable this status message by setting the Use the checkbox below for a quick retry:
📝 WalkthroughWalkthroughThis PR performs a hard rename of the routing type system: ChangesRoute Type System Refactor
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~25 minutes Possibly related PRs
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Tip 💬 Introducing Slack Agent: The best way for teams to turn conversations into code.Slack Agent is built on CodeRabbit's deep understanding of your code, so your team can collaborate across the entire SDLC without losing context.
Built for teams:
One agent for your entire SDLC. Right inside Slack. 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 |
There was a problem hiding this comment.
🧹 Nitpick comments (3)
packages/collector/src/destination.ts (1)
45-62: ⚡ Quick winAvoid recomputing transformer next-map inside
resolveDestinationChain.
extractTransformerNextMap(transformers)is recomputed per call; for high event volume this adds avoidable overhead in the destination push path. Precompute it once and pass it into the resolver.♻️ Suggested refactor
function resolveDestinationChain( before: Transformer.RouteSpec | undefined, compiledBefore: CompiledNext | undefined, - transformers: Transformer.Transformers, + transformerNextMap: ReturnType<typeof extractTransformerNextMap>, ingest?: Ingest, ): string[] { if (!before) return []; if (compiledBefore) { const resolved = resolveNext(compiledBefore, buildCacheContext(ingest)); if (!resolved) return []; - return walkChain(resolved, extractTransformerNextMap(transformers)); + return walkChain(resolved, transformerNextMap); } // Without compiledBefore, before is static (string | string[]); skip Route[] case. if (isRouteArray(before)) return []; - return walkChain(before, extractTransformerNextMap(transformers)); + return walkChain(before, transformerNextMap); }+const transformerNextMap = extractTransformerNextMap(collector.transformers); const postChain = resolveDestinationChain( before, compiledBefore, - collector.transformers, + transformerNextMap, destIngest, ); ... const nextChain = resolveDestinationChain( nextConfig, compiledNext, - collector.transformers, + transformerNextMap, destIngest, );🤖 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 `@packages/collector/src/destination.ts` around lines 45 - 62, The function resolveDestinationChain currently calls extractTransformerNextMap(transformers) on every invocation causing overhead; change resolveDestinationChain signature to accept a precomputed transformerNextMap (the return type of extractTransformerNextMap) and replace the internal extractTransformerNextMap calls with that parameter, then update callers to compute transformerNextMap once (using extractTransformerNextMap(transformers)) and pass it into resolveDestinationChain; keep existing logic with resolveNext, buildCacheContext, walkChain and isRouteArray unchanged.skills/walkeros-using-cli/flow-configuration.md (1)
195-201: ⚡ Quick winAdd a compact
Routeshape reference whereRoute[]is first introduced.
Route[]is now documented in three tables, but the object shape isn’t shown nearby. A short inline schema snippet would reduce ambiguity for users editingflow.json.📝 Suggested doc addition
+`Route` shape used in conditional chains: +```json +{ + "match": "*" | { "key": "ingest.path", "operator": "prefix", "value": "/api" }, + "next": "transformerId" | ["transformerA", "transformerB"] +} +```Also applies to: 226-230, 254-259
🤖 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 `@skills/walkeros-using-cli/flow-configuration.md` around lines 195 - 201, Add a compact inline "Route" shape reference where `Route[]` is first introduced (the `before` property table) that shows the object fields and allowed forms so editors know what to put in flow.json: describe a Route object with a "match" field (either "*" or an object with "key","operator","value" for prefix matches) and a "next" field (either a single transformer id string or an array of transformer ids). Insert the same brief snippet near the other two `Route[]` occurrences (the other table blocks noted) so all three tables (around the `before` uses) have the same compact schema reference.packages/collector/src/transformer.ts (1)
455-465: ⚡ Quick winConsider extracting a shared
resolveRouteSpechelper.The same "if
isRouteArray→compileNext+resolveNext, else passthrough" branching now appears in three places (transformer.before resolution, forkresult.next, and unifiedresult.next). A small helper would centralize the rule and make the three sites symmetric:♻️ Suggested helper
function resolveRouteSpec( spec: Transformer.RouteSpec | undefined, ctx: ReturnType<typeof buildCacheContext>, ): string | string[] | undefined { if (!spec) return undefined; if (typeof spec === 'string') return spec; if (!isRouteArray(spec)) return spec; // plain string[] return resolveNext(compileNext(spec), ctx) ?? undefined; }Call sites then collapse to e.g.
const beforeStartId = resolveRouteSpec(transformerBefore, buildCacheContext(ingest, processedEvent));and the no-match passthrough at line 620–624 can be expressed as a singleif (!resolvedNext) { ... }after the helper call.Also applies to: 531-542, 611-627
🤖 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 `@packages/collector/src/transformer.ts` around lines 455 - 465, Extract the repeated branching into a helper like resolveRouteSpec(spec, ctx) that returns string | string[] | undefined; implement it to return undefined for falsy spec, return spec when typeof spec === 'string', return spec when Array.isArray(spec) && !isRouteArray(spec), otherwise return resolveNext(compileNext(spec), ctx) ?? undefined. Replace the three sites that perform this logic (resolution of transformer.config.before in transformerBefore, resolution of fork result.next, and unified result.next) to call resolveRouteSpec(transformerBefore, buildCacheContext(ingest, processedEvent)) or the appropriate ctx from buildCacheContext, and simplify the downstream no-match passthrough checks to a single if (!resolvedNext) { ... } after the helper call.
🤖 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 `@packages/collector/src/destination.ts`:
- Around line 45-62: The function resolveDestinationChain currently calls
extractTransformerNextMap(transformers) on every invocation causing overhead;
change resolveDestinationChain signature to accept a precomputed
transformerNextMap (the return type of extractTransformerNextMap) and replace
the internal extractTransformerNextMap calls with that parameter, then update
callers to compute transformerNextMap once (using
extractTransformerNextMap(transformers)) and pass it into
resolveDestinationChain; keep existing logic with resolveNext,
buildCacheContext, walkChain and isRouteArray unchanged.
In `@packages/collector/src/transformer.ts`:
- Around line 455-465: Extract the repeated branching into a helper like
resolveRouteSpec(spec, ctx) that returns string | string[] | undefined;
implement it to return undefined for falsy spec, return spec when typeof spec
=== 'string', return spec when Array.isArray(spec) && !isRouteArray(spec),
otherwise return resolveNext(compileNext(spec), ctx) ?? undefined. Replace the
three sites that perform this logic (resolution of transformer.config.before in
transformerBefore, resolution of fork result.next, and unified result.next) to
call resolveRouteSpec(transformerBefore, buildCacheContext(ingest,
processedEvent)) or the appropriate ctx from buildCacheContext, and simplify the
downstream no-match passthrough checks to a single if (!resolvedNext) { ... }
after the helper call.
In `@skills/walkeros-using-cli/flow-configuration.md`:
- Around line 195-201: Add a compact inline "Route" shape reference where
`Route[]` is first introduced (the `before` property table) that shows the
object fields and allowed forms so editors know what to put in flow.json:
describe a Route object with a "match" field (either "*" or an object with
"key","operator","value" for prefix matches) and a "next" field (either a single
transformer id string or an array of transformer ids). Insert the same brief
snippet near the other two `Route[]` occurrences (the other table blocks noted)
so all three tables (around the `before` uses) have the same compact schema
reference.
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro
Run ID: e34491d7-8ea2-43d7-b277-9960f69f021d
⛔ Files ignored due to path filters (2)
package-lock.jsonis excluded by!**/package-lock.jsonpackages/destinations/demo/package-lock.jsonis excluded by!**/package-lock.json
📒 Files selected for processing (50)
.changeset/destination-demo-cross-platform.md.changeset/route-typing-rename.mdpackage.jsonpackages/cli/src/commands/bundle/bundler.tspackages/cli/src/commands/push/__tests__/dispatch-integration.test.tspackages/cli/src/commands/push/__tests__/simulate-isolation.test.tspackages/cli/src/commands/push/dispatch-simulate.tspackages/cli/src/commands/push/index.tspackages/cli/src/commands/push/run.tspackages/cli/src/commands/setup/resolve.tspackages/cli/src/commands/validate/validators/flow.tspackages/collector/src/__tests__/source-chain-integration.test.tspackages/collector/src/__tests__/transformer-branch.test.tspackages/collector/src/__tests__/transformer-chain-integration.test.tspackages/collector/src/destination.tspackages/collector/src/transformer.tspackages/core/src/__tests__/schemas/matcher.test.tspackages/core/src/branch.tspackages/core/src/route.tspackages/core/src/schemas/destination.tspackages/core/src/schemas/flow.tspackages/core/src/schemas/index.tspackages/core/src/schemas/matcher.tspackages/core/src/schemas/transformer.tspackages/core/src/types/destination.tspackages/core/src/types/flow.tspackages/core/src/types/source.tspackages/core/src/types/store.tspackages/core/src/types/transformer.tspackages/destinations/demo/CHANGELOG.mdpackages/destinations/demo/LICENSEpackages/destinations/demo/README.mdpackages/destinations/demo/jest.config.mjspackages/destinations/demo/package.jsonpackages/destinations/demo/src/__tests__/index.test.tspackages/destinations/demo/src/dev.tspackages/destinations/demo/src/examples/env.tspackages/destinations/demo/src/examples/index.tspackages/destinations/demo/src/examples/step.tspackages/destinations/demo/src/index.tspackages/destinations/demo/src/schemas/index.tspackages/destinations/demo/src/schemas/mapping.tspackages/destinations/demo/src/schemas/settings.tspackages/destinations/demo/src/types.tspackages/destinations/demo/tsconfig.jsonpackages/destinations/demo/tsup.config.tsskills/walkeros-understanding-flow/SKILL.mdskills/walkeros-using-cli/flow-configuration.mdwebsite/docs/getting-started/flow/index.mdxwebsite/static/schema/flow/v4.json
Preview deployed |
|
🚀 Stable release published Packages Install: 🐳 Docker images published
Docker: |
Summary by CodeRabbit
Breaking Changes
NextRule/NexttoRoute/RouteSpecacross configuration APIs.before,next) now accept conditional routing viaRoute[]with match expressions.New Features
Bug Fixes
Documentation
RouteSpecrouting model.