Skip to content

feat: allow object format for range parameters#222

Draft
deflis wants to merge 2 commits intomasterfrom
feature/range-param-object-4859039751617875636
Draft

feat: allow object format for range parameters#222
deflis wants to merge 2 commits intomasterfrom
feature/range-param-object-4859039751617875636

Conversation

@deflis
Copy link
Copy Markdown
Owner

@deflis deflis commented Apr 10, 2026

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 like length, sasie, time, and kaiwaritu natively accept objects matching { min?: T, max?: T } | { equal: T }.

Changes Made:

  • Added RangeParam type to utility types.
  • Enhanced parameter processing inside NovelSearchBuilderBase by creating a range2string utility which handles parsing the new object shape into the min-max format expected by the API.
  • Updated typing and overloading for the related parameters (length, sasie, time, and kaiwaritu).
  • Added robust unit test coverage.

PR created automatically by Jules for task 4859039751617875636 started by @deflis

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>
@google-labs-jules
Copy link
Copy Markdown

👋 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 @jules. You can find this option in the Pull Request section of your global Jules UI settings. You can always switch back!

New to Jules? Learn more at jules.google/docs.


For security, I will only act on instructions from the user who triggered this task.

Copy link
Copy Markdown

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 | "">;
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

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 | "">;

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

minかmaxのどちらかがあった時だけ値をセットするように。型でも制限すると尚良い。

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ご指摘ありがとうございます!RangeParam型の定義を修正し、min または max (あるいは equal)が必ず含まれるように制約を加えました。また、range2string内で両方指定されなかった場合に備え、undefined を返すようにしてsetで不要な空文字が設定されないようガードを追加しました。

*/
kaiwaritu(range: RangeParam<number>): this;

kaiwaritu(minOrRange: number | RangeParam<number>, max?: number): this {
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

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 {

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

会話率も同じシグネチャのほうがいい

- 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>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant