Skip to content
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

Merged
merged 1 commit into from
Oct 21, 2024
Merged

Conversation

hackerwins
Copy link
Member

@hackerwins hackerwins commented Oct 21, 2024

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

  • Added relevant tests or not required
  • Didn't break anything

Summary by CodeRabbit

Release Notes

  • New Features

    • Added support for a new operation type ArraySet in the protocol.
  • Improvements

    • Streamlined data type handling by replacing Long with native bigint in various classes.
    • Enhanced error handling in integration tests for better robustness.
    • Updated TypeScript configurations to support ECMAScript 2020 features.
  • Bug Fixes

    • Corrected minor documentation issues in the Yorkie service.
  • Tests

    • Expanded integration tests to cover more scenarios, including error management and synchronization modes.
    • Enhanced tests for the Document class to validate nested updates, undo/redo functionality, and concurrent operations.

Copy link

coderabbitai bot commented Oct 21, 2024

Walkthrough

The pull request introduces significant modifications across various files in the SDK, primarily focusing on the conversion functions in converter.ts, Protobuf definitions in resources.proto, and TypeScript classes generated from Protobuf definitions. Key changes include the removal of unnecessary conversions to Long types in favor of native bigint types, updates to error handling, and the introduction of new message types and service methods. The changes enhance the clarity and efficiency of the code while maintaining existing functionality.

Changes

File Path Change Summary
packages/sdk/src/api/converter.ts Modified conversion functions to use bigint instead of Long. Updated error handling in toPresenceChange and fromPresenceChange.
packages/sdk/src/api/yorkie/v1/resources.proto Removed jstype = JS_STRING option from fields in ChangeID, Checkpoint, and TimeTicket. Added new message type ArraySet to Operation.
packages/sdk/src/api/yorkie/v1/resources_pb.ts Generated TypeScript definitions from Protobuf, including enumerations and message classes for the Yorkie API.
packages/sdk/src/api/yorkie/v1/yorkie.proto Corrected documentation comment from "provides a API" to "provides an API".
packages/sdk/src/api/yorkie/v1/yorkie_connect.ts Introduced YorkieService with methods for client activation and document management.
packages/sdk/src/api/yorkie/v1/yorkie_pb.ts Generated TypeScript definitions for requests and responses related to client activation and document management.
packages/sdk/src/document/change/change_id.ts Changed ChangeID class properties from Long to bigint. Updated constructor and methods accordingly.
packages/sdk/src/document/change/checkpoint.ts Updated Checkpoint class to use bigint instead of Long for serverSeq.
packages/sdk/src/document/document.ts Modified applySnapshot method to use bigint for serverSeq.
packages/sdk/src/document/time/ticket.ts Changed TimeTicket class properties from Long to bigint. Updated constructor and methods accordingly.
packages/sdk/test/integration/client_test.ts Updated tests to use bigint for server sequence comparisons and improved error handling.
packages/sdk/test/integration/object_test.ts Enhanced tests for Document class to cover various operations, error handling, and concurrent modifications.
packages/sdk/tsconfig.json Updated TypeScript configuration to target ES2020.
packages/sdk/buf.gen.yaml Updated import options for es and connect-es plugins to remove js_import_style=module.
packages/sdk/src/api/yorkie/v1/resources_pb.d.ts Deleted TypeScript definitions for Protobuf messages and enums related to the Yorkie API.
packages/sdk/src/api/yorkie/v1/yorkie_connect.d.ts Deleted TypeScript declarations for YorkieService and its associated RPC methods.
packages/sdk/src/api/yorkie/v1/yorkie_pb.d.ts Deleted TypeScript definitions for various requests and responses related to client activation and document management.
packages/sdk/src/api/yorkie/v1/yorkie_pb.js Deleted JavaScript definitions of message types used in the Yorkie API.
packages/sdk/src/api/yorkie/v1/resources_pb.js Deleted JavaScript definitions for Protobuf messages and enums related to the Yorkie API.

Assessment against linked issues

Objective Addressed Explanation
Remove jstype=string from .proto and replace Long with Bigint (1023)
Ensure conversion functions utilize bigint instead of Long (1023)

