Skip to content

Minor changes & major refactors#405

Open
adespawn wants to merge 7 commits intoscylladb:mainfrom
adespawn:drop-more-deprecated
Open

Minor changes & major refactors#405
adespawn wants to merge 7 commits intoscylladb:mainfrom
adespawn:drop-more-deprecated

Conversation

@adespawn
Copy link
Contributor

@adespawn adespawn commented Mar 2, 2026

This is a combination of the following minor changes:

  • Clean up buffer allocation (the existing code handled cases that were relevant 9 years ago)
  • Removed even more code that handles long unsupported node versions.
  • Fix package.json (for some reason this bug stayed there for a looong time now)
  • Convert metadata module classes (this is a preparation for implementation of Adding support for Metadata class #261)
  • Updated client pool test, in a way that fixes: Hosts out of order #282
  • Refactor Encoder. In the short term, this should improve core readability. In the long term, it will help us with the transition to TS (Transition to TypeScript #350)
  • Internal TS types refactor, to improve type recognition in VSCode

@adespawn adespawn force-pushed the drop-more-deprecated branch from 1f316ac to a812258 Compare March 2, 2026 15:02
@adespawn adespawn changed the title Some cleanup Minor changes Mar 2, 2026
@adespawn adespawn requested a review from Copilot March 2, 2026 15:06
@adespawn adespawn marked this pull request as ready for review March 2, 2026 15:06
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR bundles a few cleanup changes across the Node.js driver, including modernizing Buffer allocation helpers, fixing the all-tests script wiring, and converting several metadata model modules to ES classes as groundwork for upcoming Metadata API work (#261).

Changes:

  • Update package.json test script to run integration and unit-not-supported.
  • Remove legacy Buffer allocation fallbacks and re-export modern Buffer.* methods from lib/utils.js.
  • Convert multiple metadata model constructors (table/view/index/function/aggregate/data-collection) from function constructors to ES classes.

Reviewed changes

Copilot reviewed 8 out of 8 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
package.json Adjusts all-tests script to current test suite layout (integration, unit-not-supported).
lib/utils.js Removes deprecated Buffer allocation compatibility code; re-exports Buffer.alloc/allocUnsafe/from.
lib/metadata/data-collection.js Converts DataCollection to an ES class (but still uses legacy inheritance pattern).
lib/metadata/table-metadata.js Converts TableMetadata to an ES class (currently still calls DataCollection.call).
lib/metadata/materialized-view.js Converts MaterializedView to an ES class (currently still calls DataCollection.call).
lib/metadata/schema-index.js Converts Index to an ES class and moves helpers to static/instance methods.
lib/metadata/schema-function.js Converts SchemaFunction to an ES class.
lib/metadata/aggregate.js Converts Aggregate to an ES class.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@adespawn adespawn force-pushed the drop-more-deprecated branch from a812258 to df754a8 Compare March 3, 2026 09:58
@adespawn adespawn requested review from wprzytula and removed request for wprzytula March 3, 2026 10:02
@adespawn adespawn changed the title Minor changes Minor changes & major refactors Mar 3, 2026
@adespawn adespawn mentioned this pull request Mar 10, 2026
nikagra
nikagra previously approved these changes Mar 12, 2026
adespawn and others added 7 commits March 18, 2026 09:57
When this code was first written in 2017, Buffer methods were not supported across
all node versions. As of 2026, this is no longer the case - we delete
the custom implementations and re-export the
proper buffer methods to avoid tedious refactoring of all internal usages.
This commit (almost) automatically converts all class functions in metadata module to class syntax.
This is a update based on the discussion in scylladb#282. Initially,
the test was assuming that the fist host is the one provided.
We decided to not uphold this assumption. As a result this
commit updates the test to properly check for all combinations of
host orders, by using Chai's `expect` instead of `assert`.

I also added a small node about this in the migration guide.
HostMap.toJSON had a custom implementation, that was used when
Object.fromEntries was not available. This is supported since Node 12,
so we can safely remove this code, and rely fully on Object.fromEntries.

https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/fromEntries#browser_compatibility
Before, some members of the encoder were set in the separate
setEncoders and defineInstanceMembers functions. This reduced the
readability and type safety of the code. This commit refactors
all of those members to be set in a single class, the Encoder inherits
from. This allows better type readability across the encoder,
and should improve readability.

Historically, the separation between Encoder and it's members likely existed
because previously Encoder was exposed in the API (it no longer is)
and such separation allowed to keep members of this class private
(invisible in the public API docs). This approach hoverer reduced
also internal documentation readability, which is now fixed.

Currently those members are kept separate to easier code reading / editing.
EncoderMembers focuses on encoding/decoding methods for individual types,
while Encoder "public" (only for the driver) part of the API.
Why we want to make this change.
Exporting from TS under a namespace meant, that when importing the value,
we had different internal API.

Ex. when importing `const types = require("./types");`
to access `Integer` we had to type:
 - `types.Integer` when importing JS code
 - `types.types.Integer` when importing TS code.
This didn't impact the public API due to the way it was re-exported in main.d.ts.

Hover this caused the built-in tools in VScode to incorrectly recognize
the imported types (VScode tried to import the TS file,
while in practice js file was imported). This commit updates
the internal part of TS api to fix this problem, without changing
the external TS api, fixing the internal type recognition in TS.
@adespawn
Copy link
Contributor Author

Updated all the comments. Need the approve again, as the last one becomes stale when any changes are introduced.

@adespawn
Copy link
Contributor Author

@nikagra Could you approve if you agree with the changes, or let me know if you want more time for the review?

Copy link

@nikagra nikagra left a comment

Choose a reason for hiding this comment

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

👍

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.

Hosts out of order

3 participants