Skip to content

feat: array find and findIndex / reset#87

Merged
anton62k merged 2 commits intomasterfrom
feat/array-find-row-root-reset
Feb 18, 2026
Merged

feat: array find and findIndex / reset#87
anton62k merged 2 commits intomasterfrom
feat/array-find-row-root-reset

Conversation

@anton62k
Copy link
Contributor

@anton62k anton62k commented Feb 18, 2026

Summary by cubic

Adds array search to ArrayValueNode and a simple one-call reset for RowModel. Also exposes a typed root node on RowModel for easier navigation.

  • New Features
    • ArrayValueNode: add find(predicate) and findIndex(predicate); typed versions on TypedArrayValueNode.
    • RowModel: add root getter for direct, typed root access (InferNode).
    • RowModel: add reset(data?) to replace the entire row with new data or schema defaults, then commit.
    • Docs: update README and TableModel docs with root, reset, and array search examples; switch to row.patches.
    • Tests: add coverage for root, reset (including defaults), and array find/findIndex behavior.

Written for commit 48998f2. Summary will update on new commits.

@coderabbitai
Copy link

coderabbitai bot commented Feb 18, 2026

No actionable comments were generated in the recent review. 🎉


📝 Walkthrough

Walkthrough

Adds a typed root accessor and a reset(data?) lifecycle method to RowModel (and TypedRowModel), exposes patches as a public property, and adds predicate search methods (find, findIndex) to ArrayValueNode and its typed variants; updates implementation, docs, and tests accordingly.

Changes

Cohort / File(s) Summary
Documentation
README.md, src/model/table/README.md, src/model/table/README.md
Docs updated to describe new RowModel members (root, reset, patches, lifecycle methods) and ArrayValueNode methods (find, findIndex); typed overloads and reset semantics documented.
RowModel Types
src/model/table/row/types.ts, src/model/table/row/typed.ts
Added readonly root and reset(data?: ...) to RowModel and TypedRowModel interfaces (typed root uses InferNode<S>).
RowModel Implementation
src/model/table/row/RowModelImpl.ts
Constructor extended to accept schema and optional refSchemas; added public root getter and reset(data?) that computes default or uses provided data, sets value and commits; preserved commit/revert/patchs exposure.
ArrayValueNode API
src/model/value-node/ArrayValueNode.ts, src/model/value-node/types.ts, src/types/typed.ts
Added find(predicate) and findIndex(predicate) to ArrayValueNode (untyped and typed) delegating to internal items array for predicate-based node searches.
Tests
src/model/table/row/__tests__/RowModel.spec.ts
Updated tests to pass schema into RowModelImpl; added/expanded tests for root delegation, reset behavior (with data, defaults, dirty state), and find/findIndex on array nodes.

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~45 minutes

Possibly related PRs

Suggested reviewers

  • cubic-dev-ai
🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Title check ✅ Passed The title accurately describes the main changes: adding array find/findIndex methods and reset functionality to RowModel.
Description check ✅ Passed The description is well-related to the changeset, detailing the new features (array find/findIndex, root getter, reset method) and documentation updates.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch feat/array-find-row-root-reset

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 2

🧹 Nitpick comments (3)
src/model/table/row/RowModelImpl.ts (1)

123-127: reset with null silently falls through to defaults — consider documenting or guarding.