Possibly related PRs

  • Restrict presence object type to JSON serializable values #898: This PR enhances type safety by introducing a Json type that restricts values to JSON serializable types, aligning with the main PR's updates to conversion functions that handle ChangeID, Checkpoint, and TimeTicket types, ensuring they are compatible with JSON serialization.
  • Update CHANGELOG.md for v0.5.1 #910: This PR mentions that the presence object type has been restricted to only allow JSON serializable values, which directly connects to the changes made in the main PR regarding the handling of types in conversion functions.

🐰 In the code, we hop and play,
With bigint here to save the day!
No more Long, just simple and bright,
Our conversions now feel just right!
From converter to tests, we cheer,
A cleaner codebase, oh so dear! 🐇


📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between a8c8a0a and 688cd0e.

📒 Files selected for processing (19)
  • packages/sdk/buf.gen.yaml (1 hunks)
  • 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.d.ts (0 hunks)
  • packages/sdk/src/api/yorkie/v1/resources_pb.js (0 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.d.ts (0 hunks)
  • packages/sdk/src/api/yorkie/v1/yorkie_connect.ts (2 hunks)
  • packages/sdk/src/api/yorkie/v1/yorkie_pb.d.ts (0 hunks)
  • packages/sdk/src/api/yorkie/v1/yorkie_pb.js (0 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 with no reviewable changes (5)
  • packages/sdk/src/api/yorkie/v1/resources_pb.d.ts
  • packages/sdk/src/api/yorkie/v1/resources_pb.js
  • packages/sdk/src/api/yorkie/v1/yorkie_connect.d.ts
  • packages/sdk/src/api/yorkie/v1/yorkie_pb.d.ts
  • packages/sdk/src/api/yorkie/v1/yorkie_pb.js
✅ Files skipped from review due to trivial changes (1)
  • packages/sdk/src/api/yorkie/v1/resources_pb.ts
🚧 Files skipped from review as they are similar to previous changes (11)
  • packages/sdk/buf.gen.yaml
  • packages/sdk/src/api/yorkie/v1/resources.proto
  • packages/sdk/src/api/yorkie/v1/yorkie.proto
  • packages/sdk/src/api/yorkie/v1/yorkie_connect.ts
  • packages/sdk/src/api/yorkie/v1/yorkie_pb.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/test/integration/object_test.ts
  • packages/sdk/tsconfig.json
🧰 Additional context used
🔇 Additional comments (9)
packages/sdk/test/integration/client_test.ts (4)

525-525: Correct use of BigInt for server sequence numbers

The change from regular integers to BigInt (e.g., 1n, 2n) aligns with the PR objective of replacing Long with bigint. This is the correct approach for handling large integer values.

As mentioned in a previous review comment, consider using assert.strictEqual instead of assert.equal for BigInt comparisons to ensure both type and value equality.

Also applies to: 530-530


547-547: Consistent use of BigInt for server sequence number

The change to use BigInt (2n) is consistent with the previous changes and aligns with the PR objective.

As mentioned earlier, consider using assert.strictEqual instead of assert.equal for BigInt comparisons.


564-564: Consistent use of BigInt for server sequence number

The change to use BigInt (4n) is consistent with the previous changes and aligns with the PR objective.

As mentioned in previous comments, consider using assert.strictEqual instead of assert.equal for BigInt comparisons.


Line range hint 525-564: Overall assessment of BigInt changes

The changes in this file consistently replace regular integers with BigInt for server sequence numbers. This aligns well with the PR objective of updating the target to ES2020 and replacing Long with bigint. These modifications enhance the tests' ability to handle large integer values, which is crucial for ensuring the SDK's correct behavior with potentially large server sequence numbers.

To further improve the tests:

  1. Consider applying the assert.strictEqual change suggested in the previous comments throughout the file for consistency and type safety.
  2. It might be beneficial to add a test case that specifically checks the handling of very large sequence numbers (e.g., beyond 2^53 - 1) to verify the full advantage of using BigInt.
packages/sdk/src/api/converter.ts (5)

151-151: LGTM: Simplified serverSeq assignment

The direct assignment of serverSeq without conversion aligns with the PR objective of updating to ES2020 and using native bigint. This change simplifies the code and improves readability.


162-162: LGTM: Direct lamport assignment in toChangeID

The direct assignment of the lamport value without conversion is consistent with the PR's goal of updating to ES2020 and using native bigint. This change simplifies the code and improves its readability.


176-176: LGTM: Simplified lamport assignment in toTimeTicket

The direct assignment of the lamport value without conversion in the toTimeTicket function is in line with the PR's objective of updating to ES2020 and using native bigint. This change enhances code simplicity and readability.


1313-1313: ⚠️ Potential issue

Verify necessity of BigInt conversion in fromCheckpoint

The serverSeq is being converted to BigInt here, which seems inconsistent with the direct assignments in functions like toCheckpoint. This might be necessary due to how Protobuf serializes these values, but it's worth verifying.

Consider checking if this conversion can be removed to maintain consistency with other changes in this PR.

To verify the necessity of this conversion, let's check how PbCheckpoint is defined:


807-813: ⚠️ Potential issue

Address TODO and ensure consistency in bigint handling

There's a TODO comment about removing BigInt conversion, yet the conversion is still present for lamport and serverSeq. This seems inconsistent with the direct assignments in other functions (e.g., toChangeID, toTimeTicket).

Consider addressing this TODO by removing the BigInt conversion if possible, or clarify why it's still necessary here but not in other functions.

To verify the necessity of this conversion, let's check how PbChangeID is defined:


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?

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

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)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

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: 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 InitialCheckpoint

In the equals method:

  • Consider using === instead of == for comparing bigint values. While == works, === is preferred for strict equality checks in TypeScript/JavaScript.

The InitialCheckpoint constant initialization with 0n is correct for a bigint literal.

Suggested change for line 92:

- this.clientSeq === other.clientSeq && this.serverSeq == other.serverSeq
+ this.clientSeq === other.clientSeq && this.serverSeq === other.serverSeq

Also applies to: 108-108


Migration Incomplete: Remaining Long Usages Found

The Checkpoint class has been successfully migrated from Long to bigint. However, the following files still import and use Long:

  • 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 all Long imports are either removed or replaced with bigint in the listed files.
  • Update Type Usages: Replace all instances of Long types with bigint to maintain consistency.
  • Review Test Cases: Update test cases to reflect the changes from Long to bigint.

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 bigint

The changes in this file successfully migrate the Checkpoint class from using Long to bigint. This includes updates to:

  1. Property types
  2. Constructor and method signatures
  3. Comparison logic
  4. Equality checks
  5. 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 of Long for Checkpoint:

🏁 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 ts

Length 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 ts

Length 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.ts

Length 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 ts

Length of output: 9097

packages/sdk/src/api/yorkie/v1/resources.proto (1)

Line range hint 1-380: Summary of changes and suggestions for next steps

The changes in this file align well with the PR objectives:

  1. Removal of jstype = JS_STRING options improves type consistency and supports the transition from Long to bigint.
  2. Addition of the ArraySet operation expands the SDK's functionality.

Suggestions for next steps:

  1. Provide documentation or comments explaining the use case and behavior of the new ArraySet operation.
  2. Ensure that corresponding changes have been made in the TypeScript implementation to handle the new bigint types correctly.
  3. Update any relevant tests to cover the new ArraySet operation and the changed field types.
  4. 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 to bigint for the serverSeq 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 for serverSeq.

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 as Uint8Array

The TimeTicket class uses Uint8Array for actorId. While this is acceptable, ensure that the rest of the application correctly handles Uint8Array 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

📥 Commits

Files that changed from the base of the PR and between b7c769c and c43641b.

📒 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 and lib 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 and lib in tsconfig.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
fi

Length of output: 639

packages/sdk/src/document/change/checkpoint.ts (5)

23-23: LGTM: Property type updated to bigint

The change from Long to bigint for the serverSeq property is consistent with the PR objectives and aligns with similar changes across the codebase.


26-26: LGTM: Constructor signature updated

The constructor parameter type change for serverSeq from Long to bigint is consistent with the property type change and ensures type safety.


34-34: LGTM: Static method signature updated

The static of method parameter type change for serverSeq from Long to bigint is consistent with the constructor and property type changes, maintaining type consistency across the class.


58-59: LGTM: Comparison logic updated for bigint

The comparison logic in the forward method has been correctly updated to use the > operator, which is appropriate for bigint values. This change maintains the original logic while adapting to the new data type.


82-82: LGTM: Method return type updated

The getServerSeq method return type change from Long to bigint 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 objectives

The changes to serverSeq and lamport properties from Long to bigint 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 correctly

The constructor parameters for lamport and serverSeq have been correctly updated to bigint, maintaining consistency with the property type changes. This ensures type safety throughout the class.


52-54: LGTM: Static method parameter types updated correctly

The static of method parameters for lamport and serverSeq have been correctly updated to bigint, maintaining consistency with the constructor parameter changes. This ensures type safety and proper object creation.


63-63: LGTM: Correct bigint operation in next method

The next method has been updated to use the correct bigint addition (+ 1n) instead of the previous Long.add(1). This change is consistent with the transition to bigint and uses the correct literal notation for bigint values.


71-72: LGTM: syncLamport method correctly updated for bigint

The syncLamport method has been properly updated to work with bigint:

  1. The parameter type is now bigint.
  2. The comparison uses the correct > operator for bigint values.
  3. 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 correctly

The getLamport method's return type has been correctly updated to bigint, maintaining consistency with the lamport property type change. This ensures type safety for consumers of this method.


145-145: LGTM: InitialChangeID correctly initialized with bigint

The InitialChangeID constant has been correctly updated to use the bigint literal 0n instead of Long.fromInt(0, true). This change is consistent with the transition to bigint and ensures that the initial change ID is properly typed.


Line range hint 1-145: Overall assessment: Successful transition to bigint

The changes in this file successfully implement the transition from Long to bigint as per the PR objectives. All relevant properties, method parameters, and return types have been updated consistently. The use of bigint literals (e.g., 0n, 1n) is correct throughout the file.

These changes offer several benefits:

  1. Improved type consistency by using native JavaScript bigint type.
  2. Simplified code by removing the dependency on the long library.
  3. 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 for ChangeID fields

The removal of jstype = JS_STRING from server_seq and lamport fields in the ChangeID 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: New ArraySet operation added

The addition of the ArraySet message to the Operation 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 to Operation types

The ArraySet operation has been correctly added to the body oneof field of the Operation 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 in Checkpoint and TimeTicket

The removal of jstype = JS_STRING from the server_seq field in Checkpoint and the lamport field in TimeTicket 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: Simplified toCheckpoint function

The 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: Simplified toChangeID function

The 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: Simplified toTimeTicket function

The 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 bigint

The modification in fromChangeID to directly use lamport and serverSeq 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:

  1. Simplify the code by removing unnecessary conversions
  2. Potentially improve performance by using native bigint types
  3. Maintain consistency across the codebase

Great job on implementing this transition smoothly and consistently!


1311-1311: LGTM: Simplified fromCheckpoint function

The modification in fromCheckpoint to directly use serverSeq 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 transition

This 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, and fromCheckpoint).

