-
Notifications
You must be signed in to change notification settings - Fork 97
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Update target to ES2020 and replace Long with bigint #912
Conversation
WalkthroughThe pull request introduces significant modifications across various files in the SDK, primarily focusing on the conversion functions in Changes
Assessment against linked issues
Possibly related PRs
📜 Recent review detailsConfiguration used: CodeRabbit UI 📒 Files selected for processing (19)
💤 Files with no reviewable changes (5)
✅ Files skipped from review due to trivial changes (1)
🚧 Files skipped from review as they are similar to previous changes (11)
🧰 Additional context used🔇 Additional comments (9)
Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media? 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (Invoked using PR comments)
Other keywords and placeholders
CodeRabbit Configuration File (
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 7
🧹 Outside diff range and nitpick comments (6)
packages/sdk/src/document/change/checkpoint.ts (2)
92-92
: Consider using strict equality and LGTM for InitialCheckpointIn the
equals
method:
- Consider using
===
instead of==
for comparingbigint
values. While==
works,===
is preferred for strict equality checks in TypeScript/JavaScript.The
InitialCheckpoint
constant initialization with0n
is correct for abigint
literal.Suggested change for line 92:
- this.clientSeq === other.clientSeq && this.serverSeq == other.serverSeq + this.clientSeq === other.clientSeq && this.serverSeq === other.serverSeqAlso applies to: 108-108
Migration Incomplete: Remaining
Long
Usages FoundThe
Checkpoint
class has been successfully migrated fromLong
tobigint
. However, the following files still import and useLong
:
packages/sdk/test/unit/document/crdt/counter_test.ts
packages/sdk/test/unit/document/crdt/primitive_test.ts
packages/sdk/test/integration/primitive_test.ts
packages/sdk/test/integration/counter_test.ts
packages/sdk/src/document/crdt/primitive.ts
packages/sdk/src/document/crdt/counter.ts
packages/sdk/src/document/operation/increase_operation.ts
packages/sdk/src/document/json/counter.ts
Action Items:
- Remove or Replace
Long
Imports: Ensure that allLong
imports are either removed or replaced withbigint
in the listed files.- Update Type Usages: Replace all instances of
Long
types withbigint
to maintain consistency.- Review Test Cases: Update test cases to reflect the changes from
Long
tobigint
.This complete migration is necessary to prevent type mismatches and enhance code maintainability.
🔗 Analysis chain
Line range hint
1-108
: Overall assessment: Consistent migration from Long to bigintThe changes in this file successfully migrate the
Checkpoint
class from usingLong
tobigint
. This includes updates to:
- Property types
- Constructor and method signatures
- Comparison logic
- Equality checks
- Constant initialization
These changes align with the PR objectives and improve the code by using native JavaScript
bigint
type. This should lead to better performance and easier maintenance.To ensure the changes are applied consistently across the codebase, it's important to verify that all usages of this class have been updated accordingly.
To verify the consistent usage of
bigint
instead ofLong
forCheckpoint
:🏁 Scripts executed
The following scripts were executed for the analysis:
Script:
#!/bin/bash # Description: Check for any remaining usage of Long type with Checkpoint # Test 1: Search for Long type usage with Checkpoint echo "Searching for Long type usage with Checkpoint:" rg -i 'checkpoint.*long' --type ts # Test 2: Verify bigint usage with Checkpoint echo "Verifying bigint usage with Checkpoint:" rg -i 'checkpoint.*bigint' --type ts # Test 3: Check for any remaining Long imports echo "Checking for any remaining Long imports:" rg -i "import.*long.*from" --type tsLength of output: 985
Script:
#!/bin/bash # Description: Comprehensive search for bigint usage with Checkpoint # Test 1: Search for bigint type usage in Checkpoint class echo "Searching for 'bigint' type usage within the Checkpoint class:" rg -i 'Checkpoint.*bigint' --type ts # Test 2: Search for bigint literals or operations related to Checkpoint echo "Searching for bigint literals or operations within the Checkpoint class:" rg -i 'Checkpoint.*\b0n\b' --type ts # Test 3: Verify all method parameters and returns use bigint where appropriate echo "Verifying method signatures in Checkpoint use bigint:" rg -i 'Checkpoint.*\(.*bigint.*\)' --type tsLength of output: 640
Script:
#!/bin/bash # Description: Enhanced search for bigint usage within the Checkpoint class and related contexts # Test 1: Search for 'bigint' declarations within checkpoint.ts echo "Searching for 'bigint' declarations in checkpoint.ts:" rg -i 'bigint' packages/sdk/src/document/change/checkpoint.ts # Test 2: Search for 'bigint' in constructor parameters within Checkpoint class echo "Searching for 'bigint' in Checkpoint constructor parameters:" rg -i 'constructor\(.*bigint.*\)' packages/sdk/src/document/change/checkpoint.ts # Test 3: Search for 'bigint' in method return types within Checkpoint class echo "Searching for 'bigint' return types in Checkpoint methods:" rg -i 'public .*(): bigint' packages/sdk/src/document/change/checkpoint.ts # Test 4: Ensure no 'Long' types remain in checkpoint.ts echo "Ensuring no 'Long' types are present in checkpoint.ts:" rg -i 'Long' packages/sdk/src/document/change/checkpoint.tsLength of output: 1146
Script:
#!/bin/bash # Description: Search for any remaining 'Long' imports and usages across the codebase # Test 1: Search for 'Long' imports in all TypeScript files echo "Searching for 'Long' imports across the codebase:" rg -i "import.*Long.*from" --type ts # Test 2: Search for any usage of 'Long' type outside of imports echo "Searching for 'Long' type usages outside of imports:" rg -i '\bLong\b' --type ts # Test 3: Verify if 'bigint' is used consistently in places where 'Long' was previously used echo "Verifying 'bigint' usage in place of 'Long':" rg -i '\bbigint\b' --type tsLength of output: 9097
packages/sdk/src/api/yorkie/v1/resources.proto (1)
Line range hint
1-380
: Summary of changes and suggestions for next stepsThe changes in this file align well with the PR objectives:
- Removal of
jstype = JS_STRING
options improves type consistency and supports the transition from Long to bigint.- Addition of the
ArraySet
operation expands the SDK's functionality.Suggestions for next steps:
- Provide documentation or comments explaining the use case and behavior of the new
ArraySet
operation.- Ensure that corresponding changes have been made in the TypeScript implementation to handle the new bigint types correctly.
- Update any relevant tests to cover the new
ArraySet
operation and the changed field types.- Consider updating the SDK's documentation to reflect these protocol changes, especially regarding the new operation type and the change from Long to bigint.
packages/sdk/src/document/document.ts (1)
1384-1385
: LGTM! Consider updating the method documentation.The change from
Long
tobigint
for theserverSeq
parameter is correct and aligns with the PR objectives. This improves type safety by using a native JavaScript type.Consider updating the method's JSDoc comment to reflect the new
bigint
type forserverSeq
.packages/sdk/test/integration/object_test.ts (1)
Line range hint
735-788
: Duplicated test function: 'Should not propagate changes when there is no applied undo operation'It appears that the test function
Should not propagate changes when there is no applied undo operation
is duplicated starting at line 735. There are two identical test cases with the same name and code. This duplication may lead to confusion and unnecessary redundancy.Apply the following diff to remove the duplicated test:
@@ -735,54 +735,0 @@ -it(`Should not propagate changes when there is no applied undo operation`, async function ({ - task, -}) { - interface TestDoc { - shape?: { color: string }; - } - const docKey = toDocKey(`${task.name}-${new Date().getTime()}`); - const doc1 = new Document<TestDoc>(docKey); - const doc2 = new Document<TestDoc>(docKey); - - const client1 = new Client(testRPCAddr); - const client2 = new Client(testRPCAddr); - await client1.activate(); - await client2.activate(); - - await client1.attach(doc1, { syncMode: SyncMode.Manual }); - let doc1ChangeID = doc1.getChangeID(); - let doc1Checkpoint = doc1.getCheckpoint(); - assert.equal(doc1ChangeID.getClientSeq(), 1); - assert.equal(doc1Checkpoint.getClientSeq(), 1); - assert.equal(doc1Checkpoint.getServerSeq(), 1n); - - doc1.update((root) => { - root.shape = { color: 'black' }; - }, 'init doc'); - await client1.sync(); - assert.equal(doc1.toSortedJSON(), '{"shape":{"color":"black"}}'); - doc1ChangeID = doc1.getChangeID(); - doc1Checkpoint = doc1.getCheckpoint(); - assert.equal(doc1ChangeID.getClientSeq(), 2); - assert.equal(doc1Checkpoint.getClientSeq(), 2); - assert.equal(doc1Checkpoint.getServerSeq(), 2n); - - await client2.attach(doc2, { syncMode: SyncMode.Manual }); - assert.equal(doc2.toSortedJSON(), '{"shape":{"color":"black"}}'); - - doc2.update((root) => { - delete root.shape; - }, 'delete shape'); - await client2.sync(); - await client1.sync(); - assert.equal(doc1.toSortedJSON(), '{}'); - assert.equal(doc2.toSortedJSON(), '{}'); - doc1ChangeID = doc1.getChangeID(); - doc1Checkpoint = doc1.getCheckpoint(); - assert.equal(doc1ChangeID.getClientSeq(), 2); - assert.equal(doc1Checkpoint.getClientSeq(), 2); - assert.equal(doc1Checkpoint.getServerSeq(), 4n); - - // c2 deleted the shape, so the reverse operation cannot be applied - doc1.history.undo(); - assert.equal(doc1.toSortedJSON(), '{}'); - assert.equal(doc1.getRedoStackForTest().length, 0); - assert.equal(doc1.history.canRedo(), false); -});packages/sdk/src/api/yorkie/v1/resources_pb.ts (1)
2578-2589
: Ensure Correct Handling of Actor IDs asUint8Array
The
TimeTicket
class usesUint8Array
foractorId
. While this is acceptable, ensure that the rest of the application correctly handlesUint8Array
for IDs and that there are utility methods for converting to and from string representations if necessary.Consider adding helper functions to serialize and deserialize
actorId
for ease of use.
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
📒 Files selected for processing (13)
- packages/sdk/src/api/converter.ts (6 hunks)
- packages/sdk/src/api/yorkie/v1/resources.proto (5 hunks)
- packages/sdk/src/api/yorkie/v1/resources_pb.ts (1 hunks)
- packages/sdk/src/api/yorkie/v1/yorkie.proto (1 hunks)
- packages/sdk/src/api/yorkie/v1/yorkie_connect.ts (1 hunks)
- packages/sdk/src/api/yorkie/v1/yorkie_pb.ts (1 hunks)
- packages/sdk/src/document/change/change_id.ts (5 hunks)
- packages/sdk/src/document/change/checkpoint.ts (5 hunks)
- packages/sdk/src/document/document.ts (2 hunks)
- packages/sdk/src/document/time/ticket.ts (6 hunks)
- packages/sdk/test/integration/client_test.ts (3 hunks)
- packages/sdk/test/integration/object_test.ts (10 hunks)
- packages/sdk/tsconfig.json (1 hunks)
✅ Files skipped from review due to trivial changes (1)
- packages/sdk/src/api/yorkie/v1/yorkie.proto
🧰 Additional context used
🔇 Additional comments (48)
packages/sdk/tsconfig.json (3)
3-3
: LGTM: Target update aligns with PR objectives.Updating the
target
to "ES2020" is in line with the PR's goal of updating the target JavaScript version. This change enables the use of ES2020 features, including BigInt, which supports the transition from Long to bigint types.
6-6
: LGTM: Library update consistent with target change.Updating the
lib
array to include "ES2020" is consistent with the target update and ensures that TypeScript recognizes ES2020 library features during compilation. Retaining "dom" maintains support for DOM types.
3-6
: Verify compatibility with project dependencies and target environments.The updates to both
target
andlib
are appropriate for the PR objectives and should enable the use of ES2020 features, including BigInt. However, it's important to ensure these changes are compatible with the project's dependencies and target environments.Please run the following script to check for any potential compatibility issues:
Review the output of this script to ensure there are no compatibility concerns with the move to ES2020.
✅ Verification successful
Compatibility Verified with Project Dependencies and Target Environments
The updates to
target
andlib
intsconfig.json
have been verified and no compatibility issues were found with project dependencies or target environments.🏁 Scripts executed
The following scripts were executed for the analysis:
Script:
#!/bin/bash # Description: Check for potential compatibility issues with ES2020 # Test: Check if any dependencies specify ES2019 or lower as their target echo "Checking package.json for dependencies with potential compatibility issues:" jq '.dependencies + .devDependencies' package.json | grep -i "es201[0-9]" # Test: Look for any explicit ES2019 or lower usage in the codebase echo "Checking for explicit ES2019 or lower usage in the codebase:" rg -i "es201[0-9]" --type ts --type js # Test: Check if there are any browser targets specified that might not support ES2020 echo "Checking for browser targets in browserslist config (if exists):" if [ -f ".browserslistrc" ]; then cat .browserslistrc elif [ -f "package.json" ]; then jq '.browserslist' package.json fiLength of output: 639
packages/sdk/src/document/change/checkpoint.ts (5)
23-23
: LGTM: Property type updated to bigintThe change from
Long
tobigint
for theserverSeq
property is consistent with the PR objectives and aligns with similar changes across the codebase.
26-26
: LGTM: Constructor signature updatedThe constructor parameter type change for
serverSeq
fromLong
tobigint
is consistent with the property type change and ensures type safety.
34-34
: LGTM: Static method signature updatedThe static
of
method parameter type change forserverSeq
fromLong
tobigint
is consistent with the constructor and property type changes, maintaining type consistency across the class.
58-59
: LGTM: Comparison logic updated for bigintThe comparison logic in the
forward
method has been correctly updated to use the>
operator, which is appropriate forbigint
values. This change maintains the original logic while adapting to the new data type.
82-82
: LGTM: Method return type updatedThe
getServerSeq
method return type change fromLong
tobigint
is consistent with the property type change, ensuring type consistency throughout the class.packages/sdk/src/document/change/change_id.ts (8)
30-32
: LGTM: Type changes align with PR objectivesThe changes to
serverSeq
andlamport
properties fromLong
tobigint
are consistent with the PR objectives and the changes in other files. This update improves type consistency and leverages native JavaScript features.
37-39
: LGTM: Constructor parameter types updated correctlyThe constructor parameters for
lamport
andserverSeq
have been correctly updated tobigint
, maintaining consistency with the property type changes. This ensures type safety throughout the class.
52-54
: LGTM: Static method parameter types updated correctlyThe static
of
method parameters forlamport
andserverSeq
have been correctly updated tobigint
, maintaining consistency with the constructor parameter changes. This ensures type safety and proper object creation.
63-63
: LGTM: Correct bigint operation in next methodThe
next
method has been updated to use the correctbigint
addition (+ 1n
) instead of the previousLong.add(1)
. This change is consistent with the transition tobigint
and uses the correct literal notation forbigint
values.
71-72
: LGTM: syncLamport method correctly updated for bigintThe
syncLamport
method has been properly updated to work withbigint
:
- The parameter type is now
bigint
.- The comparison uses the correct
>
operator forbigint
values.- The
bigint
addition (+ 1n
) is used correctly.These changes ensure that the Lamport clock synchronization works correctly with the new
bigint
type.Also applies to: 76-76
113-113
: LGTM: getLamport return type updated correctlyThe
getLamport
method's return type has been correctly updated tobigint
, maintaining consistency with thelamport
property type change. This ensures type safety for consumers of this method.
145-145
: LGTM: InitialChangeID correctly initialized with bigintThe
InitialChangeID
constant has been correctly updated to use thebigint
literal0n
instead ofLong.fromInt(0, true)
. This change is consistent with the transition tobigint
and ensures that the initial change ID is properly typed.
Line range hint
1-145
: Overall assessment: Successful transition to bigintThe changes in this file successfully implement the transition from
Long
tobigint
as per the PR objectives. All relevant properties, method parameters, and return types have been updated consistently. The use ofbigint
literals (e.g.,0n
,1n
) is correct throughout the file.These changes offer several benefits:
- Improved type consistency by using native JavaScript
bigint
type.- Simplified code by removing the dependency on the
long
library.- Potentially improved performance by using native
bigint
operations.The modifications maintain the existing functionality while enhancing the code's clarity and efficiency. Great job on implementing these changes consistently throughout the file!
packages/sdk/src/api/yorkie/v1/resources.proto (4)
60-61
: LGTM: Improved type consistency forChangeID
fieldsThe removal of
jstype = JS_STRING
fromserver_seq
andlamport
fields in theChangeID
message aligns with the PR objective of replacing Long with bigint. This change improves type consistency and potentially enhances performance by using native numeric types in JavaScript.
139-144
: LGTM: NewArraySet
operation addedThe addition of the
ArraySet
message to theOperation
message expands the SDK's functionality, likely allowing for direct manipulation of array elements. The structure is consistent with other operation types.Could you provide some context on the specific use cases for this new operation type and how it differs from existing array manipulation operations?
157-157
: LGTM:ArraySet
added toOperation
typesThe
ArraySet
operation has been correctly added to thebody
oneof field of theOperation
message. This addition is consistent with the introduction of the new operation type and follows the correct numbering sequence.
335-335
: LGTM: Consistent type updates inCheckpoint
andTimeTicket
The removal of
jstype = JS_STRING
from theserver_seq
field inCheckpoint
and thelamport
field inTimeTicket
is consistent with earlier changes and aligns with the PR objective of replacing Long with bigint. This improves type consistency across the protocol.To ensure these changes are reflected correctly in the SDK implementation:
Also applies to: 346-346
packages/sdk/src/api/converter.ts (6)
151-153
: LGTM: SimplifiedtoCheckpoint
functionThe change to directly use
serverSeq
without conversion aligns with the PR objective of replacing Long with bigint. This simplification potentially improves performance by avoiding unnecessary conversions.
162-164
: LGTM: SimplifiedtoChangeID
functionThe direct use of
lamport
without conversion is consistent with the PR objective and the previous changes. This modification maintains consistency across the codebase and potentially improves performance.
176-178
: LGTM: SimplifiedtoTimeTicket
functionThe modification to directly use
lamport
without conversion is in line with the PR objective and the previous changes. This consistent approach simplifies the code and potentially improves performance across the codebase.
809-811
: LGTM: Completed transition from Long to bigintThe modification in
fromChangeID
to directly uselamport
andserverSeq
without conversion completes the transition from Long to bigint. This change, along with the previous modifications, successfully implements the PR objective across both directions of conversion (to and from Protobuf format).These changes collectively:
- Simplify the code by removing unnecessary conversions
- Potentially improve performance by using native bigint types
- Maintain consistency across the codebase
Great job on implementing this transition smoothly and consistently!
1311-1311
: LGTM: SimplifiedfromCheckpoint
functionThe modification in
fromCheckpoint
to directly useserverSeq
without conversion is consistent with the previous changes and completes the transition from Long to bigint for Checkpoint conversion. This change maintains the consistency of the approach throughout the file.
Line range hint
1-1585
: Overall assessment: Successful implementation of ES2020 target and Long to bigint transitionThis PR successfully achieves its objective of updating the target to ES2020 and replacing Long with bigint in the
converter.ts
file. The changes are consistent across all affected functions (toCheckpoint
,toChangeID
,toTimeTicket
,fromChangeID
, andfromCheckpoint
).Key improvements:
- Simplified code by removing unnecessary conversions
- Potential performance improvements by using native bigint types
- Consistent implementation across both directions of conversion (to and from Protobuf format)
- Maintained code clarity and readability
The changes align well with modern JavaScript practices and should result in more efficient and maintainable code. Great job on this update!
packages/sdk/src/document/document.ts (1)
1656-1657
: LGTM! Correct conversion to bigint.The update to use
BigInt(serverSeq)
is correct and consistent with the changes made to theapplySnapshot
method signature. This ensures that theserverSeq
is properly converted from a string to abigint
before being passed to the method.packages/sdk/src/api/yorkie/v1/yorkie_connect.ts (1)
1-106
: LGTM!The
YorkieService
and its methods are correctly defined according to the Protobuf service specifications. The generated code aligns with the project's architecture and coding standards.packages/sdk/src/document/time/ticket.ts (7)
48-48
: Ensurebigint
compatibility across target environmentsThe use of
bigint
requires environments that support ES2020 or newer. Please verify that all target environments where this SDK is used are compatible withbigint
. If not, consider providing a fallback or polyfill.
52-54
: Update constructor to acceptlamport
asbigint
The constructor now accepts
lamport
as abigint
, aligning with the updated property type. Ensure that all instantiations ofTimeTicket
are updated accordingly.
62-65
: Updateof
method to acceptlamport
asbigint
The static
of
method now acceptslamport
as abigint
. Ensure that any calls to this method pass abigint
value forlamport
.
125-127
: UpdategetLamport
method to returnbigint
The
getLamport
method now returns abigint
, consistent with the updatedlamport
type.
163-167
: Modify comparison logic to usebigint
operatorsIn the
compare
method, the comparison oflamport
values now uses standard comparison operators (>
,<
) suitable forbigint
types.
186-186
: DefineMaxLamport
as abigint
literal
MaxLamport
is now defined using thebigint
literal9223372036854775807n
, representing the maximumInt64
value.
189-191
: InitializeInitialTimeTicket
withbigint
literalIn
InitialTimeTicket
, thelamport
is now initialized with0n
, abigint
literal.packages/sdk/src/api/yorkie/v1/yorkie_pb.ts (1)
23-23
: Ensure correct import paths and exportsVerify that
ChangePack
andDocEvent
are correctly imported from"./resources_pb.js"
. Incorrect import paths or missing exports can lead to runtime errors.Run the following script to confirm that
ChangePack
andDocEvent
are exported fromresources_pb.js
:packages/sdk/test/integration/object_test.ts (10)
659-659
: Appropriate use of BigInt literal in assertionThe assertion at line 659 correctly compares
doc1Checkpoint.getServerSeq()
with1n
. SincegetServerSeq()
returns abigint
, using the1n
BigInt literal ensures accurate comparison.
670-670
: Consistent use of BigInt literals in assertionsAt line 670, comparing
doc1Checkpoint.getServerSeq()
with2n
maintains consistency withbigint
types across assertions.
686-686
: Consistent use of BigInt literals in assertionsThe assertion at line 686 appropriately uses
4n
for comparingbigint
values.
701-701
: Consistent use of BigInt literals in assertionsAt line 701, the comparison with
4n
continues the correct usage ofbigint
literals in assertions.
712-712
: Consistent use of BigInt literals in assertionsLine 712 correctly compares
doc1Checkpoint.getServerSeq()
with5n
, ensuring accuratebigint
comparisons.
735-735
: Consistent use of BigInt literals in assertionsAt line 735, the assertion uses
1n
, which is appropriate forbigint
comparisons.
746-746
: Consistent use of BigInt literals in assertionsLine 746 correctly compares with
2n
, maintaining consistency.
762-762
: Consistent use of BigInt literals in assertionsAt line 762, the use of
4n
in the assertion is appropriate.
777-777
: Consistent use of BigInt literals in assertionsLine 777 continues the correct pattern by comparing with
4n
.
788-788
: Consistent use of BigInt literals in assertionsAt line 788, comparing with
5n
is appropriate forbigint
types.packages/sdk/src/api/yorkie/v1/resources_pb.ts (2)
2667-2710
: Incomplete Implementation ofDocEvent
HandlingThe
DocEvent
class defines events likeDOCUMENT_CHANGED
,DOCUMENT_WATCHED
, etc., but there is no implementation detail or methods associated with handling these events. Ensure that event handling logic is implemented elsewhere and that this class integrates properly with it.Please confirm that the event handling for
DocEvent
is properly implemented in other parts of the codebase.You can run the following script to search for usages of
DocEvent
:#!/bin/bash # Description: Search for implementations or usages of DocEvent. # Find all references to DocEvent in the codebase rg 'DocEvent' packages/sdk/src/
1159-1195
: Clarify the Use ofUint8Array
for ValuesIn the
JSONElementSimple
class, thevalue
field is aUint8Array
, which may not be suitable for representing all value types, especially when usingbigint
. This could lead to serialization/deserialization issues.Please confirm that using
Uint8Array
is appropriate for allValueType
cases, especially with the shift tobigint
. Consider whether a different representation is needed.You can run the following script to check for usages of
Uint8Array
in value fields:
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 1
🧹 Outside diff range and nitpick comments (6)
packages/sdk/test/integration/object_test.ts (1)
Line range hint
659-789
: Overall assessment: Successful transition to BigInt with a minor issueThe changes in this file successfully implement the transition from Long to bigint, which aligns with the PR objective and the move to ES2020. The use of BigInt literals (e.g.,
1n
,2n
,4n
,5n
) is consistent throughout the file and correctly implements the required changes.However, there is a duplicate test case starting from line 735 that should be addressed to maintain a clean and efficient test suite.
Action items:
- Remove the duplicate test case (either the one starting at line 659 or the one at line 735).
- After removing the duplicate, please verify that all unique test scenarios are still covered.
packages/sdk/src/api/converter.ts (5)
809-809
: LGTM with suggestion: BigInt conversion forlamport
The conversion of
lamport
to BigInt aligns with the PR objective. However, consider adding a safety check to ensure the input is valid for BigInt conversion.BigInt(Number.isSafeInteger(pbChangeID.lamport) ? pbChangeID.lamport : 0)This prevents potential runtime errors if the input is not a valid integer.
811-811
: LGTM with suggestion: BigInt conversion forserverSeq
The conversion of
serverSeq
to BigInt aligns with the PR objective. However, consider adding a safety check to ensure the input is valid for BigInt conversion, similar to thelamport
conversion:BigInt(Number.isSafeInteger(pbChangeID.serverSeq) ? pbChangeID.serverSeq : 0)This prevents potential runtime errors if the input is not a valid integer.
824-824
: LGTM with suggestion: BigInt conversion forlamport
infromTimeTicket
The conversion of
lamport
to BigInt in thefromTimeTicket
function aligns with the PR objective. However, consider adding a safety check to ensure the input is valid for BigInt conversion:BigInt(Number.isSafeInteger(pbTimeTicket.lamport) ? pbTimeTicket.lamport : 0)This prevents potential runtime errors if the input is not a valid integer and maintains consistency with other BigInt conversions in this file.
1311-1311
: LGTM with suggestion: BigInt conversion forserverSeq
infromCheckpoint
The conversion of
serverSeq
to BigInt in thefromCheckpoint
function aligns with the PR objective. However, consider adding a safety check to ensure the input is valid for BigInt conversion:BigInt(Number.isSafeInteger(pbCheckpoint.serverSeq) ? pbCheckpoint.serverSeq : 0)This prevents potential runtime errors if the input is not a valid integer and maintains consistency with other BigInt conversions in this file.
Line range hint
1-1511
: Overall assessment: Consistent BigInt implementation with room for improvementThe changes in this file consistently implement the replacement of Long with BigInt, aligning well with the PR objectives. The code is simplified and more consistent. However, there's a recurring need for input validation in BigInt conversions.
Consider implementing a utility function for safe BigInt conversion:
function safeBigInt(value: number | string): bigint { return BigInt(Number.isSafeInteger(Number(value)) ? value : 0); }Then use this function throughout the file for all BigInt conversions. This would improve code safety and maintainability.
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
📒 Files selected for processing (13)
- packages/sdk/src/api/converter.ts (6 hunks)
- packages/sdk/src/api/yorkie/v1/resources.proto (5 hunks)
- packages/sdk/src/api/yorkie/v1/resources_pb.ts (1 hunks)
- packages/sdk/src/api/yorkie/v1/yorkie.proto (1 hunks)
- packages/sdk/src/api/yorkie/v1/yorkie_connect.ts (1 hunks)
- packages/sdk/src/api/yorkie/v1/yorkie_pb.ts (1 hunks)
- packages/sdk/src/document/change/change_id.ts (5 hunks)
- packages/sdk/src/document/change/checkpoint.ts (5 hunks)
- packages/sdk/src/document/document.ts (2 hunks)
- packages/sdk/src/document/time/ticket.ts (6 hunks)
- packages/sdk/test/integration/client_test.ts (3 hunks)
- packages/sdk/test/integration/object_test.ts (10 hunks)
- packages/sdk/tsconfig.json (1 hunks)
✅ Files skipped from review due to trivial changes (1)
- packages/sdk/src/api/yorkie/v1/yorkie_pb.ts
🚧 Files skipped from review as they are similar to previous changes (9)
- packages/sdk/src/api/yorkie/v1/resources.proto
- packages/sdk/src/api/yorkie/v1/resources_pb.ts
- packages/sdk/src/api/yorkie/v1/yorkie.proto
- packages/sdk/src/api/yorkie/v1/yorkie_connect.ts
- packages/sdk/src/document/change/change_id.ts
- packages/sdk/src/document/change/checkpoint.ts
- packages/sdk/src/document/document.ts
- packages/sdk/src/document/time/ticket.ts
- packages/sdk/tsconfig.json
🧰 Additional context used
🔇 Additional comments (12)
packages/sdk/test/integration/object_test.ts (5)
659-660
: LGTM: Correct use of BigInt literalThe change from Long to bigint is correctly implemented here, using the BigInt literal
1n
. This aligns with the PR objective and the move to ES2020.
670-671
: LGTM: Consistent use of BigInt literalThe change to use the BigInt literal
2n
is consistent with the previous change and correctly implements the transition from Long to bigint.
686-687
: LGTM: Consistent BigInt usageThe use of BigInt literal
4n
for asserting theserverSeq
is consistent with the previous changes and correctly implements the transition to bigint.
701-702
: LGTM: Consistent BigInt usage in assertionsThe assertion using BigInt literal
4n
forserverSeq
is consistent with the previous changes and correctly implements the transition to bigint.
712-713
: LGTM: Consistent BigInt usage maintainedThe assertion using BigInt literal
5n
forserverSeq
maintains consistency with the previous changes and correctly implements the transition to bigint.packages/sdk/test/integration/client_test.ts (4)
530-530
: Useassert.strictEqual
for BigInt comparisonsThis comment is identical to the previous one and applies here as well.
547-547
: Useassert.strictEqual
for BigInt comparisonsThis comment is identical to the first one and applies to both of these lines as well.
Also applies to: 564-564
Line range hint
525-564
: Overall, the changes look good and align with the PR objectivesThe updates to use BigInt literals in the test assertions are consistent with the goal of replacing Long with BigInt. The tests cover various scenarios and seem to be comprehensive. The only suggestion is to use
assert.strictEqual
for more precise BigInt comparisons, as mentioned in the previous comments.
525-525
: 🛠️ Refactor suggestionUse
assert.strictEqual
for BigInt comparisonsFor more precise BigInt comparisons, consider using
assert.strictEqual
instead ofassert.equal
. This ensures both type and value equality.- assert.equal(checkpoint.getServerSeq(), 1n); + assert.strictEqual(checkpoint.getServerSeq(), 1n);packages/sdk/src/api/converter.ts (3)
151-151
: LGTM: SimplifiedserverSeq
assignmentThe direct assignment of
serverSeq
fromcheckpoint.getServerSeq()
aligns with the PR objective of replacing Long with bigint. This change simplifies the code by removing unnecessary type conversion.
162-162
: LGTM: Simplifiedlamport
assignmentThe direct assignment of
lamport
fromchangeID.getLamport()
is consistent with the PR objective of replacing Long with bigint. This change simplifies the code by removing unnecessary type conversion.
176-176
: LGTM: Simplifiedlamport
assignment intoTimeTicket
The direct assignment of
lamport
fromticket.getLamport()
in thetoTimeTicket
function is consistent with the PR objective of replacing Long with bigint. This change simplifies the code by removing unnecessary type conversion.
e1f94f1
to
a8c8a0a
Compare
This commit Streamlines data type handling by replacing Long with native. It also updates target to ECMAScript 2020. Despite the introduction of bigint, but Long still remains in Counter. We need to remove Long.
What this PR does / why we need it?
Update target to ES2020 and replace Long with bigint
Any background context you want to provide?
What are the relevant tickets?
Fixes yorkie-team/yorkie#1023
Checklist
Summary by CodeRabbit
Release Notes
New Features
ArraySet
in the protocol.Improvements
Long
with nativebigint
in various classes.Bug Fixes
Tests
Document
class to validate nested updates, undo/redo functionality, and concurrent operations.