Repository navigation
Implement workflow.list and workflow.listByName - #189
Conversation
📝 WalkthroughWalkthroughAdds paginated workflow listing endpoints and client APIs: Changes
Sequence Diagram(s)sequenceDiagram
participant Client
participant Server as WorkflowManager
participant Component as workflow queries
participant DB as Workflows Table
Client->>Server: WorkflowManager.list(name?, opts?)
Server->>Component: ctx.runQuery('list' / 'listByName', args)
Component->>DB: query workflows (use .index("name") if filtering)
DB-->>Component: paginated workflow docs
Component->>Server: mapped PublicWorkflow pagination result
Server-->>Client: PaginationResult<PublicWorkflow>
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~25 minutes Poem
🚥 Pre-merge checks | ✅ 2 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing touches
📜 Recent review detailsConfiguration used: defaults Review profile: CHILL Plan: Pro ⛔ Files ignored due to path filters (1)
📒 Files selected for processing (1)
🚧 Files skipped from review as they are similar to previous changes (1)
✏️ Tip: You can disable this entire section by setting 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.
Actionable comments posted: 3
🤖 Fix all issues with AI agents
In `@example/convex/README.md`:
- Line 68: The example uses an invalid call ctx.db.get("messages", id); replace
it with the correct Convex signature ctx.db.get(id) so the function passes only
the document ID (variable id) to ctx.db.get, and update any surrounding code or
comments that implied a collection-name parameter to reflect that ctx.db.get
accepts a single ID argument.
In `@src/component/workflow.ts`:
- Around line 122-130: The vPublicWorkflow validator is missing the runResult
field so Convex will strip it from responses; update the vPublicWorkflow object
to include runResult (e.g., add runResult: v.optional(vResultValidator) or
runResult: vResultValidator depending on whether RunResult can be null/absent)
and ensure vResultValidator (from `@convex-dev/workpool`) is imported and used so
the validator matches the PublicWorkflow type returned by publicWorkflow.
In `@src/types.ts`:
- Around line 26-42: The vPublicWorkflow validator is missing the runResult
property even though publicWorkflow returns runResult: workflow.runResult;
update the vPublicWorkflow definition to include runResult (e.g., add runResult:
v.optional(v.any()) or an appropriate typed validator) so the runtime schema
matches the PublicWorkflow type; ensure the added validator uses the same
optional/required semantics as the PublicWorkflow field and keep VPublicWorkflow
and the _publicWorkflow assertion consistent.
🧹 Nitpick comments (1)
README.md (1)
541-560: Documentation for listing methods looks good.The new section clearly documents the
list,listByName, andlistStepsmethods with appropriate code examples. Consider varying the sentence structure to avoid three consecutive "Use" sentences (e.g., "CalllistStepswith..." or "To get steps, use...").
📜 Review details
Configuration used: defaults
Review profile: CHILL
Plan: Pro
⛔ Files ignored due to path filters (3)
example/convex/_generated/dataModel.d.tsis excluded by!**/_generated/**src/component/_generated/component.tsis excluded by!**/_generated/**src/component/_generated/dataModel.tsis excluded by!**/_generated/**
📒 Files selected for processing (7)
README.mdexample/convex/README.mdexample/convex/tsconfig.jsonsrc/client/index.tssrc/component/schema.tssrc/component/workflow.tssrc/types.ts
🧰 Additional context used
🧬 Code graph analysis (3)
src/types.ts (1)
src/client/index.ts (4)
WorkflowId(44-44)vWorkflowId(41-41)vWorkflowStep(42-42)WorkflowStep(45-45)
src/component/workflow.ts (3)
src/component/_generated/dataModel.ts (1)
Doc(30-33)src/types.ts (3)
PublicWorkflow(26-32)vPaginationResult(119-135)vPublicWorkflow(34-39)src/client/index.ts (2)
list(232-247)listByName(260-277)
src/client/index.ts (1)
src/types.ts (1)
PublicWorkflow(26-32)
🪛 LanguageTool
README.md
[style] ~554-~554: Three successive sentences begin with the same word. Consider rewording the sentence or use a thesaurus to find a synonym.
Context: ...der:function", { order: "desc" }); ``` Use listSteps with a workflow's ID to get...
(ENGLISH_WORD_REPEAT_BEGINNING_RULE)
🔇 Additional comments (10)
example/convex/tsconfig.json (3)
2-13: LGTM! Good documentation and organization.The added comments clearly explain the config's purpose and distinguish between optional and required settings. The option values are appropriate for a Convex project.
15-17: Verify thelib/targetmismatch is intentional.
targetis set to"ESNext"butlibis set to["ES2021", "dom"]. This means type definitions for ES2022+ features (e.g.,Array.prototype.at,Object.hasOwn,Error.cause) won't be available, even though the target allows their syntax. Also,DOM.Iterablewas removed, which provides iterator types for DOM collections.If newer APIs are needed, consider aligning:
- "lib": ["ES2021", "dom"], + "lib": ["ESNext", "DOM", "DOM.Iterable"],
23-24: LGTM! Fixed glob patterns.The
includepattern is now explicit (["./**/*"]instead of[""]), andexcludeuses a consistent relative path prefix. These are proper corrections.src/component/schema.ts (1)
179-179: LGTM!The new index on the
namefield correctly enables efficient lookups for thelistByNamequery. Sincenameis optional (v.optional(v.string())), workflows without a name will still be indexed withundefined, which is appropriate behavior.src/types.ts (1)
83-83: LGTM!Good improvement renaming the type assertion variable to
_workflowStepfor clarity, consistent with the new_publicWorkflowpattern.src/client/index.ts (2)
222-247: Newlistmethod implementation looks good.The method follows the established pattern from
listSteps, with sensible defaults (ascending order, 100 items per page). The JSDoc is comprehensive.
249-277: NewlistByNamemethod implementation is correct.Consistent with the
listmethod, properly passes thenamefilter parameter to the component endpoint. Both methods use matching pagination defaults and type handling.src/component/workflow.ts (3)
28-33: LGTM!The new imports for
PublicWorkflow,vPublicWorkflow,Doc, andIdare correctly added to support the new listing functionality.
162-178: LGTM!The
listquery implementation is correct:
- Uses
paginatorfrom convex-helpers for proper pagination support- Accepts order and pagination options as expected by the client
- Maps results through
publicWorkflowto transform internal documents to public representationThe type assertion on line 176 is necessary due to the
maptransformation changing the page item type.
180-198: LGTM!The
listByNamequery implementation correctly uses thenameindex on the workflows table for efficient filtering. The implementation is consistent with thelistquery pattern, and the index is properly defined in the schema.
✏️ Tip: You can disable this entire section by setting review_details to false in your review settings.
ianmacartney
left a comment
There was a problem hiding this comment.
Looks good! Can you try it out with the pkg-pr-new link (I'll generate it now)
commit: |
|
Can confirm. With the pkg-pr-new version adding this mutation and running it worked to cleanup the workflows for my test email sending. /**
* Cleanup test email workflows.
*
* Cleans up the oldest 100 test email workflows.
*/
export const cleanupTestEmailWorkflows = internalMutation({
args: {},
handler: async (ctx) => {
const workflows = await workflow.listByName(
ctx,
"email/test:sendTestEmailWorkflow",
{ order: "asc", paginationOpts: { cursor: null, numItems: 100 } }
);
for (const wf of workflows.page) {
await workflow.cleanup(ctx, wf.workflowId);
}
},
}); |
|
Thanks @dantman - just released it in |
This implements two new methods of listing workflows. One for all workflows
workflow.listwhich is ordered by creation. And one for workflows matching a specific nameworkflow.listByName.These may be useful in user side attempts to cleanup workflows or create a dashboard listing the status of workflows.
I was not able to get
npm linkto work in my project so I have not been able to actually try out the new methods.By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.
Summary by CodeRabbit
New Features
Documentation
✏️ Tip: You can customize this high-level summary in your review settings.