Key improvements:

  1. Simplified code by removing unnecessary conversions
  2. Potential performance improvements by using native bigint types
  3. Consistent implementation across both directions of conversion (to and from Protobuf format)
  4. 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 the applySnapshot method signature. This ensures that the serverSeq is properly converted from a string to a bigint 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: Ensure bigint compatibility across target environments

The use of bigint requires environments that support ES2020 or newer. Please verify that all target environments where this SDK is used are compatible with bigint. If not, consider providing a fallback or polyfill.


52-54: Update constructor to accept lamport as bigint

The constructor now accepts lamport as a bigint, aligning with the updated property type. Ensure that all instantiations of TimeTicket are updated accordingly.


62-65: Update of method to accept lamport as bigint

The static of method now accepts lamport as a bigint. Ensure that any calls to this method pass a bigint value for lamport.


125-127: Update getLamport method to return bigint

The getLamport method now returns a bigint, consistent with the updated lamport type.


163-167: Modify comparison logic to use bigint operators

In the compare method, the comparison of lamport values now uses standard comparison operators (>, <) suitable for bigint types.


186-186: Define MaxLamport as a bigint literal

MaxLamport is now defined using the bigint literal 9223372036854775807n, representing the maximum Int64 value.


189-191: Initialize InitialTimeTicket with bigint literal

