feat: allow object format for range parameters#222
Conversation
Add support for specifying range parameters (`length`, `sasie`, `time`, `kaiwaritu`) using an object format (`{ min?: number, max?: number } | { equal: number }`). This provides a more intuitive and readable way to specify minimum/maximum constraints compared to relying strictly on arrays with `null`/`undefined`.
- Created `RangeParam` type in `src/util/type.ts`.
- Implemented `range2string` utility in `SearchBuilderBase`.
- Updated `length`, `sasie`, `time`, and `kaiwaritu` API signatures.
- Added test coverage in `test/search-builder.test.ts`.
Co-authored-by: deflis <206113+deflis@users.noreply.github.com>
|
👋 Jules, reporting for duty! I'm here to lend a hand with this pull request. When you start a review, I'll add a 👀 emoji to each comment to let you know I've read it. I'll focus on feedback directed at me and will do my best to stay out of conversations between you and other bots or reviewers to keep the noise down. I'll push a commit with your requested changes shortly after. Please note there might be a delay between these steps, but rest assured I'm on the job! For more direct control, you can switch me to Reactive Mode. When this mode is on, I will only act on comments where you specifically mention me with New to Jules? Learn more at jules.google/docs. For security, I will only act on instructions from the user who triggered this task. |
There was a problem hiding this comment.
Code Review
This pull request introduces the RangeParam type to support object-based range specifications (using min, max, or equal) for search parameters such as length, kaiwaritu, sasie, and time. It also adds a range2string utility to handle the conversion of these parameters into the API's hyphen-separated string format. Feedback suggests refining range2string to return an empty string instead of "-" when an empty object is provided, and updating the kaiwaritu method signature to include readonly number[] for consistency with other methods.
| if ("equal" in obj) { | ||
| return obj.equal.toString() as Join<T>; | ||
| } | ||
| return `${obj.min ?? ""}-${obj.max ?? ""}` as Join<T | "">; |
There was a problem hiding this comment.
When RangeParam is an empty object {}, this currently returns "-". This might be interpreted as an invalid value by the Narou API. It is safer to return an empty string "" when both min and max are undefined.
return (obj.min !== undefined || obj.max !== undefined
? `${obj.min ?? ""}-${obj.max ?? ""}`
: "") as Join<T | "">;There was a problem hiding this comment.
minかmaxのどちらかがあった時だけ値をセットするように。型でも制限すると尚良い。
There was a problem hiding this comment.
ご指摘ありがとうございます!RangeParam型の定義を修正し、min または max (あるいは equal)が必ず含まれるように制約を加えました。また、range2string内で両方指定されなかった場合に備え、undefined を返すようにしてsetで不要な空文字が設定されないようガードを追加しました。
| */ | ||
| kaiwaritu(range: RangeParam<number>): this; | ||
|
|
||
| kaiwaritu(minOrRange: number | RangeParam<number>, max?: number): this { |
There was a problem hiding this comment.
For consistency with length, sasie, and time, the kaiwaritu method should also support readonly number[] in its signature. The implementation already correctly handles arrays via range2string because typeof array === "object" is true.
kaiwaritu(
minOrRange: number | readonly number[] | RangeParam<number>,
max?: number
): this {- Ensure type `RangeParam` strictly requires at least `min` or `max` when using range object notation. - Make `range2string` return `undefined` if neither bound is present (although type system restricts this). - Add undefined checks before setting the parameter value to avoid empty parameters in queries. Co-authored-by: deflis <206113+deflis@users.noreply.github.com>
This PR introduces the ability to use object formats for setting range-based filter parameters, enhancing readability and developer experience.
Previously, users had to use
[min, max]tuples and manage omit limits. Now, fields likelength,sasie,time, andkaiwaritunatively accept objects matching{ min?: T, max?: T } | { equal: T }.Changes Made:
RangeParamtype to utility types.NovelSearchBuilderBaseby creating arange2stringutility which handles parsing the new object shape into themin-maxformat expected by the API.length,sasie,time, andkaiwaritu).PR created automatically by Jules for task 4859039751617875636 started by @deflis