The nullish coalescing (??) means reset(null) will generate defaults instead of attempting to set null. While reset(undefined) (i.e. no argument) → defaults is clearly intentional, the null case is implicit. This is likely fine in practice (null isn't a valid root value), but it may surprise callers.

Consider either documenting this behavior or using an explicit undefined check if you want to allow null to be passed through:

Option: explicit undefined check (only if null should be a valid value)
  reset(data?: unknown): void {
-   const value = data ?? generateDefaultValue(this._schema, { refSchemas: this._refSchemas });
+   const value = data === undefined
+     ? generateDefaultValue(this._schema, { refSchemas: this._refSchemas })
+     : data;
    this._tree.setValue('', value);
    this._tree.commit();
  }
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@src/model/table/row/RowModelImpl.ts` around lines 123 - 127, The reset method
currently treats null the same as undefined because it uses the nullish
coalescing operator; decide whether null should be preserved or treated as "use
defaults" and implement one of two fixes: (A) if null should be preserved,
change the value selection to use an explicit undefined check so that
reset(null) passes null through to this._tree.setValue('', data) instead of
calling generateDefaultValue; (B) if null should be treated as "no value", add a
short JSDoc comment on reset (and/or a runtime guard) stating that null is
treated as a request to generate defaults and leave the existing nullish
coalescing behavior; reference the reset method, generateDefaultValue, and
this._tree.setValue when making the change.
README.md (2)

331-331: TypedRowModel<S> description omits commit and revert.

The #### RowModel table documents both commit() and revert(), but the TypedRowModel<S> row in the Type Utilities table only lists root, getValue, setValue, getPlainValue, and reset. Users may not realise those lifecycle methods are also accessible on a typed model. Consider adding them (or a brief note like "…plus commit/revert"):

📝 Suggested fix
-| `TypedRowModel<S>` | RowModel with typed `root`, `getValue`, `setValue`, `getPlainValue`, `reset` |
+| `TypedRowModel<S>` | RowModel with typed `root`, `getValue`, `setValue`, `getPlainValue`, `reset`, `commit`, `revert` |
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@README.md` at line 331, Update the README Type Utilities table entry for
TypedRowModel<S> to include the lifecycle methods commit and revert (e.g.,
extend the description to "RowModel with typed root, getValue, setValue,
getPlainValue, reset, plus commit/revert") so it matches the RowModel
documentation; modify the TypedRowModel<S> row text to explicitly mention commit
and revert to make the API surfaces consistent and discoverable.

265-277: Consider documenting return values for find and findIndex.

find returns the matched node or undefined (if no match), and findIndex returns -1 (if no match) — mirroring native JS Array semantics. Noting this explicitly in the table would save callers a trip to source/tests:

📝 Suggested clarification
-| `find(predicate)` | Find first element matching predicate |
-| `findIndex(predicate)` | Find index of first element matching predicate |
+| `find(predicate)` | Find first element matching predicate, or `undefined` |
+| `findIndex(predicate)` | Find index of first matching element, or `-1` |
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@README.md` around lines 265 - 277, The documentation for ArrayValueNode's
methods is missing return-value details for find and findIndex; update the
README table entry for ArrayValueNode (methods `find` and `findIndex`) to
explicitly state that `find(predicate)` returns the matched node or `undefined`
if no match, and that `findIndex(predicate)` returns the index or `-1` when no
match (mirroring native JS Array semantics) so callers know the exact return
behavior.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@README.md`:
- Line 53: Update the inline comment for row.root to reflect the typed schema
return type: change the inaccurate reference to ObjectValueNode and state that
when the schema is created with obj() the root is of type InferNode<S> (the
typed resolved variant) rather than the untyped ObjectValueNode; locate the
usage of row.root in the Quick Start example and replace the parenthetical type
note to mention InferNode<S> and/or “typed root node” so it aligns with the API
table.
- Line 52: The RowModel API reference table is missing the patches property
referenced earlier; update the RowModel section to include a "patches" entry
describing that RowModel.patches is an array of JSON Patch operations (used to
inspect or apply diffs), indicate its type (e.g., Array/JSONPatchOperation[]),
and a short description and example usage so users can find row.patches in the
reference alongside root, reset, commit, and revert; locate the RowModel table
and add the patches row referencing RowModel.patches to match the Quick Start
usage.

---

Nitpick comments:
In `@README.md`:
- Line 331: Update the README Type Utilities table entry for TypedRowModel<S> to
include the lifecycle methods commit and revert (e.g., extend the description to
"RowModel with typed root, getValue, setValue, getPlainValue, reset, plus
commit/revert") so it matches the RowModel documentation; modify the
TypedRowModel<S> row text to explicitly mention commit and revert to make the
API surfaces consistent and discoverable.
- Around line 265-277: The documentation for ArrayValueNode's methods is missing
return-value details for find and findIndex; update the README table entry for
ArrayValueNode (methods `find` and `findIndex`) to explicitly state that
`find(predicate)` returns the matched node or `undefined` if no match, and that
`findIndex(predicate)` returns the index or `-1` when no match (mirroring native
JS Array semantics) so callers know the exact return behavior.

In `@src/model/table/row/RowModelImpl.ts`:
- Around line 123-127: The reset method currently treats null the same as
undefined because it uses the nullish coalescing operator; decide whether null
should be preserved or treated as "use defaults" and implement one of two fixes:
(A) if null should be preserved, change the value selection to use an explicit
undefined check so that reset(null) passes null through to
this._tree.setValue('', data) instead of calling generateDefaultValue; (B) if
null should be treated as "no value", add a short JSDoc comment on reset (and/or
a runtime guard) stating that null is treated as a request to generate defaults
and leave the existing nullish coalescing behavior; reference the reset method,
generateDefaultValue, and this._tree.setValue when making the change.

@sonarqubecloud
Copy link

@anton62k anton62k merged commit 2b1882b into master Feb 18, 2026
7 checks passed
@anton62k anton62k deleted the feat/array-find-row-root-reset branch February 18, 2026 17:07
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