In InitialTimeTicket, the lamport is now initialized with 0n, a bigint literal.

packages/sdk/src/api/yorkie/v1/yorkie_pb.ts (1)

23-23: Ensure correct import paths and exports

Verify that ChangePack and DocEvent 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 and DocEvent are exported from resources_pb.js:

packages/sdk/test/integration/object_test.ts (10)

659-659: Appropriate use of BigInt literal in assertion

The assertion at line 659 correctly compares doc1Checkpoint.getServerSeq() with 1n. Since getServerSeq() returns a bigint, using the 1n BigInt literal ensures accurate comparison.


670-670: Consistent use of BigInt literals in assertions

At line 670, comparing doc1Checkpoint.getServerSeq() with 2n maintains consistency with bigint types across assertions.


686-686: Consistent use of BigInt literals in assertions

The assertion at line 686 appropriately uses 4n for comparing bigint values.


701-701: Consistent use of BigInt literals in assertions

At line 701, the comparison with 4n continues the correct usage of bigint literals in assertions.


712-712: Consistent use of BigInt literals in assertions

Line 712 correctly compares doc1Checkpoint.getServerSeq() with 5n, ensuring accurate bigint comparisons.


735-735: Consistent use of BigInt literals in assertions

At line 735, the assertion uses 1n, which is appropriate for bigint comparisons.


