Make limiter bindings truly type-safe with a context-first defineJob API #2
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Problem
The current limiter API is only partially type-safe.
Today jobs are authored in a shape like:
This gives good checking for the limiter payload shape, but TypeScript cannot infer the limiter selector input from the sibling
inputschema field inside the same object literal.As a result:
This is a TypeScript inference limitation caused by the current API shape, not a runtime bug.
Goal
Make limiter bindings truly type-safe by ensuring that:
inputschemaProposed API
Move to a context-first
defineJobsignature:Why this is better
This gives
defineJobeverything it needs up front:So
Lcan be typed with:This solves the missing bridge in the current API.
Expected type behavior
This should be valid:
This should fail because the job input is wrong:
This should fail because the limiter payload shape is wrong:
This should also fail because the limiter payload value type is wrong:
Suggested implementation model
Conceptually:
defineJob()accepts context first:{ limiters }defineJob()accepts the job spec secondTInputfrominputL.tenantL.mailbox.whenlimitscallback with those helpersSuggested signature
Something in this direction:
Scope
This should be treated as a breaking API improvement.
It is not a runtime correctness issue. The current package works. This change is about making the authoring API match the type-safety expectations set by the rest of the library.
Acceptance criteria
.when(...)predicate input is inferred from the job input schematsdcoverage proves the improved inference