feat(core,ast): add a match predicate to Generator, aligned with Macro - #3828
Merged
Conversation
Add an optional match(node, ctx) => boolean to Generator, checked by KubbDriver#runGenerators before calling schema/operation. A generator whose match resolves false is skipped for that node entirely, with no extra context work and no render call. Omitting match keeps today's behavior of always running, so this is purely additive. renderGeneratorSchema/renderGeneratorOperation in mocks.ts honor match too, so a generator's own unit tests exercise the same skip behavior as real dispatch. This replaces the need for a plugin to hand-roll its own dispatcher when several of its generators only apply to a subset of nodes each, as plugin-react-query's createOperationDispatcher does today in kubb-labs/plugins#728. Fixes #3826. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01LnAWjXX2zoWWScgn7NsLaf
🦋 Changeset detectedLatest commit: c0f1b9d The changes in this PR will be included in the next version bump. This PR includes changesets to release 12 packages
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
@kubb/adapter-oas
@kubb/ast
@kubb/cli
@kubb/core
@kubb/kit
kubb
@kubb/mcp
@kubb/parser-md
@kubb/parser-ts
@kubb/plugin-barrel
@kubb/renderer-jsx
unplugin-kubb
commit: |
Contributor
|
Size Change: +281 B (+0.07%) Total Size: 410 kB 📦 View Changed
ℹ️ View Unchanged
|
…wait checks Macro.when hasn't shipped yet (still part of the pending, unreleased macro-ast-transform-layer changeset), so rename it to match for consistency with the new Generator.match predicate added in the previous commit — same concept, same name, across both abstractions. Also extract the await out of the compound if conditions in KubbDriver#runGenerators and the mocks.ts test helpers into a plain matches variable first, for readability. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01LnAWjXX2zoWWScgn7NsLaf
4 tasks
Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01LnAWjXX2zoWWScgn7NsLaf
3 tasks
…-match-predicate # Conflicts: # packages/core/src/KubbDriver.ts
stijnvanhulle
added a commit
to kubb-labs/plugins
that referenced
this pull request
Jul 18, 2026
…d of the dispatcher (#730) * refactor(plugin-react-query): use the new core match predicate instead of the dispatcher Give each of the five hook generators a match predicate instead of classifying and bailing out inside operation(). This is what createOperationDispatcher (added in #728 to fix kubb-labs/kubb#3816) was working around: @kubb/core's Generator now supports match natively, so the core driver skips a non-matching generator before calling it and plugin.ts goes back to registering the five generators directly. Generated output is unchanged (verified against tests/3.0.x/pluginReactQuery.test.ts's 11-config snapshot suite, run locally against a kubb build linked from ../kubb via pnpm-workspace.yaml's commented-out overrides). Requires kubb-labs/kubb#3828 to merge and release before this is mergeable: without match support in the driver, these generators would run unconditionally for every operation, since the old classify-and-bail guards were moved into match. Do not merge until the kubb catalog version here is bumped past that release. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01LnAWjXX2zoWWScgn7NsLaf * docs: tighten the match predicate changeset Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01LnAWjXX2zoWWScgn7NsLaf * chore: bump kubb catalog to 5.0.0-beta.104 and simplify match predicates The published beta.104 carries the match predicate support this branch depends on. Simplify each generator's match to narrow SchemaNode | OperationNode via a single cast plus isHttpOperationNode instead of a node.kind string check, and drop the queryParam regex normalization in favor of a plain includes() check against both the plain and optional key. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01LnAWjXX2zoWWScgn7NsLaf --------- Co-authored-by: Claude <noreply@anthropic.com>
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.
🎯 Changes
KubbDriver#runGeneratorsalways calls every registered generator'sschema/operationmethod for every node it applies to. A generator that only wants a subset of nodes has no declarative way to say so, so it gets called for every node and has to classify-and-bail at the top of its own method.This adds an optional
matchpredicate toGenerator(packages/core/src/defineGenerator.ts):KubbDriver#runGeneratorschecks it in both dispatch loops (schema and operation) and skips a generator entirely for a node whenmatchresolvesfalse— no extra context work beyond what's already built per node, no render call. Omittingmatchkeeps today's behavior of always running, so this is purely additive and doesn't change output for any existing generator.renderGeneratorSchema/renderGeneratorOperationinpackages/core/src/mocks.tshonormatchtoo, so a generator's own unit tests exercise the same skip behavior as real dispatch.matchintentionally does not gateoperations, which already runs once per plugin on the full batch rather than per node.Macro(packages/ast/src/defineMacro.ts) already had the same concept under a different name (when). Since that field hasn't shipped yet — it's part of the still-pending, unreleasedmacro-ast-transform-layerchangeset — this PR renames it tomatchtoo, so both abstractions use the same name for "skip this callback for a node." No breaking change: nothing has consumedMacro.whenin a release yet.This unblocks a follow-up in kubb-labs/plugins reverting
plugin-react-query's hand-rolledcreateOperationDispatcher(added in kubb-labs/plugins#728 to fix #3816) back to five plain declarative generators, each with its ownmatch, instead of manually classifying once and callingjsxRenderer()/ctx.upsertFile()itself.Fixes #3826.
✅ Checklist
pnpm run test.🚀 Release Impact