746-746: Consistent use of BigInt literals in assertions

Line 746 correctly compares with 2n, maintaining consistency.


762-762: Consistent use of BigInt literals in assertions

At line 762, the use of 4n in the assertion is appropriate.


777-777: Consistent use of BigInt literals in assertions

Line 777 continues the correct pattern by comparing with 4n.


788-788: Consistent use of BigInt literals in assertions

At line 788, comparing with 5n is appropriate for bigint types.

packages/sdk/src/api/yorkie/v1/resources_pb.ts (2)

2667-2710: Incomplete Implementation of DocEvent Handling

The DocEvent class defines events like DOCUMENT_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 of Uint8Array for Values

In the JSONElementSimple class, the value field is a Uint8Array, which may not be suitable for representing all value types, especially when using bigint. This could lead to serialization/deserialization issues.

Please confirm that using Uint8Array is appropriate for all ValueType cases, especially with the shift to bigint. Consider whether a different representation is needed.

You can run the following script to check for usages of Uint8Array in value fields:

packages/sdk/src/document/time/ticket.ts Show resolved Hide resolved
packages/sdk/src/api/yorkie/v1/yorkie_pb.ts Show resolved Hide resolved
packages/sdk/test/integration/client_test.ts Show resolved Hide resolved
packages/sdk/src/api/yorkie/v1/resources_pb.ts Outdated Show resolved Hide resolved
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: 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 issue

The 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:

  1. Remove the duplicate test case (either the one starting at line 659 or the one at line 735).
  2. 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 for lamport

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 for serverSeq

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 the lamport 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 for lamport in fromTimeTicket

The conversion of lamport to BigInt in the fromTimeTicket 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 for serverSeq in fromCheckpoint

The conversion of serverSeq to BigInt in the fromCheckpoint 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 improvement

The 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

📥 Commits

Files that changed from the base of the PR and between c43641b and e238015.

📒 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 literal

The 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 literal

The 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 usage

The use of BigInt literal 4n for asserting the serverSeq is consistent with the previous changes and correctly implements the transition to bigint.


701-702: LGTM: Consistent BigInt usage in assertions

The assertion using BigInt literal 4n for serverSeq is consistent with the previous changes and correctly implements the transition to bigint.


712-713: LGTM: Consistent BigInt usage maintained

The assertion using BigInt literal 5n for serverSeq maintains consistency with the previous changes and correctly implements the transition to bigint.

packages/sdk/test/integration/client_test.ts (4)

530-530: Use assert.strictEqual for BigInt comparisons

This comment is identical to the previous one and applies here as well.


547-547: Use assert.strictEqual for BigInt comparisons

This 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 objectives

The 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 suggestion

Use assert.strictEqual for BigInt comparisons

For more precise BigInt comparisons, consider using assert.strictEqual instead of assert.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: Simplified serverSeq assignment

The direct assignment of serverSeq from checkpoint.getServerSeq() aligns with the PR objective of replacing Long with bigint. This change simplifies the code by removing unnecessary type conversion.


162-162: LGTM: Simplified lamport assignment

The direct assignment of lamport from changeID.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: Simplified lamport assignment in toTimeTicket

The direct assignment of lamport from ticket.getLamport() in the toTimeTicket function is consistent with the PR objective of replacing Long with bigint. This change simplifies the code by removing unnecessary type conversion.

packages/sdk/test/integration/object_test.ts Show resolved Hide resolved
@hackerwins hackerwins merged commit cdeeef7 into main Oct 21, 2024
2 checks passed
@hackerwins hackerwins deleted the bigint branch October 21, 2024 05:28
JOOHOJANG pushed a commit that referenced this pull request Oct 22, 2024
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.
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.

Remove jstype=string from .proto and replace Long with Bigintin js-sdk
1 participant