-
Notifications
You must be signed in to change notification settings - Fork 9
feat(api): Allow recipe() to be called with just a function #2008
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat(api): Allow recipe() to be called with just a function #2008
Conversation
The recipe() function now accepts just a function parameter without
requiring a name or schema. This provides a more ergonomic API for
simple recipes where the schema can be inferred from default values.
Changes:
- Added function-only overload to recipe() that accepts just a function
- Updated implementation to handle undefined argumentSchema
- Refactored schema creation logic to eliminate code duplication
- Schema generated from function-only recipes does not have a description field
- Added tests for function-only recipe syntax
- Added transformer fixtures for recipes without names
Usage:
recipe((input: { x: any }) => {
input.x.setDefault(42);
return { result: input.x * 2 };
});
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude <noreply@anthropic.com>
Remove recipe name parameters throughout the codebase where the names don't add meaningful value. Names were mostly duplicating information already available from the file name or [NAME] symbol. Changes: - built-in.ts: Removed type parameter, use type inference - opaque-ref.ts: Removed "mapping function" name from internal map - Multiple pattern files: Removed redundant names, use inline types Files updated: - array-in-cell-ast-nocomponents, charm-ref-in-cell, charms-ref-in-cell - cheeseboard, common-tools, counter, ct-render, dice - instantiate-recipe, linkedlist-in-cell, llm, nested-counter, output_schema All patterns still function identically using the more concise function-only syntax. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No issues found across 10 files
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No issues found across 15 files
Add transformer support for recipe() calls without explicit type arguments.
When recipe() is called with just a function parameter that has a type
annotation, the transformer now infers and injects the schema automatically.
Examples:
- recipe((state: State) => ...) → recipe(toSchema(State), (state) => ...)
- recipe("name", (state: State) => ...) → recipe(toSchema(State), (state) => ...)
This change maintains backward compatibility by only transforming when
an explicit type annotation is present on the function parameter.
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude <noreply@anthropic.com>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Reviewed changes from recent commits (found 3 issues).
3 issues found across 27 files
Prompt for AI agents (all 3 issues)
Understand the root cause of the following 3 issues and fix them.
<file name="packages/ts-transformers/src/transformers/schema-injection.ts">
<violation number="1" location="packages/ts-transformers/src/transformers/schema-injection.ts:228">
This rewrite drops the recipe name when callers pass `recipe("name", (input: T) => ...)`, so the resulting schema no longer carries its description. Please preserve the original string argument when rebuilding the call.</violation>
</file>
<file name="docs/common/RECIPES.md">
<violation number="1" location="docs/common/RECIPES.md:18">
This bullet still claims the arguments are a descriptive name and a function, but with the new overload the name is optional—please update the wording to reflect that.</violation>
<violation number="2" location="docs/common/RECIPES.md:703">
The reactive string example now references `notification.count`, but the surrounding text and previous version use `notifications.count`, so this snippet no longer compiles as written.</violation>
</file>
React with 👍 or 👎 to teach cubic. Mention @cubic-dev-ai to give feedback, ask questions, or re-run the review.
… parameter Add test fixtures demonstrating that recipe() with explicit type arguments but no name parameter correctly transforms and injects schemas. New fixtures: - counter-recipe-no-name: recipe<RecipeState>((state) => ...) - map-single-capture-with-type-arg-no-name: recipe<State>((state) => ...) - jsx-conditional-rendering-no-name: recipe<State>((state) => ...) - map-handler-reference-with-type-arg-no-name: recipe<State>((state) => ...) These fixtures validate that the transformer handles recipe() calls with type arguments but without the optional name parameter, ensuring schema injection works correctly in this configuration. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
…name", (input: T) => ...)
Previously, when transforming recipe calls with both a name string and a typed
parameter like `recipe("MyRecipe", (input: Input) => ...)`, the transformer
would drop the name argument, resulting in `recipe(toSchema<Input>(), (input) => ...)`.
This caused the resulting schema to lose its description.
Now the transformer correctly preserves the name argument, producing:
`recipe("MyRecipe", toSchema<Input>(), (input) => ...)`
Added test fixture to verify the fix.
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude <noreply@anthropic.com>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No issues found across 11 files
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No issues found across 4 files
The recipe() function now accepts just a function parameter without requiring a name or schema. This provides a more ergonomic API for simple recipes where the schema can be inferred from default values.
Changes:
Usage:
recipe((input: { x: number }) => { return { result: derive(input.x, x => x * 2 }; });
🤖 Generated with Claude Code
Summary by cubic
recipe() can now be called with just a function, without a name or schema. For simple recipes, the input schema is inferred from defaults; when the function parameter is typed, the transformer injects toSchema automatically.
New Features
Refactors
Written for commit 409a66d. Summary will update automatically on new commits.