Skip to content

feat(core): add support for readonly attribute arrays - #18186

Merged
WikiRik merged 4 commits into
mainfrom
ephys/readonly-attributes
Apr 4, 2026
Merged

WikiRik merged 4 commits into
mainfrom
ephys/readonly-attributes

Conversation

@ephys

@ephys ephys commented Apr 4, 2026 •

Copy link
Copy Markdown
Member

Pull Request Checklist

  • Have you added new tests to prevent regressions?
  • If a documentation update is necessary, have you opened a PR to the documentation repository?
  • Did you update the typescript typings accordingly (if applicable)?
  • Does the description below contain a link to an existing issue (Closes #[issue]) or a description of the issue you are solving?
  • Does the name of your PR follow our conventions?

Description of Changes

This is just a tiny typing change to allow the attributes array to be readonly.

We never mutate that array, so it should not cause an issue.

List of Breaking Changes

  • The type of beforeFind hooks has been changed from FindOptions to WritableDeep<FindOptions>
  • The type of the beforeCount has been changed from CountOptions to WritableDeep<CountOptions>

Summary by CodeRabbit

  • Chores

    • Removed changelog entries from the project and all core packages.
  • Refactor

    • Enhanced hook parameter types with stricter type safety through improved type wrappers.
    • Updated attribute selector and filter arrays to use readonly variants, enforcing immutability constraints.
    • Improved type system consistency across find and count-related hook operations.
    • Added runtime deprecation handling for improved compatibility.

@ephys
ephys requested a review from a team as a code owner April 4, 2026 17:34
@ephys
ephys requested review from WikiRik and sdepold April 4, 2026 17:34
@coderabbitai

coderabbitai Bot commented Apr 4, 2026 •

Copy link
Copy Markdown
Contributor
📝 Walkthrough

Walkthrough

Changelog entries are removed across multiple packages. Core package type signatures for model hooks are updated to accept WritableDeep option types, FindAttributeOptions now enforces ReadonlyArray for attribute selectors, a Node.js deprecation code is added to the test ignore list, and type test assertions are updated accordingly.

Changes

Cohort / File(s) Summary
Changelog Removals
CHANGELOG.md, packages/core/CHANGELOG.md, packages/utils/CHANGELOG.md, packages/validator-js/CHANGELOG.md
Removed entire changelog content including version 7.0.0-alpha.48 entries and header documentation.
Model Hooks Type Updates
packages/core/src/model-hooks.ts
Updated beforeCount, beforeFind, beforeFindAfterExpandIncludeAll, and beforeFindAfterOptions hook method parameters to accept WritableDeep<CountOptions<TAttributes>> and WritableDeep<FindOptions<TAttributes>> instead of raw option types. Added WritableDeep import from type-fest.
FindAttributeOptions Type Strictness
packages/core/src/model.d.ts
Changed array parameters in FindAttributeOptions<TAttributes> from mutable Array<...> to ReadonlyArray<...> for attribute selectors and exclude/include properties.
Type Test Updates
packages/core/test/types/hooks.ts, packages/core/test/types/models/user.ts
Re-enabled and updated type assertions for hooks to expect WritableDeep<typeof args> instead of SemiDeepWritable. Added WritableDeep type imports.
Test Configuration
packages/core/test/support.ts
Added 'DEP0169' Node.js deprecation code to the ignoredDeprecations list to suppress related runtime warnings in tests.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Suggested reviewers

  • sdepold
  • WikiRik

Poem

🐰 twitching nose of delight
Type-safety hops all the way,
ReadonlyArray guards the fields,
WritableDeep lets changes play,
Changelogs fade, but tests still glow! ✨

🚥 Pre-merge checks | ✅ 2 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (2 passed)
Check name Status Explanation
Title check ✅ Passed The title 'feat(core): add support for readonly attribute arrays' directly aligns with the main change: updating FindAttributeOptions to use ReadonlyArray instead of Array, allowing readonly attribute arrays in the API.
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.

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

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch ephys/readonly-attributes

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.

@WikiRik

WikiRik commented Apr 4, 2026

Copy link
Copy Markdown
Member

I also temporarily muted deprecation DEP0169 (url.parse), otherwise tests can't run on node 24

Do you mind if we do that in #18185? I'll update that this evening

@ephys

ephys commented Apr 4, 2026

Copy link
Copy Markdown
Member Author

Of course! I'll keep it uncommitted locally instead :)

@WikiRik
WikiRik enabled auto-merge (squash) April 4, 2026 18:07
@WikiRik
WikiRik merged commit c8f4aaf into main Apr 4, 2026
54 checks passed
@WikiRik
WikiRik deleted the ephys/readonly-attributes branch April 4, 2026 18:40
papandreou added a commit to papandreou/sequelize that referenced this pull request Apr 15, 2026
* main: (200 commits)
  meta: update actions/upload-artifact action to v7.0.1 (sequelize#18212)
  meta: update sequelize AUTHORS (sequelize#18208)
  feat(cli): add migration generate, run, status & undo (sequelize#18193)
  feat(core): Drop the ability to specify the dialect as a string (sequelize#18204)
  feat: update some dialect adapters (sequelize#18189)
  feat(postgres): replace pg-hstore with inline hstore parser (sequelize#18151)
  feat(core): add `sql.random`, improve `Order` typing (sequelize#18203)
  meta: use Sequelize Bot for drafting PRs (sequelize#18201)
  meta: automatically mark unfinished PRs as draft (sequelize#18197)
  meta: update dependency @oclif/test to v4.1.18 (sequelize#18198)
  fix(core): replace @typeparam with @template in JSDoc (sequelize#18094)
  feat(core): Add support for UUID v7 (sequelize#17832)
  meta: update sequelize AUTHORS (sequelize#18190)
  meta: update dependency @oclif/plugin-help to ^6.2.43 (sequelize#18195)
  meta: update dependency esbuild to v0.28.0 (sequelize#18192)
  meta: update dependency @oclif/plugin-help to ^6.2.42 (sequelize#18191)
  meta: update dependency @oclif/core to ^4.10.5 (sequelize#18187)
  meta: update sequelize AUTHORS (sequelize#18158)
  feat: add Node 24 support, drop Node 18 (sequelize#18185)
  feat(core): add support for readonly attribute arrays (sequelize#18186)
  ...
@wikirik-agent wikirik-agent mentioned this pull request Sep 26, 2026
5 tasks done
wikirik-agent added a commit that referenced this pull request Oct 3, 2026
expect-type's `toEqualTypeOf` now uses TypeScript's own type identity, and `.parameter()`/`.returns` cover every overload of a function. The type tests are adjusted accordingly:

- The hook parameter tests (#12959) check that the parameters extend their writable version, which is what catches readonly arrays. The writable helper treats the Sequelize classes that hook options may contain (Transaction, Association, AbstractQuery, SQL expressions) as opaque, and allows readonly attribute lists (#18186). The find hooks are declared with `WritableDeep<FindOptions>` since #18186 and their options are too large for expect-type, so they are no longer checked.
- The `set` and `previous` assertions in the model type tests list the parameter and return types of every overload.

Co-Authored-By: Claude Fable 5.1 <[email protected]>
wikirik-agent added a commit that referenced this pull request Oct 4, 2026
expect-type's `toEqualTypeOf` now uses TypeScript's own type identity, and `.parameter()`/`.returns` cover every overload of a function. The type tests are adjusted accordingly:

- The hook parameter tests (#12959) check that the parameters extend their writable version, which is what catches readonly arrays. The writable helper treats the Sequelize classes that hook options may contain (Transaction, Association, AbstractQuery, SQL expressions) as opaque, and allows readonly attribute lists (#18186). The find hooks are declared with `WritableDeep<FindOptions>` since #18186 and their options are too large for expect-type, so they are no longer checked.
- The `set` and `previous` assertions in the model type tests list the parameter and return types of every overload.

Co-Authored-By: Claude Fable 5.1 <[email protected]>
wikirik-agent added a commit that referenced this pull request Oct 5, 2026
expect-type's `toEqualTypeOf` now uses TypeScript's own type identity, and `.parameter()`/`.returns` cover every overload of a function. The type tests are adjusted accordingly:

- The hook parameter tests (#12959) check that the parameters extend their writable version, which is what catches readonly arrays. The writable helper treats the Sequelize classes that hook options may contain (Transaction, Association, AbstractQuery, SQL expressions) as opaque, and allows readonly attribute lists (#18186). The find hooks are declared with `WritableDeep<FindOptions>` since #18186 and their options are too large for expect-type, so they are no longer checked.
- The `set` and `previous` assertions in the model type tests list the parameter and return types of every overload.

Co-Authored-By: Claude Fable 5.1 <[email protected]>
wikirik-agent added a commit that referenced this pull request Oct 5, 2026
expect-type's `toEqualTypeOf` now uses TypeScript's own type identity, and `.parameter()`/`.returns` cover every overload of a function. The type tests are adjusted accordingly:

- The hook parameter tests (#12959) check that the parameters extend their writable version, which is what catches readonly arrays. The writable helper treats the Sequelize classes that hook options may contain (Transaction, Association, AbstractQuery, SQL expressions) as opaque, and allows readonly attribute lists (#18186). The find hooks are declared with `WritableDeep<FindOptions>` since #18186 and their options are too large for expect-type, so they are no longer checked.
- The `set` and `previous` assertions in the model type tests list the parameter and return types of every overload.

Co-Authored-By: Claude Fable 5.1 <[email protected]>
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.

2 participants