feat: type-safe labels via TLabels generic#75
Conversation
Add optional `labels` Zod schema to `DurablyOptions` for compile-time type checking and runtime validation of labels on trigger(). - Add `TLabels` generic to `Run`, `RunFilter`, `TriggerOptions`, `TriggerAndWaitOptions`, `JobHandle`, `Durably`, and related types - All generics default to `Record<string, string>` for backward compat - Runtime validation in trigger() and batchTrigger() when schema provided - Skip undefined values in RunFilter labels (partial filter safety) - Make toClientRun generic to preserve label types - Add type tests for TLabels inference and propagation - Update docs: llms.md, create-durably.md, define-job.md, index.md Closes #66 Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
|
Warning Rate limit exceeded
⌛ How to resolve this issue?After the wait time has elapsed, a review can be triggered using the We recommend that you space out your commits to avoid hitting the rate limit. 🚦 How do rate limits work?CodeRabbit enforces hourly rate limits for each developer per organization. Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout. Please see our FAQ for further information. ⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (1)
📝 WalkthroughWalkthroughAdds generic, type-safe label support (TLabels) across the Durably public and internal type surfaces. Labels can now be defined via an optional Zod schema in createDurably and are propagated to Run, TypedRun, JobHandle, TriggerOptions, TriggerAndWaitOptions, RunFilter, storage types, and related APIs; runtime label validation wired into trigger/batch flows. Changes
Estimated code review effort🎯 4 (Complex) | ⏱️ ~45 minutes Possibly related PRs
Poem
🚥 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)
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 |
- Add 3 runtime tests: reject invalid labels on trigger(), reject on batchTrigger(), accept valid labels - Add TypedRun type definition to llms.md - Regenerate llms.txt Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
There was a problem hiding this comment.
Actionable comments posted: 2
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In `@packages/durably/docs/llms.md`:
- Around line 471-498: Update the generic constraints in the doc interfaces to
match the real API by adding "extends Record<string, string>" to the TLabels
generic on JobHandle, TriggerOptions, TriggerAndWaitOptions (and the other
similar occurrences noted) so the signatures read e.g. JobHandle<TName, TInput,
TOutput, TLabels extends Record<string, string> = Record<string, string>> and
TriggerOptions<TLabels extends Record<string, string> = Record<string, string>>;
locate these types by name in the docs and apply the same constraint to the
matching generic declarations around the other referenced lines.
- Around line 36-37: The example uses Zod's z but doesn't import it; add an
import for Zod (e.g., import { z } from "zod") near the top of the snippet so
that the labels: z.object({ organizationId: z.string(), env: z.string() }) line
compiles; locate the example by the labels symbol or the z.object usage and
insert the z import alongside the other imports in the snippet.
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro
Run ID: 1c7fe0e9-5675-4a6f-856d-02fdce29eb9f
📒 Files selected for processing (10)
packages/durably/docs/llms.mdpackages/durably/src/durably.tspackages/durably/src/index.tspackages/durably/src/job.tspackages/durably/src/storage.tspackages/durably/tests/node/types.test.tswebsite/api/create-durably.mdwebsite/api/define-job.mdwebsite/api/index.mdwebsite/public/llms.txt
- Add missing `z` import to createDurably example snippet - Add `extends Record<string, string>` constraints to all TLabels generics in doc type definitions (JobHandle, TriggerOptions, TriggerAndWaitOptions, RunFilter, TypedRun) - Add TypedRun type definition - Add 3 runtime tests for labels schema validation - Regenerate llms.txt Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In `@packages/durably/docs/llms.md`:
- Around line 494-496: The package's main entry does not re-export the
BatchTriggerInput type used in JobHandle.batchTrigger, so consumers can't import
that type; update the package's main export file to re-export BatchTriggerInput
(e.g., add BatchTriggerInput to the export list or add an explicit export {
BatchTriggerInput } from its defining module) alongside the existing JobHandle
export so the documented signature is accessible to consumers.
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro
Run ID: aad899df-7124-4830-9ab2-374465095e4f
📒 Files selected for processing (3)
packages/durably/docs/llms.mdpackages/durably/tests/shared/run-api.shared.tswebsite/public/llms.txt
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Summary
labelsZod schema toDurablyOptionsfor compile-time type checking and runtime validationTLabelsgeneric parameter toRun,RunFilter,TriggerOptions,TriggerAndWaitOptions,JobHandle,Durably, and related typesRecord<string, string>— fully backward compatibleDetails
When a
labelsschema is provided tocreateDurably():trigger()andbatchTrigger()validate labels at runtimeRunFilter.labelsbecomesPartial<TLabels>for type-safe filteringregister()→JobHandle→trigger()Changes
packages/durably/src/storage.ts—Run<TLabels>,RunFilter<TLabels>,CreateRunInput<TLabels>,ClientRun<TLabels>, generictoClientRun()packages/durably/src/job.ts—TriggerOptions<TLabels>,TriggerAndWaitOptions<TLabels>,JobHandle<..., TLabels>, labels validation intrigger()andbatchTrigger()packages/durably/src/durably.ts—DurablyOptions<TLabels>,Durably<TJobs, TLabels>, labels schema propagationpackages/durably/src/index.ts— ExportTriggerOptionspackages/durably/tests/node/types.test.ts— 8 type-level testsllms.md,create-durably.md,define-job.md,index.md,llms.txtTest plan
pnpm validate)Closes #66
🤖 Generated with Claude Code
Summary by CodeRabbit
New Features
Improvements
Tests
Documentation